agent

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2021 License: MPL-2.0 Imports: 5 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 = []tfe.RunStatus{tfe.RunPlanQueued, tfe.RunApplyQueued}
)

Functions

This section is empty.

Types

type Agent

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

	logr.Logger

	// 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

	ConfigurationVersionService otf.ConfigurationVersionService
	StateVersionService         otf.StateVersionService

	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)
}

type Executor

type Executor struct {
	logr.Logger

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

func (*Executor) Do

func (e *Executor) Do(run *otf.Run) error

type ExecutorEnvironment

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

type MockJobGetter

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

func NewMockJobGetter

func NewMockJobGetter(job ...otf.Job) *MockJobGetter

func (*MockJobGetter) GetJob

func (s *MockJobGetter) GetJob() <-chan otf.Job

type MockSpooler

type MockSpooler struct {
	Spooler
	// contains filtered or unexported fields
}

func NewMockSpooler

func NewMockSpooler(opt ...MockSpoolerOption) *MockSpooler

func (*MockSpooler) GetCancelation

func (s *MockSpooler) GetCancelation() <-chan otf.Job

func (*MockSpooler) GetJob

func (s *MockSpooler) GetJob() <-chan otf.Job

type MockSpoolerOption

type MockSpoolerOption func(*MockSpooler)

func WithCanceledJobs

func WithCanceledJobs(job ...otf.Job) MockSpoolerOption

func WithMockJobs

func WithMockJobs(job ...otf.Job) MockSpoolerOption

type RunLister

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

type Spooler

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

	// GetJob receives spooled job
	GetJob() <-chan otf.Job

	// GetCancelation receives cancelation request for a job
	GetCancelation() <-chan otf.Job
}

Spooler is a daemon from which jobs can be retrieved

type SpoolerDaemon

type SpoolerDaemon struct {

	// EventService allows subscribing to stream of events
	otf.EventService

	// 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, es otf.EventService, 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.Job

GetCancelation returns a channel of cancelation requests

func (*SpoolerDaemon) GetJob

func (s *SpoolerDaemon) GetJob() <-chan otf.Job

GetJob returns a channel of queued jobs

func (*SpoolerDaemon) Start

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

Start starts the spooler

type Supervisor

type Supervisor struct {
	logr.Logger

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

	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, 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 jobs on behalf of a supervisor.

func (*Worker) Start

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

Start starts the worker which waits for jobs 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