From 99693d8ec0a3129ce515b76b3c5c1ff85b0dc590 Mon Sep 17 00:00:00 2001 From: mr Date: Thu, 23 Jan 2025 08:35:28 +0100 Subject: [PATCH] light modification --- dbs/mongo/mongo.go | 2 -- .../collaborative_area/collaborative_area.go | 2 -- models/resources/models.go | 3 -- models/resources/resource.go | 6 ---- models/workflow/workflow_mongo_accessor.go | 3 -- .../workflow_execution_mongo_accessor.go | 28 ++++++++++++++----- .../workflow_execution/workflow_scheduler.go | 2 -- models/workspace/workspace_mongo_accessor.go | 2 -- tools/api.go | 2 -- tools/remote_caller.go | 4 --- 10 files changed, 21 insertions(+), 33 deletions(-) diff --git a/dbs/mongo/mongo.go b/dbs/mongo/mongo.go index 6983747..6b46812 100644 --- a/dbs/mongo/mongo.go +++ b/dbs/mongo/mongo.go @@ -3,7 +3,6 @@ package mongo import ( "context" "errors" - "fmt" "slices" "time" @@ -289,7 +288,6 @@ func (m *MongoDB) Search(filters *dbs.Filters, collection_name string) (*mongo.C } opts := options.Find() opts.SetLimit(100) - fmt.Println("Filters: ", CollectionMap, collection_name) targetDBCollection := CollectionMap[collection_name] orList := bson.A{} andList := bson.A{} diff --git a/models/collaborative_area/collaborative_area.go b/models/collaborative_area/collaborative_area.go index 07d4918..3d6fc38 100644 --- a/models/collaborative_area/collaborative_area.go +++ b/models/collaborative_area/collaborative_area.go @@ -1,7 +1,6 @@ package collaborative_area import ( - "fmt" "slices" "time" @@ -72,7 +71,6 @@ func (ao *CollaborativeArea) Clear(peerID string) { func (ao *CollaborativeArea) VerifyAuth(request *tools.APIRequest) bool { if (ao.AllowedPeersGroup != nil || config.GetConfig().Whitelist) && request != nil { if grps, ok := ao.AllowedPeersGroup[request.PeerID]; ok || config.GetConfig().Whitelist { - fmt.Println("grps", grps, "ok", ok, "config.GetConfig().Whitelist", config.GetConfig().Whitelist) if slices.Contains(grps, "*") || (!ok && config.GetConfig().Whitelist) { return true } diff --git a/models/resources/models.go b/models/resources/models.go index 1781b16..01eb610 100644 --- a/models/resources/models.go +++ b/models/resources/models.go @@ -1,8 +1,6 @@ package resources import ( - "fmt" - "cloud.o-forge.io/core/oc-lib/models/utils" "cloud.o-forge.io/core/oc-lib/tools" ) @@ -38,7 +36,6 @@ func (r *ResourceSet) Fill(request *tools.APIRequest) { (&ProcessingResource{}): r.Processings, (&WorkflowResource{}): r.Workflows, } { - fmt.Println(len(v), k) for _, id := range v { d, _, e := k.GetAccessor(request).LoadOne(id) if e == nil { diff --git a/models/resources/resource.go b/models/resources/resource.go index 095d429..882013a 100644 --- a/models/resources/resource.go +++ b/models/resources/resource.go @@ -1,7 +1,6 @@ package resources import ( - "fmt" "slices" "cloud.o-forge.io/core/oc-lib/config" @@ -101,17 +100,13 @@ func (abs *AbstractIntanciatedResource[T]) VerifyAuth(request *tools.APIRequest) func verifyAuthAction[T ResourceInstanceITF](baseInstance []T, request *tools.APIRequest) []T { instances := []T{} - fmt.Println("baseInstance", baseInstance) for _, instance := range baseInstance { _, peerGroups := instance.GetPeerGroups() - fmt.Println("peerGroups", peerGroups, request) for _, peers := range peerGroups { if request == nil { continue } - fmt.Println("request.PeerID]", peers[request.PeerID]) if grps, ok := peers[request.PeerID]; ok || config.GetConfig().Whitelist { - fmt.Println("grps", grps, request.Groups) if (ok && slices.Contains(grps, "*")) || (!ok && config.GetConfig().Whitelist) { instances = append(instances, instance) continue @@ -160,7 +155,6 @@ func (ri *ResourceInstance[T]) GetPricingsProfiles(peerID string, groups []strin func (ri *ResourceInstance[T]) GetPeerGroups() ([]ResourcePartnerITF, []map[string][]string) { groups := []map[string][]string{} partners := []ResourcePartnerITF{} - fmt.Println("ri.Partnerships", ri.Partnerships) for _, p := range ri.Partnerships { partners = append(partners, p) groups = append(groups, p.GetPeerGroups()) diff --git a/models/workflow/workflow_mongo_accessor.go b/models/workflow/workflow_mongo_accessor.go index a0e782b..428808f 100644 --- a/models/workflow/workflow_mongo_accessor.go +++ b/models/workflow/workflow_mongo_accessor.go @@ -1,8 +1,6 @@ package workflow import ( - "fmt" - "cloud.o-forge.io/core/oc-lib/dbs" "cloud.o-forge.io/core/oc-lib/logs" "cloud.o-forge.io/core/oc-lib/models/collaborative_area/shallow_collaborative_area" @@ -91,7 +89,6 @@ func (a *workflowMongoAccessor) share(realData *Workflow, delete bool, caller *t // UpdateOne updates a workflow in the database func (a *workflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) { // avoid the update if the schedule is the same - fmt.Println(len(set.(*Workflow).Graph.Links)) res, code, err := utils.GenericUpdateOne(set, id, a, &Workflow{}) if code != 200 { return nil, code, err diff --git a/models/workflow_execution/workflow_execution_mongo_accessor.go b/models/workflow_execution/workflow_execution_mongo_accessor.go index c08137c..64dfed1 100644 --- a/models/workflow_execution/workflow_execution_mongo_accessor.go +++ b/models/workflow_execution/workflow_execution_mongo_accessor.go @@ -13,11 +13,24 @@ import ( type workflowExecutionMongoAccessor struct { utils.AbstractAccessor + shallow bool +} + +func newShallowAccessor(request *tools.APIRequest) *workflowExecutionMongoAccessor { + return &workflowExecutionMongoAccessor{ + shallow: true, + AbstractAccessor: utils.AbstractAccessor{ + Logger: logs.CreateLogger(tools.WORKFLOW_EXECUTION.String()), // Create a logger with the data type + Request: request, + Type: tools.WORKFLOW_EXECUTION, + }, + } } func NewAccessor(request *tools.APIRequest) *workflowExecutionMongoAccessor { return &workflowExecutionMongoAccessor{ - utils.AbstractAccessor{ + shallow: false, + AbstractAccessor: utils.AbstractAccessor{ Logger: logs.CreateLogger(tools.WORKFLOW_EXECUTION.String()), // Create a logger with the data type Request: request, Type: tools.WORKFLOW_EXECUTION, @@ -43,13 +56,13 @@ func (wfa *workflowExecutionMongoAccessor) CopyOne(data utils.DBObject) (utils.D func (a *workflowExecutionMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) { return utils.GenericLoadOne[*WorkflowExecutions](id, func(d utils.DBObject) (utils.DBObject, int, error) { - if d.(*WorkflowExecutions).State == enum.DRAFT && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) { - utils.GenericDeleteOne(d.GetID(), a) + if d.(*WorkflowExecutions).State == enum.DRAFT && !a.shallow && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) { + utils.GenericDeleteOne(d.GetID(), newShallowAccessor(a.Request)) return nil, 404, errors.New("not found") } - if d.(*WorkflowExecutions).State == enum.SCHEDULED && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) { + if d.(*WorkflowExecutions).State == enum.SCHEDULED && !a.shallow && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) { d.(*WorkflowExecutions).State = enum.FORGOTTEN - utils.GenericRawUpdateOne(d, id, a) + utils.GenericRawUpdateOne(d, id, newShallowAccessor(a.Request)) } return d, 200, nil }, a) @@ -66,12 +79,13 @@ func (a *workflowExecutionMongoAccessor) Search(filters *dbs.Filters, search str func (a *workflowExecutionMongoAccessor) getExec() func(utils.DBObject) utils.ShallowDBObject { return func(d utils.DBObject) utils.ShallowDBObject { if d.(*WorkflowExecutions).State == enum.DRAFT && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) { - utils.GenericDeleteOne(d.GetID(), a) + utils.GenericDeleteOne(d.GetID(), newShallowAccessor(a.Request)) return nil } if d.(*WorkflowExecutions).State == enum.SCHEDULED && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) { d.(*WorkflowExecutions).State = enum.FORGOTTEN - utils.GenericRawUpdateOne(d, d.GetID(), a) + d, _, _ = utils.GenericRawUpdateOne(d, d.GetID(), newShallowAccessor(a.Request)) + return d } return d } diff --git a/models/workflow_execution/workflow_scheduler.go b/models/workflow_execution/workflow_scheduler.go index 98d2f61..3398371 100644 --- a/models/workflow_execution/workflow_scheduler.go +++ b/models/workflow_execution/workflow_scheduler.go @@ -58,7 +58,6 @@ func (ws *WorkflowSchedule) CheckBooking(wfID string, request *tools.APIRequest) } wf := res.(*workflow.Workflow) longest, priceds, wf, err := wf.Planify(ws.Start, ws.End, request) - fmt.Println("longest", longest, err) if err != nil { return false, wf, []*WorkflowExecutions{}, err } @@ -68,7 +67,6 @@ func (ws *WorkflowSchedule) CheckBooking(wfID string, request *tools.APIRequest) ws.Warning = "The workflow may be too long to be executed in the given time frame, we will try to book it anyway\n" } execs, err := ws.getExecutions(wf) - fmt.Println("execs", execs, err) if err != nil { return false, wf, []*WorkflowExecutions{}, err } diff --git a/models/workspace/workspace_mongo_accessor.go b/models/workspace/workspace_mongo_accessor.go index 4b6fcb5..9d46842 100644 --- a/models/workspace/workspace_mongo_accessor.go +++ b/models/workspace/workspace_mongo_accessor.go @@ -2,7 +2,6 @@ package workspace import ( "errors" - "fmt" "cloud.o-forge.io/core/oc-lib/dbs" "cloud.o-forge.io/core/oc-lib/logs" @@ -116,7 +115,6 @@ func (a *workspaceMongoAccessor) Search(filters *dbs.Filters, search string, isD This function is used to share the workspace with the peers */ func (a *workspaceMongoAccessor) share(realData *Workspace, method tools.METHOD, caller *tools.HTTPCaller) { - fmt.Println("Sharing workspace", realData, caller) if realData == nil || realData.Shared == "" || caller == nil || caller.Disabled { return } diff --git a/tools/api.go b/tools/api.go index 4877a35..f5d2110 100644 --- a/tools/api.go +++ b/tools/api.go @@ -3,7 +3,6 @@ package tools import ( "encoding/json" "errors" - "fmt" "strings" "cloud.o-forge.io/core/oc-lib/config" @@ -150,7 +149,6 @@ func (a *API) CheckRemoteAPIs(apis []DataType) (State, map[string]string, error) continue } json.Unmarshal(b, &resp) - fmt.Println(string(b)) if resp.Data == nil { // state = REDUCED_SERVICE // If the response is empty, return reduced service continue diff --git a/tools/remote_caller.go b/tools/remote_caller.go index 64dbde7..3a65ff1 100644 --- a/tools/remote_caller.go +++ b/tools/remote_caller.go @@ -3,7 +3,6 @@ package tools import ( "bytes" "encoding/json" - "fmt" "io" "net/http" "net/url" @@ -94,17 +93,14 @@ func (caller *HTTPCaller) CallDelete(url string, subpath string) ([]byte, error) func (caller *HTTPCaller) CallPost(url string, subpath string, body interface{}, types ...string) ([]byte, error) { postBody, err := json.Marshal(body) if err != nil { - fmt.Println(postBody) return nil, err } responseBody := bytes.NewBuffer(postBody) - fmt.Println(responseBody) contentType := "application/json" if len(types) > 0 { contentType = types[0] } resp, err := http.Post(url+subpath, contentType, responseBody) - fmt.Println(resp, err) if err != nil || resp == nil || resp.Body == nil { return nil, err }