light modification
This commit is contained in:
parent
0e798dac50
commit
99693d8ec0
@ -3,7 +3,6 @@ package mongo
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"slices"
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -289,7 +288,6 @@ func (m *MongoDB) Search(filters *dbs.Filters, collection_name string) (*mongo.C
|
|||||||
}
|
}
|
||||||
opts := options.Find()
|
opts := options.Find()
|
||||||
opts.SetLimit(100)
|
opts.SetLimit(100)
|
||||||
fmt.Println("Filters: ", CollectionMap, collection_name)
|
|
||||||
targetDBCollection := CollectionMap[collection_name]
|
targetDBCollection := CollectionMap[collection_name]
|
||||||
orList := bson.A{}
|
orList := bson.A{}
|
||||||
andList := bson.A{}
|
andList := bson.A{}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package collaborative_area
|
package collaborative_area
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"slices"
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -72,7 +71,6 @@ func (ao *CollaborativeArea) Clear(peerID string) {
|
|||||||
func (ao *CollaborativeArea) VerifyAuth(request *tools.APIRequest) bool {
|
func (ao *CollaborativeArea) VerifyAuth(request *tools.APIRequest) bool {
|
||||||
if (ao.AllowedPeersGroup != nil || config.GetConfig().Whitelist) && request != nil {
|
if (ao.AllowedPeersGroup != nil || config.GetConfig().Whitelist) && request != nil {
|
||||||
if grps, ok := ao.AllowedPeersGroup[request.PeerID]; ok || config.GetConfig().Whitelist {
|
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) {
|
if slices.Contains(grps, "*") || (!ok && config.GetConfig().Whitelist) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package resources
|
package resources
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
)
|
)
|
||||||
@ -38,7 +36,6 @@ func (r *ResourceSet) Fill(request *tools.APIRequest) {
|
|||||||
(&ProcessingResource{}): r.Processings,
|
(&ProcessingResource{}): r.Processings,
|
||||||
(&WorkflowResource{}): r.Workflows,
|
(&WorkflowResource{}): r.Workflows,
|
||||||
} {
|
} {
|
||||||
fmt.Println(len(v), k)
|
|
||||||
for _, id := range v {
|
for _, id := range v {
|
||||||
d, _, e := k.GetAccessor(request).LoadOne(id)
|
d, _, e := k.GetAccessor(request).LoadOne(id)
|
||||||
if e == nil {
|
if e == nil {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package resources
|
package resources
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"slices"
|
"slices"
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/config"
|
"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 {
|
func verifyAuthAction[T ResourceInstanceITF](baseInstance []T, request *tools.APIRequest) []T {
|
||||||
instances := []T{}
|
instances := []T{}
|
||||||
fmt.Println("baseInstance", baseInstance)
|
|
||||||
for _, instance := range baseInstance {
|
for _, instance := range baseInstance {
|
||||||
_, peerGroups := instance.GetPeerGroups()
|
_, peerGroups := instance.GetPeerGroups()
|
||||||
fmt.Println("peerGroups", peerGroups, request)
|
|
||||||
for _, peers := range peerGroups {
|
for _, peers := range peerGroups {
|
||||||
if request == nil {
|
if request == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Println("request.PeerID]", peers[request.PeerID])
|
|
||||||
if grps, ok := peers[request.PeerID]; ok || config.GetConfig().Whitelist {
|
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) {
|
if (ok && slices.Contains(grps, "*")) || (!ok && config.GetConfig().Whitelist) {
|
||||||
instances = append(instances, instance)
|
instances = append(instances, instance)
|
||||||
continue
|
continue
|
||||||
@ -160,7 +155,6 @@ func (ri *ResourceInstance[T]) GetPricingsProfiles(peerID string, groups []strin
|
|||||||
func (ri *ResourceInstance[T]) GetPeerGroups() ([]ResourcePartnerITF, []map[string][]string) {
|
func (ri *ResourceInstance[T]) GetPeerGroups() ([]ResourcePartnerITF, []map[string][]string) {
|
||||||
groups := []map[string][]string{}
|
groups := []map[string][]string{}
|
||||||
partners := []ResourcePartnerITF{}
|
partners := []ResourcePartnerITF{}
|
||||||
fmt.Println("ri.Partnerships", ri.Partnerships)
|
|
||||||
for _, p := range ri.Partnerships {
|
for _, p := range ri.Partnerships {
|
||||||
partners = append(partners, p)
|
partners = append(partners, p)
|
||||||
groups = append(groups, p.GetPeerGroups())
|
groups = append(groups, p.GetPeerGroups())
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package workflow
|
package workflow
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||||
"cloud.o-forge.io/core/oc-lib/logs"
|
"cloud.o-forge.io/core/oc-lib/logs"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/collaborative_area/shallow_collaborative_area"
|
"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
|
// UpdateOne updates a workflow in the database
|
||||||
func (a *workflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
func (a *workflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||||
// avoid the update if the schedule is the same
|
// 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{})
|
res, code, err := utils.GenericUpdateOne(set, id, a, &Workflow{})
|
||||||
if code != 200 {
|
if code != 200 {
|
||||||
return nil, code, err
|
return nil, code, err
|
||||||
|
@ -13,11 +13,24 @@ import (
|
|||||||
|
|
||||||
type workflowExecutionMongoAccessor struct {
|
type workflowExecutionMongoAccessor struct {
|
||||||
utils.AbstractAccessor
|
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 {
|
func NewAccessor(request *tools.APIRequest) *workflowExecutionMongoAccessor {
|
||||||
return &workflowExecutionMongoAccessor{
|
return &workflowExecutionMongoAccessor{
|
||||||
utils.AbstractAccessor{
|
shallow: false,
|
||||||
|
AbstractAccessor: utils.AbstractAccessor{
|
||||||
Logger: logs.CreateLogger(tools.WORKFLOW_EXECUTION.String()), // Create a logger with the data type
|
Logger: logs.CreateLogger(tools.WORKFLOW_EXECUTION.String()), // Create a logger with the data type
|
||||||
Request: request,
|
Request: request,
|
||||||
Type: tools.WORKFLOW_EXECUTION,
|
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) {
|
func (a *workflowExecutionMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||||
return utils.GenericLoadOne[*WorkflowExecutions](id, func(d utils.DBObject) (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) {
|
if d.(*WorkflowExecutions).State == enum.DRAFT && !a.shallow && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
|
||||||
utils.GenericDeleteOne(d.GetID(), a)
|
utils.GenericDeleteOne(d.GetID(), newShallowAccessor(a.Request))
|
||||||
return nil, 404, errors.New("not found")
|
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
|
d.(*WorkflowExecutions).State = enum.FORGOTTEN
|
||||||
utils.GenericRawUpdateOne(d, id, a)
|
utils.GenericRawUpdateOne(d, id, newShallowAccessor(a.Request))
|
||||||
}
|
}
|
||||||
return d, 200, nil
|
return d, 200, nil
|
||||||
}, a)
|
}, a)
|
||||||
@ -66,12 +79,13 @@ func (a *workflowExecutionMongoAccessor) Search(filters *dbs.Filters, search str
|
|||||||
func (a *workflowExecutionMongoAccessor) getExec() func(utils.DBObject) utils.ShallowDBObject {
|
func (a *workflowExecutionMongoAccessor) getExec() func(utils.DBObject) utils.ShallowDBObject {
|
||||||
return func(d utils.DBObject) utils.ShallowDBObject {
|
return func(d utils.DBObject) utils.ShallowDBObject {
|
||||||
if d.(*WorkflowExecutions).State == enum.DRAFT && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
if d.(*WorkflowExecutions).State == enum.SCHEDULED && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
|
if d.(*WorkflowExecutions).State == enum.SCHEDULED && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
|
||||||
d.(*WorkflowExecutions).State = enum.FORGOTTEN
|
d.(*WorkflowExecutions).State = enum.FORGOTTEN
|
||||||
utils.GenericRawUpdateOne(d, d.GetID(), a)
|
d, _, _ = utils.GenericRawUpdateOne(d, d.GetID(), newShallowAccessor(a.Request))
|
||||||
|
return d
|
||||||
}
|
}
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,6 @@ func (ws *WorkflowSchedule) CheckBooking(wfID string, request *tools.APIRequest)
|
|||||||
}
|
}
|
||||||
wf := res.(*workflow.Workflow)
|
wf := res.(*workflow.Workflow)
|
||||||
longest, priceds, wf, err := wf.Planify(ws.Start, ws.End, request)
|
longest, priceds, wf, err := wf.Planify(ws.Start, ws.End, request)
|
||||||
fmt.Println("longest", longest, err)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, wf, []*WorkflowExecutions{}, err
|
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"
|
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)
|
execs, err := ws.getExecutions(wf)
|
||||||
fmt.Println("execs", execs, err)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, wf, []*WorkflowExecutions{}, err
|
return false, wf, []*WorkflowExecutions{}, err
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package workspace
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||||
"cloud.o-forge.io/core/oc-lib/logs"
|
"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
|
This function is used to share the workspace with the peers
|
||||||
*/
|
*/
|
||||||
func (a *workspaceMongoAccessor) share(realData *Workspace, method tools.METHOD, caller *tools.HTTPCaller) {
|
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 {
|
if realData == nil || realData.Shared == "" || caller == nil || caller.Disabled {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package tools
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/config"
|
"cloud.o-forge.io/core/oc-lib/config"
|
||||||
@ -150,7 +149,6 @@ func (a *API) CheckRemoteAPIs(apis []DataType) (State, map[string]string, error)
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
json.Unmarshal(b, &resp)
|
json.Unmarshal(b, &resp)
|
||||||
fmt.Println(string(b))
|
|
||||||
if resp.Data == nil { //
|
if resp.Data == nil { //
|
||||||
state = REDUCED_SERVICE // If the response is empty, return reduced service
|
state = REDUCED_SERVICE // If the response is empty, return reduced service
|
||||||
continue
|
continue
|
||||||
|
@ -3,7 +3,6 @@ package tools
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"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) {
|
func (caller *HTTPCaller) CallPost(url string, subpath string, body interface{}, types ...string) ([]byte, error) {
|
||||||
postBody, err := json.Marshal(body)
|
postBody, err := json.Marshal(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(postBody)
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
responseBody := bytes.NewBuffer(postBody)
|
responseBody := bytes.NewBuffer(postBody)
|
||||||
fmt.Println(responseBody)
|
|
||||||
contentType := "application/json"
|
contentType := "application/json"
|
||||||
if len(types) > 0 {
|
if len(types) > 0 {
|
||||||
contentType = types[0]
|
contentType = types[0]
|
||||||
}
|
}
|
||||||
resp, err := http.Post(url+subpath, contentType, responseBody)
|
resp, err := http.Post(url+subpath, contentType, responseBody)
|
||||||
fmt.Println(resp, err)
|
|
||||||
if err != nil || resp == nil || resp.Body == nil {
|
if err != nil || resp == nil || resp.Body == nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user