correct share infinite loop
This commit is contained in:
parent
93903b4938
commit
c309d97623
@ -11,6 +11,8 @@ import (
|
|||||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||||
"cloud.o-forge.io/core/oc-lib/logs"
|
"cloud.o-forge.io/core/oc-lib/logs"
|
||||||
"cloud.o-forge.io/core/oc-lib/models"
|
"cloud.o-forge.io/core/oc-lib/models"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/collaborative_area"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/collaborative_area/rules/rule"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/data"
|
"cloud.o-forge.io/core/oc-lib/models/resources/data"
|
||||||
@ -22,8 +24,6 @@ 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"
|
||||||
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/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
"github.com/goraz/onion"
|
"github.com/goraz/onion"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
|
@ -3,11 +3,11 @@ package collaborative_area
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/collaborative_area/rules/rule"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
w "cloud.o-forge.io/core/oc-lib/models/workflow"
|
w "cloud.o-forge.io/core/oc-lib/models/workflow"
|
||||||
"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/rules/rule"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
@ -6,11 +6,11 @@ import (
|
|||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/collaborative_area/rules/rule"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
w "cloud.o-forge.io/core/oc-lib/models/workflow"
|
w "cloud.o-forge.io/core/oc-lib/models/workflow"
|
||||||
"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/rules/rule"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/static"
|
"cloud.o-forge.io/core/oc-lib/static"
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
)
|
)
|
||||||
@ -150,7 +150,7 @@ func (wfa *collaborativeAreaMongoAccessor) sharedWorkflow(shared *CollaborativeA
|
|||||||
|
|
||||||
// sharedWorkspace is a function that shares the collaborative area to the peers
|
// sharedWorkspace is a function that shares the collaborative area to the peers
|
||||||
func (wfa *collaborativeAreaMongoAccessor) deleteToPeer(shared *CollaborativeArea) {
|
func (wfa *collaborativeAreaMongoAccessor) deleteToPeer(shared *CollaborativeArea) {
|
||||||
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[tools.COLLABORATIVE_AREA] == nil {
|
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[tools.COLLABORATIVE_AREA] == nil || wfa.Caller.Disabled {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
paccess := (&peer.Peer{})
|
paccess := (&peer.Peer{})
|
||||||
@ -167,7 +167,7 @@ func (wfa *collaborativeAreaMongoAccessor) deleteToPeer(shared *CollaborativeAre
|
|||||||
|
|
||||||
// sharedWorkspace is a function that shares the collaborative area to the peers
|
// sharedWorkspace is a function that shares the collaborative area to the peers
|
||||||
func (wfa *collaborativeAreaMongoAccessor) sendToPeer(shared *CollaborativeArea) {
|
func (wfa *collaborativeAreaMongoAccessor) sendToPeer(shared *CollaborativeArea) {
|
||||||
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[tools.COLLABORATIVE_AREA] == nil {
|
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[tools.COLLABORATIVE_AREA] == nil || wfa.Caller.Disabled {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -5,6 +5,8 @@ import (
|
|||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/booking"
|
"cloud.o-forge.io/core/oc-lib/models/booking"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/collaborative_area"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/collaborative_area/rules/rule"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
||||||
d "cloud.o-forge.io/core/oc-lib/models/resources/data"
|
d "cloud.o-forge.io/core/oc-lib/models/resources/data"
|
||||||
@ -15,8 +17,6 @@ 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"
|
||||||
collaborative_area "cloud.o-forge.io/core/oc-lib/models/workspace/shared"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/workspace/shared/rules/rule"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -83,6 +83,8 @@ func (ao *ResourceModel) GetID() string {
|
|||||||
return ao.UUID
|
return ao.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ao *ResourceModel) UpToDate() {}
|
||||||
|
|
||||||
func (r *ResourceModel) GenerateID() {
|
func (r *ResourceModel) GenerateID() {
|
||||||
r.UUID = uuid.New().String()
|
r.UUID = uuid.New().String()
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,12 @@ package utils
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||||
"cloud.o-forge.io/core/oc-lib/logs"
|
"cloud.o-forge.io/core/oc-lib/logs"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/static"
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@ -22,8 +24,10 @@ var validate = validator.New(validator.WithRequiredStructEnabled())
|
|||||||
* every data in base root model should inherit from this struct (only exception is the ResourceModel)
|
* every data in base root model should inherit from this struct (only exception is the ResourceModel)
|
||||||
*/
|
*/
|
||||||
type AbstractObject struct {
|
type AbstractObject struct {
|
||||||
UUID string `json:"id,omitempty" bson:"id,omitempty" validate:"required"`
|
UUID string `json:"id,omitempty" bson:"id,omitempty" validate:"required"`
|
||||||
Name string `json:"name,omitempty" bson:"name,omitempty" validate:"required"`
|
Name string `json:"name,omitempty" bson:"name,omitempty" validate:"required"`
|
||||||
|
UpdateDate time.Time `json:"update_date" bson:"update_date"`
|
||||||
|
LastPeerWriter string `json:"last_peer_writer" bson:"last_peer_writer"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetID returns the id of the object (abstract)
|
// GetID returns the id of the object (abstract)
|
||||||
@ -36,6 +40,11 @@ func (ao *AbstractObject) GetName() string {
|
|||||||
return ao.Name
|
return ao.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ao *AbstractObject) UpToDate() {
|
||||||
|
ao.UpdateDate = time.Now()
|
||||||
|
ao.LastPeerWriter, _ = static.GetMyLocalJsonPeer()
|
||||||
|
}
|
||||||
|
|
||||||
// GetAccessor returns the accessor of the object (abstract)
|
// GetAccessor returns the accessor of the object (abstract)
|
||||||
func (dma *AbstractObject) GetAccessor(caller *tools.HTTPCaller) Accessor {
|
func (dma *AbstractObject) GetAccessor(caller *tools.HTTPCaller) Accessor {
|
||||||
return nil
|
return nil
|
||||||
|
@ -19,6 +19,7 @@ type DBObject interface {
|
|||||||
GenerateID()
|
GenerateID()
|
||||||
GetID() string
|
GetID() string
|
||||||
GetName() string
|
GetName() string
|
||||||
|
UpToDate()
|
||||||
Deserialize(j map[string]interface{}) DBObject
|
Deserialize(j map[string]interface{}) DBObject
|
||||||
Serialize() map[string]interface{}
|
Serialize() map[string]interface{}
|
||||||
GetAccessor(caller *tools.HTTPCaller) Accessor
|
GetAccessor(caller *tools.HTTPCaller) Accessor
|
||||||
|
@ -7,13 +7,13 @@ import (
|
|||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/collaborative_area/shallow_collaborative_area"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources"
|
"cloud.o-forge.io/core/oc-lib/models/resources"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
|
"cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
|
||||||
"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_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"
|
||||||
)
|
)
|
||||||
@ -158,7 +158,7 @@ func (wfa *workflowMongoAccessor) book(id string, realData *Workflow, execs []*w
|
|||||||
* share is a function that shares a workflow to the peers if the workflow is shared
|
* share is a function that shares a workflow to the peers if the workflow is shared
|
||||||
*/
|
*/
|
||||||
func (wfa *workflowMongoAccessor) share(realData *Workflow, delete bool, caller *tools.HTTPCaller) {
|
func (wfa *workflowMongoAccessor) share(realData *Workflow, delete bool, caller *tools.HTTPCaller) {
|
||||||
if realData.Shared == nil || len(realData.Shared) == 0 { // no shared no sharing
|
if realData.Shared == nil || len(realData.Shared) == 0 || caller.Disabled { // no shared no sharing
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, sharedID := range realData.Shared { // loop through the shared ids
|
for _, sharedID := range realData.Shared { // loop through the shared ids
|
||||||
@ -280,7 +280,6 @@ func (wfa *workflowMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject,
|
|||||||
func (wfa *workflowMongoAccessor) execute(workflow *Workflow, delete bool, active 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"}},
|
||||||
@ -289,8 +288,7 @@ func (wfa *workflowMongoAccessor) execute(workflow *Workflow, delete bool, activ
|
|||||||
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 {
|
||||||
rr, c, err := accessor.DeleteOne(r.GetID())
|
accessor.DeleteOne(r.GetID())
|
||||||
fmt.Println("DEL", rr, c, err)
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/collaborative_area/shallow_collaborative_area"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/data"
|
"cloud.o-forge.io/core/oc-lib/models/resources/data"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
|
"cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
|
||||||
@ -12,7 +13,6 @@ 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_collaborative_area"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ func New() *workspaceMongoAccessor {
|
|||||||
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)
|
||||||
if code == 200 && res != nil {
|
if code == 200 && res != nil {
|
||||||
wfa.share(res.(*Workspace), true, wfa.Caller) // Share the deletion to the peers
|
wfa.share(res.(*Workspace), tools.DELETE, wfa.Caller) // Share the deletion to the peers
|
||||||
}
|
}
|
||||||
return res, code, err
|
return res, code, err
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ 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{})
|
||||||
if code == 200 && res != nil {
|
if code == 200 && res != nil {
|
||||||
wfa.share(res.(*Workspace), false, wfa.Caller)
|
wfa.share(res.(*Workspace), tools.PUT, wfa.Caller)
|
||||||
}
|
}
|
||||||
return res, code, err
|
return res, code, err
|
||||||
}
|
}
|
||||||
@ -204,8 +204,8 @@ func (wfa *workspaceMongoAccessor) Search(filters *dbs.Filters, search string) (
|
|||||||
/*
|
/*
|
||||||
This function is used to share the workspace with the peers
|
This function is used to share the workspace with the peers
|
||||||
*/
|
*/
|
||||||
func (wfa *workspaceMongoAccessor) share(realData *Workspace, delete bool, caller *tools.HTTPCaller) {
|
func (wfa *workspaceMongoAccessor) share(realData *Workspace, method tools.METHOD, caller *tools.HTTPCaller) {
|
||||||
if realData.Shared == "" {
|
if realData.Shared == "" || caller.Disabled {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
access := (&shallow_collaborative_area.ShallowCollaborativeArea{}).GetAccessor(nil)
|
access := (&shallow_collaborative_area.ShallowCollaborativeArea{}).GetAccessor(nil)
|
||||||
@ -220,7 +220,7 @@ func (wfa *workspaceMongoAccessor) share(realData *Workspace, delete bool, calle
|
|||||||
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
|
||||||
}
|
}
|
||||||
if delete { // If the workspace is deleted, share the deletion
|
if method == tools.DELETE { // If the workspace is deleted, share the deletion
|
||||||
history := NewHistory()
|
history := NewHistory()
|
||||||
history.StoreOne(history.MapFromWorkspace(res.(*Workspace)))
|
history.StoreOne(history.MapFromWorkspace(res.(*Workspace)))
|
||||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKSPACE, tools.DELETE, map[string]interface{}{}, caller)
|
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKSPACE, tools.DELETE, map[string]interface{}{}, caller)
|
||||||
|
@ -40,13 +40,15 @@ func ToMethod(str string) METHOD {
|
|||||||
var HTTPCallerInstance = &HTTPCaller{} // Singleton instance of the HTTPCaller
|
var HTTPCallerInstance = &HTTPCaller{} // Singleton instance of the HTTPCaller
|
||||||
|
|
||||||
type HTTPCaller struct {
|
type HTTPCaller struct {
|
||||||
URLS map[DataType]map[METHOD]string // Map of the different methods and their urls
|
URLS map[DataType]map[METHOD]string // Map of the different methods and their urls
|
||||||
|
Disabled bool // Disabled flag
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHTTPCaller creates a new instance of the HTTP Caller
|
// NewHTTPCaller creates a new instance of the HTTP Caller
|
||||||
func NewHTTPCaller(urls map[DataType]map[METHOD]string) *HTTPCaller {
|
func NewHTTPCaller(urls map[DataType]map[METHOD]string) *HTTPCaller {
|
||||||
return &HTTPCaller{
|
return &HTTPCaller{
|
||||||
URLS: urls, // Set the urls defined in the config & based on the data name type & method
|
URLS: urls, // Set the urls defined in the config & based on the data name type & method
|
||||||
|
Disabled: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user