mission

package
v1.0.0-beta.113 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package mission — Command payload + processor component.

A MissionCommand is a Graphable that stamps a `mission.command` triple on the mission entity's ENTITY_STATES record. The rule engine watches ENTITY_STATES; when `mission.command=launch` appears on a mission entity, the lifecycle-mission-launch rule fires lifecycle_transition to drive the Manager state.

The processor is intentionally tiny — pure NATS Subscribe (not JetStream consumer), no batching, no retry — because its only job in the e2e tier is to translate UDP → Graphable. Production apps wanting a similar shape would use the iot_sensor example as a template for richer transport handling.

Package mission implements the demo Mission lifecycle workflow used by the lifecycle e2e tier. State is the Participant; Transitions declares the phase graph; Register wires the workflow into pkg/lifecycle.Manager.

The package intentionally lives under cmd/e2e-semstreams so the production semstreams binary does not register this workflow — per ADR-049 the framework provides the substrate (Manager, lifecycle-gateway component, lifecycle_* rule actions); apps own their workflow types.

Index

Constants

View Source
const (
	CommandPayloadDomain   = "mission"
	CommandPayloadCategory = "command"
	CommandPayloadVersion  = "v1"
)

CommandPayloadDomain / Category / Version is the payload-registry type discriminator for MissionCommand JSON envelopes.

View Source
const (
	PredicatePhase       = "mission.phase"
	PredicateOwnerOrgID  = "mission.owner_org_id"
	PredicateNote        = "mission.note"
	PredicateAuditSource = "mission.last_transition_source"
	PredicateAuditAt     = "mission.last_transition_at"
	PredicateAuditFrom   = "mission.last_transition_from"
	PredicateAuditNote   = "mission.last_transition_note"
)

Predicate names for projection (ADR-049). Manager.Transition writes `mission.phase`; UpdateFromOperator writes `mission.owner_org_id` and `mission.note`; the audit predicates carry source attribution.

View Source
const (
	PhasePlanning  = "planning"
	PhaseFlying    = "flying"
	PhaseCompleted = "completed"
	PhaseAborted   = "aborted"
)

Phases of a mission.

View Source
const CommandComponentName = "mission-command"

CommandComponentName is the registered component-factory key.

View Source
const EntityIDPattern = "*.*.lifecycle.gcs.mission.*"

EntityIDPattern matches mission entities in the federated graph. Six-segment org.platform.domain.system.type.instance shape per pkg/types.EntityID; the org + platform + instance segments wildcard while domain (`lifecycle`), system (`gcs`), and type (`mission`) pin the canonical mission shape.

View Source
const Workflow = "mission"

Workflow is the registered workflow type name.

Variables

Transitions is the declared phase graph for a Mission.

planning ──> flying ──> completed
    └──> aborted
    flying ──> aborted

completed + aborted are terminal (no out-edges).

Functions

func EntityIDFor

func EntityIDFor(orgID, platform, missionID string) string

EntityIDFor returns the federated 6-part entity ID for a mission given the standard parts. Exposed as a helper so the e2e scenario / seeder can use the same shape.

func NewComponent

func NewComponent(rawConfig json.RawMessage, deps component.Dependencies) (component.Discoverable, error)

NewComponent is the factory called by the component registry.

func Register

func Register(registry *component.Registry) error

Register registers the mission-command factory with the component registry.

func RegisterPayloads

func RegisterPayloads(reg *payloadregistry.Registry) error

RegisterPayloads registers the mission.command.v1 envelope shape.

func WorkflowDeclaration

func WorkflowDeclaration() lifecycle.Workflow

WorkflowDeclaration returns the lifecycle.Workflow ready to pass to Manager.Register. Centralized here so cmd/e2e-semstreams/main.go + the lifecycle-gateway both see the same schema.

Types

type Command

type Command struct {
	OrgID     string `json:"org_id"`
	Platform  string `json:"platform"`
	MissionID string `json:"mission_id"`
	Command   string `json:"command"`
}

Command is a Graphable that targets a mission entity by ID and stamps a single `mission.command` triple. The Subject of every triple is the federated 6-part entity ID composed from OrgID + Platform + MissionID — must match the State.EntityID() of the mission instance the rule should transition.

func (*Command) EntityID

func (c *Command) EntityID() string

EntityID returns the federated identifier the command targets.

func (*Command) MarshalJSON

func (c *Command) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler via the alias-recursion pattern. Required for message.NewBaseMessage to accept Command as a Payload (the Payload interface includes json.Marshaler).

func (*Command) Schema

func (c *Command) Schema() message.Type

Schema implements message.Payload.

func (*Command) Triples

func (c *Command) Triples() []message.Triple

Triples returns the single command triple. graph-ingest writes this into ENTITY_STATES; the rule engine fires on the predicate.

func (*Command) UnmarshalJSON

func (c *Command) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler symmetrically.

func (*Command) Validate

func (c *Command) Validate() error

Validate enforces the minimal field set.

type Component

type Component struct {
	// contains filtered or unexported fields
}

Component subscribes to a single core-NATS subject, parses JSON commands, and republishes them as BaseMessage-wrapped Graphables to the configured output subject. Output flows through graph-ingest which lands the triple in ENTITY_STATES, where the rule engine picks it up.

func (*Component) ConfigSchema

func (c *Component) ConfigSchema() component.ConfigSchema

ConfigSchema implements component.Discoverable.

func (*Component) DataFlow

func (c *Component) DataFlow() component.FlowMetrics

DataFlow returns a minimal flow metric stub (this processor is e2e-only, not a production hotpath).

func (*Component) Health

func (c *Component) Health() component.HealthStatus

Health reports component health.

func (*Component) Initialize

func (c *Component) Initialize() error

Initialize is a no-op — subscriptions land in Start.

func (*Component) InputPorts

func (c *Component) InputPorts() []component.Port

InputPorts returns the configured input ports.

func (*Component) IsStarted

func (c *Component) IsStarted() bool

IsStarted reports running state.

func (*Component) Meta

func (c *Component) Meta() component.Metadata

Meta implements component.Discoverable.

func (*Component) OutputPorts

func (c *Component) OutputPorts() []component.Port

OutputPorts returns the configured output ports.

func (*Component) Start

func (c *Component) Start(ctx context.Context) error

Start subscribes to the input subject.

func (*Component) Stop

func (c *Component) Stop(_ time.Duration) error

Stop unsubscribes + flips running.

type ComponentConfig

type ComponentConfig struct {
	Ports    *component.PortConfig `json:"ports"`
	OrgID    string                `json:"org_id"`
	Platform string                `json:"platform"`
}

ComponentConfig configures the mission-command processor.

type State

type State struct {
	EntityIDField string `json:"entity_id" lifecycle:"id"`
	PhaseField    string `json:"phase" lifecycle:"phase,predicate=mission.phase"`
	OwnerOrgID    string `json:"owner_org_id,omitempty" lifecycle:"operator_writable,predicate=mission.owner_org_id"`
	Note          string `json:"note,omitempty" lifecycle:"operator_writable,predicate=mission.note"`
}

State is a lifecycle.Participant for the Mission workflow.

Field tags (ADR-049):

  • lifecycle:"id" — identity
  • lifecycle:"phase,predicate=mission.phase" — phase triple
  • lifecycle:"operator_writable,predicate=mission.*" — patchable via operator API

The projection layer round-trips between the entity's triples in ENTITY_STATES and this struct on every Get / Transition; the Participant is a typed VIEW over triples, not a private blob.

func New

func New() *State

New returns a freshly-initialized State. Apps don't call this on read — Manager.Get projects fresh instances from the registered Schema via reflection. New is here for Create-side callers (e.g. seedMission in cmd/e2e-semstreams/main.go).

func (*State) EntityID

func (s *State) EntityID() string

EntityID returns the federated 6-part identifier.

func (*State) IsTerminal

func (s *State) IsTerminal() bool

IsTerminal returns true when the current phase has no declared out-edges in Transitions.

func (*State) ParentEntityID

func (s *State) ParentEntityID() string

ParentEntityID returns "" — missions have no parent workflow in this demo.

func (*State) Phase

func (s *State) Phase() string

Phase returns the current phase.

func (*State) Workflow

func (s *State) Workflow() string

Workflow returns the registered workflow type name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL