diff --git a/models/booking/booking.go b/models/booking/booking.go index 35ce927..7b14d62 100644 --- a/models/booking/booking.go +++ b/models/booking/booking.go @@ -36,6 +36,10 @@ type Booking struct { ResourceID string `json:"resource_id,omitempty" bson:"resource_id,omitempty" validate:"required"` // could be a Compute or a Storage InstanceID string `json:"instance_id,omitempty" bson:"instance_id,omitempty" validate:"required"` // could be a Compute or a Storage + // Authorization: identifies who created this draft and the Check session it belongs to. + // Used to verify UPDATE and DELETE orders from remote schedulers. + SchedulerPeerID string `json:"scheduler_peer_id,omitempty" bson:"scheduler_peer_id,omitempty"` + SchedulingSessionID string `json:"scheduling_session_id,omitempty" bson:"scheduling_session_id,omitempty"` } func (b *Booking) CalcDeltaOfExecution() map[string]map[string]models.MetricResume { diff --git a/models/booking/planner/planner.go b/models/booking/planner/planner.go index 8d83edd..a33f35f 100644 --- a/models/booking/planner/planner.go +++ b/models/booking/planner/planner.go @@ -58,10 +58,15 @@ func GenerateShallow(request *tools.APIRequest) (*Planner, error) { func generate(request *tools.APIRequest, shallow bool) (*Planner, error) { accessor := booking.NewAccessor(request) - bookings, code, err := accessor.Search(nil, "*", false) + // Include both confirmed (IsDraft=false) and draft (IsDraft=true) bookings + // so the planner reflects the full picture: first-come first-served on all + // pending reservations regardless of confirmation state. + confirmed, code, err := accessor.Search(nil, "*", false) if code != 200 || err != nil { return nil, err } + drafts, _, _ := accessor.Search(nil, "*", true) + bookings := append(confirmed, drafts...) p := &Planner{ GeneratedAt: time.Now(), diff --git a/models/resources/purchase_resource/purchase_resource.go b/models/resources/purchase_resource/purchase_resource.go index 2a5b9bf..e8e1ccf 100644 --- a/models/resources/purchase_resource/purchase_resource.go +++ b/models/resources/purchase_resource/purchase_resource.go @@ -19,6 +19,10 @@ type PurchaseResource struct { InstanceID string `json:"instance_id,omitempty" bson:"instance_id,omitempty" validate:"required"` // could be a Compute or a Storage ResourceType tools.DataType `json:"resource_type" bson:"resource_type" validate:"required"` + + // Authorization: identifies who created this draft and the Check session it belongs to. + SchedulerPeerID string `json:"scheduler_peer_id,omitempty" bson:"scheduler_peer_id,omitempty"` + SchedulingSessionID string `json:"scheduling_session_id,omitempty" bson:"scheduling_session_id,omitempty"` } func (d *PurchaseResource) GetAccessor(request *tools.APIRequest) utils.Accessor { diff --git a/models/workflow_execution/workflow_execution.go b/models/workflow_execution/workflow_execution.go index 751ab18..42b0d59 100755 --- a/models/workflow_execution/workflow_execution.go +++ b/models/workflow_execution/workflow_execution.go @@ -165,8 +165,9 @@ func (d *WorkflowExecution) buyEach(bs pricing.BillingStrategy, executionsID str end := start.Add(time.Duration(priced.GetExplicitDurationInS()) * time.Second) bookingItem := &purchase_resource.PurchaseResource{ AbstractObject: utils.AbstractObject{ - UUID: uuid.New().String(), - Name: d.GetName() + "_" + executionsID + "_" + wfID, + UUID: uuid.New().String(), + Name: d.GetName() + "_" + executionsID + "_" + wfID, + IsDraft: true, }, PricedItem: m, ExecutionID: d.GetID(), @@ -224,12 +225,13 @@ func (d *WorkflowExecution) bookEach(executionsID string, wfID string, dt tools. json.Unmarshal(b, &m) bookingItem := &booking.Booking{ AbstractObject: utils.AbstractObject{ - UUID: uuid.New().String(), - Name: d.GetName() + "_" + executionsID + "_" + wfID, + UUID: uuid.New().String(), + Name: d.GetName() + "_" + executionsID + "_" + wfID, + IsDraft: true, }, PricedItem: m, ExecutionsID: executionsID, - State: enum.SCHEDULED, + State: enum.DRAFT, ResourceID: priced.GetID(), InstanceID: priced.GetInstanceID(), ResourceType: dt,