|
@@ -17,22 +17,25 @@ const (
|
|
dbNotAvailable = "database not available"
|
|
dbNotAvailable = "database not available"
|
|
)
|
|
)
|
|
|
|
|
|
-// NetDbPaths2Func TODO
|
|
|
|
-var NetDbPaths2Func = map[string]diagnostic.HTTPHandlerFunc{
|
|
|
|
- "/join": dbJoin,
|
|
|
|
- "/networkpeers": dbPeers,
|
|
|
|
- "/clusterpeers": dbClusterPeers,
|
|
|
|
- "/joinnetwork": dbJoinNetwork,
|
|
|
|
- "/leavenetwork": dbLeaveNetwork,
|
|
|
|
- "/createentry": dbCreateEntry,
|
|
|
|
- "/updateentry": dbUpdateEntry,
|
|
|
|
- "/deleteentry": dbDeleteEntry,
|
|
|
|
- "/getentry": dbGetEntry,
|
|
|
|
- "/gettable": dbGetTable,
|
|
|
|
- "/networkstats": dbNetworkStats,
|
|
|
|
|
|
+type Mux interface {
|
|
|
|
+ HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
|
|
}
|
|
}
|
|
|
|
|
|
-func dbJoin(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
+func (nDB *NetworkDB) RegisterDiagnosticHandlers(m Mux) {
|
|
|
|
+ m.HandleFunc("/join", nDB.dbJoin)
|
|
|
|
+ m.HandleFunc("/networkpeers", nDB.dbPeers)
|
|
|
|
+ m.HandleFunc("/clusterpeers", nDB.dbClusterPeers)
|
|
|
|
+ m.HandleFunc("/joinnetwork", nDB.dbJoinNetwork)
|
|
|
|
+ m.HandleFunc("/leavenetwork", nDB.dbLeaveNetwork)
|
|
|
|
+ m.HandleFunc("/createentry", nDB.dbCreateEntry)
|
|
|
|
+ m.HandleFunc("/updateentry", nDB.dbUpdateEntry)
|
|
|
|
+ m.HandleFunc("/deleteentry", nDB.dbDeleteEntry)
|
|
|
|
+ m.HandleFunc("/getentry", nDB.dbGetEntry)
|
|
|
|
+ m.HandleFunc("/gettable", nDB.dbGetTable)
|
|
|
|
+ m.HandleFunc("/networkstats", nDB.dbNetworkStats)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (nDB *NetworkDB) dbJoin(w http.ResponseWriter, r *http.Request) {
|
|
_ = r.ParseForm()
|
|
_ = r.ParseForm()
|
|
diagnostic.DebugHTTPForm(r)
|
|
diagnostic.DebugHTTPForm(r)
|
|
_, json := diagnostic.ParseHTTPFormOptions(r)
|
|
_, json := diagnostic.ParseHTTPFormOptions(r)
|
|
@@ -53,24 +56,19 @@ func dbJoin(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- nDB, ok := ctx.(*NetworkDB)
|
|
|
|
- if ok {
|
|
|
|
- err := nDB.Join(strings.Split(r.Form["members"][0], ","))
|
|
|
|
- if err != nil {
|
|
|
|
- rsp := diagnostic.FailCommand(fmt.Errorf("%s error in the DB join %s", r.URL.Path, err))
|
|
|
|
- logger.WithError(err).Error("join cluster failed")
|
|
|
|
- diagnostic.HTTPReply(w, rsp, json)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- logger.Info("join cluster done")
|
|
|
|
- diagnostic.HTTPReply(w, diagnostic.CommandSucceed(nil), json)
|
|
|
|
|
|
+ err := nDB.Join(strings.Split(r.Form["members"][0], ","))
|
|
|
|
+ if err != nil {
|
|
|
|
+ rsp := diagnostic.FailCommand(fmt.Errorf("%s error in the DB join %s", r.URL.Path, err))
|
|
|
|
+ logger.WithError(err).Error("join cluster failed")
|
|
|
|
+ diagnostic.HTTPReply(w, rsp, json)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- diagnostic.HTTPReply(w, diagnostic.FailCommand(fmt.Errorf(dbNotAvailable)), json)
|
|
|
|
|
|
+
|
|
|
|
+ logger.Info("join cluster done")
|
|
|
|
+ diagnostic.HTTPReply(w, diagnostic.CommandSucceed(nil), json)
|
|
}
|
|
}
|
|
|
|
|
|
-func dbPeers(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
+func (nDB *NetworkDB) dbPeers(w http.ResponseWriter, r *http.Request) {
|
|
_ = r.ParseForm()
|
|
_ = r.ParseForm()
|
|
diagnostic.DebugHTTPForm(r)
|
|
diagnostic.DebugHTTPForm(r)
|
|
_, json := diagnostic.ParseHTTPFormOptions(r)
|
|
_, json := diagnostic.ParseHTTPFormOptions(r)
|
|
@@ -91,25 +89,20 @@ func dbPeers(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- nDB, ok := ctx.(*NetworkDB)
|
|
|
|
- if ok {
|
|
|
|
- peers := nDB.Peers(r.Form["nid"][0])
|
|
|
|
- rsp := &diagnostic.TableObj{Length: len(peers)}
|
|
|
|
- for i, peerInfo := range peers {
|
|
|
|
- if peerInfo.IP == "unknown" {
|
|
|
|
- rsp.Elements = append(rsp.Elements, &diagnostic.PeerEntryObj{Index: i, Name: "orphan-" + peerInfo.Name, IP: peerInfo.IP})
|
|
|
|
- } else {
|
|
|
|
- rsp.Elements = append(rsp.Elements, &diagnostic.PeerEntryObj{Index: i, Name: peerInfo.Name, IP: peerInfo.IP})
|
|
|
|
- }
|
|
|
|
|
|
+ peers := nDB.Peers(r.Form["nid"][0])
|
|
|
|
+ rsp := &diagnostic.TableObj{Length: len(peers)}
|
|
|
|
+ for i, peerInfo := range peers {
|
|
|
|
+ if peerInfo.IP == "unknown" {
|
|
|
|
+ rsp.Elements = append(rsp.Elements, &diagnostic.PeerEntryObj{Index: i, Name: "orphan-" + peerInfo.Name, IP: peerInfo.IP})
|
|
|
|
+ } else {
|
|
|
|
+ rsp.Elements = append(rsp.Elements, &diagnostic.PeerEntryObj{Index: i, Name: peerInfo.Name, IP: peerInfo.IP})
|
|
}
|
|
}
|
|
- logger.WithField("response", fmt.Sprintf("%+v", rsp)).Info("network peers done")
|
|
|
|
- diagnostic.HTTPReply(w, diagnostic.CommandSucceed(rsp), json)
|
|
|
|
- return
|
|
|
|
}
|
|
}
|
|
- diagnostic.HTTPReply(w, diagnostic.FailCommand(fmt.Errorf(dbNotAvailable)), json)
|
|
|
|
|
|
+ logger.WithField("response", fmt.Sprintf("%+v", rsp)).Info("network peers done")
|
|
|
|
+ diagnostic.HTTPReply(w, diagnostic.CommandSucceed(rsp), json)
|
|
}
|
|
}
|
|
|
|
|
|
-func dbClusterPeers(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
+func (nDB *NetworkDB) dbClusterPeers(w http.ResponseWriter, r *http.Request) {
|
|
_ = r.ParseForm()
|
|
_ = r.ParseForm()
|
|
diagnostic.DebugHTTPForm(r)
|
|
diagnostic.DebugHTTPForm(r)
|
|
_, json := diagnostic.ParseHTTPFormOptions(r)
|
|
_, json := diagnostic.ParseHTTPFormOptions(r)
|
|
@@ -123,21 +116,16 @@ func dbClusterPeers(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
})
|
|
})
|
|
logger.Info("cluster peers")
|
|
logger.Info("cluster peers")
|
|
|
|
|
|
- nDB, ok := ctx.(*NetworkDB)
|
|
|
|
- if ok {
|
|
|
|
- peers := nDB.ClusterPeers()
|
|
|
|
- rsp := &diagnostic.TableObj{Length: len(peers)}
|
|
|
|
- for i, peerInfo := range peers {
|
|
|
|
- rsp.Elements = append(rsp.Elements, &diagnostic.PeerEntryObj{Index: i, Name: peerInfo.Name, IP: peerInfo.IP})
|
|
|
|
- }
|
|
|
|
- logger.WithField("response", fmt.Sprintf("%+v", rsp)).Info("cluster peers done")
|
|
|
|
- diagnostic.HTTPReply(w, diagnostic.CommandSucceed(rsp), json)
|
|
|
|
- return
|
|
|
|
|
|
+ peers := nDB.ClusterPeers()
|
|
|
|
+ rsp := &diagnostic.TableObj{Length: len(peers)}
|
|
|
|
+ for i, peerInfo := range peers {
|
|
|
|
+ rsp.Elements = append(rsp.Elements, &diagnostic.PeerEntryObj{Index: i, Name: peerInfo.Name, IP: peerInfo.IP})
|
|
}
|
|
}
|
|
- diagnostic.HTTPReply(w, diagnostic.FailCommand(fmt.Errorf(dbNotAvailable)), json)
|
|
|
|
|
|
+ logger.WithField("response", fmt.Sprintf("%+v", rsp)).Info("cluster peers done")
|
|
|
|
+ diagnostic.HTTPReply(w, diagnostic.CommandSucceed(rsp), json)
|
|
}
|
|
}
|
|
|
|
|
|
-func dbCreateEntry(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
+func (nDB *NetworkDB) dbCreateEntry(w http.ResponseWriter, r *http.Request) {
|
|
_ = r.ParseForm()
|
|
_ = r.ParseForm()
|
|
diagnostic.DebugHTTPForm(r)
|
|
diagnostic.DebugHTTPForm(r)
|
|
unsafe, json := diagnostic.ParseHTTPFormOptions(r)
|
|
unsafe, json := diagnostic.ParseHTTPFormOptions(r)
|
|
@@ -176,22 +164,17 @@ func dbCreateEntry(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- nDB, ok := ctx.(*NetworkDB)
|
|
|
|
- if ok {
|
|
|
|
- if err := nDB.CreateEntry(tname, nid, key, decodedValue); err != nil {
|
|
|
|
- rsp := diagnostic.FailCommand(err)
|
|
|
|
- diagnostic.HTTPReply(w, rsp, json)
|
|
|
|
- logger.WithError(err).Error("create entry failed")
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- logger.Info("create entry done")
|
|
|
|
- diagnostic.HTTPReply(w, diagnostic.CommandSucceed(nil), json)
|
|
|
|
|
|
+ if err := nDB.CreateEntry(tname, nid, key, decodedValue); err != nil {
|
|
|
|
+ rsp := diagnostic.FailCommand(err)
|
|
|
|
+ diagnostic.HTTPReply(w, rsp, json)
|
|
|
|
+ logger.WithError(err).Error("create entry failed")
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- diagnostic.HTTPReply(w, diagnostic.FailCommand(fmt.Errorf(dbNotAvailable)), json)
|
|
|
|
|
|
+ logger.Info("create entry done")
|
|
|
|
+ diagnostic.HTTPReply(w, diagnostic.CommandSucceed(nil), json)
|
|
}
|
|
}
|
|
|
|
|
|
-func dbUpdateEntry(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
+func (nDB *NetworkDB) dbUpdateEntry(w http.ResponseWriter, r *http.Request) {
|
|
_ = r.ParseForm()
|
|
_ = r.ParseForm()
|
|
diagnostic.DebugHTTPForm(r)
|
|
diagnostic.DebugHTTPForm(r)
|
|
unsafe, json := diagnostic.ParseHTTPFormOptions(r)
|
|
unsafe, json := diagnostic.ParseHTTPFormOptions(r)
|
|
@@ -230,21 +213,16 @@ func dbUpdateEntry(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- nDB, ok := ctx.(*NetworkDB)
|
|
|
|
- if ok {
|
|
|
|
- if err := nDB.UpdateEntry(tname, nid, key, decodedValue); err != nil {
|
|
|
|
- logger.WithError(err).Error("update entry failed")
|
|
|
|
- diagnostic.HTTPReply(w, diagnostic.FailCommand(err), json)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- logger.Info("update entry done")
|
|
|
|
- diagnostic.HTTPReply(w, diagnostic.CommandSucceed(nil), json)
|
|
|
|
|
|
+ if err := nDB.UpdateEntry(tname, nid, key, decodedValue); err != nil {
|
|
|
|
+ logger.WithError(err).Error("update entry failed")
|
|
|
|
+ diagnostic.HTTPReply(w, diagnostic.FailCommand(err), json)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- diagnostic.HTTPReply(w, diagnostic.FailCommand(fmt.Errorf(dbNotAvailable)), json)
|
|
|
|
|
|
+ logger.Info("update entry done")
|
|
|
|
+ diagnostic.HTTPReply(w, diagnostic.CommandSucceed(nil), json)
|
|
}
|
|
}
|
|
|
|
|
|
-func dbDeleteEntry(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
+func (nDB *NetworkDB) dbDeleteEntry(w http.ResponseWriter, r *http.Request) {
|
|
_ = r.ParseForm()
|
|
_ = r.ParseForm()
|
|
diagnostic.DebugHTTPForm(r)
|
|
diagnostic.DebugHTTPForm(r)
|
|
_, json := diagnostic.ParseHTTPFormOptions(r)
|
|
_, json := diagnostic.ParseHTTPFormOptions(r)
|
|
@@ -271,22 +249,17 @@ func dbDeleteEntry(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
nid := r.Form["nid"][0]
|
|
nid := r.Form["nid"][0]
|
|
key := r.Form["key"][0]
|
|
key := r.Form["key"][0]
|
|
|
|
|
|
- nDB, ok := ctx.(*NetworkDB)
|
|
|
|
- if ok {
|
|
|
|
- err := nDB.DeleteEntry(tname, nid, key)
|
|
|
|
- if err != nil {
|
|
|
|
- logger.WithError(err).Error("delete entry failed")
|
|
|
|
- diagnostic.HTTPReply(w, diagnostic.FailCommand(err), json)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- logger.Info("delete entry done")
|
|
|
|
- diagnostic.HTTPReply(w, diagnostic.CommandSucceed(nil), json)
|
|
|
|
|
|
+ err := nDB.DeleteEntry(tname, nid, key)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logger.WithError(err).Error("delete entry failed")
|
|
|
|
+ diagnostic.HTTPReply(w, diagnostic.FailCommand(err), json)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- diagnostic.HTTPReply(w, diagnostic.FailCommand(fmt.Errorf(dbNotAvailable)), json)
|
|
|
|
|
|
+ logger.Info("delete entry done")
|
|
|
|
+ diagnostic.HTTPReply(w, diagnostic.CommandSucceed(nil), json)
|
|
}
|
|
}
|
|
|
|
|
|
-func dbGetEntry(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
+func (nDB *NetworkDB) dbGetEntry(w http.ResponseWriter, r *http.Request) {
|
|
_ = r.ParseForm()
|
|
_ = r.ParseForm()
|
|
diagnostic.DebugHTTPForm(r)
|
|
diagnostic.DebugHTTPForm(r)
|
|
unsafe, json := diagnostic.ParseHTTPFormOptions(r)
|
|
unsafe, json := diagnostic.ParseHTTPFormOptions(r)
|
|
@@ -313,31 +286,26 @@ func dbGetEntry(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
nid := r.Form["nid"][0]
|
|
nid := r.Form["nid"][0]
|
|
key := r.Form["key"][0]
|
|
key := r.Form["key"][0]
|
|
|
|
|
|
- nDB, ok := ctx.(*NetworkDB)
|
|
|
|
- if ok {
|
|
|
|
- value, err := nDB.GetEntry(tname, nid, key)
|
|
|
|
- if err != nil {
|
|
|
|
- logger.WithError(err).Error("get entry failed")
|
|
|
|
- diagnostic.HTTPReply(w, diagnostic.FailCommand(err), json)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var encodedValue string
|
|
|
|
- if unsafe {
|
|
|
|
- encodedValue = string(value)
|
|
|
|
- } else {
|
|
|
|
- encodedValue = base64.StdEncoding.EncodeToString(value)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- rsp := &diagnostic.TableEntryObj{Key: key, Value: encodedValue}
|
|
|
|
- logger.WithField("response", fmt.Sprintf("%+v", rsp)).Info("get entry done")
|
|
|
|
- diagnostic.HTTPReply(w, diagnostic.CommandSucceed(rsp), json)
|
|
|
|
|
|
+ value, err := nDB.GetEntry(tname, nid, key)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logger.WithError(err).Error("get entry failed")
|
|
|
|
+ diagnostic.HTTPReply(w, diagnostic.FailCommand(err), json)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- diagnostic.HTTPReply(w, diagnostic.FailCommand(fmt.Errorf(dbNotAvailable)), json)
|
|
|
|
|
|
+
|
|
|
|
+ var encodedValue string
|
|
|
|
+ if unsafe {
|
|
|
|
+ encodedValue = string(value)
|
|
|
|
+ } else {
|
|
|
|
+ encodedValue = base64.StdEncoding.EncodeToString(value)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ rsp := &diagnostic.TableEntryObj{Key: key, Value: encodedValue}
|
|
|
|
+ logger.WithField("response", fmt.Sprintf("%+v", rsp)).Info("get entry done")
|
|
|
|
+ diagnostic.HTTPReply(w, diagnostic.CommandSucceed(rsp), json)
|
|
}
|
|
}
|
|
|
|
|
|
-func dbJoinNetwork(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
+func (nDB *NetworkDB) dbJoinNetwork(w http.ResponseWriter, r *http.Request) {
|
|
_ = r.ParseForm()
|
|
_ = r.ParseForm()
|
|
diagnostic.DebugHTTPForm(r)
|
|
diagnostic.DebugHTTPForm(r)
|
|
_, json := diagnostic.ParseHTTPFormOptions(r)
|
|
_, json := diagnostic.ParseHTTPFormOptions(r)
|
|
@@ -360,21 +328,16 @@ func dbJoinNetwork(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
nid := r.Form["nid"][0]
|
|
nid := r.Form["nid"][0]
|
|
|
|
|
|
- nDB, ok := ctx.(*NetworkDB)
|
|
|
|
- if ok {
|
|
|
|
- if err := nDB.JoinNetwork(nid); err != nil {
|
|
|
|
- logger.WithError(err).Error("join network failed")
|
|
|
|
- diagnostic.HTTPReply(w, diagnostic.FailCommand(err), json)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- logger.Info("join network done")
|
|
|
|
- diagnostic.HTTPReply(w, diagnostic.CommandSucceed(nil), json)
|
|
|
|
|
|
+ if err := nDB.JoinNetwork(nid); err != nil {
|
|
|
|
+ logger.WithError(err).Error("join network failed")
|
|
|
|
+ diagnostic.HTTPReply(w, diagnostic.FailCommand(err), json)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- diagnostic.HTTPReply(w, diagnostic.FailCommand(fmt.Errorf(dbNotAvailable)), json)
|
|
|
|
|
|
+ logger.Info("join network done")
|
|
|
|
+ diagnostic.HTTPReply(w, diagnostic.CommandSucceed(nil), json)
|
|
}
|
|
}
|
|
|
|
|
|
-func dbLeaveNetwork(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
+func (nDB *NetworkDB) dbLeaveNetwork(w http.ResponseWriter, r *http.Request) {
|
|
_ = r.ParseForm()
|
|
_ = r.ParseForm()
|
|
diagnostic.DebugHTTPForm(r)
|
|
diagnostic.DebugHTTPForm(r)
|
|
_, json := diagnostic.ParseHTTPFormOptions(r)
|
|
_, json := diagnostic.ParseHTTPFormOptions(r)
|
|
@@ -397,21 +360,16 @@ func dbLeaveNetwork(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
nid := r.Form["nid"][0]
|
|
nid := r.Form["nid"][0]
|
|
|
|
|
|
- nDB, ok := ctx.(*NetworkDB)
|
|
|
|
- if ok {
|
|
|
|
- if err := nDB.LeaveNetwork(nid); err != nil {
|
|
|
|
- logger.WithError(err).Error("leave network failed")
|
|
|
|
- diagnostic.HTTPReply(w, diagnostic.FailCommand(err), json)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- logger.Info("leave network done")
|
|
|
|
- diagnostic.HTTPReply(w, diagnostic.CommandSucceed(nil), json)
|
|
|
|
|
|
+ if err := nDB.LeaveNetwork(nid); err != nil {
|
|
|
|
+ logger.WithError(err).Error("leave network failed")
|
|
|
|
+ diagnostic.HTTPReply(w, diagnostic.FailCommand(err), json)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- diagnostic.HTTPReply(w, diagnostic.FailCommand(fmt.Errorf(dbNotAvailable)), json)
|
|
|
|
|
|
+ logger.Info("leave network done")
|
|
|
|
+ diagnostic.HTTPReply(w, diagnostic.CommandSucceed(nil), json)
|
|
}
|
|
}
|
|
|
|
|
|
-func dbGetTable(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
+func (nDB *NetworkDB) dbGetTable(w http.ResponseWriter, r *http.Request) {
|
|
_ = r.ParseForm()
|
|
_ = r.ParseForm()
|
|
diagnostic.DebugHTTPForm(r)
|
|
diagnostic.DebugHTTPForm(r)
|
|
unsafe, json := diagnostic.ParseHTTPFormOptions(r)
|
|
unsafe, json := diagnostic.ParseHTTPFormOptions(r)
|
|
@@ -436,35 +394,30 @@ func dbGetTable(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
tname := r.Form["tname"][0]
|
|
tname := r.Form["tname"][0]
|
|
nid := r.Form["nid"][0]
|
|
nid := r.Form["nid"][0]
|
|
|
|
|
|
- nDB, ok := ctx.(*NetworkDB)
|
|
|
|
- if ok {
|
|
|
|
- table := nDB.GetTableByNetwork(tname, nid)
|
|
|
|
- rsp := &diagnostic.TableObj{Length: len(table)}
|
|
|
|
- i := 0
|
|
|
|
- for k, v := range table {
|
|
|
|
- var encodedValue string
|
|
|
|
- if unsafe {
|
|
|
|
- encodedValue = string(v.Value)
|
|
|
|
- } else {
|
|
|
|
- encodedValue = base64.StdEncoding.EncodeToString(v.Value)
|
|
|
|
- }
|
|
|
|
- rsp.Elements = append(rsp.Elements,
|
|
|
|
- &diagnostic.TableEntryObj{
|
|
|
|
- Index: i,
|
|
|
|
- Key: k,
|
|
|
|
- Value: encodedValue,
|
|
|
|
- Owner: v.owner,
|
|
|
|
- })
|
|
|
|
- i++
|
|
|
|
|
|
+ table := nDB.GetTableByNetwork(tname, nid)
|
|
|
|
+ rsp := &diagnostic.TableObj{Length: len(table)}
|
|
|
|
+ i := 0
|
|
|
|
+ for k, v := range table {
|
|
|
|
+ var encodedValue string
|
|
|
|
+ if unsafe {
|
|
|
|
+ encodedValue = string(v.Value)
|
|
|
|
+ } else {
|
|
|
|
+ encodedValue = base64.StdEncoding.EncodeToString(v.Value)
|
|
}
|
|
}
|
|
- logger.WithField("response", fmt.Sprintf("%+v", rsp)).Info("get table done")
|
|
|
|
- diagnostic.HTTPReply(w, diagnostic.CommandSucceed(rsp), json)
|
|
|
|
- return
|
|
|
|
|
|
+ rsp.Elements = append(rsp.Elements,
|
|
|
|
+ &diagnostic.TableEntryObj{
|
|
|
|
+ Index: i,
|
|
|
|
+ Key: k,
|
|
|
|
+ Value: encodedValue,
|
|
|
|
+ Owner: v.owner,
|
|
|
|
+ })
|
|
|
|
+ i++
|
|
}
|
|
}
|
|
- diagnostic.HTTPReply(w, diagnostic.FailCommand(fmt.Errorf(dbNotAvailable)), json)
|
|
|
|
|
|
+ logger.WithField("response", fmt.Sprintf("%+v", rsp)).Info("get table done")
|
|
|
|
+ diagnostic.HTTPReply(w, diagnostic.CommandSucceed(rsp), json)
|
|
}
|
|
}
|
|
|
|
|
|
-func dbNetworkStats(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
+func (nDB *NetworkDB) dbNetworkStats(w http.ResponseWriter, r *http.Request) {
|
|
_ = r.ParseForm()
|
|
_ = r.ParseForm()
|
|
diagnostic.DebugHTTPForm(r)
|
|
diagnostic.DebugHTTPForm(r)
|
|
_, json := diagnostic.ParseHTTPFormOptions(r)
|
|
_, json := diagnostic.ParseHTTPFormOptions(r)
|
|
@@ -485,24 +438,19 @@ func dbNetworkStats(ctx interface{}, w http.ResponseWriter, r *http.Request) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- nDB, ok := ctx.(*NetworkDB)
|
|
|
|
- if ok {
|
|
|
|
- nDB.RLock()
|
|
|
|
- networks := nDB.networks[nDB.config.NodeID]
|
|
|
|
- network, ok := networks[r.Form["nid"][0]]
|
|
|
|
-
|
|
|
|
- entries := -1
|
|
|
|
- qLen := -1
|
|
|
|
- if ok {
|
|
|
|
- entries = int(network.entriesNumber.Load())
|
|
|
|
- qLen = network.tableBroadcasts.NumQueued()
|
|
|
|
- }
|
|
|
|
- nDB.RUnlock()
|
|
|
|
|
|
+ nDB.RLock()
|
|
|
|
+ networks := nDB.networks[nDB.config.NodeID]
|
|
|
|
+ network, ok := networks[r.Form["nid"][0]]
|
|
|
|
|
|
- rsp := diagnostic.CommandSucceed(&diagnostic.NetworkStatsResult{Entries: entries, QueueLen: qLen})
|
|
|
|
- logger.WithField("response", fmt.Sprintf("%+v", rsp)).Info("network stats done")
|
|
|
|
- diagnostic.HTTPReply(w, rsp, json)
|
|
|
|
- return
|
|
|
|
|
|
+ entries := -1
|
|
|
|
+ qLen := -1
|
|
|
|
+ if ok {
|
|
|
|
+ entries = int(network.entriesNumber.Load())
|
|
|
|
+ qLen = network.tableBroadcasts.NumQueued()
|
|
}
|
|
}
|
|
- diagnostic.HTTPReply(w, diagnostic.FailCommand(fmt.Errorf(dbNotAvailable)), json)
|
|
|
|
|
|
+ nDB.RUnlock()
|
|
|
|
+
|
|
|
|
+ rsp := diagnostic.CommandSucceed(&diagnostic.NetworkStatsResult{Entries: entries, QueueLen: qLen})
|
|
|
|
+ logger.WithField("response", fmt.Sprintf("%+v", rsp)).Info("network stats done")
|
|
|
|
+ diagnostic.HTTPReply(w, rsp, json)
|
|
}
|
|
}
|