Drop the plan state from the store and the assignments: migration 0108 and placement-only assignments (release 6, issue 1945 B9, B4)
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package inventory
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -37,84 +35,3 @@ const (
|
||||
ProvFailed = "failed"
|
||||
ProvRemoved = "removed"
|
||||
)
|
||||
|
||||
// ProvLookup answers a client's newest report of a module on a machine; false when it has said nothing of it.
|
||||
type ProvLookup func(node, module string) (ProvReport, bool)
|
||||
|
||||
// OutcomeProvisioningFailed begins the outcome of a send whose module's files the provisioner failed to place.
|
||||
const OutcomeProvisioningFailed = "provisioning failed"
|
||||
|
||||
// ProvisionedSend is a machine's report of a send, with its provisioner client's reports of every module the send
|
||||
// handed to it: what a walk counts as that machine's report. engine and reported are the machine's own report and
|
||||
// whether it said one. A failed client report is the send's outcome, whatever the machine said; none, or one not
|
||||
// yet applied on the build sent, leaves the send unreported.
|
||||
func ProvisionedSend(node string, send SentDeclaration, engine AppliedReport, reported bool, prov ProvLookup) (AppliedReport, bool) {
|
||||
if len(send.Provisioned) == 0 {
|
||||
return engine, reported
|
||||
}
|
||||
// The machine's own failure, or its wait for a busy container, is its report whatever the client says.
|
||||
if reported && (engine.Outcome != OutcomeApplied || engine.Waiting) {
|
||||
return engine, true
|
||||
}
|
||||
modules := make([]string, 0, len(send.Provisioned))
|
||||
for m := range send.Provisioned {
|
||||
modules = append(modules, m)
|
||||
}
|
||||
sort.Strings(modules)
|
||||
at, placed := engine.At, true
|
||||
for _, m := range modules {
|
||||
r, said := ProvReport{}, false
|
||||
if prov != nil {
|
||||
r, said = prov(node, m)
|
||||
}
|
||||
switch {
|
||||
case said && r.Status == ProvFailed && aboutTheSend(r, send, send.Provisioned[m]):
|
||||
return AppliedReport{At: r.At, Outcome: fmt.Sprintf("%s (%s: %s)", OutcomeProvisioningFailed, m,
|
||||
orNoReason(r.Reason))}, true
|
||||
case said && r.Status == ProvApplied && r.Templates == send.Provisioned[m]:
|
||||
if r.At.After(at) {
|
||||
at = r.At
|
||||
}
|
||||
default:
|
||||
placed = false
|
||||
}
|
||||
}
|
||||
if !reported || !placed {
|
||||
return AppliedReport{}, false
|
||||
}
|
||||
engine.At = at
|
||||
return engine, true
|
||||
}
|
||||
|
||||
// Only is the send narrowed to what it handed to the provisioner for the named modules: a delivery waits on the
|
||||
// modules it carries, never on another module the same machine's declaration hands (ADR 0362 §1-2, issue 840).
|
||||
// A send handing nothing is returned as it is.
|
||||
func (s SentDeclaration) Only(modules ...string) SentDeclaration {
|
||||
if len(s.Provisioned) == 0 {
|
||||
return s
|
||||
}
|
||||
kept := map[string]string{}
|
||||
for _, m := range modules {
|
||||
if d, ok := s.Provisioned[m]; ok {
|
||||
kept[m] = d
|
||||
}
|
||||
}
|
||||
s.Provisioned = kept
|
||||
return s
|
||||
}
|
||||
|
||||
// aboutTheSend says a client's failure is about what the send handed: on the build's templates, or, said before it
|
||||
// had any to name (its templates could not be fetched), no earlier than the send.
|
||||
func aboutTheSend(r ProvReport, send SentDeclaration, digest string) bool {
|
||||
if r.Templates != "" {
|
||||
return r.Templates == digest
|
||||
}
|
||||
return send.At.IsZero() || !r.At.Before(send.At)
|
||||
}
|
||||
|
||||
func orNoReason(s string) string {
|
||||
if s == "" {
|
||||
return "no reason given"
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user