adjust self

This commit is contained in:
mr
2026-02-23 14:07:39 +01:00
parent 12c506e9a7
commit 19b0f10e71
5 changed files with 20 additions and 59 deletions

View File

@@ -65,8 +65,9 @@ const (
NATIVE_TOOL = tools.NATIVE_TOOL NATIVE_TOOL = tools.NATIVE_TOOL
) )
func GetMySelf() (string, error) { func GetMySelf() (*peer.Peer, error) {
return utils.GetMySelf((&peer.Peer{}).GetAccessor(&tools.APIRequest{Admin: true})) pp, err := utils.GetMySelf((&peer.Peer{}).GetAccessor(&tools.APIRequest{Admin: true}))
return pp.(*peer.Peer), err
} }
func IsMySelf(peerID string) (bool, string) { func IsMySelf(peerID string) (bool, string) {

View File

@@ -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 // 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) { 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, Admin: true,
})) // get the local peer })) // get the local peer
if err != nil { if err != nil || pp == nil {
return data, 404, err return data, 404, err
} }
data.(*CollaborativeArea).Clear(id) // set the creator data.(*CollaborativeArea).Clear(pp.GetID()) // set the creator
// retrieve or proper peer // retrieve or proper peer
if data.(*CollaborativeArea).CollaborativeAreaRule != nil { if data.(*CollaborativeArea).CollaborativeAreaRule != nil {
data.(*CollaborativeArea).CollaborativeAreaRule = &CollaborativeAreaRule{} data.(*CollaborativeArea).CollaborativeAreaRule = &CollaborativeAreaRule{}
} }
data.(*CollaborativeArea).CollaborativeAreaRule.Creator = id data.(*CollaborativeArea).CollaborativeAreaRule.Creator = pp.GetID()
d, code, err := utils.GenericStoreOne(data.(*CollaborativeArea).Trim(), a) d, code, err := utils.GenericStoreOne(data.(*CollaborativeArea).Trim(), a)
if code == 200 { if code == 200 {
a.sharedWorkflow(d.(*CollaborativeArea), d.GetID()) // create all shared workflows a.sharedWorkflow(d.(*CollaborativeArea), d.GetID()) // create all shared workflows

View File

@@ -271,15 +271,15 @@ func (ri *ResourceInstance[T]) GetPeerGroups() ([]ResourcePartnerITF, []map[stri
groups = append(groups, p.GetPeerGroups()) groups = append(groups, p.GetPeerGroups())
} }
if len(groups) == 0 { if len(groups) == 0 {
id, err := utils.GetMySelf((&peer.Peer{}).GetAccessor(&tools.APIRequest{ pp, err := utils.GetMySelf((&peer.Peer{}).GetAccessor(&tools.APIRequest{
Admin: true, Admin: true,
})) }))
if err != nil { if err != nil || pp == nil {
return partners, groups return partners, groups
} }
groups = []map[string][]string{ groups = []map[string][]string{
{ {
id: {"*"}, pp.GetID(): {"*"},
}, },
} }
// TODO make allow all only for self. // 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 { func (rp *ResourcePartnerShip[T]) GetPeerGroups() map[string][]string {
if len(rp.PeerGroups) == 0 { 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, Admin: true,
})) }))
if err != nil { if err != nil || pp == nil {
return rp.PeerGroups return rp.PeerGroups
} }
return map[string][]string{ return map[string][]string{
id: {"*"}, pp.GetID(): {"*"},
} }
} }
return rp.PeerGroups return rp.PeerGroups

View File

@@ -175,24 +175,24 @@ func GenericRawUpdateOne(set DBObject, id string, a Accessor) (DBObject, int, er
return a.LoadOne(id) return a.LoadOne(id)
} }
func GetMySelf(wfa Accessor) (string, error) { func GetMySelf(wfa Accessor) (ShallowDBObject, error) {
id, err := GenerateNodeID() id, err := GenerateNodeID()
if err != nil { if err != nil {
return "", err return nil, err
} }
datas, _, _ := wfa.Search(nil, id, false) datas, _, _ := wfa.Search(nil, id, false)
if len(datas) > 0 { 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) { func IsMySelf(peerID string, wfa Accessor) (bool, string) {
id, err := GetMySelf(wfa) pp, err := GetMySelf(wfa)
if err != nil { if err != nil || pp == nil {
return false, "" return false, ""
} }
return peerID == id, id return peerID == pp.GetID(), pp.GetID()
} }
func GenerateNodeID() (string, error) { func GenerateNodeID() (string, error) {

View File

@@ -17,46 +17,6 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive" "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 * 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 * Warning: No user can write (del, post, put) a workflow execution, it is only used by the system