H6 fingerprint-for-daemons: only a daemon whose want names a fingerprint is handed MESH_FINGERPRINT
Builds: design 47 H2 H-A-710 (1) (hq 27369077)
This commit is contained in:
@@ -3,8 +3,10 @@ package compositions
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
@@ -239,7 +241,7 @@ func Split(node string, resources []json.RawMessage, fps map[string]string, fill
|
||||
pathOf[head.Path] = key
|
||||
}
|
||||
if head.Module != "" {
|
||||
if raw, err = withFingerprint(raw, head.Type, fps[head.Module]); err != nil {
|
||||
if raw, err = withFingerprint(raw, head.Type, head.Module, fps[head.Module]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if raw, err = withBundleFingerprints(raw, head.Type, fps); err != nil {
|
||||
@@ -262,16 +264,24 @@ func Split(node string, resources []json.RawMessage, fps map[string]string, fill
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// FingerprintVar is the environment value every process the node-engine starts, a daemon or a container, holds: the
|
||||
// fingerprint of the want it applies. mesh-sdk's runtime reads it once at the process's start as the process's own build
|
||||
// (novox/hq ADR 0656 §1, design 47 *The fingerprint handover*).
|
||||
// FingerprintVar is the environment value every daemon the node-engine starts holds: the fingerprint of the want it
|
||||
// applies. mesh-sdk's runtime reads it once at the process's start as the process's own build (novox/hq ADR 0656 §1,
|
||||
// design 47 *The fingerprint handover*). A container is handed none (H-A-710).
|
||||
const FingerprintVar = "MESH_FINGERPRINT"
|
||||
|
||||
// withFingerprint is raw, when it is a daemon or a container, with FingerprintVar in its env set to fp. The value is
|
||||
// the node-engine's to say, so one a module declared of that name is replaced. Another resource, or no fingerprint, is
|
||||
// returned as it is.
|
||||
func withFingerprint(raw json.RawMessage, kind, fp string) (json.RawMessage, error) {
|
||||
if fp == "" || (kind != string(declaration.TypeProcess) && kind != string(declaration.TypeContainer)) {
|
||||
// journal says one line in the node-engine's journal (its standard error); a variable so a test reads what was said.
|
||||
var journal = func(line string) { fmt.Fprintf(os.Stderr, "mesh-host: %s\n", line) }
|
||||
|
||||
// takenOutSaid is each module a value of FingerprintVar taken out of an env was said for, once per node-engine process.
|
||||
var takenOutSaid sync.Map
|
||||
|
||||
// withFingerprint is raw with FingerprintVar in its env set to fp when it is a daemon and the want names a fingerprint
|
||||
// (design 47 H2, H-A-710 (1)). The value is the node-engine's to say, so one a module declared of that name is replaced.
|
||||
// A container is handed none, and a daemon whose want names none no more, so no process reports a build it was never
|
||||
// handed: a value of that name in such an env is taken out, said once per module and node-engine process. Another
|
||||
// resource is returned as it is.
|
||||
func withFingerprint(raw json.RawMessage, kind, module, fp string) (json.RawMessage, error) {
|
||||
if kind != string(declaration.TypeProcess) && kind != string(declaration.TypeContainer) {
|
||||
return raw, nil
|
||||
}
|
||||
var fields map[string]json.RawMessage
|
||||
@@ -284,7 +294,23 @@ func withFingerprint(raw json.RawMessage, kind, fp string) (json.RawMessage, err
|
||||
return nil, fmt.Errorf("compositions: the env of a %s resource is not words by name: %w", kind, err)
|
||||
}
|
||||
}
|
||||
env[FingerprintVar] = fp
|
||||
if kind == string(declaration.TypeProcess) && fp != "" {
|
||||
env[FingerprintVar] = fp
|
||||
} else {
|
||||
declared, has := env[FingerprintVar]
|
||||
if !has {
|
||||
return raw, nil
|
||||
}
|
||||
delete(env, FingerprintVar)
|
||||
if _, said := takenOutSaid.LoadOrStore(module, true); !said {
|
||||
journal(fmt.Sprintf("%s: %s is taken out of the env of a %s it declares (%q): the node-engine hands it to a daemon whose want names a fingerprint, and to nothing else (H-A-710)",
|
||||
module, FingerprintVar, kind, declared))
|
||||
}
|
||||
}
|
||||
if len(env) == 0 {
|
||||
delete(fields, "env")
|
||||
return json.Marshal(fields)
|
||||
}
|
||||
body, err := json.Marshal(env)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user