runner

package
v0.0.0-...-1dd1f65 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package runner contains low-level code for running the machine node via SSH and locally.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

type Factory interface {
	// MakeRunner creates a new Runner, representing a particular invoker session on a machine, and outputting to ldir.
	// It takes the plan p in case the factory is waiting to get machine configuration from it.
	MakeRunner(ldir string, p *plan.Plan, obs ...copier.Observer) (Runner, error)

	// Closer captures that Runner spawners can be closed once no more runners are needed.
	// For SSH runner spawners, this will close the SSH connection.
	io.Closer
}

Factory is the interface of factories for machine node runners.

Runner factories can contain disposable state (for example, long-running SSH connections), and so can be closed.

func FactoryFromRemoteConfig

func FactoryFromRemoteConfig(gc *remote.Config, mc *remote.MachineConfig) (Factory, error)

FactoryFromRemoteConfig creates a remote factory using gc and mc, if mc is non-nil; else, it creates a local factory.

type FromPlanFactory

type FromPlanFactory struct {
	// The global remoting config used for any remote connections initiated by this factory.
	Config *remote.Config
	// contains filtered or unexported fields
}

FromPlanFactory is a runner factory that instantiates either a SSH or local runner depending on the machine configuration inside the first plan passed to it.

This is useful for single-shot invocation over a plan, where there is no benefit to setting up a connection based on central machine/SSH configuration. In the director, the invoker will set up the machine configuration in advance, and there is no need to consult the plan.

func (*FromPlanFactory) Close

func (p *FromPlanFactory) Close() error

Close closes the runner factory, if it was ever instantiated.

func (*FromPlanFactory) MakeRunner

func (p *FromPlanFactory) MakeRunner(ldir string, pl *plan.Plan, obs ...copier.Observer) (Runner, error)

MakeRunner makes a runner using the machine configuration in pl.

type InvocationGetter

type InvocationGetter interface {
	// MachBin retrieves the default binary name for the node.
	MachBin() string
	// MachArgs computes the argument set for invoking the node binary.
	MachArgs(dir string) []string
}

InvocationGetter is the interface of types that tell the invoker how to invoke the machine node.

type LocalFactory

type LocalFactory struct{}

LocalFactory allows spawning of local runners using said path as the local directory.

func (LocalFactory) Close

func (l LocalFactory) Close() error

Close does nothing.

func (LocalFactory) MakeRunner

func (l LocalFactory) MakeRunner(ldir string, _ *plan.Plan, _ ...copy2.Observer) (Runner, error)

type LocalRunner

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

LocalRunner runs the machine-runner locally.

func NewLocalRunner

func NewLocalRunner(dir string) *LocalRunner

NewLocalRunner creates a new LocalRunner.

func (*LocalRunner) Recv

func (r *LocalRunner) Recv(ctx context.Context, _, rp *plan.Plan) (*plan.Plan, error)

Recv effectively does nothing but implement the general runner interface obligations and make sure the context is live.

func (*LocalRunner) Send

func (r *LocalRunner) Send(ctx context.Context, p *plan.Plan) (*plan.Plan, error)

Send effectively does nothing but implement the general runner interface obligations and make sure the context is live.

func (*LocalRunner) Start

Start starts the machine-runner binary locally using ctx, and returns a pipeset for talking to it.

func (*LocalRunner) Wait

func (r *LocalRunner) Wait() error

Wait waits for the running machine-runner binary to terminate.

type RemoteFactory

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

RemoteFactory is a factory that produces runners in the form of SSH sessions.

func NewRemoteFactory

func NewRemoteFactory(gc *remote.Config, mc *remote.MachineConfig) (*RemoteFactory, error)

NewRemoteFactory opens a SSH connection using Config and mc. If successful, it creates a runner factory over it.

func (*RemoteFactory) Close

func (s *RemoteFactory) Close() error

Close closes the underlying SSH connection being used for runners created by this factory.

func (*RemoteFactory) MakeRunner

func (s *RemoteFactory) MakeRunner(ldir string, _ *plan.Plan, obs ...copier.Observer) (Runner, error)

MakeRunner constructs a runner using this factory's open SSH connection.

type RemoteRunner

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

RemoteRunner runs the machine-runner via SSH.

func NewRemoteRunner

func NewRemoteRunner(r *remote.MachineRunner, localRoot string, o ...copier.Observer) (*RemoteRunner, error)

NewRemoteRunner creates a new RemoteRunner.

func (*RemoteRunner) Recv

func (r *RemoteRunner) Recv(ctx context.Context, locp, remp *plan.Plan) (*plan.Plan, error)

Recv copies bits of remp into locp, including run information and any compiler failures. It uses SFTP to transfer back any compile logs.

func (*RemoteRunner) Send

func (r *RemoteRunner) Send(ctx context.Context, p *plan.Plan) (*plan.Plan, error)

Send translates p to the remote host, using SFTP to copy over any recipe files.

func (*RemoteRunner) Start

Start starts a SSH session connected to a machine node with the quantities specified in qs.

func (*RemoteRunner) Wait

func (r *RemoteRunner) Wait() error

Wait waits for either the SSH session to finish, or the context supplied to Start to close.

type Runner

type Runner interface {
	// Send performs any copying and transformation needed for p to run.
	// It returns a pointer to the plan to send to the machine node, which may or may not be p.
	Send(ctx context.Context, p *plan.Plan) (*plan.Plan, error)

	// Start starts the machine binary, returning a set of pipe readers and writers to use for communication with it.
	Start(ctx context.Context, qs quantity.MachNodeSet) (*remote.Pipeset, error)

	// Wait blocks waiting for the command to finish (or the context passed into Start to cancel).
	Wait() error

	// Recv merges the post-run plan runp into the original plan origp, copying back any files needed.
	// It returns a pointer to the final 'merged', which may or may not be origp and runp.
	// It may modify origp in place.
	Recv(ctx context.Context, origp, runp *plan.Plan) (*plan.Plan, error)
}

Runner is the interface of types that know how to run the machine node.

Jump to

Keyboard shortcuts

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