removed caller from checkPeerStatus() parameters by adding the path to url
This commit is contained in:
		@@ -48,28 +48,21 @@ func (p *PeerCache) urlFormat(url string, dt tools.DataType) string {
 | 
				
			|||||||
			url = strings.ReplaceAll(url, localhost, dt.API()+":8080/oc")
 | 
								url = strings.ReplaceAll(url, localhost, dt.API()+":8080/oc")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		url = url + "/" + strings.ReplaceAll(dt.API(), "oc-", "")
 | 
							url = url + "/" + dt.API()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return url
 | 
						return url
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// checkPeerStatus checks the status of a peer
 | 
					// checkPeerStatus checks the status of a peer
 | 
				
			||||||
func (p *PeerCache) checkPeerStatus(peerID string, appName string, caller *tools.HTTPCaller) (*Peer, bool) {
 | 
					func (p *PeerCache) checkPeerStatus(peerID string, appName string) (*Peer, bool) {
 | 
				
			||||||
	api := tools.API{}
 | 
						api := tools.API{}
 | 
				
			||||||
	access := NewShallowAccessor()
 | 
						access := NewShallowAccessor()
 | 
				
			||||||
	res, code, _ := access.LoadOne(peerID) // Load the peer from db
 | 
						res, code, _ := access.LoadOne(peerID) // Load the peer from db
 | 
				
			||||||
	if code != 200 {                       // no peer no party
 | 
						if code != 200 {                       // no peer no party
 | 
				
			||||||
		return nil, false
 | 
							return nil, false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	methods := caller.URLS[tools.PEER] // Get the methods url of the peer
 | 
					
 | 
				
			||||||
	if methods == nil {
 | 
						url := p.urlFormat(res.(*Peer).Url, tools.PEER) + "/status" // Format the URL
 | 
				
			||||||
		return res.(*Peer), false
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	meth := methods[tools.POST] // Get the POST method to check status
 | 
					 | 
				
			||||||
	if meth == "" {
 | 
					 | 
				
			||||||
		return res.(*Peer), false
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	url := p.urlFormat(res.(*Peer).Url, tools.PEER) + meth // Format the URL
 | 
					 | 
				
			||||||
	state, services := api.CheckRemotePeer(url)
 | 
						state, services := api.CheckRemotePeer(url)
 | 
				
			||||||
	res.(*Peer).ServicesState = services                              // Update the services states of the peer
 | 
						res.(*Peer).ServicesState = services                              // Update the services states of the peer
 | 
				
			||||||
	access.UpdateOne(res, peerID)                                     // Update the peer in the db
 | 
						access.UpdateOne(res, peerID)                                     // Update the peer in the db
 | 
				
			||||||
@@ -89,7 +82,7 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string,
 | 
				
			|||||||
	url := ""
 | 
						url := ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check the status of the peer
 | 
						// Check the status of the peer
 | 
				
			||||||
	if mypeer, ok := p.checkPeerStatus(peerID, dt.API(), caller); !ok && mypeer != nil {
 | 
						if mypeer, ok := p.checkPeerStatus(peerID, dt.API()); !ok && mypeer != nil {
 | 
				
			||||||
		// If the peer is not reachable, add the execution to the failed executions list
 | 
							// If the peer is not reachable, add the execution to the failed executions list
 | 
				
			||||||
		pexec := &PeerExecution{
 | 
							pexec := &PeerExecution{
 | 
				
			||||||
			Method:   method.String(),
 | 
								Method:   method.String(),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,6 @@ package tools
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/config"
 | 
						"cloud.o-forge.io/core/oc-lib/config"
 | 
				
			||||||
@@ -98,7 +97,6 @@ func (a *API) SubscribeRouter(infos []*beego.ControllerInfo) {
 | 
				
			|||||||
	nats := NewNATSCaller()
 | 
						nats := NewNATSCaller()
 | 
				
			||||||
	discovery := map[string][]string{}
 | 
						discovery := map[string][]string{}
 | 
				
			||||||
	for _, info := range infos {
 | 
						for _, info := range infos {
 | 
				
			||||||
		fmt.Println("DISCOVERY", info.GetPattern())
 | 
					 | 
				
			||||||
		path := strings.ReplaceAll(info.GetPattern(), "/oc/", "/"+strings.ReplaceAll(config.GetAppName(), "oc-", ""))
 | 
							path := strings.ReplaceAll(info.GetPattern(), "/oc/", "/"+strings.ReplaceAll(config.GetAppName(), "oc-", ""))
 | 
				
			||||||
		for k, v := range info.GetMethod() {
 | 
							for k, v := range info.GetMethod() {
 | 
				
			||||||
			if discovery[path] == nil {
 | 
								if discovery[path] == nil {
 | 
				
			||||||
@@ -117,8 +115,8 @@ func (a *API) SubscribeRouter(infos []*beego.ControllerInfo) {
 | 
				
			|||||||
// CheckRemotePeer checks the state of a remote peer
 | 
					// CheckRemotePeer checks the state of a remote peer
 | 
				
			||||||
func (a *API) CheckRemotePeer(url string) (State, map[string]int) {
 | 
					func (a *API) CheckRemotePeer(url string) (State, map[string]int) {
 | 
				
			||||||
	// Check if the database is up
 | 
						// Check if the database is up
 | 
				
			||||||
	caller := NewHTTPCaller(map[DataType]map[METHOD]string{}) // Create a new http caller
 | 
					 | 
				
			||||||
	var resp APIStatusResponse
 | 
						var resp APIStatusResponse
 | 
				
			||||||
 | 
						caller := NewHTTPCaller(map[DataType]map[METHOD]string{}) // Create a new http caller
 | 
				
			||||||
	b, err := caller.CallPost(url, "", map[string]interface{}{}) // Call the status endpoint of the peer
 | 
						b, err := caller.CallPost(url, "", map[string]interface{}{}) // Call the status endpoint of the peer
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return DEAD, map[string]int{} // If the peer is not reachable, return dead
 | 
							return DEAD, map[string]int{} // If the peer is not reachable, return dead
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user