Compare commits
4 Commits
23a9d648d2
...
bugfix/boo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
778ffa05a1 | ||
|
|
3c15907427 | ||
|
|
9ae5f3b91d | ||
|
|
3a2141aab5 |
@@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/logs"
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/enum"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
@@ -39,6 +40,8 @@ func (wfa *Booking) Check(id string, start time.Time, end *time.Time, parrallelA
|
||||
end = &e
|
||||
}
|
||||
accessor := NewAccessor(nil)
|
||||
l := logs.GetLogger().With().Str("Search Check", "Booking").Logger()
|
||||
l.Debug().Msg("Starting to search")
|
||||
res, code, err := accessor.Search(&dbs.Filters{
|
||||
And: map[string][]dbs.Filter{ // check if there is a booking on the same compute resource by filtering on the compute_resource_id, the state and the execution date
|
||||
"resource_id": {{Operator: dbs.EQUAL.String(), Value: id}},
|
||||
@@ -49,6 +52,9 @@ func (wfa *Booking) Check(id string, start time.Time, end *time.Time, parrallelA
|
||||
},
|
||||
},
|
||||
}, "", wfa.IsDraft)
|
||||
|
||||
l.Debug().Msg("Search finished")
|
||||
|
||||
if code != 200 {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -29,7 +29,28 @@ type PeerCache struct {
|
||||
|
||||
// urlFormat formats the URL of the peer with the data type API function
|
||||
func (p *PeerCache) urlFormat(hostUrl string, dt tools.DataType) string {
|
||||
return hostUrl + "/" + strings.ReplaceAll(dt.API(), "oc-", "")
|
||||
// localhost is replaced by the local peer URL
|
||||
// because localhost must collide on a web request security protocol
|
||||
/*localhost := ""
|
||||
if strings.Contains(hostUrl, "localhost") {
|
||||
localhost = "localhost"
|
||||
}
|
||||
if strings.Contains(hostUrl, "127.0.0.1") {
|
||||
localhost = "127.0.0.1"
|
||||
}
|
||||
if localhost != "" {
|
||||
r := regexp.MustCompile("(" + localhost + ":[0-9]+)")
|
||||
t := r.FindString(hostUrl)
|
||||
if t != "" {
|
||||
hostUrl = strings.Replace(hostUrl, t, dt.API()+":8080/oc", -1)
|
||||
} else {
|
||||
hostUrl = strings.ReplaceAll(hostUrl, localhost, dt.API()+":8080/oc")
|
||||
}
|
||||
} else {*/
|
||||
hostUrl = hostUrl + "/" + strings.ReplaceAll(dt.API(), "oc-", "")
|
||||
//}
|
||||
fmt.Println("Contacting", hostUrl)
|
||||
return hostUrl
|
||||
}
|
||||
|
||||
// checkPeerStatus checks the status of a peer
|
||||
@@ -65,7 +86,7 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string,
|
||||
// If the peer is not reachable, add the execution to the failed executions list
|
||||
pexec := &PeerExecution{
|
||||
Method: method.String(),
|
||||
Url: p.urlFormat((mypeer.Url), dt) + path, // the url is constitued of : host URL + resource path + action path (ex : mypeer.com/datacenter/resourcetype/path/to/action)
|
||||
Url: p.urlFormat((mypeer.Url), dt) + path, // the url is constitued of : host URL + resource path + action path (ex : mypeer.com/datacenter/resourcetype/path/to/action)
|
||||
Body: body,
|
||||
DataType: dt.EnumIndex(),
|
||||
DataID: dataID,
|
||||
@@ -78,7 +99,7 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string,
|
||||
return nil, errors.New("peer " + peerID + " not found")
|
||||
}
|
||||
// If the peer is reachable, launch the execution
|
||||
url = p.urlFormat((mypeer.Url), dt) + path // Format the URL
|
||||
url = p.urlFormat((mypeer.Url), dt) + path // Format the URL
|
||||
tmp := mypeer.FailedExecution // Get the failed executions list
|
||||
mypeer.FailedExecution = []PeerExecution{} // Reset the failed executions list
|
||||
NewShallowAccessor().UpdateOne(mypeer, peerID) // Update the peer in the db
|
||||
|
||||
@@ -31,43 +31,6 @@ func (d *Workflow) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
||||
return NewAccessor(request) // Create a new instance of the accessor
|
||||
}
|
||||
|
||||
type Deps struct {
|
||||
Source string
|
||||
Dest string
|
||||
}
|
||||
|
||||
func (w *Workflow) isDependancy(id string) []Deps {
|
||||
dependancyOfIDs := []Deps{}
|
||||
for _, link := range w.Graph.Links {
|
||||
if _, ok := w.Graph.Items[link.Destination.ID]; !ok {
|
||||
continue
|
||||
}
|
||||
source := w.Graph.Items[link.Destination.ID].Processing
|
||||
if id == link.Source.ID && source != nil {
|
||||
dependancyOfIDs = append(dependancyOfIDs, Deps{Source: source.GetName(), Dest: link.Destination.ID})
|
||||
}
|
||||
sourceWF := w.Graph.Items[link.Destination.ID].Workflow
|
||||
if id == link.Source.ID && sourceWF != nil {
|
||||
dependancyOfIDs = append(dependancyOfIDs, Deps{Source: sourceWF.GetName(), Dest: link.Destination.ID})
|
||||
}
|
||||
}
|
||||
return dependancyOfIDs
|
||||
}
|
||||
|
||||
func (w *Workflow) GetDependencies(id string) (dependencies []Deps) {
|
||||
for _, link := range w.Graph.Links {
|
||||
if _, ok := w.Graph.Items[link.Source.ID]; !ok {
|
||||
continue
|
||||
}
|
||||
source := w.Graph.Items[link.Source.ID].Processing
|
||||
if id == link.Destination.ID && source != nil {
|
||||
dependencies = append(dependencies, Deps{Source: source.GetName(), Dest: link.Source.ID})
|
||||
continue
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (w *Workflow) GetGraphItems(f func(item graph.GraphItem) bool) (list_datas []graph.GraphItem) {
|
||||
for _, item := range w.Graph.Items {
|
||||
if f(item) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||
"cloud.o-forge.io/core/oc-lib/logs"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type APIRequest struct {
|
||||
@@ -135,8 +136,10 @@ func (a *API) CheckRemotePeer(url string) (State, map[string]int) {
|
||||
|
||||
// CheckRemoteAPIs checks the state of remote APIs from your proper OC
|
||||
func (a *API) CheckRemoteAPIs(apis []DataType) (State, map[string]string, error) {
|
||||
id := uuid.New()
|
||||
l := logs.GetLogger().With().Str("id",id.String()).Logger()
|
||||
l.Debug().Msg("Start checking")
|
||||
// Check if the database is up
|
||||
l := logs.GetLogger()
|
||||
new := map[string]string{}
|
||||
caller := NewHTTPCaller(map[DataType]map[METHOD]string{}) // Create a new http caller
|
||||
code := 0
|
||||
@@ -144,10 +147,10 @@ func (a *API) CheckRemoteAPIs(apis []DataType) (State, map[string]string, error)
|
||||
state := ALIVE
|
||||
reachable := false
|
||||
for _, api := range apis { // Check the state of each remote API in the list
|
||||
l.Debug().Msg("Checking : " + api.String() + " at " + api.API())
|
||||
var resp APIStatusResponse
|
||||
b, err := caller.CallGet("http://"+api.API()+":8080", "/oc/version/status") // Call the status endpoint of the remote API (standard OC status endpoint)
|
||||
if err != nil {
|
||||
l.Error().Msg(api.String() + " not reachable")
|
||||
state = REDUCED_SERVICE // If a remote API is not reachable, return reduced service
|
||||
continue
|
||||
}
|
||||
@@ -164,7 +167,6 @@ func (a *API) CheckRemoteAPIs(apis []DataType) (State, map[string]string, error)
|
||||
reachable = true // If the remote API is reachable, set reachable to true cause we are not dead
|
||||
}
|
||||
if !reachable {
|
||||
l.Error().Msg("Peer check returned no answers")
|
||||
state = DEAD // If no remote API is reachable, return dead, nobody is alive
|
||||
}
|
||||
if code > 0 {
|
||||
|
||||
Reference in New Issue
Block a user