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"`
|
||||
}
|
||||
|
||||
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 {
|
||||
return paths[collection].(string)
|
||||
return paths[collection]
|
||||
}
|
||||
|
||||
func AddPath(collection LibDataEnum, path string) {
|
||||
|
@ -32,7 +32,7 @@ type PeerCache struct {
|
||||
Executions []*PeerExecution
|
||||
}
|
||||
|
||||
func (p *PeerCache) checkPeerStatus(peerID string) bool {
|
||||
func (p *PeerCache) checkPeerStatus(peerID string, caller *tools.HTTPCaller) bool {
|
||||
api := tools.API{}
|
||||
access := (&Peer{}).GetAccessor(nil)
|
||||
res, code, _ := access.LoadOne(peerID)
|
||||
@ -44,7 +44,15 @@ func (p *PeerCache) checkPeerStatus(peerID string) bool {
|
||||
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
|
||||
}
|
||||
|
||||
@ -69,7 +77,7 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, isMySelf bool, dataID str
|
||||
if _, ok := methods[method]; !ok {
|
||||
return nil, errors.New("no path found")
|
||||
}
|
||||
if !p.checkPeerStatus(peerID) {
|
||||
if !p.checkPeerStatus(peerID, caller) {
|
||||
return nil, err
|
||||
}
|
||||
if method == tools.POST {
|
||||
|
@ -60,7 +60,7 @@ func (a *API) CheckRemotePeer(url string) State {
|
||||
// Check if the database is up
|
||||
caller := NewHTTPCaller(map[string]map[METHOD]string{})
|
||||
var resp APIStatusResponse
|
||||
b, err := caller.CallGet(url, "/status")
|
||||
b, err := caller.CallPost(url, "/status", []string{})
|
||||
if err != nil {
|
||||
return DEAD
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ func (caller *HTTPCaller) CallDelete(url string, subpath string) ([]byte, error)
|
||||
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)
|
||||
responseBody := bytes.NewBuffer(postBody)
|
||||
resp, err := http.Post(url+subpath, "application/json", responseBody)
|
||||
|
Loading…
Reference in New Issue
Block a user