peers logic
This commit is contained in:
@@ -18,9 +18,10 @@ import (
|
||||
|
||||
type AbstractWorkflow struct {
|
||||
resources.ResourceSet
|
||||
Graph *graph.Graph `bson:"graph,omitempty" json:"graph,omitempty"`
|
||||
Schedule *WorkflowSchedule `bson:"schedule,omitempty" json:"schedule,omitempty"`
|
||||
Shared []string `json:"shared,omitempty" bson:"shared,omitempty"`
|
||||
Graph *graph.Graph `bson:"graph,omitempty" json:"graph,omitempty"`
|
||||
ScheduleActive bool `bson:"schedule_active,omitempty" json:"schedule_active,omitempty"`
|
||||
Schedule *WorkflowSchedule `bson:"schedule,omitempty" json:"schedule,omitempty"`
|
||||
Shared []string `json:"shared,omitempty" bson:"shared,omitempty"`
|
||||
}
|
||||
|
||||
func (w *AbstractWorkflow) isDCLink(link graph.GraphLink) (bool, string) {
|
||||
|
@@ -1,9 +1,7 @@
|
||||
package oclib
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
@@ -80,6 +78,9 @@ func (wfa *workflowMongoAccessor) getExecutions(id string, data *Workflow) ([]*w
|
||||
}
|
||||
|
||||
func (wfa *workflowMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||
wfa.execution(id, &Workflow{
|
||||
AbstractWorkflow: AbstractWorkflow{ScheduleActive: false},
|
||||
}, true)
|
||||
return wfa.GenericDeleteOne(id, wfa)
|
||||
}
|
||||
|
||||
@@ -91,9 +92,6 @@ func (wfa *workflowMongoAccessor) book(id string, realData *Workflow, execs []*w
|
||||
if _, ok := methods[tools.POST]; !ok {
|
||||
return errors.New("no path found")
|
||||
}
|
||||
if realData.Schedule == nil {
|
||||
return nil
|
||||
}
|
||||
res, _, _ := wfa.LoadOne(id)
|
||||
r := res.(*Workflow)
|
||||
g := r.Graph
|
||||
@@ -113,22 +111,20 @@ func (wfa *workflowMongoAccessor) book(id string, realData *Workflow, execs []*w
|
||||
if peerID == "" {
|
||||
continue
|
||||
}
|
||||
p, code, _ := (&peer.Peer{}).GetAccessor(nil).LoadOne(peerID)
|
||||
paccess := (&peer.Peer{})
|
||||
p, code, _ := paccess.GetAccessor(nil).LoadOne(peerID)
|
||||
if code != 200 {
|
||||
continue
|
||||
}
|
||||
resp, err := wfa.Caller.CallPost(p.(*peer.Peer).Url, methods[tools.POST], (&workflow_execution.WorkflowExecutions{
|
||||
ResourceID: dc_id,
|
||||
Executions: execs,
|
||||
}).Serialize())
|
||||
if err != nil {
|
||||
b, err := paccess.LaunchPeerExecution(p.GetID(), "", p.(*peer.Peer).Url, utils.BOOKING, tools.POST,
|
||||
(&workflow_execution.WorkflowExecutions{
|
||||
WorkflowID: id,
|
||||
ResourceID: dc_id,
|
||||
Executions: execs,
|
||||
}).Serialize(), wfa.Caller)
|
||||
if err != nil && b == nil {
|
||||
return err
|
||||
}
|
||||
var response map[string]interface{}
|
||||
json.Unmarshal(resp, &response)
|
||||
if code, ok := response["code"]; ok && code != 200 {
|
||||
return errors.New(fmt.Sprintf("%v", response["error"]))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -136,9 +132,17 @@ func (wfa *workflowMongoAccessor) book(id string, realData *Workflow, execs []*w
|
||||
}
|
||||
|
||||
func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delete bool) (int, error) {
|
||||
if realData.Schedule == nil {
|
||||
if realData.Schedule == nil && realData.ScheduleActive {
|
||||
return 200, nil
|
||||
}
|
||||
if realData.Schedule == nil && !realData.ScheduleActive {
|
||||
mongo.MONGOService.DeleteMultiple(map[string]interface{}{
|
||||
"state": 1,
|
||||
"workflow_id": id,
|
||||
}, utils.WORKFLOW_EXECUTION.String())
|
||||
err := wfa.book(id, realData, []*workflow_execution.WorkflowExecution{})
|
||||
return 200, err
|
||||
}
|
||||
res, _, _ := wfa.LoadOne(id)
|
||||
r := res.(*Workflow)
|
||||
if r.Schedule != nil && r.Schedule.Start == realData.Schedule.Start && r.Schedule.End == realData.Schedule.End && r.Schedule.Cron == realData.Schedule.Cron {
|
||||
@@ -159,7 +163,7 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet
|
||||
"state": 1,
|
||||
}, utils.WORKFLOW_EXECUTION.String())
|
||||
}
|
||||
if err == nil && len(execs) > 0 {
|
||||
if len(execs) > 0 {
|
||||
for _, obj := range execs {
|
||||
_, code, err := accessor.StoreOne(obj)
|
||||
if code != 200 {
|
||||
|
Reference in New Issue
Block a user