-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrest_server_debug_file_locator.go
66 lines (56 loc) · 1.43 KB
/
rest_server_debug_file_locator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"github.com/RobinUS2/golang-jresp"
"github.com/julienschmidt/httprouter"
"net/http"
"strings"
)
// List shards for file
func GetDebugFileLocatorShards(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
// Response object
jr := jresp.NewJsonResp()
// Auth
if !restServer.auth(r) {
restServer.notAuthorized(w)
return
}
// Get filename
file := strings.TrimSpace(r.URL.Query().Get("filename"))
if len(file) < 1 {
jr.Error("Please provide the 'filename' as query parameter")
fmt.Fprint(w, jr.ToString(restServer.PrettyPrint))
return
}
// Locate
res, scanCount, e := datastore.LocateFile(file)
if e != nil {
jr.Error(fmt.Sprintf("%s", e))
fmt.Fprint(w, jr.ToString(restServer.PrettyPrint))
return
}
// Shard IDs
var shardIds []string = make([]string, 0)
for _, shardIdx := range res {
shardIds = append(shardIds, uuidToString(shardIdx.ShardId))
}
// Response
jr.Set("shards", shardIds)
jr.Set("shards_scanned", scanCount)
jr.OK()
fmt.Fprint(w, jr.ToString(restServer.PrettyPrint))
}
// Map from shard to node locations
func GetDebugFileLocatorShardLocations(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
// Response object
jr := jresp.NewJsonResp()
// Auth
if !restServer.auth(r) {
restServer.notAuthorized(w)
return
}
// Response
jr.Set("shards", datastore.fileLocator.ShardLocations())
jr.OK()
fmt.Fprint(w, jr.ToString(restServer.PrettyPrint))
}