modules

package
v0.47.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 35 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package modules runs the module task types of smart services and other namespaces (TASK-20 to TASK-29) and keeps their resources: removal through the outbox and health checks.

Index

Constants

View Source
const (
	TypeProcessDeployment      = "process_deployment"
	TypeProcessDeploymentStart = "process_deployment_start"
)
View Source
const (
	TypeInfo             = "info"
	TypeImport           = "import"
	TypeExport           = "export"
	TypeAnalytics        = "analytics"
	TypeDeviceRepository = "device_repository"
)

Task types of the former module workers (TASK-22 to TASK-26).

View Source
const TypeWatcher = "watcher"

Variables

This section is empty.

Functions

func Delete

func Delete(ctx context.Context, client *http.Client, userToken auth.UserTokenSource, info model.ModuleDeleteInfo) error

Delete calls the delete URL of a module with the token of its user; 2xx and 404 count as removed, as with the module workers.

func UsedResources

func UsedResources(process *bpmn.Process) model.UsedResources

UsedResources reads the process models, flows and import types the module tasks of a process name as literal text, as smart-service-repository indexes its releases: an id in an expression or a script is not known before the task runs (SMS-15).

Types

type Check

type Check func(ctx context.Context, m model.Module) (problem string, err error)

Check examines the resource of a module. A non-empty problem becomes the module error once confirmed; an error means the check itself failed and leaves the module as it is.

type ExportDatabase

type ExportDatabase struct {
	ID            string
	Name          string
	Description   string
	Type          string
	Deployment    string
	Url           string
	EwFilterTopic string
	UserId        string
	Public        bool
}

type ExportInstance

type ExportInstance struct {
	ID               uuid.UUID
	Name             string
	Description      string
	EntityName       string
	ServiceName      string
	Topic            string
	ApplicationId    uuid.UUID
	Database         string
	Measurement      string
	Filter           string
	FilterType       string
	TimePath         string
	TimePrecision    *string
	UserId           string
	Generated        bool
	RancherServiceId string
	Offset           string
	ExportDatabaseID string
	ExportDatabase   ExportDatabase
	TimestampFormat  string
	Values           []ExportValue
	CreatedAt        time.Time
	UpdatedAt        time.Time
}

ExportInstance is the export as serving answers it; the module keeps it under "export" with the field names of serving.

type ExportValue

type ExportValue struct {
	InstanceID uuid.UUID
	Name       string
	Type       string
	Path       string
	Tag        bool
}

type FilterCriteria

type FilterCriteria struct {
	Interaction   string `json:"interaction"`
	FunctionId    string `json:"function_id"`
	DeviceClassId string `json:"device_class_id"`
	// Deprecated: use AspectIds; AspectId is an alias for an AspectIds list with a single element.
	AspectId  string   `json:"aspect_id"`
	AspectIds []string `json:"aspect_ids,omitempty"`
}

FilterCriteria selects services and paths of devices for an input port.

type FlowCell

type FlowCell struct {
	Id      string   `json:"id"`
	InPorts []string `json:"inPorts,omitempty"`
	Config  []struct {
		Name string `json:"name,omitempty"`
		Type string `json:"type,omitempty"`
	} `json:"config,omitempty"`
}

FlowCell is an operator of a flow with its input ports and configuration

type GenericHttp

type GenericHttp interface {
	Do(namespace string, req *http.Request) (*http.Response, error)
}

GenericHttp sends requests from models under the HTTP policy of a namespace (NS-04).

type Handler

type Handler interface {
	Do(ctx context.Context, task Task) (modules []model.Module, outputs map[string]any, err error)
}

Handler implements a module task type. Modules it returns become effects of the task; the runtime removes new ones again if the engine cannot apply the result.

type ImportConfig

type ImportConfig struct {
	Name  string `json:"name"`
	Value any    `json:"value"`
}

type ImportInstance

type ImportInstance struct {
	Id           string         `json:"id"`
	Name         string         `json:"name"`
	ImportTypeId string         `json:"import_type_id"`
	Image        string         `json:"image"`
	KafkaTopic   string         `json:"kafka_topic"`
	Configs      []ImportConfig `json:"configs"`
	Restart      *bool          `json:"restart"`
	CreatedAt    time.Time      `json:"created_at"`
	UpdatedAt    time.Time      `json:"updated_at"`
	Generated    bool           `json:"generated"`
}

ImportInstance is the import as import-deploy answers it; the module keeps it under "import".

type InputTopic

type InputTopic struct {
	Name        string    `json:"name,omitempty"`
	FilterType  string    `json:"filterType,omitempty"`
	FilterValue string    `json:"filterValue,omitempty"`
	Mappings    []Mapping `json:"mappings,omitempty"`
}

type Maintenance

type Maintenance interface {
	StartMaintenanceInternal(ctx context.Context, id string, procedure string, variables map[string]any) (model.Instance, error)
	StartMaintenanceRerun(ctx context.Context, rerun store.MaintenanceRerun) (model.Instance, error)
}

Maintenance starts maintenance procedures without a caller (SMS-13). While a run of the procedure is running, StartMaintenanceInternal queues a rerun instead, which StartMaintenanceRerun starts once that run ended (SNRGY-5143).

type Mapping

type Mapping struct {
	Dest   string `json:"dest,omitempty"`
	Source string `json:"source,omitempty"`
}

type Namespaces

type Namespaces interface {
	Get(name string) (model.Namespace, bool)
}

Namespaces gives the referenced namespaces of the namespace of an instance (NS-08).

type NodeConfig

type NodeConfig struct {
	Name  string `json:"name,omitempty"`
	Value string `json:"value,omitempty"`
}

type NodeInput

type NodeInput struct {
	FilterIds  string      `json:"filterIds,omitempty"`
	FilterType string      `json:"filterType"`
	TopicName  string      `json:"topicName,omitempty"`
	Values     []NodeValue `json:"values,omitempty"`
}

type NodeValue

type NodeValue struct {
	Name string `json:"name,omitempty"`
	Path string `json:"path,omitempty"`
}

type Operator

type Operator struct {
	Id             string            `json:"id,omitempty"`
	Name           string            `json:"name,omitempty"`
	ImageId        string            `json:"imageId,omitempty"`
	DeploymentType string            `json:"deploymentType,omitempty"`
	OperatorId     string            `json:"operatorId,omitempty"`
	Config         map[string]string `json:"config,omitempty"`
	InputTopics    []InputTopic
}

type Pipeline

type Pipeline struct {
	Id          uuid.UUID  `json:"id,omitempty"`
	Name        string     `json:"name,omitempty"`
	Description string     `json:"description,omitempty"`
	Operators   []Operator `json:"operators,omitempty"`
}

Pipeline is the answer of flow-engine; the module keeps it under "pipeline".

type PipelineNode

type PipelineNode struct {
	NodeId      string       `json:"nodeId,omitempty"`
	Inputs      []NodeInput  `json:"inputs,omitempty"`
	Config      []NodeConfig `json:"config,omitempty"`
	PersistData bool         `json:"persistData,omitempty"`
}

type PipelineRequest

type PipelineRequest struct {
	Id                 string         `json:"id,omitempty"`
	FlowId             string         `json:"flowId,omitempty"`
	Name               string         `json:"name,omitempty"`
	Description        string         `json:"description,omitempty"`
	WindowTime         int            `json:"windowTime,omitempty"`
	ConsumeAllMessages bool           `json:"consumeAllMessages,omitempty"`
	MergeStrategy      string         `json:"mergeStrategy,omitempty"`
	Nodes              []PipelineNode `json:"nodes,omitempty"`
}

type Processes

type Processes interface {
	GetModel(ctx context.Context, token string, namespace string, id string) (model.Model, error)
	GetModelVersion(ctx context.Context, token string, namespace string, id string, version int) (model.ModelVersion, error)
	CreateDeployment(ctx context.Context, token string, namespace string, input model.DeploymentInput) (model.Deployment, error)
	PutDeployment(ctx context.Context, token string, namespace string, id string, input model.DeploymentInput) (model.Deployment, error)
	StartInstance(ctx context.Context, token string, namespace string, input model.StartInstanceInput) (model.Instance, error)
	// the gateways the user may read (SYNC-12)
	ListNetworks(ctx context.Context, token string) ([]model.Network, error)
	// removes the deployments and instances these modules create (SMS-06)
	Resources
}

Processes is the part of the engine API the process modules use, with the owner's token.

type Remover

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

Remover removes the resources of deleted modules from the outbox, with growing pauses between attempts, so that nothing is left behind when a service is down (SMS-06).

func NewRemover

func NewRemover(s *store.Store, userToken auth.UserTokenSource, logger *slog.Logger) *Remover

func (*Remover) Process

func (this *Remover) Process(ctx context.Context) error

Process works off the due removals; failed ones are retried later.

func (*Remover) Run

func (this *Remover) Run(ctx context.Context, interval time.Duration)

Run processes due removals until ctx is done.

func (*Remover) SetImportDeployUrl added in v0.10.7

func (this *Remover) SetImportDeployUrl(url string)

SetImportDeployUrl sends the removal of imports the module worker created to import-deploy directly. The worker deleted them through Kong, and the migration kept that URL (MIG-01); Kong denies the client of the engine there, because Ladon has no policy for it (SNRGY-5025).

func (*Remover) SetResources

func (this *Remover) SetResources(resources Resources)

SetResources removes the resources of the engine through the controller, so that those of gateways are deleted there too.

type Resources

type Resources interface {
	RemoveResource(ctx context.Context, ref model.ResourceRef) error
}

Resources removes the deployments, instances and watches of the engine that modules refer to. The controller deletes those of a gateway there as well, as through the API (SMS-12).

type Runtime

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

Runtime runs module handlers like the module workers did: string inputs are rendered as templates against the variables, prescripts and postscripts run with the script API of the worker library, and modules and variable changes become effects of the task (TASK-28).

func NewRuntime

func NewRuntime(s *store.Store, settings Settings, tokens auth.UserTokenSource, logger *slog.Logger) *Runtime

NewRuntime creates the runtime; tokens gives the tokens of owners, e.g. the token exchange.

func (*Runtime) AddCheck

func (this *Runtime) AddCheck(moduleType string, check Check)

AddCheck registers the health check of a module type.

func (*Runtime) AddProcessModules

func (this *Runtime) AddProcessModules(processes Processes, namespaces Namespaces)

AddProcessModules registers process_deployment (TASK-20) and process_deployment_start (TASK-21).

func (*Runtime) AddWatcher

func (this *Runtime) AddWatcher(maintenance Maintenance, generic GenericHttp, settings WatcherSettings)

AddWatcher registers the watcher task type (TASK-27): instead of an own database and API, the watches are rows of the engine, checked by every replica in turn.

func (*Runtime) CheckModules

func (this *Runtime) CheckModules(ctx context.Context, interval time.Duration, recheck time.Duration) error

CheckModules checks the modules whose last check is older than interval, and those with an error or a suspected finding whose last check is older than recheck. A finding becomes the module error only when a check at least recheck later still has it, so a pipeline whose pod is replaced does not show as an error.

func (*Runtime) CheckResources

func (this *Runtime) CheckResources(ctx context.Context) error

CheckResources checks every deployment version that is current or still has instances and names resources in its module tasks.

func (*Runtime) CheckWatches

func (this *Runtime) CheckWatches(ctx context.Context) error

CheckWatches checks the due watches once.

func (*Runtime) DeviceDeleted added in v0.39.0

func (this *Runtime) DeviceDeleted(ctx context.Context, deviceId string) error

DeviceDeleted makes the watches due whose device group contained a device that device-repository announced as deleted: it leaves the device in the stored group, which therefore announces no change, but no longer returns it (SNRGY-5132).

func (*Runtime) DeviceGroupChanged added in v0.39.0

func (this *Runtime) DeviceGroupChanged(ctx context.Context, groupId string) error

DeviceGroupChanged makes the watches of a device group due, after device-repository announced that the group was written or deleted (SNRGY-5132).

func (*Runtime) Register

func (this *Runtime) Register(e *engine.Engine, settings Settings)

Register makes the module task types available to an engine whose services are configured, so that a deploy reports a missing one instead of an incident later.

func (*Runtime) RunHealthChecks

func (this *Runtime) RunHealthChecks(ctx context.Context, interval time.Duration, recheck time.Duration)

RunHealthChecks checks every module once per interval, like the module workers did (SMS-11), and a module with an error or a suspected finding once per recheck.

func (*Runtime) RunResourceChecks

func (this *Runtime) RunResourceChecks(ctx context.Context, cycle time.Duration)

RunResourceChecks checks the resources of all deployment versions every cycle; 0 does nothing.

func (*Runtime) RunWatches

func (this *Runtime) RunWatches(ctx context.Context, tick time.Duration)

RunWatches checks due watches until ctx is done.

func (*Runtime) SetAdminToken

func (this *Runtime) SetAdminToken(token auth.TokenSource)

SetAdminToken sets the token of the engine for the check of used resources.

func (*Runtime) SetBlocklist added in v0.31.0

func (this *Runtime) SetBlocklist(blocklist *script.Blocklist)

SetBlocklist refuses to run pre- and postscripts that ended the engine (EXPR-03).

func (*Runtime) SetCrashBrake added in v0.30.0

func (this *Runtime) SetCrashBrake(brake *crashbrake.Brake)

SetCrashBrake records the pre- and postscripts of module tasks as running in the brake (EXPR-03).

func (*Runtime) StartReruns added in v0.44.6

func (this *Runtime) StartReruns(ctx context.Context) error

StartReruns starts the reruns of maintenance procedures whose run ended (SNRGY-5143). A rerun that cannot start is retried, unless the instance or its procedure is gone or the start is invalid, which a retry would not change.

type ServingRequest

type ServingRequest struct {
	FilterType       string                `json:"FilterType,omitempty" validate:"required"`
	Filter           string                `json:"Filter,omitempty" validate:"required"`
	Name             string                `json:"Name,omitempty" validate:"required"`
	EntityName       string                `json:"EntityName,omitempty" validate:"required"`
	ServiceName      string                `json:"ServiceName,omitempty" validate:"required"`
	Description      string                `json:"Description,omitempty"`
	Topic            string                `json:"Topic,omitempty" validate:"required"`
	TimePath         string                `json:"TimePath,omitempty"`
	TimePrecision    string                `json:"TimePrecision,omitempty"`
	Generated        bool                  `json:"generated,omitempty"`
	Offset           string                `json:"Offset,omitempty" validate:"required"`
	ForceUpdate      bool                  `json:"ForceUpdate,omitempty"`
	Values           []ServingRequestValue `json:"Values,omitempty"`
	ExportDatabaseID string                `json:"ExportDatabaseID,omitempty"`
	TimestampFormat  string                `json:"TimestampFormat,omitempty"`
}

ServingRequest asks serving for an export. Filter conventions: for operatorId the filter is "<pipeline>:<operator>" and the topic "analytics-<operator name>", for import_id the import id and its kafka topic.

type ServingRequestValue

type ServingRequestValue struct {
	Name string `json:"Name,omitempty"`
	Type string `json:"Type,omitempty"`
	Path string `json:"Path,omitempty"`
	Tag  bool   `json:"Tag"`
}

type Settings

type Settings struct {
	// nil if not configured
	DeviceRepository   devicerepository.Interface
	DeviceSelection    dsclient.Client
	DeviceSelectionUrl string
	DeviceManagerUrl   string
	FlowEngineUrl      string
	FlowParserUrl      string
	ImportDeployUrl    string
	ServingServiceUrl  string
	// repositories of flows and import types, asked whether used resources changed (SMS-15)
	FlowRepoUrl         string
	ImportRepositoryUrl string

	AnalyticsEnableMultiplePaths  bool
	AnalyticsDevicePathPrefix     string
	AnalyticsGroupPathPrefix      string
	AnalyticsImportPathPrefix     string
	AnalyticsRemoveImportPathRoot bool

	DeviceGroupNamePrefix      string
	DeviceGroupAttributeOrigin string

	InfoAdditionalModuleDataFields bool
}

Settings are the configuration values of the former module workers (TASK-29). The parameter prefixes are part of the model format and stay those of the workers: "<task type>.".

type Task

type Task struct {
	// the job; module ids are "<instance>.<job>", as "<process instance>.<task>" before
	Id             string
	InstanceId     string
	RootInstanceId string
	DeploymentId   string
	ElementId      string
	Namespace      string
	Owner          string
	Inputs         map[string]any
}

Task is a module task as a handler sees it: the inputs after the templates were rendered.

func (Task) ModuleId

func (this Task) ModuleId(suffix ...string) string

ModuleId is the id of a module the task creates; suffixes tell several apart.

func (Task) String

func (this Task) String(name string) (string, bool)

String reads an input that has to be a string.

type WatcherSettings

type WatcherSettings struct {
	AllowGenericRequests bool
	MinInterval          time.Duration
	DefaultInterval      time.Duration
	// device-repository announces changes of device groups and deletions of devices to the
	// engine (Kafka), so a watch of a device group is checked on those instead of by interval
	// (SNRGY-5132)
	DeviceGroupEvents bool
	// with announcements, a watch of a device group is still checked after this time since its
	// last check, in case an announcement was missed; 24 h if not positive
	DeviceGroupRecheck time.Duration
}

WatcherSettings are the values of the former watcher worker (TASK-29).

Directories

Path Synopsis
Package compat keeps the module task types compatible with the former smart service module workers (TASK-28): string inputs are templates over the instance variables, and prescript and postscript inputs run with the script API of smart-service-module-worker-lib, ported from that library.
Package compat keeps the module task types compatible with the former smart service module workers (TASK-28): string inputs are templates over the instance variables, and prescript and postscript inputs run with the script API of smart-service-module-worker-lib, ported from that library.

Jump to

Keyboard shortcuts

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