add shared logic on peer

This commit is contained in:
mr
2024-08-30 09:14:03 +02:00
parent 2e8246fb2f
commit db78c70dc3
7 changed files with 216 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
package oclib
package workflow
import (
"encoding/json"

View File

@@ -1,4 +1,4 @@
package oclib
package workflow
import (
"errors"
@@ -13,6 +13,7 @@ import (
"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"
"cloud.o-forge.io/core/oc-lib/models/workspace/shared/shallow_shared_workspace"
"cloud.o-forge.io/core/oc-lib/tools"
cron "github.com/robfig/cron/v3"
)
@@ -86,6 +87,7 @@ func (wfa *workflowMongoAccessor) DeleteOne(id string) (utils.DBObject, int, err
if res != nil && code == 200 {
wfa.execute(res.(*Workflow), false)
}
wfa.share(res.(*Workflow), true, wfa.Caller)
return res, code, err
}
@@ -134,6 +136,35 @@ func (wfa *workflowMongoAccessor) book(id string, realData *Workflow, execs []*w
return nil
}
func (wfa *workflowMongoAccessor) share(realData *Workflow, delete bool, caller *tools.HTTPCaller) {
if realData.Shared == nil || len(realData.Shared) == 0 {
return
}
for _, sharedID := range realData.Shared {
access := (&shallow_shared_workspace.ShallowSharedWorkspace{}).GetAccessor(nil)
res, code, _ := access.LoadOne(sharedID)
if code != 200 {
continue
}
var err error
paccess := &peer.Peer{}
for _, p := range res.(*shallow_shared_workspace.ShallowSharedWorkspace).Peers {
paccess.UUID = p
if paccess.IsMySelf() {
continue
}
if delete {
_, err = paccess.LaunchPeerExecution(p, res.GetID(), utils.WORKFLOW, tools.DELETE, map[string]interface{}{}, caller)
} else {
_, err = paccess.LaunchPeerExecution(p, res.GetID(), utils.WORKFLOW, tools.PUT, res.Serialize(), caller)
}
}
if err != nil {
wfa.Logger.Error().Msg(err.Error())
}
}
}
func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delete bool) (int, error) {
var err error
nats := tools.NewNATSCaller()
@@ -200,16 +231,11 @@ func (wfa *workflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (util
}
}
wfa.execute(res.(*Workflow), false)
wfa.share(res.(*Workflow), false, wfa.Caller)
return res, code, err
}
func (wfa *workflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
/*new := data.(*Workflow)
for _, i := range new.Graph.Items {
if i.Datacenter == nil && i.Processing == nil && i.Storage == nil && i.Workflow == nil && i.Data == nil {
return nil, 422, errors.New("graph item should have at least one resource data is corrupted")
}
}*/
res, code, err := wfa.GenericStoreOne(data, wfa)
if err != nil {
return nil, code, err

View File

@@ -1,4 +1,4 @@
package oclib
package workflow
import "time"

View File

@@ -1,4 +1,4 @@
package oclib
package workflow
import (
"testing"