Draft booking flow

This commit is contained in:
mr
2026-03-16 08:52:31 +01:00
parent 12ba346427
commit 465b91fd6e
4 changed files with 21 additions and 6 deletions

View File

@@ -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 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 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 { func (b *Booking) CalcDeltaOfExecution() map[string]map[string]models.MetricResume {

View File

@@ -58,10 +58,15 @@ func GenerateShallow(request *tools.APIRequest) (*Planner, error) {
func generate(request *tools.APIRequest, shallow bool) (*Planner, error) { func generate(request *tools.APIRequest, shallow bool) (*Planner, error) {
accessor := booking.NewAccessor(request) 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 { if code != 200 || err != nil {
return nil, err return nil, err
} }
drafts, _, _ := accessor.Search(nil, "*", true)
bookings := append(confirmed, drafts...)
p := &Planner{ p := &Planner{
GeneratedAt: time.Now(), GeneratedAt: time.Now(),

View File

@@ -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 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"` 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 { func (d *PurchaseResource) GetAccessor(request *tools.APIRequest) utils.Accessor {

View File

@@ -167,6 +167,7 @@ func (d *WorkflowExecution) buyEach(bs pricing.BillingStrategy, executionsID str
AbstractObject: utils.AbstractObject{ AbstractObject: utils.AbstractObject{
UUID: uuid.New().String(), UUID: uuid.New().String(),
Name: d.GetName() + "_" + executionsID + "_" + wfID, Name: d.GetName() + "_" + executionsID + "_" + wfID,
IsDraft: true,
}, },
PricedItem: m, PricedItem: m,
ExecutionID: d.GetID(), ExecutionID: d.GetID(),
@@ -226,10 +227,11 @@ func (d *WorkflowExecution) bookEach(executionsID string, wfID string, dt tools.
AbstractObject: utils.AbstractObject{ AbstractObject: utils.AbstractObject{
UUID: uuid.New().String(), UUID: uuid.New().String(),
Name: d.GetName() + "_" + executionsID + "_" + wfID, Name: d.GetName() + "_" + executionsID + "_" + wfID,
IsDraft: true,
}, },
PricedItem: m, PricedItem: m,
ExecutionsID: executionsID, ExecutionsID: executionsID,
State: enum.SCHEDULED, State: enum.DRAFT,
ResourceID: priced.GetID(), ResourceID: priced.GetID(),
InstanceID: priced.GetInstanceID(), InstanceID: priced.GetInstanceID(),
ResourceType: dt, ResourceType: dt,