runner

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package runner providers various structs and interfaces for Running arbitrary Jobs in a Driver.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

type Collector interface {
	// Collect will read from the given io.Reader and store what was read as an
	// artifact under the given name. The number of bytes read from the given
	// io.Reader are returned, along with any errors that occur.
	Collect(string, io.Reader) (int64, error)
}

Collector is the interface that defines how files from the Driver will be collected from the Driver during execution of the Runner. Files that are collected from a Driver are known as Artifacts to the Runner.

type Driver

type Driver interface {
	// Each driver should implement the io.Writer interface, so that the driver
	// can write the output of what it's doing to the underlying io.Writer
	// implementation, for example os.Stdout.
	io.Writer

	// Create should create the Driver, and prepare it so it will be ready for
	// Jobs to be executed on it. It takes a context that will be used to cancel
	// out of the creation of the Driver quickly. The env slice of strings are
	// the environment variables that will be set on the driver, the strings in
	// the slice are formatted as key=value. The given Placer will be used to
	// place the given objects in the driver.
	Create(context.Context, []string, Passthrough, Placer) error

	// Execute should run the given Job on the Driver, and use the given
	// Collector, to collect any Artifacts for that Job. If the Job fails then
	// it should be marked as failed via the Failed method.
	Execute(*Job, Collector)

	// Destroy should render the driver unusable for executing Jobs, and clear
	// up any resources that may have been created via the Driver.
	Destroy()
}

Driver is the interface that defines how a Job should be executed for the Runner.

type Job

type Job struct {
	io.Writer

	// Stage is the name of the Stage to which the Job belongs.
	Stage string

	// Name is the name of the Job.
	Name string

	// Commands is the list of the commands that should be executed in the
	// Driver when the Job is executed.
	Commands []string

	// Artifacts is the Passthrough that denotes how Artifacts in the Driver
	// should map to the host.
	Artifacts Passthrough

	// Status is the Status of the Job once it has completed execution.
	Status Status
	// contains filtered or unexported fields
}

Job is the struct that represents a Job to be executed in a Driver. Similar to the Runner it has an underlying io.Writer that will have progress of the Job execution written to it. Each Job will belong to a Stage, and will be executed in the order that Job was added to the Stage.

func (*Job) Failed

func (j *Job) Failed(err error)

Mark a job as failed. The only errors that should be passed to this method should be errors pertaining to the functionality of the driver executing the job.

type Passthrough

type Passthrough struct {
	Values map[string]string
}

Passthrough represents files we want passing between the guest and host environments. This is a simple map, whereby the key is the source file and the value is the destination. Objects and artifacts are the two entities that can be passed from one environment to the next.

Objects are passed from the host to the guest. The key for an object passthrough represents the source file on the host, and the value represents the destination on the guest environment.

Artifacts are passed from the guest to the host. The key for an artifact passthrough represents the source file on the guest, and the value represents the destination on the host environment.

func (Passthrough) MarshalYAML

func (p Passthrough) MarshalYAML() (interface{}, error)

func (*Passthrough) Set

func (p *Passthrough) Set(key, val string)

func (*Passthrough) UnmarshalYAML

func (p *Passthrough) UnmarshalYAML(unmarshal func(interface{}) error) error

In the manifest YAML file passthrough is expected to be presented like so:

[source] => [destination]

The [destination] is optional, and if not provided the based of the [source] will be used intstead.

type Placer

type Placer interface {
	// Place will take the object of the given name and write its contents to
	// the given io.Writer. The number of bytes written from the given
	// io.Writer are returned, along with any errors that occur.
	Place(string, io.Writer) (int64, error)

	// Stat will return the os.FileInfo of the object of the given name.
	Stat(string) (os.FileInfo, error)
}

Placer is the interface that defines how files from a host will be placed into a Driver during execution of the Runner. Files that are placed into a Driver are known as Objects to the Runner.

type Runner

type Runner struct {
	io.Writer

	// Env is a slice of environment variables to set during job exectuion. The
	// variables are expected to be formatted as key=value.
	Env []string

	// Objects are the files we want to place into the driver during Job
	// execution.
	Objects Passthrough

	// Placer is what to use for placing objects into the driver during Job
	// execution.
	Placer Placer

	// Collect is what to use for collecting artifacts from the driver during
	// Job execution.
	Collector Collector

	// Status is the status of the Runner was a run has been completed.
	Status Status
	// contains filtered or unexported fields
}

Runner is the struct for executing Jobs. Jobs are grouped together into stages. The order in which stages are added to the Runner is the order in which they will be executed when the Runner is run. The runner expects to have an underlying io.Writer, to which progress of each Stage and Job being executed will be written.

func (*Runner) Add

func (r *Runner) Add(stages ...*Stage)

Add adds the given stages to the Runner. The stages are stored in an underlying map where the key is the name of the Stage. A slice of the stage names is used to maintain the order in which stages are added.

func (*Runner) HandleDriverCreate

func (r *Runner) HandleDriverCreate(f func())

HandleDriverCreate sets the given callback as the underlying handler for driver creation. This would typically be used for capturing timing information regarding driver creation, for example.

func (*Runner) HandleJobComplete

func (r *Runner) HandleJobComplete(f jobHandler)

HandleJobComplete sets the given callback as the underlying handler for Job completion. This will be passed the job that was just completed.

func (*Runner) HandleJobStart

func (r *Runner) HandleJobStart(f jobHandler)

HandleJobStart sets the given callback as the underlying handler for when a Job starts. This will be passed the Job that just started.

func (*Runner) Remove

func (r *Runner) Remove(stages ...string)

Remove removes the given Stages from the Runner based off the given names.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, d Driver) error

Run executes the Runner using the given Driver. The given context.Context is used to handle cancellation of the Runner, as well as cancellation of the underlying Driver during creation. If the Runner fails the errRunFailed will be returned.

func (*Runner) Stages

func (r *Runner) Stages() map[string]*Stage

Stages returns the underlying map of the stages for the Runner.

type Stage

type Stage struct {

	// Name is the name of the Stage. Stage names are unqiue to a runner.
	Name string

	// CanFail denotes whether or not it is acceptable for a Stage to fail.
	// This is applied to each Job that is added to a Stage.
	CanFail bool
	// contains filtered or unexported fields
}

Stage contains the jobs to run. The order in which the jobs are added to a Stage is the order in which they're executed.

func (*Stage) Add

func (s *Stage) Add(jobs ...*Job)

Add adds the given Jobs to the current Stage. The order in which the Jobs are added are the order in which they are executed.

func (*Stage) Get

func (s *Stage) Get(name string) (*Job, bool)

Get returns the Job of the given name, and a boolean value denoting if the given Job exists in the current Stage.

type Status

type Status uint8
const (
	Queued             Status = iota // queued
	Running                          // running
	Passed                           // passed
	PassedWithFailures               // passed_with_failures
	Failed                           // failed
	Killed                           // killed
	TimedOut                         // timed_out
)

func (*Status) Scan

func (s *Status) Scan(val interface{}) error

Scan scans the given interface value into the current Status. If the value scans into an empty byte slice, then the Status is set to Queued, otherwise UnmarshalText is used to attempt to try and get the Status.

func (Status) String

func (i Status) String() string

func (*Status) UnmarshalText

func (s *Status) UnmarshalText(b []byte) error

UnmarshalText unmarshals the given byte slice into the current Status, if it is a valid Status for the Runner. If the byte slice is of an unknown Status then the error "unknown status" is returned.

func (Status) Value

func (s Status) Value() (driver.Value, error)

Value returns the underlying string value for the current status to be used for database insertion.

Jump to

Keyboard shortcuts

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