|
|
|
@@ -22,11 +22,21 @@ import (
|
|
|
|
|
|
|
|
|
|
type workflowMongoAccessor struct {
|
|
|
|
|
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
|
|
|
|
|
|
|
|
|
computeResourceAccessor utils.Accessor
|
|
|
|
|
collaborativeAreaAccessor utils.Accessor
|
|
|
|
|
executionAccessor utils.Accessor
|
|
|
|
|
workspaceAccessor utils.Accessor
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// New creates a new instance of the workflowMongoAccessor
|
|
|
|
|
func New() *workflowMongoAccessor {
|
|
|
|
|
return &workflowMongoAccessor{}
|
|
|
|
|
func New(peerID string, groups []string) *workflowMongoAccessor {
|
|
|
|
|
return &workflowMongoAccessor{
|
|
|
|
|
computeResourceAccessor: (&compute.ComputeResource{}).GetAccessor(peerID, groups, nil),
|
|
|
|
|
collaborativeAreaAccessor: (&shallow_collaborative_area.ShallowCollaborativeArea{}).GetAccessor(peerID, groups, nil),
|
|
|
|
|
executionAccessor: (&workflow_execution.WorkflowExecution{}).GetAccessor(peerID, groups, nil),
|
|
|
|
|
workspaceAccessor: (&workspace.Workspace{}).GetAccessor(peerID, groups, nil),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@@ -127,7 +137,6 @@ func (wfa *workflowMongoAccessor) book(id string, realData *Workflow, execs []*w
|
|
|
|
|
g = realData.Graph
|
|
|
|
|
}
|
|
|
|
|
if g != nil && g.Links != nil && len(g.Links) > 0 { // if the graph is set and has links then book the workflow (even on ourselves)
|
|
|
|
|
accessor := (&compute.ComputeResource{}).GetAccessor(nil)
|
|
|
|
|
isDCFound := []string{}
|
|
|
|
|
for _, link := range g.Links {
|
|
|
|
|
if ok, dc_id := realData.isDCLink(link); ok { // check if the link is a link between a compute and a resource booking is only on compute
|
|
|
|
@@ -135,7 +144,7 @@ func (wfa *workflowMongoAccessor) book(id string, realData *Workflow, execs []*w
|
|
|
|
|
continue
|
|
|
|
|
} // if the compute is already found, skip it
|
|
|
|
|
isDCFound = append(isDCFound, dc_id)
|
|
|
|
|
dc, code, _ := accessor.LoadOne(dc_id)
|
|
|
|
|
dc, code, _ := wfa.computeResourceAccessor.LoadOne(dc_id)
|
|
|
|
|
if code != 200 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
@@ -169,8 +178,7 @@ func (wfa *workflowMongoAccessor) share(realData *Workflow, delete bool, caller
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
for _, sharedID := range realData.Shared { // loop through the shared ids
|
|
|
|
|
access := (&shallow_collaborative_area.ShallowCollaborativeArea{}).GetAccessor(nil)
|
|
|
|
|
res, code, _ := access.LoadOne(sharedID)
|
|
|
|
|
res, code, _ := wfa.collaborativeAreaAccessor.LoadOne(sharedID)
|
|
|
|
|
if code != 200 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
@@ -186,7 +194,8 @@ func (wfa *workflowMongoAccessor) share(realData *Workflow, delete bool, caller
|
|
|
|
|
history.StoreOne(history.MapFromWorkflow(res.(*Workflow)))
|
|
|
|
|
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKFLOW, tools.DELETE, map[string]interface{}{}, caller)
|
|
|
|
|
} else { // if the workflow is updated, share the update
|
|
|
|
|
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKFLOW, tools.PUT, res.Serialize(), caller)
|
|
|
|
|
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKFLOW, tools.PUT,
|
|
|
|
|
res.Serialize(res), caller)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
@@ -211,7 +220,6 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet
|
|
|
|
|
return 409, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
accessor := (&workflow_execution.WorkflowExecution{}).GetAccessor(nil)
|
|
|
|
|
execs, err := wfa.getExecutions(id, realData) // get the executions of the workflow
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 422, err
|
|
|
|
@@ -226,7 +234,7 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet
|
|
|
|
|
}
|
|
|
|
|
fmt.Println("BOOKING", delete)
|
|
|
|
|
for _, obj := range execs {
|
|
|
|
|
_, code, err := accessor.StoreOne(obj)
|
|
|
|
|
_, code, err := wfa.executionAccessor.StoreOne(obj)
|
|
|
|
|
fmt.Println("EXEC", code, err)
|
|
|
|
|
if code != 200 {
|
|
|
|
|
return code, err
|
|
|
|
@@ -301,21 +309,20 @@ func (wfa *workflowMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject,
|
|
|
|
|
// it stores the workflow resources in a specific workspace to never have a conflict in UI and logic
|
|
|
|
|
func (wfa *workflowMongoAccessor) execute(workflow *Workflow, delete bool, active bool) {
|
|
|
|
|
|
|
|
|
|
accessor := (&workspace.Workspace{}).GetAccessor(nil)
|
|
|
|
|
filters := &dbs.Filters{
|
|
|
|
|
Or: map[string][]dbs.Filter{ // filter by standard workspace name attached to a workflow
|
|
|
|
|
"abstractobject.name": {{dbs.LIKE.String(), workflow.Name + "_workspace"}},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
resource, _, err := accessor.Search(filters, "")
|
|
|
|
|
resource, _, err := wfa.workspaceAccessor.Search(filters, "")
|
|
|
|
|
if delete { // if delete is set to true, delete the workspace
|
|
|
|
|
for _, r := range resource {
|
|
|
|
|
accessor.DeleteOne(r.GetID())
|
|
|
|
|
wfa.workspaceAccessor.DeleteOne(r.GetID())
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if err == nil && len(resource) > 0 { // if the workspace already exists, update it
|
|
|
|
|
accessor.UpdateOne(&workspace.Workspace{
|
|
|
|
|
wfa.workspaceAccessor.UpdateOne(&workspace.Workspace{
|
|
|
|
|
Active: active,
|
|
|
|
|
ResourceSet: resources.ResourceSet{
|
|
|
|
|
Datas: workflow.Datas,
|
|
|
|
@@ -326,7 +333,7 @@ func (wfa *workflowMongoAccessor) execute(workflow *Workflow, delete bool, activ
|
|
|
|
|
},
|
|
|
|
|
}, resource[0].GetID())
|
|
|
|
|
} else { // if the workspace does not exist, create it
|
|
|
|
|
accessor.StoreOne(&workspace.Workspace{
|
|
|
|
|
wfa.workspaceAccessor.StoreOne(&workspace.Workspace{
|
|
|
|
|
Active: active,
|
|
|
|
|
AbstractObject: utils.AbstractObject{Name: workflow.Name + "_workspace"},
|
|
|
|
|
ResourceSet: resources.ResourceSet{
|
|
|
|
@@ -354,7 +361,6 @@ func (wfa *workflowMongoAccessor) LoadOne(id string) (utils.DBObject, int, error
|
|
|
|
|
if (workflow.Schedule.End != nil && now.After(*workflow.Schedule.End)) || (workflow.Schedule.End == nil && workflow.Schedule.Start != nil && now.After(*workflow.Schedule.Start)) { // if the start date is passed, then you can book
|
|
|
|
|
workflow.ScheduleActive = false
|
|
|
|
|
wfa.GenericRawUpdateOne(&workflow, id, wfa)
|
|
|
|
|
|
|
|
|
|
} // if the start date is passed, update the executions
|
|
|
|
|
}
|
|
|
|
|
wfa.execute(&workflow, false, true) // if no workspace is attached to the workflow, create it
|
|
|
|
|