deployer

package
v0.0.0-...-7db8050 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: AGPL-3.0 Imports: 63 Imported by: 15

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Manifold

func Manifold(config ManifoldConfig) dependency.Manifold

Manifold returns a dependency manifold that runs a deployer worker, using the resource names defined in the supplied config.

func NewDeployer

func NewDeployer(st API, logger Logger, ctx Context) (worker.Worker, error)

NewDeployer returns a Worker that deploys and recalls unit agents via ctx, taking a machine id to operate on.

func UnitManifolds

func UnitManifolds(config UnitManifoldsConfig) dependency.Manifolds

UnitManifolds returns a set of co-configured manifolds covering the various responsibilities of nested unit agent.

Thou Shalt Not Use String Literals In This Function. Or Else.

Types

type API

type API interface {
	Machine(names.MachineTag) (Machine, error)
	Unit(names.UnitTag) (Unit, error)
}

API is used to define the methods that the deployer makes.

type Context

type Context interface {
	worker.Worker

	// DeployUnit causes the agent for the specified unit to be started and run
	// continuously until further notice without further intervention. It will
	// return an error if the agent is already deployed.
	DeployUnit(unitName, initialPassword string) error

	// RecallUnit causes the agent for the specified unit to be stopped, and
	// the agent's data to be destroyed. It will return an error if the agent
	// was not deployed by the manager.
	RecallUnit(unitName string) error

	// DeployedUnits returns the names of all units deployed by the manager.
	DeployedUnits() ([]string, error)

	// AgentConfig returns the agent config for the machine agent that is
	// running the deployer.
	AgentConfig() agent.Config

	Report() map[string]interface{}
}

Context abstracts away the differences between different unit deployment strategies; where a Deployer is responsible for what to deploy, a Context is responsible for how to deploy.

func NewNestedContext

func NewNestedContext(config ContextConfig) (Context, error)

NewNestedContext creates a new deployer context that is responsible for running the workers for units as individual dependency engines in a runner it owns.

type ContextConfig

type ContextConfig struct {
	Agent                    agent.Agent
	Clock                    clock.Clock
	Hub                      Hub
	Logger                   Logger
	UnitEngineConfig         func() dependency.EngineConfig
	SetupLogging             func(*loggo.Context, agent.Config)
	UnitManifolds            func(config UnitManifoldsConfig) dependency.Manifolds
	RebootMonitorStatePurger RebootMonitorStatePurger
}

ContextConfig contains all the information that the nested context needs to run.

func (*ContextConfig) Validate

func (c *ContextConfig) Validate() error

Validate ensures all the required values are set.

type Deployer

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

Deployer is responsible for deploying and recalling unit agents, according to changes in a set of state units; and for the final removal of its agents' units from state when they are no longer needed.

func (*Deployer) Handle

func (d *Deployer) Handle(_ <-chan struct{}, unitNames []string) error

Handle is called for new value in the StringsWatcher.

func (*Deployer) Report

func (d *Deployer) Report() map[string]interface{}

Report is shown in the engine report.

func (*Deployer) SetUp

func (d *Deployer) SetUp() (watcher.StringsWatcher, error)

SetUp is called by the NewStringsWorker to create the watcher that drives the worker.

func (*Deployer) TearDown

func (d *Deployer) TearDown() error

TearDown stops the embedded context.

type Hub

type Hub interface {
	Publish(topic string, data interface{}) func()
	Subscribe(topic string, handler func(string, interface{})) func()
}

Hub is a pubsub hub used for internal messaging.

type Logger

type Logger interface {
	Errorf(string, ...interface{})
	Warningf(string, ...interface{})
	Infof(string, ...interface{})
	Debugf(string, ...interface{})
	Tracef(string, ...interface{})
}

Logger represents a logger used by the context.

type Machine

type Machine interface {
	WatchUnits() (watcher.StringsWatcher, error)
}

Machine defines the methods that the deployer makes on a machine in the model.

type ManifoldConfig

type ManifoldConfig struct {
	AgentName     string
	APICallerName string
	Clock         clock.Clock
	Hub           Hub
	Logger        Logger

	UnitEngineConfig func() dependency.EngineConfig
	SetupLogging     func(*loggo.Context, agent.Config)
	NewDeployContext func(ContextConfig) (Context, error)
}

ManifoldConfig defines the names of the manifolds on which a Manifold will depend.

type RebootMonitorStatePurger

type RebootMonitorStatePurger interface {
	PurgeState(tag names.Tag) error
}

RebootMonitorStatePurger is implemented by types that can clean up the internal reboot-tracking state for a particular entity.

type Unit

type Unit interface {
	Life() life.Value
	Name() string
	Remove() error
	SetPassword(password string) error
	SetStatus(unitStatus status.Status, info string, data map[string]interface{}) error
}

Unit defines the methods that the deployer makes on a unit in the model.

type UnitAgent

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

UnitAgent wraps the agent config for this unit.

func NewUnitAgent

func NewUnitAgent(config UnitAgentConfig) (*UnitAgent, error)

NewUnitAgent constructs an "agent" that is responsible for defining the workers for the unit and wraps access and updates to the agent.conf file for the unit. The method expects that there is an agent.conf file written in the <datadir>/agents/unit-<name> directory. It would be good to remove this need moving forwards and have unit agent logging overrides allowable in the machine agent config file.

func (*UnitAgent) ChangeConfig

func (a *UnitAgent) ChangeConfig(change agent.ConfigMutator) error

ChangeConfig modifies this configuration using the given mutator.

func (*UnitAgent) CurrentConfig

func (a *UnitAgent) CurrentConfig() agent.Config

CurrentConfig returns the agent config for this agent.

type UnitAgentConfig

type UnitAgentConfig struct {
	Name             string
	DataDir          string
	Clock            clock.Clock
	Logger           Logger
	UnitEngineConfig func() dependency.EngineConfig
	UnitManifolds    func(UnitManifoldsConfig) dependency.Manifolds
	SetupLogging     func(*loggo.Context, agent.Config)
}

UnitAgentConfig is a params struct with the values necessary to construct a working unit agent.

func (*UnitAgentConfig) Validate

func (u *UnitAgentConfig) Validate() error

Validate ensures all the required values are set.

type UnitManifoldsConfig

type UnitManifoldsConfig struct {

	// LoggingContext holds the unit writers so that the loggers
	// for the unit get tagged with the right source.
	LoggingContext *loggo.Context

	// Agent contains the agent that will be wrapped and made available to
	// its dependencies via a dependency.Engine.
	Agent coreagent.Agent

	// LogSource will be read from by the logsender component.
	LogSource logsender.LogRecordCh

	// LeadershipGuarantee controls the behaviour of the leadership tracker.
	LeadershipGuarantee time.Duration

	// AgentConfigChanged is set whenever the unit agent's config
	// is updated.
	AgentConfigChanged *voyeur.Value

	// ValidateMigration is called by the migrationminion during the
	// migration process to check that the agent will be ok when
	// connected to the new target controller.
	ValidateMigration func(base.APICaller) error

	// UpdateLoggerConfig is a function that will save the specified
	// config value as the logging config in the agent.conf file.
	UpdateLoggerConfig func(string) error

	// MachineLock is a central source for acquiring the machine lock.
	// This is used by a number of workers to ensure serialisation of actions
	// across the machine.
	MachineLock machinelock.Lock

	// Clock supplies timekeeping services to various workers.
	Clock clock.Clock
}

UnitManifoldsConfig allows specialisation of the result of Manifolds.

Jump to

Keyboard shortcuts

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