51 lines
1.7 KiB
Go
51 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"sort"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/compose/frombus"
|
|
"git.novox.be/novox/mesh-sdk/go/delivery"
|
|
)
|
|
|
|
// placementExport prints each node's placement as the catalogue's placement file says it (novox/hq ADR 0555 §6, issue
|
|
// 1126): what a person decided of the node and where its modules run, read by this controller's own code from its own
|
|
// store, as JSON keyed by node. The one verb the controller gains for its exit (the operator, 2026-10-26 19:06:40, ADR
|
|
// 0547 §1's one exception besides §5's grant): read once by the seed of the placement files, whose pull request merges
|
|
// only when its composition check composes every node equal to what it runs. It reads the same Input every composition
|
|
// of this controller reads (readMeshAndNodes, readSettings) and writes nothing.
|
|
//
|
|
// It moves a piece of the research "The controller, NATS-native": the controller's last node data (node rows, placement,
|
|
// ports, pins, bindings, config placement) leaves it for the catalogue, before its exit at ADR 0547's third milestone.
|
|
func placementExport(ctx context.Context, open *stores, args []string) error {
|
|
if len(args) > 1 {
|
|
return errors.New("node placement-export [<name>]")
|
|
}
|
|
in, _, err := readMeshAndNodes(ctx, open)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if _, err := readSettings(ctx, open, &in); err != nil {
|
|
return err
|
|
}
|
|
var names []string
|
|
if len(args) == 1 {
|
|
names = []string{args[0]}
|
|
} else {
|
|
for _, n := range in.Nodes {
|
|
names = append(names, n.Name)
|
|
}
|
|
sort.Strings(names)
|
|
}
|
|
out := make(map[string]delivery.Placement, len(names))
|
|
for _, name := range names {
|
|
p, err := frombus.Export(in, name)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
out[name] = p
|
|
}
|
|
return printJSON(out)
|
|
}
|