precise workspace flow
This commit is contained in:
parent
274ce57f5b
commit
e311553eb1
@ -3,9 +3,9 @@ package oclib
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
|
||||
"cloud.o-forge.io/core/oc-lib/models/workspace"
|
||||
@ -74,7 +74,38 @@ func (wfa *workflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (util
|
||||
if code, err := wfa.execution(set.(*Workflow), true); err != nil {
|
||||
return nil, code, err
|
||||
}
|
||||
return wfa.GenericUpdateOne(set, id, wfa, &Workflow{})
|
||||
res, code, err := wfa.GenericUpdateOne(set, id, wfa, &Workflow{})
|
||||
if code != 200 {
|
||||
return nil, code, err
|
||||
}
|
||||
workflow := res.(*Workflow)
|
||||
accessor := (&workspace.Workspace{}).GetAccessor()
|
||||
resource, _, err := accessor.Search(workflow.Name+"_workspace", "abstractobject.name")
|
||||
if err == nil && len(resource) > 0 {
|
||||
for _, r := range resource {
|
||||
accessor.UpdateOne(&workspace.Workspace{
|
||||
ResourceSet: resources.ResourceSet{
|
||||
Datas: workflow.Datas,
|
||||
Processings: workflow.Processings,
|
||||
Storages: workflow.Storages,
|
||||
Workflows: workflow.Workflows,
|
||||
Datacenters: workflow.Datacenters,
|
||||
},
|
||||
}, r.GetID())
|
||||
}
|
||||
} else {
|
||||
accessor.StoreOne(&workspace.Workspace{
|
||||
AbstractObject: utils.AbstractObject{Name: workflow.Name + "_workspace"},
|
||||
ResourceSet: resources.ResourceSet{
|
||||
Datas: workflow.Datas,
|
||||
Processings: workflow.Processings,
|
||||
Storages: workflow.Storages,
|
||||
Workflows: workflow.Workflows,
|
||||
Datacenters: workflow.Datacenters,
|
||||
},
|
||||
})
|
||||
}
|
||||
return res, code, err
|
||||
}
|
||||
|
||||
func (wfa *workflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
@ -101,43 +132,31 @@ func (wfa *workflowMongoAccessor) LoadOne(id string) (utils.DBObject, int, error
|
||||
}
|
||||
res_mongo.Decode(&workflow)
|
||||
// add to workspace
|
||||
access := (&workspace.Workspace{}).GetAccessor()
|
||||
ws, _, err := mongo.MONGOService.LoadFilter(map[string]interface{}{
|
||||
"active": true,
|
||||
}, utils.WORKSPACE.String())
|
||||
if err == nil {
|
||||
var results []workspace.Workspace
|
||||
if err = ws.All(mongo.MngoCtx, &results); err != nil {
|
||||
return nil, 404, err
|
||||
}
|
||||
for _, res := range results {
|
||||
for _, w := range workflow.Workflows {
|
||||
if !slices.Contains(res.Workflows, w) {
|
||||
res.Workflows = append(res.Workflows, w)
|
||||
}
|
||||
}
|
||||
for _, w := range workflow.Datas {
|
||||
if !slices.Contains(res.Datas, w) {
|
||||
res.Datas = append(res.Datas, w)
|
||||
}
|
||||
}
|
||||
for _, w := range workflow.Datacenters {
|
||||
if !slices.Contains(res.Datacenters, w) {
|
||||
res.Datacenters = append(res.Datacenters, w)
|
||||
}
|
||||
}
|
||||
for _, w := range workflow.Storages {
|
||||
if !slices.Contains(res.Storages, w) {
|
||||
res.Storages = append(res.Storages, w)
|
||||
}
|
||||
}
|
||||
for _, w := range workflow.Processings {
|
||||
if !slices.Contains(res.Processings, w) {
|
||||
res.Processings = append(res.Processings, w)
|
||||
}
|
||||
}
|
||||
access.UpdateOne(&res, res.GetID())
|
||||
accessor := (&workspace.Workspace{}).GetAccessor()
|
||||
resource, _, err := accessor.Search(workflow.Name+"_workspace", "abstractobject.name")
|
||||
if err == nil && len(resource) > 0 {
|
||||
for _, r := range resource {
|
||||
accessor.UpdateOne(&workspace.Workspace{
|
||||
ResourceSet: resources.ResourceSet{
|
||||
Datas: workflow.Datas,
|
||||
Processings: workflow.Processings,
|
||||
Storages: workflow.Storages,
|
||||
Workflows: workflow.Workflows,
|
||||
Datacenters: workflow.Datacenters,
|
||||
},
|
||||
}, r.GetID())
|
||||
}
|
||||
} else {
|
||||
accessor.StoreOne(&workspace.Workspace{
|
||||
AbstractObject: utils.AbstractObject{Name: workflow.Name + "_workspace"},
|
||||
ResourceSet: resources.ResourceSet{
|
||||
Datas: workflow.Datas,
|
||||
Processings: workflow.Processings,
|
||||
Storages: workflow.Storages,
|
||||
Workflows: workflow.Workflows,
|
||||
Datacenters: workflow.Datacenters,
|
||||
},
|
||||
})
|
||||
}
|
||||
return &workflow, 200, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user