Files
mesh-contracts/placement/go/clients/meshmoduleassignerclient/reads.go
T

38 lines
1.5 KiB
Go

package meshmoduleassignerclient
import (
"sort"
seat "git.novox.be/novox/mesh-contracts/placement/go/seats/meshmoduleassigner"
)
// The holder of the seat and the names a reader of its states declares in its `reads` (`<module>.<state>`) and binds
// to (`<module>_<state>`): named here once, by the seat's state, so no reader builds them from a module's name
// (ADR 0634 §4; the lead's ruling of 2026-11-05).
const (
// Module is the module that holds the seat mesh-module-assigner.
Module = "mesh-delivery-assigner"
// PlacementRead and SeatHoldersRead are the states `placement` and `seat-holders`, as a manifest's `reads` names them.
PlacementRead = Module + "." + seat.StatePlacement
SeatHoldersRead = Module + "." + seat.StateSeatHolders
// PlacementBucket and SeatHoldersBucket are the states' buckets.
PlacementBucket = Module + "_" + seat.StatePlacement
SeatHoldersBucket = Module + "_" + seat.StateSeatHolders
)
// MachineNames is every machine the seat places modules on, sorted, from its state `placement` as a reader holds its
// keys: each with a node key `<node>.node` or, in the form before, `placement.<node>`. Module keys and keys of the
// state's other kinds are passed over.
func MachineNames(keys map[string][]byte) []string {
seen := map[string]bool{}
out := []string{}
for k := range keys {
if node, _, kind, err := ParseKey(k); err == nil && kind != ModuleKind && !seen[node] {
seen[node] = true
out = append(out, node)
}
}
sort.Strings(out)
return out
}