With no callers list on the seat mesh-wants, the asker a step's progress names is the one the runner writes on the StepRun it asks (C-W2), mesh-pipeline-runner. Builds: design 47 H §752 (consequence), G §496; H-A-41, H-A-88 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
82 lines
3.4 KiB
Go
82 lines
3.4 KiB
Go
package assign
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"mesh-delivery-assigner/internal/assignment"
|
|
"mesh-delivery-assigner/internal/buckets"
|
|
"sort"
|
|
"time"
|
|
|
|
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
|
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
|
occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient"
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
)
|
|
|
|
// A person's upgrade policy is the assigner's (novox/hq ADR 0565 §7, §8, issue 1953 D4, D5): kept in its state `policies`, one
|
|
// key per module, set and taken back through `mesh-wants.upgrade`. Every reader takes one derivation, mesh-sdk's
|
|
// catalogue.Upgrade: a person's choice over the module's word, its irreplaceable data and the default, the bus as any module (ADR 0601 §1).
|
|
|
|
// PoliciesBucket is the assigner's state `policies`.
|
|
func PoliciesBucket() string { return assignment.Module() + "_" + buckets.PoliciesState }
|
|
|
|
// DecodePolicies reads the policies state's values by key (the module); a value that cannot be read is left out, named.
|
|
func DecodePolicies(values map[string][]byte) (map[string]catalogue.PersonPolicy, []string) {
|
|
out := map[string]catalogue.PersonPolicy{}
|
|
var bad []string
|
|
for key, raw := range values {
|
|
var p catalogue.PersonPolicy
|
|
if err := json.Unmarshal(raw, &p); err != nil || p.V != catalogue.PersonPolicyVersion || p.Check() != nil || p.Module != key {
|
|
bad = append(bad, key)
|
|
continue
|
|
}
|
|
out[key] = p
|
|
}
|
|
sort.Strings(bad)
|
|
return out, bad
|
|
}
|
|
|
|
// PolicyOf is a module's policy and where it comes from, with the person's choice for it when there is one.
|
|
func PolicyOf(m catalogue.Manifest, chosen map[string]catalogue.PersonPolicy) (policy, from, why, by string) {
|
|
var c *catalogue.PersonPolicy
|
|
if p, ok := chosen[m.Module]; ok {
|
|
c = &p
|
|
}
|
|
return catalogue.Upgrade(m, c)
|
|
}
|
|
|
|
// KindProvisionFailed is the assigner's finding of a provision its module's want waits for that failed (ADR 0570 §4).
|
|
const KindProvisionFailed = "provision-failed"
|
|
|
|
// encode is the observation as the assigner's finding at at.
|
|
func encode(o Observed, at time.Time) (mcseat.Finding, error) { return o.Finding(at), nil }
|
|
|
|
// KindProvisionMissing is the assigner's finding of a required provision that has had no key for longer than its bound.
|
|
const KindProvisionMissing = "provision-missing"
|
|
|
|
// KindUnplaced is, from the lease write, a node that runs but no assignments names (ADR 0571 §6).
|
|
const KindUnplaced = "unplaced"
|
|
|
|
// UnplacedKey is its finding's key, `machine.<node>.unplaced`.
|
|
func UnplacedKey(node string) string {
|
|
return mcc.Key(mcc.ScopeMachine, node, KindUnplaced)
|
|
}
|
|
|
|
// UnplacedFinding is the finding of a node no assignments names since the lease write.
|
|
func UnplacedFinding(node string, at time.Time) (mcseat.Finding, error) {
|
|
summary := fmt.Sprintf("%s runs, but no assignments names it: since the controller handed its lease away nothing composes it, "+
|
|
"so the assigner writes it no want", node)
|
|
return encode(Observed{Scope: mcc.ScopeMachine, ID: node, Kind: KindUnplaced, Machine: node, Summary: summary,
|
|
Headline: clipHeadline(node + " has no assignments"), Needs: "place it with mesh-module-assigner.propose.",
|
|
Explanation: occ.NeedsYou + "place it with mesh-module-assigner.propose. " + summary + ".",
|
|
Source: "assigner." + KindUnplaced}, at)
|
|
}
|
|
|
|
func clipHeadline(s string) string {
|
|
if len([]rune(s)) <= 60 {
|
|
return s
|
|
}
|
|
return string([]rune(s)[:60])
|
|
}
|