diff --git a/entrypoint.go b/entrypoint.go index 7febfb4..97a4e0e 100644 --- a/entrypoint.go +++ b/entrypoint.go @@ -65,8 +65,9 @@ const ( NATIVE_TOOL = tools.NATIVE_TOOL ) -func GetMySelf() (string, error) { - return utils.GetMySelf((&peer.Peer{}).GetAccessor(&tools.APIRequest{Admin: true})) +func GetMySelf() (*peer.Peer, error) { + pp, err := utils.GetMySelf((&peer.Peer{}).GetAccessor(&tools.APIRequest{Admin: true})) + return pp.(*peer.Peer), err } func IsMySelf(peerID string) (bool, string) { diff --git a/models/collaborative_area/collaborative_area_mongo_accessor.go b/models/collaborative_area/collaborative_area_mongo_accessor.go index 3ce18c8..bdc1112 100644 --- a/models/collaborative_area/collaborative_area_mongo_accessor.go +++ b/models/collaborative_area/collaborative_area_mongo_accessor.go @@ -64,18 +64,18 @@ func (a *collaborativeAreaMongoAccessor) UpdateOne(set utils.DBObject, id string // StoreOne stores a collaborative area in the database, it automatically share to peers if the workspace is shared func (a *collaborativeAreaMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) { - id, err := utils.GetMySelf((&peer.Peer{}).GetAccessor(&tools.APIRequest{ + pp, err := utils.GetMySelf((&peer.Peer{}).GetAccessor(&tools.APIRequest{ Admin: true, })) // get the local peer - if err != nil { + if err != nil || pp == nil { return data, 404, err } - data.(*CollaborativeArea).Clear(id) // set the creator + data.(*CollaborativeArea).Clear(pp.GetID()) // set the creator // retrieve or proper peer if data.(*CollaborativeArea).CollaborativeAreaRule != nil { data.(*CollaborativeArea).CollaborativeAreaRule = &CollaborativeAreaRule{} } - data.(*CollaborativeArea).CollaborativeAreaRule.Creator = id + data.(*CollaborativeArea).CollaborativeAreaRule.Creator = pp.GetID() d, code, err := utils.GenericStoreOne(data.(*CollaborativeArea).Trim(), a) if code == 200 { a.sharedWorkflow(d.(*CollaborativeArea), d.GetID()) // create all shared workflows diff --git a/models/resources/resource.go b/models/resources/resource.go index a5f7862..90f5b90 100755 --- a/models/resources/resource.go +++ b/models/resources/resource.go @@ -271,15 +271,15 @@ func (ri *ResourceInstance[T]) GetPeerGroups() ([]ResourcePartnerITF, []map[stri groups = append(groups, p.GetPeerGroups()) } if len(groups) == 0 { - id, err := utils.GetMySelf((&peer.Peer{}).GetAccessor(&tools.APIRequest{ + pp, err := utils.GetMySelf((&peer.Peer{}).GetAccessor(&tools.APIRequest{ Admin: true, })) - if err != nil { + if err != nil || pp == nil { return partners, groups } groups = []map[string][]string{ { - id: {"*"}, + pp.GetID(): {"*"}, }, } // TODO make allow all only for self. @@ -356,14 +356,14 @@ func (ri *ResourcePartnerShip[T]) GetPricingsProfiles(peerID string, groups []st func (rp *ResourcePartnerShip[T]) GetPeerGroups() map[string][]string { if len(rp.PeerGroups) == 0 { - id, err := utils.GetMySelf((&peer.Peer{}).GetAccessor(&tools.APIRequest{ + pp, err := utils.GetMySelf((&peer.Peer{}).GetAccessor(&tools.APIRequest{ Admin: true, })) - if err != nil { + if err != nil || pp == nil { return rp.PeerGroups } return map[string][]string{ - id: {"*"}, + pp.GetID(): {"*"}, } } return rp.PeerGroups diff --git a/models/utils/common.go b/models/utils/common.go index 55438d5..56a81a7 100755 --- a/models/utils/common.go +++ b/models/utils/common.go @@ -175,24 +175,24 @@ func GenericRawUpdateOne(set DBObject, id string, a Accessor) (DBObject, int, er return a.LoadOne(id) } -func GetMySelf(wfa Accessor) (string, error) { +func GetMySelf(wfa Accessor) (ShallowDBObject, error) { id, err := GenerateNodeID() if err != nil { - return "", err + return nil, err } datas, _, _ := wfa.Search(nil, id, false) if len(datas) > 0 { - return datas[0].GetID(), nil + return datas[0], nil } - return "", errors.New("peer not found") + return nil, errors.New("peer not found") } func IsMySelf(peerID string, wfa Accessor) (bool, string) { - id, err := GetMySelf(wfa) - if err != nil { + pp, err := GetMySelf(wfa) + if err != nil || pp == nil { return false, "" } - return peerID == id, id + return peerID == pp.GetID(), pp.GetID() } func GenerateNodeID() (string, error) { diff --git a/models/workflow_execution/workflow_execution.go b/models/workflow_execution/workflow_execution.go index ee38443..bec36e5 100755 --- a/models/workflow_execution/workflow_execution.go +++ b/models/workflow_execution/workflow_execution.go @@ -17,46 +17,6 @@ import ( "go.mongodb.org/mongo-driver/bson/primitive" ) -type WorkflowSchedule struct { - UUID string `json:"id" validate:"required"` // ExecutionsID is the list of the executions id of the workflow - Workflow *workflow.Workflow `json:"workflow,omitempty"` // Workflow is the workflow dependancy of the schedule - WorkflowExecution []*WorkflowExecution `json:"workflow_executions,omitempty"` // WorkflowExecution is the list of executions of the workflow - Message string `json:"message,omitempty"` // Message is the message of the schedule - Warning string `json:"warning,omitempty"` // Warning is the warning message of the schedule - Start time.Time `json:"start" validate:"required,ltfield=End"` // Start is the start time of the schedule, is required and must be less than the End time - End *time.Time `json:"end,omitempty"` // End is the end time of the schedule, is required and must be greater than the Start time - DurationS float64 `json:"duration_s" default:"-1"` // End is the end time of the schedule - Cron string `json:"cron,omitempty"` // here the cron format : ss mm hh dd MM dw task - - BookingMode booking.BookingMode `json:"booking_mode,omitempty"` // BookingMode qualify the preemption order of the scheduling. if no payment allowed with preemption set up When_Possible - SelectedInstances workflow.ConfigItem `json:"selected_instances"` - SelectedPartnerships workflow.ConfigItem `json:"selected_partnerships"` - SelectedBuyings workflow.ConfigItem `json:"selected_buyings"` - SelectedStrategies workflow.ConfigItem `json:"selected_strategies"` - - SelectedBillingStrategy pricing.BillingStrategy `json:"selected_billing_strategy"` -} - -func NewScheduler(mode int, start string, end string, durationInS float64, cron string) *WorkflowSchedule { - ws := &WorkflowSchedule{ - UUID: uuid.New().String(), - Start: time.Now(), - BookingMode: booking.BookingMode(mode), - DurationS: durationInS, - Cron: cron, - } - s, err := time.Parse("2006-01-02T15:04:05", start) - if err == nil && ws.BookingMode == booking.PLANNED { - ws.Start = s // can apply a defined start other than now, if planned - } - - e, err := time.Parse("2006-01-02T15:04:05", end) - if err == nil { - ws.End = &e - } - return ws -} - /* * WorkflowExecution is a struct that represents a list of workflow executions * Warning: No user can write (del, post, put) a workflow execution, it is only used by the system