23 Commits

Author SHA1 Message Date
mr
cdf513c2c4 AT collaborative area 2024-09-27 13:23:24 +02:00
mr
eba6fd4f97 equals func on exec + draft container subobject 2024-09-27 11:45:36 +02:00
mr
1582654a9c equals func on exec + draft container subobject 2024-09-27 11:14:46 +02:00
mr
0ac55a0ec1 equals func on exec + draft container subobject 2024-09-27 08:53:14 +02:00
mr
3d58416d9b equals func on exec + draft container subobject 2024-09-26 15:52:35 +02:00
mr
279090889f add args 2024-09-25 11:44:32 +02:00
mr
8953e2cd42 delete ws 2024-09-25 10:25:13 +02:00
mr
a48bcf25e4 test booking 2024-09-25 10:06:07 +02:00
mr
2df71c6571 test booking 2024-09-25 10:02:10 +02:00
mr
89a1ab3f6e test booking 2024-09-25 09:36:10 +02:00
mr
021b461b0a test booking 2024-09-24 09:54:18 +02:00
mr
5c9adcf597 test booking 2024-09-24 09:29:59 +02:00
mr
92bb274d03 test booking 2024-09-24 09:14:56 +02:00
mr
95a4acff36 test 2024-09-23 16:15:40 +02:00
mr
50ea0969e6 test 2024-09-23 14:51:41 +02:00
mr
6acbcb6704 print to find bug 2024-09-23 14:22:05 +02:00
mr
6c9b9ea30d print to find bug 2024-09-23 11:23:51 +02:00
mr
a4374602e1 print to find bug 2024-09-23 10:59:19 +02:00
mr
610eb0cfda print to find bug 2024-09-23 10:34:08 +02:00
mr
4f798263b1 print to find bug 2024-09-23 10:12:52 +02:00
mr
a0dd8e1c42 debug on exec 2024-09-23 09:45:05 +02:00
mr
754925c32c Merge branch 'master' of https://cloud.o-forge.io/core/oc-lib 2024-09-16 16:59:12 +02:00
mr
4956166f76 failed models 2024-09-16 16:58:38 +02:00
311 changed files with 2366 additions and 151 deletions

View File

@@ -219,7 +219,7 @@ func (m *MongoDB) UpdateMultiple(set interface{}, filter map[string]interface{},
f = append(f, bson.E{Key: k, Value: v}) f = append(f, bson.E{Key: k, Value: v})
} }
targetDBCollection := CollectionMap[collection_name] targetDBCollection := CollectionMap[collection_name]
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second) MngoCtx, cancel = context.WithTimeout(context.Background(), 50*time.Second)
defer cancel() defer cancel()
res, err := targetDBCollection.UpdateMany(MngoCtx, f, dbs.InputToBson(doc, true)) res, err := targetDBCollection.UpdateMany(MngoCtx, f, dbs.InputToBson(doc, true))
if err != nil { if err != nil {
@@ -238,7 +238,7 @@ func (m *MongoDB) UpdateOne(set interface{}, id string, collection_name string)
bson.Unmarshal(b, &doc) bson.Unmarshal(b, &doc)
filter := bson.M{"_id": id} filter := bson.M{"_id": id}
targetDBCollection := CollectionMap[collection_name] targetDBCollection := CollectionMap[collection_name]
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second) MngoCtx, cancel = context.WithTimeout(context.Background(), 50*time.Second)
defer cancel() defer cancel()
_, err := targetDBCollection.UpdateOne(MngoCtx, filter, dbs.InputToBson(doc, true)) _, err := targetDBCollection.UpdateOne(MngoCtx, filter, dbs.InputToBson(doc, true))
if err != nil { if err != nil {

View File

@@ -22,7 +22,7 @@ import (
w2 "cloud.o-forge.io/core/oc-lib/models/workflow" w2 "cloud.o-forge.io/core/oc-lib/models/workflow"
"cloud.o-forge.io/core/oc-lib/models/workflow_execution" "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_workspace "cloud.o-forge.io/core/oc-lib/models/workspace/shared" collaborative_area "cloud.o-forge.io/core/oc-lib/models/workspace/shared"
"cloud.o-forge.io/core/oc-lib/models/workspace/shared/rules/rule" "cloud.o-forge.io/core/oc-lib/models/workspace/shared/rules/rule"
"cloud.o-forge.io/core/oc-lib/tools" "cloud.o-forge.io/core/oc-lib/tools"
"github.com/goraz/onion" "github.com/goraz/onion"
@@ -45,7 +45,7 @@ const (
WORKSPACE = utils.WORKSPACE WORKSPACE = utils.WORKSPACE
WORKFLOW_EXECUTION = utils.WORKFLOW_EXECUTION WORKFLOW_EXECUTION = utils.WORKFLOW_EXECUTION
PEER = utils.PEER PEER = utils.PEER
SHARED_WORKSPACE = utils.SHARED_WORKSPACE SHARED_WORKSPACE = utils.COLLABORATIVE_AREA
RULE = utils.RULE RULE = utils.RULE
BOOKING = utils.BOOKING BOOKING = utils.BOOKING
) )
@@ -146,10 +146,6 @@ func SetConfig(mongoUrl string, database string, natsUrl string, lokiUrl string,
// TODO Specify the model for each resource // TODO Specify the model for each resource
// for now only processing is specified here (not an elegant way) // for now only processing is specified here (not an elegant way)
if model == utils.PROCESSING_RESOURCE.String() { if model == utils.PROCESSING_RESOURCE.String() {
m["image"] = resource_model.Model{
Type: "string",
ReadOnly: false,
}
m["command"] = resource_model.Model{ m["command"] = resource_model.Model{
Type: "string", Type: "string",
ReadOnly: false, ReadOnly: false,
@@ -158,14 +154,16 @@ func SetConfig(mongoUrl string, database string, natsUrl string, lokiUrl string,
Type: "string", Type: "string",
ReadOnly: false, ReadOnly: false,
} }
m["execute"] = resource_model.Model{ m["env"] = resource_model.Model{
Type: "map[int]map[string]string", Type: "string",
ReadOnly: false, ReadOnly: false,
} }
} }
accessor.StoreOne(&resource_model.ResourceModel{ accessor.StoreOne(&resource_model.ResourceModel{
ResourceType: model, ResourceType: model,
Model: m, Model: map[string]map[string]resource_model.Model{
"container": m,
},
}) })
} }
} }
@@ -444,15 +442,15 @@ func (l *LibData) ToWorkspace() *workspace.Workspace {
return nil return nil
} }
func (l *LibData) ToSharedWorkspace() *shared_workspace.SharedWorkspace { func (l *LibData) ToCollaborativeArea() *collaborative_area.CollaborativeArea {
if l.Data.GetAccessor(nil).GetType() == utils.SHARED_WORKSPACE.String() { if l.Data.GetAccessor(nil).GetType() == utils.COLLABORATIVE_AREA.String() {
return l.Data.(*shared_workspace.SharedWorkspace) return l.Data.(*collaborative_area.CollaborativeArea)
} }
return nil return nil
} }
func (l *LibData) ToRule() *rule.Rule { func (l *LibData) ToRule() *rule.Rule {
if l.Data.GetAccessor(nil).GetType() == utils.SHARED_WORKSPACE.String() { if l.Data.GetAccessor(nil).GetType() == utils.COLLABORATIVE_AREA.String() {
return l.Data.(*rule.Rule) return l.Data.(*rule.Rule)
} }
return nil return nil

View File

@@ -15,7 +15,7 @@ import (
w2 "cloud.o-forge.io/core/oc-lib/models/workflow" w2 "cloud.o-forge.io/core/oc-lib/models/workflow"
"cloud.o-forge.io/core/oc-lib/models/workflow_execution" "cloud.o-forge.io/core/oc-lib/models/workflow_execution"
w3 "cloud.o-forge.io/core/oc-lib/models/workspace" w3 "cloud.o-forge.io/core/oc-lib/models/workspace"
shared_workspace "cloud.o-forge.io/core/oc-lib/models/workspace/shared" collaborative_area "cloud.o-forge.io/core/oc-lib/models/workspace/shared"
"cloud.o-forge.io/core/oc-lib/models/workspace/shared/rules/rule" "cloud.o-forge.io/core/oc-lib/models/workspace/shared/rules/rule"
) )
@@ -34,7 +34,7 @@ var models = map[string]func() utils.DBObject{
utils.WORKSPACE.String(): func() utils.DBObject { return &w3.Workspace{} }, utils.WORKSPACE.String(): func() utils.DBObject { return &w3.Workspace{} },
utils.RESOURCE_MODEL.String(): func() utils.DBObject { return &resource_model.ResourceModel{} }, utils.RESOURCE_MODEL.String(): func() utils.DBObject { return &resource_model.ResourceModel{} },
utils.PEER.String(): func() utils.DBObject { return &peer.Peer{} }, utils.PEER.String(): func() utils.DBObject { return &peer.Peer{} },
utils.SHARED_WORKSPACE.String(): func() utils.DBObject { return &shared_workspace.SharedWorkspace{} }, utils.COLLABORATIVE_AREA.String(): func() utils.DBObject { return &collaborative_area.CollaborativeArea{} },
utils.RULE.String(): func() utils.DBObject { return &rule.Rule{} }, utils.RULE.String(): func() utils.DBObject { return &rule.Rule{} },
utils.BOOKING.String(): func() utils.DBObject { return &booking.Booking{} }, utils.BOOKING.String(): func() utils.DBObject { return &booking.Booking{} },
} }

View File

@@ -113,6 +113,7 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string,
func (p *PeerCache) exec(url string, method tools.METHOD, body map[string]interface{}, caller *tools.HTTPCaller) error { func (p *PeerCache) exec(url string, method tools.METHOD, body map[string]interface{}, caller *tools.HTTPCaller) error {
var b []byte var b []byte
var err error var err error
fmt.Println("executing", url, method, body)
if method == tools.POST { // Execute the POST method if it's a POST method if method == tools.POST { // Execute the POST method if it's a POST method
b, err = caller.CallPost(url, "", body) b, err = caller.CallPost(url, "", body)
} }
@@ -127,9 +128,9 @@ func (p *PeerCache) exec(url string, method tools.METHOD, body map[string]interf
if err != nil { if err != nil {
return err return err
} }
fmt.Println("response", m["error"], m["error"] != "<nil>")
if e, ok := m["error"]; !ok && e != "" { // Check if there is an error in the response if e, ok := m["error"]; ok && e != "<nil>" { // Check if there is an error in the response
return errors.New(fmt.Sprintf("%v", m["error"])) return errors.New(fmt.Sprintf("%v", m["error"]))
} }
return err return nil
} }

View File

@@ -29,27 +29,27 @@ type AbstractResource struct {
/* /*
* GetModelValue returns the value of the model key * GetModelValue returns the value of the model key
*/ */
func (abs *AbstractResource) GetModelValue(key string) interface{} { func (abs *AbstractResource) GetModelValue(cat string, key string) interface{} {
if abs.ResourceModel == nil || abs.ResourceModel.Model == nil { if abs.ResourceModel == nil || abs.ResourceModel.Model == nil {
return nil return nil
} }
if _, ok := abs.ResourceModel.Model[key]; !ok { if _, ok := abs.ResourceModel.Model[key]; !ok {
return nil return nil
} }
return abs.ResourceModel.Model[key].Value return abs.ResourceModel.Model[cat][key].Value
} }
/* /*
* GetModelType returns the type of the model key * GetModelType returns the type of the model key
*/ */
func (abs *AbstractResource) GetModelType(key string) interface{} { func (abs *AbstractResource) GetModelType(cat string, key string) interface{} {
if abs.ResourceModel == nil || abs.ResourceModel.Model == nil { if abs.ResourceModel == nil || abs.ResourceModel.Model == nil {
return nil return nil
} }
if _, ok := abs.ResourceModel.Model[key]; !ok { if _, ok := abs.ResourceModel.Model[key]; !ok {
return nil return nil
} }
return abs.ResourceModel.Model[key].Type return abs.ResourceModel.Model[cat][key].Type
} }
/* /*
@@ -66,14 +66,14 @@ func (abs *AbstractResource) GetModelKeys() []string {
/* /*
* GetModelReadOnly returns the readonly of the model key * GetModelReadOnly returns the readonly of the model key
*/ */
func (abs *AbstractResource) GetModelReadOnly(key string) interface{} { func (abs *AbstractResource) GetModelReadOnly(cat string, key string) interface{} {
if abs.ResourceModel == nil || abs.ResourceModel.Model == nil { if abs.ResourceModel == nil || abs.ResourceModel.Model == nil {
return nil return nil
} }
if _, ok := abs.ResourceModel.Model[key]; !ok { if _, ok := abs.ResourceModel.Model[key]; !ok {
return nil return nil
} }
return abs.ResourceModel.Model[key].ReadOnly return abs.ResourceModel.Model[cat][key].ReadOnly
} }
type Model struct { type Model struct {
@@ -88,9 +88,9 @@ type Model struct {
* Warning: This struct is not user available, it is only used by the system * Warning: This struct is not user available, it is only used by the system
*/ */
type ResourceModel struct { type ResourceModel struct {
UUID string `json:"id,omitempty" bson:"id,omitempty" validate:"required"` UUID string `json:"id,omitempty" bson:"id,omitempty" validate:"required"`
ResourceType string `json:"resource_type,omitempty" bson:"resource_type,omitempty" validate:"required"` ResourceType string `json:"resource_type,omitempty" bson:"resource_type,omitempty" validate:"required"`
Model map[string]Model `json:"model,omitempty" bson:"model,omitempty"` Model map[string]map[string]Model `json:"model,omitempty" bson:"model,omitempty"`
} }
func (ao *ResourceModel) GetID() string { func (ao *ResourceModel) GetID() string {

View File

@@ -9,6 +9,19 @@ import (
"cloud.o-forge.io/core/oc-lib/tools" "cloud.o-forge.io/core/oc-lib/tools"
) )
type Container struct {
Image string `json:"image,omitempty" bson:"image,omitempty"` // Image is the container image
Command string `json:"command,omitempty" bson:"command,omitempty"` // Command is the container command
Args string `json:"args,omitempty" bson:"args,omitempty"` // Args is the container arguments
Env string `json:"env,omitempty" bson:"env,omitempty"` // Env is the container environment variables
}
type Execute struct {
Port int `json:"port,omitempty" bson:"port,omitempty"` // Port is the port
Reverse string `json:"reverse,omitempty" bson:"reverse,omitempty"` // Reverse is the reverse
PAT int `json:"pat,omitempty" bson:"pat,omitempty"` // PAT is the PAT
}
/* /*
* ProcessingResource is a struct that represents a processing resource * ProcessingResource is a struct that represents a processing resource
* it defines the resource processing * it defines the resource processing
@@ -22,6 +35,8 @@ type ProcessingResource struct {
Parallel bool `bson:"parallel,omitempty" json:"parallel,omitempty"` // Parallel is a flag that indicates if the processing is parallel Parallel bool `bson:"parallel,omitempty" json:"parallel,omitempty"` // Parallel is a flag that indicates if the processing is parallel
ScalingModel uint `bson:"scaling_model,omitempty" json:"scaling_model,omitempty"` // ScalingModel is the scaling model ScalingModel uint `bson:"scaling_model,omitempty" json:"scaling_model,omitempty"` // ScalingModel is the scaling model
DiskIO string `bson:"disk_io,omitempty" json:"disk_io,omitempty"` // DiskIO is the disk IO DiskIO string `bson:"disk_io,omitempty" json:"disk_io,omitempty"` // DiskIO is the disk IO
Container Container `bson:"container,omitempty" json:"container,omitempty"` // Container is the container
Execute []Execute `bson:"execute,omitempty" json:"execute,omitempty"` // Execute is the execution
} }
func (dma *ProcessingResource) Deserialize(j map[string]interface{}) utils.DBObject { func (dma *ProcessingResource) Deserialize(j map[string]interface{}) utils.DBObject {

View File

@@ -15,7 +15,7 @@ const (
WORKSPACE WORKSPACE
RESOURCE_MODEL RESOURCE_MODEL
PEER PEER
SHARED_WORKSPACE COLLABORATIVE_AREA
RULE RULE
BOOKING BOOKING
) )

View File

@@ -2,6 +2,7 @@ package workflow
import ( import (
"errors" "errors"
"fmt"
"strings" "strings"
"cloud.o-forge.io/core/oc-lib/dbs" "cloud.o-forge.io/core/oc-lib/dbs"
@@ -12,7 +13,7 @@ import (
"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/models/workflow_execution" "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"
"cloud.o-forge.io/core/oc-lib/models/workspace/shared/shallow_shared_workspace" "cloud.o-forge.io/core/oc-lib/models/workspace/shared/shallow_collaborative_area"
"cloud.o-forge.io/core/oc-lib/tools" "cloud.o-forge.io/core/oc-lib/tools"
cron "github.com/robfig/cron/v3" cron "github.com/robfig/cron/v3"
) )
@@ -95,9 +96,9 @@ func (wfa *workflowMongoAccessor) DeleteOne(id string) (utils.DBObject, int, err
}, true) // delete the executions }, true) // delete the executions
res, code, err := wfa.GenericDeleteOne(id, wfa) res, code, err := wfa.GenericDeleteOne(id, wfa)
if res != nil && code == 200 { if res != nil && code == 200 {
wfa.execute(res.(*Workflow), false) // up to date the workspace for the workflow wfa.execute(res.(*Workflow), true, false) // up to date the workspace for the workflow
wfa.share(res.(*Workflow), true, wfa.Caller)
} }
wfa.share(res.(*Workflow), true, wfa.Caller) // send the deletion to the peers where workflow is shared
return res, code, err return res, code, err
} }
@@ -144,6 +145,7 @@ func (wfa *workflowMongoAccessor) book(id string, realData *Workflow, execs []*w
Executions: execs, // set the executions to book "WHAT" Executions: execs, // set the executions to book "WHAT"
}).Serialize(), wfa.Caller) }).Serialize(), wfa.Caller)
if err != nil { if err != nil {
fmt.Println("BOOKING", err)
return err return err
} }
} }
@@ -160,14 +162,14 @@ func (wfa *workflowMongoAccessor) share(realData *Workflow, delete bool, caller
return return
} }
for _, sharedID := range realData.Shared { // loop through the shared ids for _, sharedID := range realData.Shared { // loop through the shared ids
access := (&shallow_shared_workspace.ShallowSharedWorkspace{}).GetAccessor(nil) access := (&shallow_collaborative_area.ShallowCollaborativeArea{}).GetAccessor(nil)
res, code, _ := access.LoadOne(sharedID) res, code, _ := access.LoadOne(sharedID)
if code != 200 { if code != 200 {
continue continue
} }
var err error var err error
paccess := &peer.Peer{} paccess := &peer.Peer{}
for _, p := range res.(*shallow_shared_workspace.ShallowSharedWorkspace).Peers { for _, p := range res.(*shallow_collaborative_area.ShallowCollaborativeArea).Peers {
paccess.UUID = p paccess.UUID = p
if paccess.IsMySelf() { // if the peer is the current peer, never share because it will create a loop if paccess.IsMySelf() { // if the peer is the current peer, never share because it will create a loop
continue continue
@@ -197,7 +199,10 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet
}, utils.WORKFLOW_EXECUTION.String()) }, utils.WORKFLOW_EXECUTION.String())
err := wfa.book(id, realData, []*workflow_execution.WorkflowExecution{}) // delete the booking of the workflow on the peers err := wfa.book(id, realData, []*workflow_execution.WorkflowExecution{}) // delete the booking of the workflow on the peers
nats.SetNATSPub(utils.WORKFLOW.String(), tools.REMOVE, realData) // send the deletion to the nats nats.SetNATSPub(utils.WORKFLOW.String(), tools.REMOVE, realData) // send the deletion to the nats
return 200, err if err != nil {
return 409, err
}
return 200, nil
} }
accessor := (&workflow_execution.WorkflowExecution{}).GetAccessor(nil) accessor := (&workflow_execution.WorkflowExecution{}).GetAccessor(nil)
execs, err := wfa.getExecutions(id, realData) // get the executions of the workflow execs, err := wfa.getExecutions(id, realData) // get the executions of the workflow
@@ -208,13 +213,8 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet
if err != nil { if err != nil {
return 409, err // if the booking fails, return an error for integrity between peers return 409, err // if the booking fails, return an error for integrity between peers
} }
if delete { // if delete is set to true, delete the executions if delete { // if delete is set to true, delete the executions
mongo.MONGOService.DeleteMultiple(map[string]interface{}{
"workflow_id": id,
"state": 1,
}, utils.WORKFLOW_EXECUTION.String())
wfa.book(id, realData, []*workflow_execution.WorkflowExecution{})
nats.SetNATSPub(utils.WORKFLOW.String(), tools.REMOVE, realData)
return 200, nil return 200, nil
} }
if len(execs) > 0 { // if the executions are set, store them if len(execs) > 0 { // if the executions are set, store them
@@ -244,19 +244,19 @@ func (wfa *workflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (util
return nil, code, err return nil, code, err
} }
if !avoid { // if the schedule is not avoided, update the executions if !avoid { // if the schedule is not avoided, update the executions
if code, err := wfa.execution(id, res.(*Workflow), true); err != nil { if code, err := wfa.execution(id, res.(*Workflow), false); code != 200 {
return nil, code, err return nil, code, errors.New("could not update the executions : " + err.Error())
} }
} }
wfa.execute(res.(*Workflow), false) // update the workspace for the workflow wfa.execute(res.(*Workflow), false, false) // update the workspace for the workflow
wfa.share(res.(*Workflow), false, wfa.Caller) // share the update to the peers wfa.share(res.(*Workflow), false, wfa.Caller) // share the update to the peers
return res, code, err return res, code, nil
} }
// StoreOne stores a workflow in the database // StoreOne stores a workflow in the database
func (wfa *workflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) { func (wfa *workflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
res, code, err := wfa.GenericStoreOne(data, wfa) res, code, err := wfa.GenericStoreOne(data, wfa)
if err != nil { if err != nil || code != 200 {
return nil, code, err return nil, code, err
} }
wfa.share(res.(*Workflow), false, wfa.Caller) // share the creation to the peers wfa.share(res.(*Workflow), false, wfa.Caller) // share the creation to the peers
@@ -264,8 +264,8 @@ func (wfa *workflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject,
if code, err := wfa.execution(res.GetID(), res.(*Workflow), false); err != nil { if code, err := wfa.execution(res.GetID(), res.(*Workflow), false); err != nil {
return nil, code, err return nil, code, err
} }
wfa.execute(res.(*Workflow), false) // store the workspace for the workflow wfa.execute(res.(*Workflow), false, false) // store the workspace for the workflow
return res, code, err return res, code, nil
} }
// CopyOne copies a workflow in the database // CopyOne copies a workflow in the database
@@ -275,9 +275,10 @@ func (wfa *workflowMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject,
// execute is a function that executes a workflow // execute is a function that executes a workflow
// it stores the workflow resources in a specific workspace to never have a conflict in UI and logic // 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) { func (wfa *workflowMongoAccessor) execute(workflow *Workflow, delete bool, active bool) {
accessor := (&workspace.Workspace{}).GetAccessor(nil) accessor := (&workspace.Workspace{}).GetAccessor(nil)
fmt.Println("DEL", workflow.Name+"_workspace", delete)
filters := &dbs.Filters{ filters := &dbs.Filters{
Or: map[string][]dbs.Filter{ // filter by standard workspace name attached to a workflow Or: map[string][]dbs.Filter{ // filter by standard workspace name attached to a workflow
"abstractobject.name": {{dbs.LIKE.String(), workflow.Name + "_workspace"}}, "abstractobject.name": {{dbs.LIKE.String(), workflow.Name + "_workspace"}},
@@ -286,13 +287,14 @@ func (wfa *workflowMongoAccessor) execute(workflow *Workflow, delete bool) {
resource, _, err := accessor.Search(filters, "") resource, _, err := accessor.Search(filters, "")
if delete { // if delete is set to true, delete the workspace if delete { // if delete is set to true, delete the workspace
for _, r := range resource { for _, r := range resource {
accessor.DeleteOne(r.GetID()) rr, c, err := accessor.DeleteOne(r.GetID())
fmt.Println("DEL", rr, c, err)
} }
return return
} }
if err == nil && len(resource) > 0 { // if the workspace already exists, update it if err == nil && len(resource) > 0 { // if the workspace already exists, update it
accessor.UpdateOne(&workspace.Workspace{ accessor.UpdateOne(&workspace.Workspace{
Active: true, Active: active,
ResourceSet: resources.ResourceSet{ ResourceSet: resources.ResourceSet{
Datas: workflow.Datas, Datas: workflow.Datas,
Processings: workflow.Processings, Processings: workflow.Processings,
@@ -303,7 +305,7 @@ func (wfa *workflowMongoAccessor) execute(workflow *Workflow, delete bool) {
}, resource[0].GetID()) }, resource[0].GetID())
} else { // if the workspace does not exist, create it } else { // if the workspace does not exist, create it
accessor.StoreOne(&workspace.Workspace{ accessor.StoreOne(&workspace.Workspace{
Active: true, Active: active,
AbstractObject: utils.AbstractObject{Name: workflow.Name + "_workspace"}, AbstractObject: utils.AbstractObject{Name: workflow.Name + "_workspace"},
ResourceSet: resources.ResourceSet{ ResourceSet: resources.ResourceSet{
Datas: workflow.Datas, Datas: workflow.Datas,
@@ -325,7 +327,7 @@ func (wfa *workflowMongoAccessor) LoadOne(id string) (utils.DBObject, int, error
return nil, code, err return nil, code, err
} }
res_mongo.Decode(&workflow) res_mongo.Decode(&workflow)
wfa.execute(&workflow, false) // if no workspace is attached to the workflow, create it wfa.execute(&workflow, false, true) // if no workspace is attached to the workflow, create it
return &workflow, 200, nil return &workflow, 200, nil
} }

View File

@@ -85,6 +85,10 @@ type WorkflowExecution struct {
WorkflowID string `json:"workflow_id" bson:"workflow_id,omitempty"` // WorkflowID is the ID of the workflow WorkflowID string `json:"workflow_id" bson:"workflow_id,omitempty"` // WorkflowID is the ID of the workflow
} }
func (wfa *WorkflowExecution) Equals(we *WorkflowExecution) bool {
return wfa.ExecDate.Equal(*we.ExecDate) && wfa.WorkflowID == we.WorkflowID
}
// tool to transform the argo status to a state // tool to transform the argo status to a state
func (wfa *WorkflowExecution) ArgoStatusToState(status string) *WorkflowExecution { func (wfa *WorkflowExecution) ArgoStatusToState(status string) *WorkflowExecution {
status = strings.ToLower(status) status = strings.ToLower(status)

View File

@@ -1,4 +1,4 @@
package shared_workspace package collaborative_area
import ( import (
"encoding/json" "encoding/json"
@@ -16,7 +16,7 @@ import (
// WARNING : it got a shallow object version, this one is the full version // WARNING : it got a shallow object version, this one is the full version
// full version is the one used by API // full version is the one used by API
// other one is a shallow version used by the Lib for import cycle problem purposes // other one is a shallow version used by the Lib for import cycle problem purposes
type SharedWorkspace struct { type CollaborativeArea struct {
utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name) utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name)
IsSent bool `json:"is_sent" bson:"-"` // IsSent is a flag that indicates if the workspace is sent IsSent bool `json:"is_sent" bson:"-"` // IsSent is a flag that indicates if the workspace is sent
CreatorID string `json:"peer_id,omitempty" bson:"peer_id,omitempty" validate:"required"` // CreatorID is the ID of the creator CreatorID string `json:"peer_id,omitempty" bson:"peer_id,omitempty" validate:"required"` // CreatorID is the ID of the creator
@@ -34,27 +34,27 @@ type SharedWorkspace struct {
SharedPeers []*peer.Peer `json:"shared_peers,omitempty" bson:"-"` // SharedPeers is the shared peers of the workspace SharedPeers []*peer.Peer `json:"shared_peers,omitempty" bson:"-"` // SharedPeers is the shared peers of the workspace
} }
func (ao *SharedWorkspace) GetID() string { func (ao *CollaborativeArea) GetID() string {
return ao.UUID return ao.UUID
} }
func (r *SharedWorkspace) GenerateID() { func (r *CollaborativeArea) GenerateID() {
if r.UUID == "" { if r.UUID == "" {
r.UUID = uuid.New().String() r.UUID = uuid.New().String()
} }
} }
func (d *SharedWorkspace) GetName() string { func (d *CollaborativeArea) GetName() string {
return d.Name return d.Name
} }
func (d *SharedWorkspace) GetAccessor(caller *tools.HTTPCaller) utils.Accessor { func (d *CollaborativeArea) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
data := New() // Create a new instance of the accessor data := New() // Create a new instance of the accessor
data.Init(utils.SHARED_WORKSPACE, caller) // Initialize the accessor with the SHARED_WORKSPACE model type data.Init(utils.COLLABORATIVE_AREA, caller) // Initialize the accessor with the SHARED_WORKSPACE model type
return data return data
} }
func (dma *SharedWorkspace) Deserialize(j map[string]interface{}) utils.DBObject { func (dma *CollaborativeArea) Deserialize(j map[string]interface{}) utils.DBObject {
b, err := json.Marshal(j) b, err := json.Marshal(j)
if err != nil { if err != nil {
return nil return nil
@@ -63,7 +63,7 @@ func (dma *SharedWorkspace) Deserialize(j map[string]interface{}) utils.DBObject
return dma return dma
} }
func (dma *SharedWorkspace) Serialize() map[string]interface{} { func (dma *CollaborativeArea) Serialize() map[string]interface{} {
var m map[string]interface{} var m map[string]interface{}
b, err := json.Marshal(dma) b, err := json.Marshal(dma)
if err != nil { if err != nil {

View File

@@ -1,4 +1,4 @@
package shared_workspace package collaborative_area
import ( import (
"fmt" "fmt"
@@ -15,35 +15,35 @@ import (
"cloud.o-forge.io/core/oc-lib/tools" "cloud.o-forge.io/core/oc-lib/tools"
) )
// SharedWorkspace is a struct that represents a shared workspace // SharedWorkspace is a struct that represents a collaborative area
type sharedWorkspaceMongoAccessor struct { type collaborativeAreaMongoAccessor struct {
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller) utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
} }
// New creates a new instance of the sharedWorkspaceMongoAccessor // New creates a new instance of the collaborativeAreaMongoAccessor
func New() *sharedWorkspaceMongoAccessor { func New() *collaborativeAreaMongoAccessor {
return &sharedWorkspaceMongoAccessor{} return &collaborativeAreaMongoAccessor{}
} }
// DeleteOne deletes a shared workspace from the database, given its ID, it automatically share to peers if the workspace is shared // DeleteOne deletes a collaborative area from the database, given its ID, it automatically share to peers if the workspace is shared
func (wfa *sharedWorkspaceMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) { func (wfa *collaborativeAreaMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
set, code, _ := wfa.LoadOne(id) set, code, _ := wfa.LoadOne(id)
if code == 200 { // always delete on peers than recreate if code == 200 { // always delete on peers than recreate
wfa.deleteToPeer(set.(*SharedWorkspace)) wfa.deleteToPeer(set.(*CollaborativeArea))
} }
wfa.sharedWorkflow(&SharedWorkspace{}, id) // create all shared workflows wfa.sharedWorkflow(&CollaborativeArea{}, id) // create all shared workflows
wfa.sharedWorkspace(&SharedWorkspace{}, id) // create all shared workspaces wfa.sharedWorkspace(&CollaborativeArea{}, id) // create all collaborative areas
return wfa.GenericDeleteOne(id, wfa) // then add on yours return wfa.GenericDeleteOne(id, wfa) // then add on yours
} }
/* /*
sharedWorkspace is a function that shares the shared workspace to the peers sharedWorkspace is a function that shares the collaborative area to the peers
*/ */
func (wfa *sharedWorkspaceMongoAccessor) sharedWorkspace(shared *SharedWorkspace, id string) { func (wfa *collaborativeAreaMongoAccessor) sharedWorkspace(shared *CollaborativeArea, id string) {
eldest, code, _ := wfa.LoadOne(id) // get the eldest eldest, code, _ := wfa.LoadOne(id) // get the eldest
accessor := (&workspace.Workspace{}).GetAccessor(nil) accessor := (&workspace.Workspace{}).GetAccessor(nil)
if code == 200 { if code == 200 {
eld := eldest.(*SharedWorkspace) eld := eldest.(*CollaborativeArea)
if eld.Workspaces != nil { // update all your workspaces in the eldest by replacing shared ref by an empty string if eld.Workspaces != nil { // update all your workspaces in the eldest by replacing shared ref by an empty string
for _, v := range eld.Workspaces { for _, v := range eld.Workspaces {
accessor.UpdateOne(&workspace.Workspace{Shared: ""}, v) accessor.UpdateOne(&workspace.Workspace{Shared: ""}, v)
@@ -51,7 +51,7 @@ func (wfa *sharedWorkspaceMongoAccessor) sharedWorkspace(shared *SharedWorkspace
continue continue
} }
paccess := (&peer.Peer{}) // send to all peers paccess := (&peer.Peer{}) // send to all peers
for _, p := range shared.Peers { // delete the shared workspace on the peer for _, p := range shared.Peers { // delete the collaborative area on the peer
b, err := paccess.LaunchPeerExecution(p, v, utils.WORKSPACE, tools.DELETE, nil, wfa.Caller) b, err := paccess.LaunchPeerExecution(p, v, utils.WORKSPACE, tools.DELETE, nil, wfa.Caller)
if err != nil && b == nil { if err != nil && b == nil {
wfa.Logger.Error().Msg("Could not send to peer " + p + ". Error: " + err.Error()) wfa.Logger.Error().Msg("Could not send to peer " + p + ". Error: " + err.Error())
@@ -61,7 +61,7 @@ func (wfa *sharedWorkspaceMongoAccessor) sharedWorkspace(shared *SharedWorkspace
} }
} }
if shared.Workspaces != nil { if shared.Workspaces != nil {
for _, v := range shared.Workspaces { // update all the shared workspaces for _, v := range shared.Workspaces { // update all the collaborative areas
workspace, code, _ := accessor.UpdateOne(&workspace.Workspace{Shared: shared.UUID}, v) // add the shared ref to workspace workspace, code, _ := accessor.UpdateOne(&workspace.Workspace{Shared: shared.UUID}, v) // add the shared ref to workspace
if wfa.Caller != nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.WORKSPACE.String()] == nil { if wfa.Caller != nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.WORKSPACE.String()] == nil {
continue continue
@@ -70,7 +70,7 @@ func (wfa *sharedWorkspaceMongoAccessor) sharedWorkspace(shared *SharedWorkspace
if code != 200 { if code != 200 {
continue continue
} }
paccess := (&peer.Peer{}) // send to all peers, add the shared workspace on the peer paccess := (&peer.Peer{}) // send to all peers, add the collaborative area on the peer
s := workspace.Serialize() s := workspace.Serialize()
s["name"] = fmt.Sprintf("%v", s["name"]) + "_" + p s["name"] = fmt.Sprintf("%v", s["name"]) + "_" + p
b, err := paccess.LaunchPeerExecution(p, v, utils.WORKSPACE, tools.POST, s, wfa.Caller) b, err := paccess.LaunchPeerExecution(p, v, utils.WORKSPACE, tools.POST, s, wfa.Caller)
@@ -81,15 +81,15 @@ func (wfa *sharedWorkspaceMongoAccessor) sharedWorkspace(shared *SharedWorkspace
} }
} }
// deleting on peers before adding, to avoid conflicts on peers side // deleting on peers before adding, to avoid conflicts on peers side
// because you have no reference to the remote shared workspace // because you have no reference to the remote collaborative area
} }
// sharedWorkflow is a function that shares the shared workflow to the peers // sharedWorkflow is a function that shares the shared workflow to the peers
func (wfa *sharedWorkspaceMongoAccessor) sharedWorkflow(shared *SharedWorkspace, id string) { func (wfa *collaborativeAreaMongoAccessor) sharedWorkflow(shared *CollaborativeArea, id string) {
accessor := (&w.Workflow{}).GetAccessor(nil) accessor := (&w.Workflow{}).GetAccessor(nil)
eldest, code, _ := wfa.LoadOne(id) // get the eldest eldest, code, _ := wfa.LoadOne(id) // get the eldest
if code == 200 { if code == 200 {
eld := eldest.(*SharedWorkspace) eld := eldest.(*CollaborativeArea)
if eld.Workflows != nil { if eld.Workflows != nil {
for _, v := range eld.Workflows { for _, v := range eld.Workflows {
data, code, _ := accessor.LoadOne(v) data, code, _ := accessor.LoadOne(v)
@@ -148,9 +148,9 @@ func (wfa *sharedWorkspaceMongoAccessor) sharedWorkflow(shared *SharedWorkspace,
// because you have no reference to the remote shared workflow // because you have no reference to the remote shared workflow
} }
// sharedWorkspace is a function that shares the shared workspace to the peers // sharedWorkspace is a function that shares the collaborative area to the peers
func (wfa *sharedWorkspaceMongoAccessor) deleteToPeer(shared *SharedWorkspace) { func (wfa *collaborativeAreaMongoAccessor) deleteToPeer(shared *CollaborativeArea) {
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.SHARED_WORKSPACE.String()] == nil { if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.COLLABORATIVE_AREA.String()] == nil {
return return
} }
paccess := (&peer.Peer{}) paccess := (&peer.Peer{})
@@ -158,16 +158,16 @@ func (wfa *sharedWorkspaceMongoAccessor) deleteToPeer(shared *SharedWorkspace) {
if (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: v}}).IsMySelf() { if (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: v}}).IsMySelf() {
continue continue
} }
b, err := paccess.LaunchPeerExecution(v, shared.UUID, utils.SHARED_WORKSPACE, tools.DELETE, nil, wfa.Caller) b, err := paccess.LaunchPeerExecution(v, shared.UUID, utils.COLLABORATIVE_AREA, tools.DELETE, nil, wfa.Caller)
if err != nil && b == nil { if err != nil && b == nil {
wfa.Logger.Error().Msg("Could not send to peer " + v + ". Error: " + err.Error()) wfa.Logger.Error().Msg("Could not send to peer " + v + ". Error: " + err.Error())
} }
} }
} }
// sharedWorkspace is a function that shares the shared workspace to the peers // sharedWorkspace is a function that shares the collaborative area to the peers
func (wfa *sharedWorkspaceMongoAccessor) sendToPeer(shared *SharedWorkspace) { func (wfa *collaborativeAreaMongoAccessor) sendToPeer(shared *CollaborativeArea) {
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.SHARED_WORKSPACE.String()] == nil { if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.COLLABORATIVE_AREA.String()] == nil {
return return
} }
@@ -177,56 +177,56 @@ func (wfa *sharedWorkspaceMongoAccessor) sendToPeer(shared *SharedWorkspace) {
continue continue
} }
shared.IsSent = true shared.IsSent = true
b, err := paccess.LaunchPeerExecution(v, v, utils.SHARED_WORKSPACE, tools.POST, shared.Serialize(), wfa.Caller) b, err := paccess.LaunchPeerExecution(v, v, utils.COLLABORATIVE_AREA, tools.POST, shared.Serialize(), wfa.Caller)
if err != nil && b == nil { if err != nil && b == nil {
wfa.Logger.Error().Msg("Could not send to peer " + v + ". Error: " + err.Error()) wfa.Logger.Error().Msg("Could not send to peer " + v + ". Error: " + err.Error())
} }
} }
} }
// UpdateOne updates a shared workspace in the database, given its ID and the new data, it automatically share to peers if the workspace is shared // UpdateOne updates a collaborative area in the database, given its ID and the new data, it automatically share to peers if the workspace is shared
func (wfa *sharedWorkspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) { func (wfa *collaborativeAreaMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
res, code, err := wfa.GenericUpdateOne(set.(*SharedWorkspace), id, wfa, &SharedWorkspace{}) res, code, err := wfa.GenericUpdateOne(set.(*CollaborativeArea), id, wfa, &CollaborativeArea{})
wfa.deleteToPeer(res.(*SharedWorkspace)) // delete the shared workspace on the peer wfa.deleteToPeer(res.(*CollaborativeArea)) // delete the collaborative area on the peer
wfa.sharedWorkflow(res.(*SharedWorkspace), id) // replace all shared workflows wfa.sharedWorkflow(res.(*CollaborativeArea), id) // replace all shared workflows
wfa.sharedWorkspace(res.(*SharedWorkspace), id) // replace all shared workspaces (not shared worspace obj but workspace one) wfa.sharedWorkspace(res.(*CollaborativeArea), id) // replace all collaborative areas (not shared worspace obj but workspace one)
wfa.sendToPeer(res.(*SharedWorkspace)) // send the shared workspace (shared workspace object) to the peers wfa.sendToPeer(res.(*CollaborativeArea)) // send the collaborative area (collaborative area object) to the peers
return res, code, err return res, code, err
} }
// StoreOne stores a shared workspace in the database, it automatically share to peers if the workspace is shared // StoreOne stores a collaborative area in the database, it automatically share to peers if the workspace is shared
func (wfa *sharedWorkspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) { func (wfa *collaborativeAreaMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
id, _ := static.GetMyLocalJsonPeer() // get the local peer id, _ := static.GetMyLocalJsonPeer() // get the local peer
data.(*SharedWorkspace).CreatorID = id // set the creator id data.(*CollaborativeArea).CreatorID = id // set the creator id
data.(*SharedWorkspace).Peers = append(data.(*SharedWorkspace).Peers, id) // add the creator id to the peers data.(*CollaborativeArea).Peers = append(data.(*CollaborativeArea).Peers, id) // add the creator id to the peers
// then reset the shared fields // then reset the shared fields
if data.(*SharedWorkspace).Workspaces == nil { if data.(*CollaborativeArea).Workspaces == nil {
data.(*SharedWorkspace).Workspaces = []string{} data.(*CollaborativeArea).Workspaces = []string{}
} }
if data.(*SharedWorkspace).Workflows == nil { if data.(*CollaborativeArea).Workflows == nil {
data.(*SharedWorkspace).Workflows = []string{} data.(*CollaborativeArea).Workflows = []string{}
} }
if data.(*SharedWorkspace).Rules == nil { if data.(*CollaborativeArea).Rules == nil {
data.(*SharedWorkspace).Rules = []string{} data.(*CollaborativeArea).Rules = []string{}
} }
d, code, err := wfa.GenericStoreOne(data.(*SharedWorkspace), wfa) d, code, err := wfa.GenericStoreOne(data.(*CollaborativeArea), wfa)
if code == 200 { if code == 200 {
wfa.sharedWorkflow(d.(*SharedWorkspace), d.GetID()) // create all shared workflows wfa.sharedWorkflow(d.(*CollaborativeArea), d.GetID()) // create all shared workflows
wfa.sharedWorkspace(d.(*SharedWorkspace), d.GetID()) // create all shared workspaces wfa.sharedWorkspace(d.(*CollaborativeArea), d.GetID()) // create all collaborative areas
wfa.sendToPeer(d.(*SharedWorkspace)) // send the shared workspace (shared workspace object) to the peers wfa.sendToPeer(d.(*CollaborativeArea)) // send the collaborative area (collaborative area object) to the peers
} }
return data, code, err return data, code, err
} }
// CopyOne copies a shared workspace in the database // CopyOne copies a CollaborativeArea in the database
func (wfa *sharedWorkspaceMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) { func (wfa *collaborativeAreaMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
return wfa.StoreOne(data) return wfa.StoreOne(data)
} }
// enrich is a function that enriches the shared workspace with the shared objects // enrich is a function that enriches the CollaborativeArea with the shared objects
func (wfa *sharedWorkspaceMongoAccessor) enrich(sharedWorkspace *SharedWorkspace) *SharedWorkspace { func (wfa *collaborativeAreaMongoAccessor) enrich(sharedWorkspace *CollaborativeArea) *CollaborativeArea {
access := (&workspace.Workspace{}).GetAccessor(nil) access := (&workspace.Workspace{}).GetAccessor(nil)
res, code, _ := access.Search(&dbs.Filters{ res, code, _ := access.Search(&dbs.Filters{
Or: map[string][]dbs.Filter{ Or: map[string][]dbs.Filter{
@@ -274,38 +274,38 @@ func (wfa *sharedWorkspaceMongoAccessor) enrich(sharedWorkspace *SharedWorkspace
return sharedWorkspace return sharedWorkspace
} }
// LoadOne loads a shared workspace from the database, given its ID and enrich it // LoadOne loads a collaborative area from the database, given its ID and enrich it
func (wfa *sharedWorkspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) { func (wfa *collaborativeAreaMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
var sharedWorkspace SharedWorkspace var sharedWorkspace CollaborativeArea
res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType()) res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
if err != nil { if err != nil {
wfa.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error()) wfa.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
return nil, code, err return nil, code, err
} }
res_mongo.Decode(&sharedWorkspace) res_mongo.Decode(&sharedWorkspace)
return wfa.enrich(&sharedWorkspace), 200, nil // enrich the shared workspace return wfa.enrich(&sharedWorkspace), 200, nil // enrich the collaborative area
} }
// LoadAll loads all the shared workspaces from the database and enrich them // LoadAll loads all the collaborative areas from the database and enrich them
func (wfa sharedWorkspaceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) { func (wfa collaborativeAreaMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{} objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType()) res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType())
if err != nil { if err != nil {
wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error()) wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error())
return nil, code, err return nil, code, err
} }
var results []SharedWorkspace var results []CollaborativeArea
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
return nil, 404, err return nil, 404, err
} }
for _, r := range results { for _, r := range results {
objs = append(objs, wfa.enrich(&r)) // enrich the shared workspace objs = append(objs, wfa.enrich(&r)) // enrich the collaborative area
} }
return objs, 200, nil return objs, 200, nil
} }
// Search searches for shared workspaces in the database, given some filters OR a search string // Search searches for collaborative areas in the database, given some filters OR a search string
func (wfa *sharedWorkspaceMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) { func (wfa *collaborativeAreaMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{} objs := []utils.ShallowDBObject{}
if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" { if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" {
filters = &dbs.Filters{ filters = &dbs.Filters{
@@ -319,12 +319,12 @@ func (wfa *sharedWorkspaceMongoAccessor) Search(filters *dbs.Filters, search str
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error()) wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
return nil, code, err return nil, code, err
} }
var results []SharedWorkspace var results []CollaborativeArea
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
return nil, 404, err return nil, 404, err
} }
for _, r := range results { for _, r := range results {
objs = append(objs, wfa.enrich(&r)) // enrich the shared workspace objs = append(objs, wfa.enrich(&r)) // enrich the collaborative area
} }
return objs, 200, nil return objs, 200, nil
} }

View File

@@ -1,4 +1,4 @@
package shallow_shared_workspace package shallow_collaborative_area
import ( import (
"encoding/json" "encoding/json"
@@ -8,7 +8,7 @@ import (
"github.com/google/uuid" "github.com/google/uuid"
) )
type ShallowSharedWorkspace struct { type ShallowCollaborativeArea struct {
utils.AbstractObject utils.AbstractObject
IsSent bool `json:"is_sent" bson:"-"` IsSent bool `json:"is_sent" bson:"-"`
CreatorID string `json:"peer_id,omitempty" bson:"peer_id,omitempty" validate:"required"` CreatorID string `json:"peer_id,omitempty" bson:"peer_id,omitempty" validate:"required"`
@@ -21,27 +21,27 @@ type ShallowSharedWorkspace struct {
Rules []string `json:"rules,omitempty" bson:"rules,omitempty"` Rules []string `json:"rules,omitempty" bson:"rules,omitempty"`
} }
func (ao *ShallowSharedWorkspace) GetID() string { func (ao *ShallowCollaborativeArea) GetID() string {
return ao.UUID return ao.UUID
} }
func (r *ShallowSharedWorkspace) GenerateID() { func (r *ShallowCollaborativeArea) GenerateID() {
if r.UUID == "" { if r.UUID == "" {
r.UUID = uuid.New().String() r.UUID = uuid.New().String()
} }
} }
func (d *ShallowSharedWorkspace) GetName() string { func (d *ShallowCollaborativeArea) GetName() string {
return d.Name return d.Name
} }
func (d *ShallowSharedWorkspace) GetAccessor(caller *tools.HTTPCaller) utils.Accessor { func (d *ShallowCollaborativeArea) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
data := New() data := New()
data.Init(utils.SHARED_WORKSPACE, caller) data.Init(utils.COLLABORATIVE_AREA, caller)
return data return data
} }
func (dma *ShallowSharedWorkspace) Deserialize(j map[string]interface{}) utils.DBObject { func (dma *ShallowCollaborativeArea) Deserialize(j map[string]interface{}) utils.DBObject {
b, err := json.Marshal(j) b, err := json.Marshal(j)
if err != nil { if err != nil {
return nil return nil
@@ -50,7 +50,7 @@ func (dma *ShallowSharedWorkspace) Deserialize(j map[string]interface{}) utils.D
return dma return dma
} }
func (dma *ShallowSharedWorkspace) Serialize() map[string]interface{} { func (dma *ShallowCollaborativeArea) Serialize() map[string]interface{} {
var m map[string]interface{} var m map[string]interface{}
b, err := json.Marshal(dma) b, err := json.Marshal(dma)
if err != nil { if err != nil {

View File

@@ -1,4 +1,4 @@
package shallow_shared_workspace package shallow_collaborative_area
import ( import (
"cloud.o-forge.io/core/oc-lib/dbs" "cloud.o-forge.io/core/oc-lib/dbs"
@@ -19,11 +19,11 @@ func (wfa *shallowSharedWorkspaceMongoAccessor) DeleteOne(id string) (utils.DBOb
} }
func (wfa *shallowSharedWorkspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) { func (wfa *shallowSharedWorkspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
return wfa.GenericUpdateOne(set.(*ShallowSharedWorkspace), id, wfa, &ShallowSharedWorkspace{}) return wfa.GenericUpdateOne(set.(*ShallowCollaborativeArea), id, wfa, &ShallowCollaborativeArea{})
} }
func (wfa *shallowSharedWorkspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) { func (wfa *shallowSharedWorkspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
return wfa.GenericStoreOne(data.(*ShallowSharedWorkspace), wfa) return wfa.GenericStoreOne(data.(*ShallowCollaborativeArea), wfa)
} }
func (wfa *shallowSharedWorkspaceMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) { func (wfa *shallowSharedWorkspaceMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
@@ -31,7 +31,7 @@ func (wfa *shallowSharedWorkspaceMongoAccessor) CopyOne(data utils.DBObject) (ut
} }
func (wfa *shallowSharedWorkspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) { func (wfa *shallowSharedWorkspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
var sharedWorkspace ShallowSharedWorkspace var sharedWorkspace ShallowCollaborativeArea
res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType()) res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
if err != nil { if err != nil {
wfa.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error()) wfa.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
@@ -48,7 +48,7 @@ func (wfa shallowSharedWorkspaceMongoAccessor) LoadAll() ([]utils.ShallowDBObjec
wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error()) wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error())
return nil, code, err return nil, code, err
} }
var results []ShallowSharedWorkspace var results []ShallowCollaborativeArea
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
return nil, 404, err return nil, 404, err
} }
@@ -72,7 +72,7 @@ func (wfa *shallowSharedWorkspaceMongoAccessor) Search(filters *dbs.Filters, sea
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error()) wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
return nil, code, err return nil, code, err
} }
var results []ShallowSharedWorkspace var results []ShallowCollaborativeArea
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
return nil, 404, err return nil, 404, err
} }

View File

@@ -12,7 +12,7 @@ import (
"cloud.o-forge.io/core/oc-lib/models/resources/storage" "cloud.o-forge.io/core/oc-lib/models/resources/storage"
w "cloud.o-forge.io/core/oc-lib/models/resources/workflow" w "cloud.o-forge.io/core/oc-lib/models/resources/workflow"
"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/models/workspace/shared/shallow_shared_workspace" "cloud.o-forge.io/core/oc-lib/models/workspace/shared/shallow_collaborative_area"
"cloud.o-forge.io/core/oc-lib/tools" "cloud.o-forge.io/core/oc-lib/tools"
) )
@@ -30,7 +30,9 @@ func New() *workspaceMongoAccessor {
// it checks if a workspace with the same name already exists // it checks if a workspace with the same name already exists
func (wfa *workspaceMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) { func (wfa *workspaceMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
res, code, err := wfa.GenericDeleteOne(id, wfa) res, code, err := wfa.GenericDeleteOne(id, wfa)
wfa.share(res.(*Workspace), true, wfa.Caller) // Share the deletion to the peers if code == 200 && res != nil {
wfa.share(res.(*Workspace), true, wfa.Caller) // Share the deletion to the peers
}
return res, code, err return res, code, err
} }
@@ -54,7 +56,9 @@ func (wfa *workspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (uti
} }
} }
res, code, err := wfa.GenericUpdateOne(set, id, wfa, &Workspace{}) res, code, err := wfa.GenericUpdateOne(set, id, wfa, &Workspace{})
wfa.share(res.(*Workspace), false, wfa.Caller) if code == 200 && res != nil {
wfa.share(res.(*Workspace), false, wfa.Caller)
}
return res, code, err return res, code, err
} }
@@ -204,14 +208,14 @@ func (wfa *workspaceMongoAccessor) share(realData *Workspace, delete bool, calle
if realData.Shared == "" { if realData.Shared == "" {
return return
} }
access := (&shallow_shared_workspace.ShallowSharedWorkspace{}).GetAccessor(nil) access := (&shallow_collaborative_area.ShallowCollaborativeArea{}).GetAccessor(nil)
res, code, _ := access.LoadOne(realData.Shared) res, code, _ := access.LoadOne(realData.Shared)
if code != 200 { if code != 200 {
return return
} }
var err error var err error
paccess := &peer.Peer{} paccess := &peer.Peer{}
for _, p := range res.(*shallow_shared_workspace.ShallowSharedWorkspace).Peers { for _, p := range res.(*shallow_collaborative_area.ShallowCollaborativeArea).Peers {
paccess.UUID = p paccess.UUID = p
if paccess.IsMySelf() { // If the peer is the current peer, never share because it will create a loop if paccess.IsMySelf() { // If the peer is the current peer, never share because it will create a loop
continue continue

BIN
swagger/favicon-16x16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 665 B

BIN
swagger/favicon-32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 628 B

60
swagger/index.html Normal file
View File

@@ -0,0 +1,60 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" />
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
<style>
html
{
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}
*,
*:before,
*:after
{
box-sizing: inherit;
}
body
{
margin:0;
background: #fafafa;
}
</style>
</head>
<body>
<div id="swagger-ui"></div>
<script src="./swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="./swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
<script>
window.onload = function() {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "https://petstore.swagger.io/v2/swagger.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
});
// End Swagger UI call region
window.ui = ui;
};
</script>
</body>
</html>

View File

@@ -0,0 +1,79 @@
<!doctype html>
<html lang="en-US">
<head>
<title>Swagger UI: OAuth2 Redirect</title>
</head>
<body>
<script>
'use strict';
function run () {
var oauth2 = window.opener.swaggerUIRedirectOauth2;
var sentState = oauth2.state;
var redirectUrl = oauth2.redirectUrl;
var isValid, qp, arr;
if (/code|token|error/.test(window.location.hash)) {
qp = window.location.hash.substring(1);
} else {
qp = location.search.substring(1);
}
arr = qp.split("&");
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';});
qp = qp ? JSON.parse('{' + arr.join() + '}',
function (key, value) {
return key === "" ? value : decodeURIComponent(value);
}
) : {};
isValid = qp.state === sentState;
if ((
oauth2.auth.schema.get("flow") === "accessCode" ||
oauth2.auth.schema.get("flow") === "authorizationCode" ||
oauth2.auth.schema.get("flow") === "authorization_code"
) && !oauth2.auth.code) {
if (!isValid) {
oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "warning",
message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
});
}
if (qp.code) {
delete oauth2.state;
oauth2.auth.code = qp.code;
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
} else {
let oauthErrorMsg;
if (qp.error) {
oauthErrorMsg = "["+qp.error+"]: " +
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
(qp.error_uri ? "More info: "+qp.error_uri : "");
}
oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "error",
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
});
}
} else {
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
}
window.close();
}
if (document.readyState !== 'loading') {
run();
} else {
document.addEventListener('DOMContentLoaded', function () {
run();
});
}
</script>
</body>
</html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

4
swagger/swagger-ui.css Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
swagger/swagger-ui.js Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More