diff --git a/models/booking/planner/planner.go b/models/booking/planner/planner.go index 3255a59..f3bd5b6 100644 --- a/models/booking/planner/planner.go +++ b/models/booking/planner/planner.go @@ -2,8 +2,10 @@ package planner import ( "encoding/json" + "fmt" "time" + "cloud.o-forge.io/core/oc-lib/dbs" "cloud.o-forge.io/core/oc-lib/models/booking" "cloud.o-forge.io/core/oc-lib/models/common/enum" "cloud.o-forge.io/core/oc-lib/models/resources" @@ -62,13 +64,22 @@ func generate(request *tools.APIRequest, shallow bool) (*Planner, error) { // 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) + confirmed, code, err := accessor.Search(&dbs.Filters{ + And: map[string][]dbs.Filter{ + "expected_start_date": {{Operator: dbs.GTE.String(), Value: time.Now().UTC()}}, + }, + }, "*", false) if code != 200 || err != nil { return nil, err } - drafts, _, _ := accessor.Search(nil, "*", true) + drafts, _, _ := accessor.Search(&dbs.Filters{ + And: map[string][]dbs.Filter{ + "expected_start_date": {{Operator: dbs.GTE.String(), Value: time.Now().UTC()}}, + }, + }, "*", true) bookings := append(confirmed, drafts...) + fmt.Println("BOOKS", len(bookings)) p := &Planner{ GeneratedAt: time.Now(), Schedule: map[string][]*PlannerSlot{}, @@ -86,6 +97,7 @@ func generate(request *tools.APIRequest, shallow bool) (*Planner, error) { // Only compute and storage resources are eligible if bk.ResourceType != tools.COMPUTE_RESOURCE && bk.ResourceType != tools.STORAGE_RESOURCE { + fmt.Println("Not eligible") continue } @@ -266,7 +278,7 @@ func extractSlotData(bk *booking.Booking, request *tools.APIRequest) (instanceID if err != nil { return } - + fmt.Println("EXTRACT CLOT", bk.ResourceType) switch bk.ResourceType { case tools.COMPUTE_RESOURCE: instanceID, usage, cap = extractComputeSlot(b, bk.ResourceID, request) @@ -283,17 +295,20 @@ func extractComputeSlot(pricedJSON []byte, resourceID string, request *tools.API var priced resources.PricedComputeResource if err := json.Unmarshal(pricedJSON, &priced); err != nil { + fmt.Println("extractComputeSlot", err) return } res, _, err := (&resources.ComputeResource{}).GetAccessor(request).LoadOne(resourceID) if err != nil { + fmt.Println("extractComputeSlot2", err) return } compute := res.(*resources.ComputeResource) instance := findComputeInstance(compute, priced.InstancesRefs) if instance == nil { + fmt.Println("extractComputeSlot no instance found", err) return } instanceID = instance.GetID()