119 lines
4.7 KiB
Go
119 lines
4.7 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
|
condseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
|
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
|
)
|
|
|
|
// RegistrationMissingKind is the runner's finding of a mover that waits on its module's registration (design 47 H H-A-262,
|
|
// G A-327): scope module, id the module, raised while a mover of a running pipeline has no registration to place its steps
|
|
// from, cleared when the registration arrives or no running pipeline still waits on it (H-A-265 (4)).
|
|
const RegistrationMissingKind = "registration-missing"
|
|
|
|
// registrationMissingID is the finding's id: the module, escaped as a key's name is.
|
|
func registrationMissingID(module string) string { return keys.EscapeName(module) }
|
|
|
|
// registrationMissing raises registration-missing of module, waited on by the pipeline key (H-A-262).
|
|
func (s *Starter) registrationMissing(module, key string) {
|
|
// Judged only once the registrations view's first read is in (design 47 H2 §788); before it, said once.
|
|
if s.RegistrationsRead != nil && !s.RegistrationsRead() {
|
|
if s.unreadSaid.CompareAndSwap(false, true) {
|
|
s.logf("registrations not yet read: no step is placed from a registration not read, and no %s is judged before they are (%s waits, in %s)", RegistrationMissingKind, module, key)
|
|
}
|
|
return
|
|
}
|
|
if s.Findings == nil {
|
|
return
|
|
}
|
|
id := registrationMissingID(module)
|
|
err := s.Findings.Write(context.Background(), condseat.Finding{Scope: mcc.ScopeModule, ID: id, Kind: RegistrationMissingKind,
|
|
Severity: condseat.FindingSeverityWarning,
|
|
Summary: fmt.Sprintf("%s has no registration: the pipeline %s waits on it for its steps", module, key),
|
|
Headline: "A pipeline waits on a module's registration",
|
|
Explanation: fmt.Sprintf("The pipeline %s moves %s, which has no registration, so none of its steps is placed (A-327). The indexer registers a module the take-in first lists (H-A-262); this is cleared when the registration of %s arrives.",
|
|
key, module, module),
|
|
Needs: "the registration of " + module,
|
|
Source: "pipeline-runner." + RegistrationMissingKind, Observer: s.Observer, At: s.now(),
|
|
Subject: condseat.Subject{Scope: mcc.ScopeModule, ID: id}})
|
|
if err != nil {
|
|
s.logf("the finding %s of %s is not written: %v", RegistrationMissingKind, module, err)
|
|
}
|
|
}
|
|
|
|
// registrationArrived clears registration-missing of module, saying why, when the findings hold it (H-A-262, H-A-265 (4)).
|
|
func (s *Starter) registrationArrived(module, why string) {
|
|
if s.Findings == nil {
|
|
return
|
|
}
|
|
id := registrationMissingID(module)
|
|
for _, f := range s.Findings.Held() {
|
|
if f.Scope != mcc.ScopeModule || f.ID != id || f.Kind != RegistrationMissingKind {
|
|
continue
|
|
}
|
|
if err := s.Findings.Clear(context.Background(), mcc.ScopeModule, id, RegistrationMissingKind, why); err != nil {
|
|
s.logf("the finding %s of %s is not cleared: %v", RegistrationMissingKind, module, err)
|
|
}
|
|
return
|
|
}
|
|
}
|
|
|
|
// JudgeRegistrationMissing clears registration-missing of every module the registrations held now name, and of every module
|
|
// no running pipeline still has an unplaced mover of (H-A-265 (4)): a pipeline that ended, failed (H-A-163) or cancelled,
|
|
// with the mover still waiting leaves no finding behind. It is judged at a pipeline's end and in Waiting.
|
|
func (s *Starter) JudgeRegistrationMissing(store Updater) {
|
|
if s.Findings == nil {
|
|
return
|
|
}
|
|
var modules []string
|
|
for _, f := range s.Findings.Held() {
|
|
if f.Scope != mcc.ScopeModule || f.Kind != RegistrationMissingKind {
|
|
continue
|
|
}
|
|
module, err := keys.UnescapeName(f.ID)
|
|
if err != nil {
|
|
module = f.ID
|
|
}
|
|
if s.Registration != nil {
|
|
if _, ok := s.Registration(module); ok {
|
|
s.registrationArrived(module, "the registration of "+module+" arrived")
|
|
continue
|
|
}
|
|
}
|
|
modules = append(modules, module)
|
|
}
|
|
if len(modules) == 0 || store == nil {
|
|
return
|
|
}
|
|
pkeys, err := allKeys(store)
|
|
if err != nil {
|
|
s.logf("the finding %s is not judged: the pipelines are not listed: %v", RegistrationMissingKind, err)
|
|
return
|
|
}
|
|
waiting := map[string]bool{}
|
|
for _, key := range pkeys {
|
|
p, _, err := store.Get(key)
|
|
if err != nil {
|
|
s.logf("the finding %s is not judged: the pipeline %s is not read: %v", RegistrationMissingKind, key, err)
|
|
return
|
|
}
|
|
if p.Outcome != seat.PipelineOutcomeRunning {
|
|
continue
|
|
}
|
|
for _, m := range modules {
|
|
if Moves(p, m) && !placed(p, m) {
|
|
waiting[m] = true
|
|
}
|
|
}
|
|
}
|
|
for _, m := range modules {
|
|
if !waiting[m] {
|
|
s.registrationArrived(m, "no running pipeline still waits on the registration of "+m)
|
|
}
|
|
}
|
|
}
|