planner trace

This commit is contained in:
mr
2026-03-20 12:09:28 +01:00
parent c34b8c6703
commit 2abc035ec0

View File

@@ -2,8 +2,10 @@ package planner
import ( import (
"encoding/json" "encoding/json"
"fmt"
"time" "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/booking"
"cloud.o-forge.io/core/oc-lib/models/common/enum" "cloud.o-forge.io/core/oc-lib/models/common/enum"
"cloud.o-forge.io/core/oc-lib/models/resources" "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 // Include both confirmed (IsDraft=false) and draft (IsDraft=true) bookings
// so the planner reflects the full picture: first-come first-served on all // so the planner reflects the full picture: first-come first-served on all
// pending reservations regardless of confirmation state. // 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 { if code != 200 || err != nil {
return nil, err 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...) bookings := append(confirmed, drafts...)
fmt.Println("BOOKS", len(bookings))
p := &Planner{ p := &Planner{
GeneratedAt: time.Now(), GeneratedAt: time.Now(),
Schedule: map[string][]*PlannerSlot{}, Schedule: map[string][]*PlannerSlot{},
@@ -86,6 +97,7 @@ func generate(request *tools.APIRequest, shallow bool) (*Planner, error) {
// Only compute and storage resources are eligible // Only compute and storage resources are eligible
if bk.ResourceType != tools.COMPUTE_RESOURCE && bk.ResourceType != tools.STORAGE_RESOURCE { if bk.ResourceType != tools.COMPUTE_RESOURCE && bk.ResourceType != tools.STORAGE_RESOURCE {
fmt.Println("Not eligible")
continue continue
} }
@@ -266,7 +278,7 @@ func extractSlotData(bk *booking.Booking, request *tools.APIRequest) (instanceID
if err != nil { if err != nil {
return return
} }
fmt.Println("EXTRACT CLOT", bk.ResourceType)
switch bk.ResourceType { switch bk.ResourceType {
case tools.COMPUTE_RESOURCE: case tools.COMPUTE_RESOURCE:
instanceID, usage, cap = extractComputeSlot(b, bk.ResourceID, request) 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 var priced resources.PricedComputeResource
if err := json.Unmarshal(pricedJSON, &priced); err != nil { if err := json.Unmarshal(pricedJSON, &priced); err != nil {
fmt.Println("extractComputeSlot", err)
return return
} }
res, _, err := (&resources.ComputeResource{}).GetAccessor(request).LoadOne(resourceID) res, _, err := (&resources.ComputeResource{}).GetAccessor(request).LoadOne(resourceID)
if err != nil { if err != nil {
fmt.Println("extractComputeSlot2", err)
return return
} }
compute := res.(*resources.ComputeResource) compute := res.(*resources.ComputeResource)
instance := findComputeInstance(compute, priced.InstancesRefs) instance := findComputeInstance(compute, priced.InstancesRefs)
if instance == nil { if instance == nil {
fmt.Println("extractComputeSlot no instance found", err)
return return
} }
instanceID = instance.GetID() instanceID = instance.GetID()