Compose the private network and the rest of the mesh over a plain Input: Generators and TheRestOfTheMesh (issues 1360, 1361). Ported from mesh-control 6c2a8d62 network.go, plan.go, seat_pass.go. Store-backed tests (aMesh) are rebuilt as Inputs from the same values; the writes they exercised (a placement through overlay place, a seat passed through the store) are Input values or a returned Pass, and the controller-only tests of a failed read or write have no counterpart here. Unit level 1.04 s of 2 s.
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package compose
|
||||
|
||||
import (
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
)
|
||||
|
||||
// LicenceProvision is what a module requires in order to be given a licence (the controller's licences.Provision).
|
||||
const LicenceProvision = "model-access"
|
||||
|
||||
// resolution works out what one node should run, from what was assigned to it: the controller's planFor up to and
|
||||
// including the resolution (plan.go planFor), and no further. A failure to compose the node's own modules is wrapped as
|
||||
// notResolvable; every other failure is returned as it is. What it leaves to the issue after is the credentials of
|
||||
// what the node takes from elsewhere and its settings.
|
||||
func (c *composer) resolution(nodeName string) (catalogue.Resolution, error) {
|
||||
node, err := c.in.node(nodeName)
|
||||
if err != nil {
|
||||
return catalogue.Resolution{}, err
|
||||
}
|
||||
shelf := c.in.Catalogue
|
||||
world, _, _, err := c.theRestOfTheMesh(nodeName)
|
||||
if err != nil {
|
||||
return catalogue.Resolution{}, err
|
||||
}
|
||||
world.Pinned = node.Pins
|
||||
// Where each of its consumers of a provision that keeps data was last sent (novox/hq ADR 0232).
|
||||
world.Bound = node.Bound
|
||||
|
||||
onNetwork, err := c.whereEveryoneIs()
|
||||
if err != nil {
|
||||
return catalogue.Resolution{}, 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.
|
||||
world.Licences, world.Using = c.licencesFor(nodeName)
|
||||
|
||||
resolved, err := catalogue.Resolve(shelf, node.Assigned,
|
||||
catalogue.Node{Name: nodeName, Site: node.Place.Site, Capabilities: node.Capabilities,
|
||||
At: onNetwork[nodeName], PublicDomain: node.PublicDomain,
|
||||
Account: node.Account, AccountHome: node.AccountHome,
|
||||
AgentAccount: node.AgentAccount, AgentAccountHome: node.AgentAccountHome}, world)
|
||||
if err != nil {
|
||||
// The node's own set does not compose: the only failure a mesh-wide gatherer may pass over.
|
||||
return catalogue.Resolution{}, notResolvable{err}
|
||||
}
|
||||
return resolved, nil
|
||||
}
|
||||
|
||||
// licencesFor is what this node can be answered with by record, and what it was put on. A mesh with no licences at all
|
||||
// is the ordinary case and not an error.
|
||||
func (c *composer) licencesFor(node string) (map[string][]catalogue.Record, map[string]map[string]catalogue.Record) {
|
||||
all := c.in.Licences
|
||||
if len(all) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
offered := map[string][]catalogue.Record{}
|
||||
byName := map[string]catalogue.Record{}
|
||||
for _, one := range all {
|
||||
record := catalogue.Record{Name: one.Name, Serves: one.Serves}
|
||||
offered[LicenceProvision] = append(offered[LicenceProvision], record)
|
||||
byName[one.Name] = record
|
||||
}
|
||||
using := map[string]map[string]catalogue.Record{}
|
||||
for _, one := range all {
|
||||
for _, h := range one.Holders {
|
||||
if h.Node != node {
|
||||
continue
|
||||
}
|
||||
if using[h.Module] == nil {
|
||||
using[h.Module] = map[string]catalogue.Record{}
|
||||
}
|
||||
using[h.Module][LicenceProvision] = byName[one.Name]
|
||||
}
|
||||
}
|
||||
return offered, using
|
||||
}
|
||||
Reference in New Issue
Block a user