package main import ( "bytes" "context" "encoding/json" "errors" "flag" "fmt" "sort" "strings" "github.com/novox/mesh-controller/internal/broker" "github.com/novox/mesh-controller/internal/catalogue" "github.com/novox/mesh-controller/internal/inventory" "github.com/novox/mesh-controller/internal/licences" "github.com/novox/mesh-controller/internal/overlay" "net" "strconv" ) // working out what one machine should be. // // Split out of main.go, which had reached 2,769 lines because appending was always the // cheapest next step. That is how novox/hq ADR 0001 records `hal/sdk` reaching 34,636: // nothing in it was wrong, and no one edit was the one that should have been a new file. // planFor works out everything a node should run, from what was assigned to it. func planFor(ctx context.Context, open *stores, nodeName string) (catalogue.Resolution, catalogue.SettingsBy, error) { inv := open.inventory shelf, err := inv.Catalogue(ctx) if err != nil { return catalogue.Resolution{}, nil, err } assigned, err := inv.Assigned(ctx, nodeName) if err != nil { return catalogue.Resolution{}, nil, err } capabilities, err := inv.ProfileOf(ctx, nodeName) if err != nil { return catalogue.Resolution{}, nil, err } places, err := inv.Overlays(ctx) if err != nil { return catalogue.Resolution{}, nil, err } var site string for _, p := range places { if p.Name == nodeName { site = p.Site } } world, err := theRestOfTheMesh(ctx, inv, shelf, nodeName) if err != nil { return catalogue.Resolution{}, nil, err } world.Pinned, err = inv.PinsFor(ctx, nodeName) if err != nil { return catalogue.Resolution{}, nil, err } onNetwork, err := whereEveryoneIs(ctx, inv, shelf) if err != nil { return catalogue.Resolution{}, nil, err } // What this mesh can answer with a record rather than a machine, and which record each of // this node's modules was put on. Read across a context boundary by name, which is what // crossing one is allowed to carry (novox/hq ADR 0008). world.Licences, world.Using, err = licencesFor(ctx, open, nodeName) if err != nil { return catalogue.Resolution{}, nil, err } // The domain this node composes its routed names under (novox/hq ADR 0066). A route // contribution carries only a label; the resolver joins