job

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2019 License: MIT Imports: 29 Imported by: 4

Documentation

Index

Constants

View Source
const (
	OutputKey     contextKey = "output"
	LoggerKey     contextKey = "logger"
	SshClientKey  contextKey = "sshClient"
	TemplatingKey contextKey = "templating"
	StdoutKey     contextKey = "stdout"
	StderrKey     contextKey = "stderr"
)

Variables

View Source
var (

	// KeepAliveInterval between two keep-alive messages.
	// Changes to the time interval only apply to newly
	// created connections.
	KeepAliveInterval = 30 * time.Second
)

Functions

func InitializeSSHClientStore

func InitializeSSHClientStore(ttl time.Duration)

InitializeSSHClientStore initialies the global SSH connection store and sets the time-to-live for unused connections.

func VisitConfig added in v0.15.0

func VisitConfig(builder ConfigBuilder, c *Config) (interface{}, error)

Types

type Branch added in v0.15.0

type Branch interface {
	Stringer
	Group
}

Branch is a node in a tree that potentially has children.

type Command added in v0.15.0

type Command struct {
	Name        string        `json:"name,omitempty"`
	Command     string        `json:"command,omitempty"`
	Commands    []*Command    `json:"commands,omitempty"`
	Flow        string        `json:"flow,omitempty"`
	Target      CommandTarget `json:"target,omitempty"`
	Retries     uint          `json:"retries,omitempty"`
	Timeout     string        `json:"timeout,omitempty"`
	IgnoreError bool          `json:"ignoreError,omitempty"`
	Stdout      *Output       `json:"stdout,omitempty"`
	Stderr      *Output       `json:"stderr,omitempty"`
}

Command describes a command that can be executed on the client or a remote host connected via SSH.

func (*Command) IsRemote added in v0.18.0

func (c *Command) IsRemote() bool

IsRemote returns true if either the command or any of its child commands are executed on the remote.

type CommandTarget added in v0.18.0

type CommandTarget string
const CommandTargetLocal CommandTarget = "local"

type Config

type Config struct {
	Name       string           `json:"name,omitempty"`
	Schedule   string           `json:"schedule,omitempty"`
	Timeout    string           `json:"timeout,omitempty"`
	Telemetry  bool             `json:"telemetry,omitempty"`
	Output     *Output          `json:"output,omitempty"`
	Host       *Host            `json:"host,omitempty"`
	HostsFile  hostsFileOrArray `json:"hosts,omitempty"`
	Pre        *Command         `json:"pre,omitempty"`
	Command    *Command         `json:"command,omitempty"`
	Post       *Command         `json:"post,omitempty"`
	Forwarding *Forwarding      `json:"forwarding,omitempty"`
	Tunnel     *Forwarding      `json:"tunnel,omitempty"`
	SCP        *ScpData         `json:"scp,omitempty"`
}

Config is the in-memory representation of a job configuration.

func ReadConfig

func ReadConfig(file string) (*Config, error)

ReadConfig parses the file into a Config.

func (*Config) ExecutionTree

func (c *Config) ExecutionTree() (flunc.Flunc, error)

ExecutionTree creates the execution tree necessary to executeCommand the configured steps.

func (*Config) JSON

func (c *Config) JSON() string

JSON generates the Config's JSON representation.

func (*Config) String

func (c *Config) String() string

func (*Config) Tree

func (c *Config) Tree(full, raw bool, maxHosts, maxCommands int) (string, error)

Tree returns a textual representation of the Config's execution tree. When full is true, housekeeping steps are included. When raw is true, template string are output in the un-interpolated form.

type ConfigBuilder added in v0.15.0

type ConfigBuilder interface {
	Sequential() Group
	Parallel() Group
	Job(name string) Group
	Output(o *Output) interface{}
	JobLogger(jobName string) interface{}
	HostLogger(jobName string, h *Host) interface{}
	Timeout(timeout time.Duration) interface{}
	SCP(scp *ScpData) interface{}
	Hosts() Group
	Host(c *Config, h *Host) Group
	ErrorSafeguard(child interface{}) interface{}
	ContextBounds(child interface{}) interface{}
	Retry(child interface{}, retries uint) interface{}
	Templating(c *Config, h *Host) interface{}
	SSHClient(host, user, keyFile, password string, keyboardInteractive map[string]string) interface{}
	Forwarding(f *Forwarding) interface{}
	Tunnel(f *Forwarding) interface{}
	Commands(cmd *Command) Group
	Command(cmd *Command) interface{}
	LocalCommand(cmd *Command) interface{}
	Stdout(o *Output) interface{}
	Stderr(o *Output) interface{}
}

type ExecutionTreeBuilder added in v0.15.0

type ExecutionTreeBuilder struct{}

ExecutionTreeBuilder creates subtrees of an execution tree.

func (*ExecutionTreeBuilder) Command added in v0.15.0

func (*ExecutionTreeBuilder) Command(cmd *Command) interface{}

Command returns a Flunc that, when executed, runs the command on the host.

It requires a logger, a SSHClient and a TemplatingEngine to function properly. It also redirects the commands STDERR and STDOUT to the ones in the context, if available. Otherwise os.Stderr and os.Stdout will be used, respectivly.

func (*ExecutionTreeBuilder) Commands added in v0.15.0

func (e *ExecutionTreeBuilder) Commands(cmd *Command) Group

Commands returns a Group that executes its contents sequentially.

func (*ExecutionTreeBuilder) ContextBounds added in v0.15.0

func (e *ExecutionTreeBuilder) ContextBounds(child interface{}) interface{}

ContextBounds returns a Flunc that, when executed, doesn't propagade the context it received from its child to its parent. Additionally the context passed to the child gets canceled as soon as the child returns. This cleans up any go routines started by the child waiting for the context.

func (*ExecutionTreeBuilder) ErrorSafeguard added in v0.15.0

func (e *ExecutionTreeBuilder) ErrorSafeguard(child interface{}) interface{}

ErrorSafeguard returns a Flunc that, when executed, will call its child. If the child returns an error the error will be logged but otherwise discarded and not passed to the parent.

It requires a logger to function properly.

func (*ExecutionTreeBuilder) Forwarding added in v0.15.0

func (*ExecutionTreeBuilder) Forwarding(f *Forwarding) interface{}

Forwarding returns a Flunc that, when executed, establishes a port forwarding from the host to the client.

It requires a logger and a SSHClient to function properly.

func (*ExecutionTreeBuilder) Host added in v0.15.0

func (e *ExecutionTreeBuilder) Host(c *Config, h *Host) Group

Host returns a Group that executes its contents sequentially.

func (*ExecutionTreeBuilder) HostLogger added in v0.15.0

func (e *ExecutionTreeBuilder) HostLogger(hostName string, h *Host) interface{}

HostLogger returns a Flunc that, when executed, adds log.Logger to the context that prefixes the log messages it prints with the host name.

It requires an Output to function properly.

func (*ExecutionTreeBuilder) Hosts added in v0.15.0

func (e *ExecutionTreeBuilder) Hosts() Group

Hosts returns a Group that executes its contents in parallel.

func (*ExecutionTreeBuilder) Job added in v0.15.0

func (e *ExecutionTreeBuilder) Job(name string) Group

Job returns a container for job-level Fluncs.

func (*ExecutionTreeBuilder) JobLogger added in v0.15.0

func (e *ExecutionTreeBuilder) JobLogger(jobName string) interface{}

JobLogger returns a Flunc that, when executed, adds log.Logger to the context that prefixes the log messages it prints with the job name.

It requires an Output to function properly.

func (*ExecutionTreeBuilder) LocalCommand added in v0.15.0

func (*ExecutionTreeBuilder) LocalCommand(cmd *Command) interface{}

LocalCommand returns a Flunc that, when executed, runs the command on the client.

It requires a logger and a TemplatingEngine to function properly. It also redirects the commands STDERR and STDOUT to the ones in the context, if available. Otherwise os.Stderr and os.Stdout will be used, respectivly.

func (*ExecutionTreeBuilder) Output added in v0.15.0

func (*ExecutionTreeBuilder) Output(o *Output) interface{}

Output returns a Flunc that, when executed, adds an io.Writer to the context. If there is already an output present, it creates an io.MultiWriter that writes to both outputs.

It requires a TemplatingEngine to function properly.

func (*ExecutionTreeBuilder) Parallel added in v0.15.0

func (e *ExecutionTreeBuilder) Parallel() Group

Parallel returns a Group that executes its contents parallel.

func (*ExecutionTreeBuilder) Retry added in v0.15.0

func (e *ExecutionTreeBuilder) Retry(child interface{}, numRetries uint) interface{}

Retry returns a Flunc that, when executed, restarts its child, if it returned an error. When numRetires retries have been made and the child still failed the latest error will be returned to the parent.

It requires a logger to function properly.

func (*ExecutionTreeBuilder) SCP added in v0.15.0

func (e *ExecutionTreeBuilder) SCP(scp *ScpData) interface{}

SCP returns a Flunc that, when executed, starts a new SCP server with the given configuration.

It requires a logger to function properly.

func (*ExecutionTreeBuilder) SSHClient added in v0.15.0

func (*ExecutionTreeBuilder) SSHClient(host, user, keyFile, password string, keyboardInteractive map[string]string) interface{}

SSHClient returns a Flunc that, when executed, adds a SSH client to the context. This is either a new client or an existing client that is being reused.

It requires a logger to function properly.

func (*ExecutionTreeBuilder) Sequential added in v0.15.0

func (e *ExecutionTreeBuilder) Sequential() Group

Sequential returns a Group that executes its contents sequentially.

func (*ExecutionTreeBuilder) Stderr added in v0.15.0

func (*ExecutionTreeBuilder) Stderr(o *Output) interface{}

Stderr returns a Flunc that, when executed, adds a file to the context that can be used as STDERR for Commands. It will close the file when the Flunc returns.

It requires a logger and a TemplatingEngine to function properly.

func (*ExecutionTreeBuilder) Stdout added in v0.15.0

func (e *ExecutionTreeBuilder) Stdout(o *Output) interface{}

Stdout returns a Flunc that, when executed, adds a file to the context that can be used as STDOUT for Commands. It will close the file, when the Flunc returns.

It requires a logger and a TemplatingEngine to function properly.

func (*ExecutionTreeBuilder) Templating added in v0.15.0

func (e *ExecutionTreeBuilder) Templating(config *Config, host *Host) interface{}

Templating returns a Flunc that, when executed, adds a new TemplatingEngine with the information from config and host to the context.

func (*ExecutionTreeBuilder) Timeout added in v0.15.0

func (e *ExecutionTreeBuilder) Timeout(timeout time.Duration) interface{}

Timeout returns a Flunc that, when executed, adds a timeout to the context after the given duration.

It requires a logger to function properly.

func (*ExecutionTreeBuilder) Tunnel added in v0.15.0

func (*ExecutionTreeBuilder) Tunnel(f *Forwarding) interface{}

Tunnel returns a Flunc that, when executed, establishes a port forwaring from the client to the host.

It requires a logger and a SSHClient to function properly.

type Forwarding added in v0.15.0

type Forwarding struct {
	RemoteHost string `json:"remoteHost,omitempty"`
	RemotePort uint16 `json:"remotePort,omitempty"`
	LocalHost  string `json:"localHost,omitempty"`
	LocalPort  uint16 `json:"localPort,omitempty"`
}

Forwarding describes a tunnel between client and host independent from the tunnels direction.

type Group added in v0.15.0

type Group interface {
	Append(children ...interface{})
	Wrap() interface{}
}

type Host added in v0.15.0

type Host struct {
	Name                string            `json:"name,omitempty"`
	Addr                string            `json:"addr,omitempty"`
	Port                uint              `json:"port,omitempty"`
	User                string            `json:"user,omitempty"`
	PrivateKey          string            `json:"privateKey,omitempty"`
	Password            string            `json:"password,omitempty"`
	KeyboardInteractive map[string]string `json:"keyboardInteractive,omitempty"`
	Tags                map[string]string `json:"tags,omitempty"`
}

Host holds all information about a host such as its address and means to authenticate via SSH.

func (*Host) String added in v0.17.0

func (h *Host) String() string

type Leaf added in v0.15.0

type Leaf string

A Leaf is a node in a tree that has no more children.

func (Leaf) String added in v0.15.0

func (s Leaf) String(v *Vars) string

type Output added in v0.15.0

type Output struct {
	File      string `json:"file,omitempty"`
	Raw       bool   `json:"raw,omitempty"`
	Overwrite bool   `json:"overwrite,omitempty"`
}

Output describes a file used for output in different scenarios such as logging and STDOUT and STDERR of commands.

func (*Output) MarshalJSON added in v0.15.0

func (o *Output) MarshalJSON() ([]byte, error)

MarshalJSON either marshals the Output as a JSON string, if both Raw and Overwrite are false. If one or both are true the Output is marshaled as a JSON object.

func (Output) String added in v0.15.0

func (o Output) String() string

func (*Output) UnmarshalJSON added in v0.15.0

func (o *Output) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals an Output either from a JSON string. In this case both Raw and Overwrite will be false. Or from a JSON object in that case Raw and Overwrite will have the values provided.

type ScpData added in v0.15.0

type ScpData struct {
	Addr    string `json:"addr,omitempty"`
	Port    uint   `json:"port,omitempty"`
	Key     string `json:"key,omitempty"`
	Verbose bool   `json:"verbose,omitempty"`
}

ScpData describes configuration for a SCP server.

func (*ScpData) String added in v0.17.0

func (s *ScpData) String() string

type SimpleBranch added in v0.15.0

type SimpleBranch struct {
	Root  Leaf
	Leafs []Stringer
	// contains filtered or unexported fields
}

SimpleBranch implements the Branch interface.

func (*SimpleBranch) Append added in v0.15.0

func (s *SimpleBranch) Append(children ...interface{})

Append adds any given number of children to the branch. All children have to implement Stringer.

func (*SimpleBranch) String added in v0.15.0

func (s *SimpleBranch) String(v *Vars) string

func (*SimpleBranch) Wrap added in v0.15.0

func (s *SimpleBranch) Wrap() interface{}

Wrap returns the branch.

type StringBuilder added in v0.15.0

type StringBuilder struct {
	Full, Raw             bool
	MaxHosts, MaxCommands int
}

func (*StringBuilder) Command added in v0.15.0

func (s *StringBuilder) Command(cmd *Command) interface{}

func (*StringBuilder) Commands added in v0.15.0

func (s *StringBuilder) Commands(cmd *Command) Group

func (*StringBuilder) ContextBounds added in v0.15.0

func (s *StringBuilder) ContextBounds(child interface{}) interface{}

func (*StringBuilder) ErrorSafeguard added in v0.15.0

func (s *StringBuilder) ErrorSafeguard(child interface{}) interface{}

func (*StringBuilder) Forwarding added in v0.15.0

func (*StringBuilder) Forwarding(f *Forwarding) interface{}

func (*StringBuilder) Host added in v0.15.0

func (s *StringBuilder) Host(c *Config, h *Host) Group

func (*StringBuilder) HostLogger added in v0.15.0

func (s *StringBuilder) HostLogger(jobName string, h *Host) interface{}

func (*StringBuilder) Hosts added in v0.15.0

func (s *StringBuilder) Hosts() Group

func (*StringBuilder) Job added in v0.15.0

func (s *StringBuilder) Job(name string) Group

func (*StringBuilder) JobLogger added in v0.15.0

func (s *StringBuilder) JobLogger(jobName string) interface{}

func (*StringBuilder) LocalCommand added in v0.15.0

func (s *StringBuilder) LocalCommand(cmd *Command) interface{}

func (*StringBuilder) Output added in v0.15.0

func (s *StringBuilder) Output(o *Output) interface{}

func (*StringBuilder) Parallel added in v0.15.0

func (*StringBuilder) Parallel() Group

func (*StringBuilder) Retry added in v0.15.0

func (s *StringBuilder) Retry(child interface{}, retries uint) interface{}

func (*StringBuilder) SCP added in v0.15.0

func (*StringBuilder) SCP(scp *ScpData) interface{}

func (*StringBuilder) SSHClient added in v0.15.0

func (*StringBuilder) SSHClient(host, user, keyFile, password string, keyboardInteractive map[string]string) interface{}

func (*StringBuilder) Sequential added in v0.15.0

func (*StringBuilder) Sequential() Group

func (*StringBuilder) Stderr added in v0.15.0

func (s *StringBuilder) Stderr(o *Output) interface{}

func (*StringBuilder) Stdout added in v0.15.0

func (s *StringBuilder) Stdout(o *Output) interface{}

func (*StringBuilder) Templating added in v0.15.0

func (s *StringBuilder) Templating(c *Config, h *Host) interface{}

func (*StringBuilder) Timeout added in v0.15.0

func (*StringBuilder) Timeout(timeout time.Duration) interface{}

func (*StringBuilder) Tunnel added in v0.15.0

func (*StringBuilder) Tunnel(f *Forwarding) interface{}

type Stringer

type Stringer interface {
	String(v *Vars) string
}

Stringer can use information stored in Vars to create a string.

type TemplatingEngine added in v0.15.0

type TemplatingEngine struct {
	Config *Config
	Host   *Host
	Env    map[string]string
	// contains filtered or unexported fields
}

A TemplatingEngine can treat templating strings as defined by the Go text/template package. It uses information from the Config, Host, environment variables and the current time to replace place holders in the string.

func (*TemplatingEngine) Interpolate added in v0.15.0

func (t *TemplatingEngine) Interpolate(templ string) (string, error)

Interpolate tries to replace all place holders present in templ with information stored in the TemplatingEngine.

type TreeBuilder added in v0.15.0

type TreeBuilder struct {
}

TreeBuilder builds a tree that can be used to create a textual representation of an execution tree.

type Vars added in v0.15.0

type Vars struct {
	Te *TemplatingEngine
}

Vars is used to store information needed to create a proper string representation of an execution tree.

Jump to

Keyboard shortcuts

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