client

package
v0.0.0-...-c5dc566 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2017 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package client provides a client for interacting with the Marmot Workflow Service. Note: interfaces here such as Builder will change. If using to fake tests, you should embed the interface in your testing interface or face possible breakage in the future.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgsType

type ArgsType int

ArgsType indicates what type of encoding the arguments are in.

const (
	// ATUnknown indicates the arguements are encoded in an unknown format.
	ATUnknown ArgsType = 0
	// ATJSON indicates the arguments will be encoded in JSON format.
	ATJSON ArgsType = 1
)

type Builder

type Builder interface {
	// AddTask adds a Task to the Labor.
	AddTask(name, desc string, opts ...TaskOption) error

	// AddPreCheck adds a Precheck to a Task. Will be added to the last
	// Task created by AddTask().
	AddPreCheck(cogPath, desc string, args proto.Message) error

	// AddContCheck adds a ContCheck to a Task. Will be added to the last
	// Task created by AddTask().
	AddContCheck(cogPath, desc string, args proto.Message) error

	// AddSequence adds a Sequence to the last Task created with AddTask().
	AddSequence(target, desc string) error

	// AddJob adds a Job to the last Sequence created with AddSequence()/
	AddJob(cogPath, desc string, args proto.Message) error

	// Labor returns a COPY of the Labor object.
	Labor() *Labor
}

Builder provides methods for building a Labor in a way that programtically friendly as an alternative to building one directly using the protocol buffer.

func NewBuilder

func NewBuilder(name, desc string, opts ...BuilderOption) (Builder, error)

NewBuilder is the constructor for Builder.

type BuilderOption

type BuilderOption func(b *builder) error

BuilderOption is options to the NewBuilder() constructor.

func Tags

func Tags(t []string) BuilderOption

Tags adds tags t to the underlying Labor.

type Control

type Control interface {
	// Submit submits a Labor to the Marmot service. If start is set, will start
	// execution immediately.  Otherwise Start() must be called. Returns the
	// ID of the Labor.
	Submit(ctx context.Context, l *Labor, start bool) (string, error)

	// Start starts execution of Labor with ID "id".
	Start(ctx context.Context, id string) error

	// Pause pauses execution of Labor with ID "id".
	Pause(ctx context.Context, id string) error

	// Resume unpauses a Labor the is in the pause state at ID "id".
	Resume(ctx context.Context, id string) error

	// Stop stops an executing Labor with the ID "id".
	Stop(ctx context.Context, id string) error

	// Wait waits for a Labor with id to reach a completion state.
	Wait(ctx context.Context, id string) error

	// Monitor returns Labor objects representing a single Labor as it is executed
	// by the service, stopping when the Labor reaches its final execution.
	// These Labors will only have state data and no args/output data.
	Monitor(ctx context.Context, id string) (chan LaborStream, error)

	// SearchLabors returns a stream of Labors matching the filter.
	SearchLabors(ctx context.Context, filter SearchFilter) (chan LaborStream, error)

	// FetchLabor returns with ID 'id'.  If 'full' is set, the input/output data
	// will be returned.
	FetchLabor(ctx context.Context, id string, full bool) (*Labor, error)

	// Close kills the connection to the service.
	Close()
}

Control provides methods for interacting with the Marmot service.

func NewControl

func NewControl(endpoint string, opts ...ControlOption) (Control, error)

NewControl is the constructor for Control.

type ControlOption

type ControlOption func(c *control) error

ControlOption is an optional argument to NewControl().

func CertAuth

func CertAuth(serverHostOverride string) ControlOption

CertAuth uses the machine's installed certs to attempt authentication. Unless running a test, serverHostOverride should be set to empty string.

func CertFileAuth

func CertFileAuth(cert, key string) ControlOption

CertFileAuth uses paths to a cert.pem and key.pem to authenticate to the service.

func Insecure

func Insecure() ControlOption

Insecure indicates to use no transport encryption. This should only be used in testing.

func PasswordAuth

func PasswordAuth(user, password string) ControlOption

PasswordAuth provides a username/password for authenticating to Marmot.

type Job

type Job struct {
	// CogPath is the name of the Cog the Job will use.
	CogPath string

	// Args are the arguments to the Cog in JSON protocol buffer format.
	// Use .SetArgs() to convert your proto.Message to JSON automatically.
	Args string

	// Output is the output from the Cog.
	Output string

	// Timeout is the amount of time a Job is allowed to run.
	Timeout time.Duration

	// Retries is the number of times to retry a Cog that fails.
	// TODO(johnsiilver): Add support for this on the server side.
	Retries int

	// RetryDelay is how long to wait between retrying a Cog.
	RetryDelay time.Duration

	Meta
}

Job represents work to be done, via a Cog.

func (*Job) GetArgs

func (j *Job) GetArgs(p proto.Message) error

GetArgs converts the JSON stored in .Args to "p".

func (*Job) SetArgs

func (j *Job) SetArgs(p proto.Message) error

SetArgs transforms "p" into JSON format and stores it in .Args. Note that it uses the "github.com/gogo/protobuf/jsonpb".Marshaler and not the standard json library encoder.

type Labor

type Labor struct {
	// Tags are single word text strings that can be used to group Labors when
	// doing a search.
	Tags []string

	// Tasks are the tasks that are associated with this Labor.
	Tasks []*Task

	Meta
}

Labor represents a total unit of work to be done.

type LaborStream

type LaborStream struct {
	Labor *Labor
	Error error
}

LaborStream is used to return the results of a stream of Labor objects.

type Meta

type Meta struct {
	// ID contains a unique UUIDv4 representing the object.
	ID string

	// Name contains the name to be displayed to users.
	Name string

	// Desc contains a description of what the object is doing.
	Desc string

	// State is the current state of the object.  It cannot be set by the client.
	State State

	// Started is when an object begins execution.
	Started time.Time

	// Ended is when an object stops execution.
	Ended time.Time

	// Submitted is when a Labor was submitted to the system.  Only valid for Labors.
	Submitted time.Time

	// Reason contains the failiure reason for an object, which is a type Reason.
	Reason Reason
}

Meta contains metadata information about different objects. Not all fields are used in every object.

type Reason

type Reason int

Reason details reasons that a Container fails.

const (
	// NoFailure indicates there was no failures in the execution.
	NoFailure Reason = 0

	// PreCheckFailure indicates that a pre check caused a failure.
	PreCheckFailure Reason = 1

	// ContChecks indicates a continuous check caused a failure.
	ContCheckFailure Reason = 2

	// MaxFailures indicates that the maximum number of Jobs failed.
	MaxFailures Reason = 3
)

Note: Changes to this list require running stringer!

func (Reason) String

func (i Reason) String() string

type SearchFilter

type SearchFilter struct {
	// States returns objects that are currently at one the "states".
	// If empty, all states are included.
	States []pb.States

	// NamePrefix/ NameSuffix locates Labors starting with the string.
	// An empty string has no filter.
	NamePrefix, NameSuffix string

	// Tags matches any Labor that has any tag listed.  An empty list has no filter.
	Tags []string

	// SubmitBegin locates any Labor that was submitted at or after this time.
	SubmitBegin time.Time

	// SubmitEnd locates any Labor that was submitted before this time.
	SubmitEnd time.Time
}

SearchFilter is used to restrict the Labors being found during a search.

type Sequence

type Sequence struct {
	// Target is the name of what this sequence targets. This could be a device,
	// a service, a directory... whatever makes sense for whatever is being done.
	Target string

	// Jobs is a sequence of jobs to execute.
	Jobs []*Job

	Meta
}

Sequence represents a sequence of Jobs to execute.

type State

type State int

State represents the exeuction state of an object. Not all states can be used in all objects.

const (
	// UnknownState indicates the object's state hasn't been set.  This should
	// be resolved before object execution.
	UnknownState State = 0

	// NotStarted indicates that the object hasn't started execution.
	NotStarted State = 1

	// AdminNotStarted indicates the Labor object was sent to the server, but
	// was not intended to run until started by an RPC or human.
	AdminNotStarted State = 2

	// Running indicates the object is currently executing.
	Running State = 3

	// Pausing indicates the object is intending to pause execution.
	Pausing State = 4

	// Paused indicates the object has paused execution.
	Paused State = 5

	// AdminPaused indicates that a human has paused execution.
	AdminPaused State = 6

	// CrisisPaused indicates that the crisis service for emergency control has
	// paused execution.
	CrisisPaused State = 7

	// Completed indicates the object has completed execution succcessfully.
	Completed State = 8

	// Failed indicates the object failed its execution.
	Failed State = 9

	// Stopping indicates the object is attempting to stop.
	Stopping State = 10

	// Stopped indicates the object's execution was stopped.
	Stopped State = 11
)

Note: Changes to this list require running stringer!

func (State) String

func (i State) String() string

type Task

type Task struct {
	// PreChecks are Jobs that are executed before executing the Jobs in the
	// Task. If any of these fail, the Task is not executed and fails.
	// This is used provide checks before initiating actions. These are run
	// concurrently.
	PreChecks []*Job

	// ContChecks are Jobs that are exeucted continuously until the task ends
	// with ContCheckInterval between runs.  If any check fails, the Task stops
	// execution and fails.  These are run concurrently.
	ContChecks []*Job

	// ToleratedFailures is how many sequence failures to tolerate before stopping.
	ToleratedFailures int

	// Concurrency is how many Jobs to run simultaneously.
	Concurrency int

	// ContCheckInterval is how long between runs of ContCheck Jobs.
	ContCheckInterval time.Duration

	// PassFailures causes the failures in this Task to be passed to the next
	// Task, acting againsts its ToleratedFailures.
	PassFailures bool

	// Sequence are a set of Jobs.
	Sequences []*Sequence

	Meta
}

Task represents a selection of work to be executed. This may represents a canary, general rollout, or set of work to be executed concurrently.

type TaskOption

type TaskOption func(t *Task)

TaskOption sets an option for a task.

func Concurrency

func Concurrency(n int) TaskOption

Concurrency sets the number of Jobs that can execute at one time within the Task. Defaults to 1.

func ContCheckInterval

func ContCheckInterval(d time.Duration) TaskOption

ContCheckInterval sets how long to wait before doing another continuous check. This defaults to 0 seconds.

func PassFailures

func PassFailures(b bool) TaskOption

PassFailures sets the next Tasks failures equal to the ending failures for this Task instead of 0. This defaults to false.

func ToleratedFailures

func ToleratedFailures(n int) TaskOption

ToleratedFailures sets the number of failures allowed before a Task stops execution. Defaults to 0.

Jump to

Keyboard shortcuts

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