agent

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2021 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package agent provides a daemon capable of running remote operations on behalf of a user.

Index

Constants

View Source
const (
	DefaultDataDir = "~/.otf-agent"
	DefaultID      = "agent-001"
)
View Source
const (
	DefaultConcurrency = 5
)
View Source
const (
	// SpoolerCapacity is the max number of queued runs the spooler can store
	SpoolerCapacity = 100
)

Variables

View Source
var (
	// QueuedStatuses are the list of run statuses that indicate it is in a
	// queued state
	QueuedStatuses = []otf.RunStatus{otf.RunPlanQueued, otf.RunApplyQueued}
)

Functions

This section is empty.

Types

type Agent

type Agent struct {
	// ID uniquely identifies the agent.
	ID string

	// DataDir stores artefacts relating to runs, i.e. downloaded plugins,
	// modules (?), configuration versions, state, etc.
	DataDir string

	// ServerAddr is the address (<host>:<port>) of the OTF server to connect
	// to.
	ServerAddr string

	Spooler

	*Supervisor
}

Agent runs remote operations

func NewAgent

NewAgent is the constructor for an Agent

func (*Agent) Start

func (a *Agent) Start(ctx context.Context)

Start starts the agent daemon

type Cancelable

type Cancelable interface {
	Cancel(force bool)
}

Cancelable is something that is cancelable, either forcefully or gracefully.

type Environment added in v0.0.8

type Environment struct {
	otf.JobService

	RunService                  otf.RunService
	ConfigurationVersionService otf.ConfigurationVersionService
	StateVersionService         otf.StateVersionService

	logr.Logger
	// contains filtered or unexported fields
}

Environment provides an execution environment for a running a run job, providing a working directory, capturing logs etc.

func NewEnvironment added in v0.0.8

func (*Environment) Cancel added in v0.0.8

func (e *Environment) Cancel(force bool)

Cancel terminates execution. Force controls whether termination is graceful or not. Performed on a best-effort basis - the func or process may have finished before they are cancelled, in which case only the next func or process will be stopped from executing.

func (*Environment) Execute added in v0.0.8

func (e *Environment) Execute(run *otf.Run, job otf.Job) (err error)

Execute executes a run (or anything with a Do(env)) and regardless of whether it fails, it'll close the environment logs.

func (*Environment) GetConfigurationVersionService added in v0.0.8

func (e *Environment) GetConfigurationVersionService() otf.ConfigurationVersionService

func (*Environment) GetPath added in v0.0.8

func (e *Environment) GetPath() string

func (*Environment) GetRunService added in v0.0.8

func (e *Environment) GetRunService() otf.RunService

func (*Environment) GetStateVersionService added in v0.0.8

func (e *Environment) GetStateVersionService() otf.StateVersionService

func (*Environment) RunCLI added in v0.0.8

func (e *Environment) RunCLI(name string, args ...string) error

RunCLI executes a CLI process in the executor.

func (*Environment) RunFunc added in v0.0.8

func (e *Environment) RunFunc(fn otf.EnvironmentFunc) error

RunFunc invokes a func in the executor.

type RunLister

type RunLister interface {
	List(otf.RunListOptions) (*otf.RunList, error)
}

type Spooler

type Spooler interface {
	// Start the daemon
	Start(context.Context) error

	// GetRun receives spooled runs
	GetRun() <-chan *otf.Run

	// GetCancelation receives requests to cancel runs
	GetCancelation() <-chan *otf.Run
}

Spooler is a daemon from which enqueued runs can be retrieved

type SpoolerDaemon

type SpoolerDaemon struct {

	// Subscriber allows subscribing to stream of events
	Subscriber

	// Logger for logging various events
	logr.Logger
	// contains filtered or unexported fields
}

SpoolerDaemon implements Spooler, receiving runs with either a queued plan or apply, and converting them into spooled jobs.

func NewSpooler

func NewSpooler(rl RunLister, sub Subscriber, logger logr.Logger) (*SpoolerDaemon, error)

NewSpooler is a constructor for a Spooler pre-populated with queued runs

func (*SpoolerDaemon) GetCancelation

func (s *SpoolerDaemon) GetCancelation() <-chan *otf.Run

GetCancelation returns a channel of cancelation requests

func (*SpoolerDaemon) GetRun added in v0.0.8

func (s *SpoolerDaemon) GetRun() <-chan *otf.Run

GetRun returns a channel of queued runs

func (*SpoolerDaemon) Start

func (s *SpoolerDaemon) Start(ctx context.Context) error

Start starts the spooler

type Subscriber added in v0.0.8

type Subscriber interface {
	Subscribe(id string) (otf.Subscription, error)
}

type Supervisor

type Supervisor struct {
	RunService                  otf.RunService
	ConfigurationVersionService otf.ConfigurationVersionService
	StateVersionService         otf.StateVersionService

	otf.JobSelector

	logr.Logger

	AgentID string

	Spooler

	*Terminator
	// contains filtered or unexported fields
}

Supervisor supervises concurrently running workers.

func NewSupervisor

func NewSupervisor(spooler Spooler, cvs otf.ConfigurationVersionService, svs otf.StateVersionService, rs otf.RunService, ps otf.PlanService, as otf.ApplyService, logger logr.Logger, concurrency int) *Supervisor

NewSupervisor is the constructor for Supervisor

func (*Supervisor) Start

func (s *Supervisor) Start(ctx context.Context)

Start starts the supervisor's workers.

type Terminator

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

Terminator handles canceling items using their ID

func NewTerminator

func NewTerminator() *Terminator

func (*Terminator) Cancel

func (t *Terminator) Cancel(id string, force bool)

func (*Terminator) CheckIn

func (t *Terminator) CheckIn(id string, job Cancelable)

func (*Terminator) CheckOut

func (t *Terminator) CheckOut(id string)

type Worker

type Worker struct {
	*Supervisor
}

Worker sequentially executes runs on behalf of a supervisor.

func (*Worker) Start

func (w *Worker) Start(ctx context.Context)

Start starts the worker which waits for runs to execute.

Directories

Path Synopsis
Package mock provides mocks for the parent agent package
Package mock provides mocks for the parent agent package

Jump to

Keyboard shortcuts

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