Booking trace API
This commit is contained in:
parent
6ef8cde225
commit
950bbf1d7b
@ -69,10 +69,14 @@ type LibData struct {
|
|||||||
Err string `bson:"error" json:"error"`
|
Err string `bson:"error" json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var paths map[LibDataEnum]interface{} = map[LibDataEnum]interface{}{}
|
var paths map[LibDataEnum]string = map[LibDataEnum]string{}
|
||||||
|
|
||||||
|
func GetPaths() map[LibDataEnum]string {
|
||||||
|
return paths
|
||||||
|
}
|
||||||
|
|
||||||
func GetPath(collection LibDataEnum) string {
|
func GetPath(collection LibDataEnum) string {
|
||||||
return paths[collection].(string)
|
return paths[collection]
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddPath(collection LibDataEnum, path string) {
|
func AddPath(collection LibDataEnum, path string) {
|
||||||
|
@ -32,7 +32,7 @@ type PeerCache struct {
|
|||||||
Executions []*PeerExecution
|
Executions []*PeerExecution
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PeerCache) checkPeerStatus(peerID string) bool {
|
func (p *PeerCache) checkPeerStatus(peerID string, caller *tools.HTTPCaller) bool {
|
||||||
api := tools.API{}
|
api := tools.API{}
|
||||||
access := (&Peer{}).GetAccessor(nil)
|
access := (&Peer{}).GetAccessor(nil)
|
||||||
res, code, _ := access.LoadOne(peerID)
|
res, code, _ := access.LoadOne(peerID)
|
||||||
@ -44,7 +44,15 @@ func (p *PeerCache) checkPeerStatus(peerID string) bool {
|
|||||||
url = strings.ReplaceAll(url, "localhost", utils.PEER.API())
|
url = strings.ReplaceAll(url, "localhost", utils.PEER.API())
|
||||||
|
|
||||||
}
|
}
|
||||||
state := api.CheckRemotePeer(url + ":8093")
|
methods := caller.URLS[utils.PEER.String()]
|
||||||
|
if methods == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
meth := methods[tools.POST]
|
||||||
|
if meth == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
state := api.CheckRemotePeer(url + meth)
|
||||||
return state != tools.DEAD
|
return state != tools.DEAD
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +77,7 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, isMySelf bool, dataID str
|
|||||||
if _, ok := methods[method]; !ok {
|
if _, ok := methods[method]; !ok {
|
||||||
return nil, errors.New("no path found")
|
return nil, errors.New("no path found")
|
||||||
}
|
}
|
||||||
if !p.checkPeerStatus(peerID) {
|
if !p.checkPeerStatus(peerID, caller) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if method == tools.POST {
|
if method == tools.POST {
|
||||||
|
@ -60,7 +60,7 @@ func (a *API) CheckRemotePeer(url string) State {
|
|||||||
// Check if the database is up
|
// Check if the database is up
|
||||||
caller := NewHTTPCaller(map[string]map[METHOD]string{})
|
caller := NewHTTPCaller(map[string]map[METHOD]string{})
|
||||||
var resp APIStatusResponse
|
var resp APIStatusResponse
|
||||||
b, err := caller.CallGet(url, "/status")
|
b, err := caller.CallPost(url, "/status", []string{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return DEAD
|
return DEAD
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ func (caller *HTTPCaller) CallDelete(url string, subpath string) ([]byte, error)
|
|||||||
return io.ReadAll(resp.Body)
|
return io.ReadAll(resp.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (caller *HTTPCaller) CallPost(url string, subpath string, body map[string]interface{}) ([]byte, error) {
|
func (caller *HTTPCaller) CallPost(url string, subpath string, body interface{}) ([]byte, error) {
|
||||||
postBody, _ := json.Marshal(body)
|
postBody, _ := json.Marshal(body)
|
||||||
responseBody := bytes.NewBuffer(postBody)
|
responseBody := bytes.NewBuffer(postBody)
|
||||||
resp, err := http.Post(url+subpath, "application/json", responseBody)
|
resp, err := http.Post(url+subpath, "application/json", responseBody)
|
||||||
|
Loading…
Reference in New Issue
Block a user