package hostops import ( "context" "log" "github.com/carlosframework/platform/internal/boxchoice" "github.com/carlosframework/platform/internal/hostclaim" "github.com/carlosframework/platform/internal/release" ) // ClaimLoads counts, from one listing of control/hosts/ (ListClaims), the // hosts whose claim names each box as op.exec, in total and per // "acct/app": choose()'s second rule until spec 2 (region HA ยง5.2, claim // P5-D2). The count only balances, so a claim that cannot be read is // logged and left out; a listing that fails is an error, because a count // of nothing would send every create to one box. func ClaimLoads(ctx context.Context, s release.Store) (map[string]boxchoice.Load, error) { hosts, err := ListClaims(ctx, s) if err != nil { return nil, err } out := map[string]boxchoice.Load{} for _, host := range hosts { obs, err := hostclaim.Read(ctx, s, host) if err != nil { log.Printf("hostops: claim loads: %s: %v", host, err) continue } if obs.Absent || obs.Claim.Holder == nil || obs.Claim.Op.Exec == "" || obs.Claim.Op.Exec == "none" { continue } box, h := obs.Claim.Op.Exec, obs.Claim.Holder l := out[box] if l.Apps == nil { l.Apps = map[string]int{} } l.Hosts++ l.Apps[h.Account+"/"+h.App]++ out[box] = l } return out, nil }