workers

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: Apache-2.0 Imports: 15 Imported by: 2

Documentation

Overview

Package workers is responsible for worker list management.

Index

Constants

View Source
const UUID string = "UUID"

UUID denotes a key in Capabilities where WorkerUUID is stored.

Variables

View Source
var (
	// ErrNotImplemented is returned when function is not implemented yet.
	ErrNotImplemented = errors.New("function not implemented")
	// ErrMissingUUID is returned when Register is called
	// with caps, which do not contain "UUID" field.
	ErrMissingUUID = errors.New("Capabilities are missing UUID entry")
	// ErrWorkerNotFound is returned when UUID argument does not match any worker on the list.
	ErrWorkerNotFound = boruta.NotFoundError("Worker")
	// ErrInMaintenance is returned when SetFail has been called for Worker in MAINTENANCE state.
	ErrInMaintenance = errors.New("It is forbidden to set FAIL state when Worker is in MAINTENANCE state")
	// ErrNotInFailOrMaintenance is returned when Deregister is called for a worker not in FAIL or MAINTENANCE state.
	// Only workers in FAIL or MAINTENANCE state can be removed from the list.
	ErrNotInFailOrMaintenance = errors.New("Worker is not in FAIL or MAINTENANCE state")
	// ErrWrongStateArgument is returned when SetState is called with incorrect state argument.
	// Worker state can be changed by Admin to IDLE or MAINTENANCE only.
	ErrWrongStateArgument = errors.New("Only state changes to IDLE and MAINTENANCE are allowed")
	// ErrForbiddenStateChange is returned when transition from state, Worker is in,
	// to state, SetState has been called with, is forbidden.
	ErrForbiddenStateChange = errors.New("Invalid state transition was requested")
	// ErrNoMatchingWorker is returned when there is no worker matching groups nor
	// capabilities required by request.
	ErrNoMatchingWorker = errors.New("No matching worker")
	// ErrMissingIP is returned when Register is called with either dryad or sshd
	// address missing IP value.
	ErrMissingIP = errors.New("IP address is missing from address")
	// ErrMissingPort is returned when Register is called with either dryad or sshd
	// address missing Port value.
	ErrMissingPort = errors.New("Port is missing from address")
	// ErrWorkerBusy is returned when worker is preparing to enter IDLE or MAINTENANCE state
	// which requires time consuming operations to be run on Dryad. During this preparations
	// Worker is blocked and cannot change state.
	ErrWorkerBusy = errors.New("worker is busy")
)

Functions

This section is empty.

Types

type Job

type Job struct {
	// Access describes details of the connection to Dryad. It is returned to the request
	// owner when a job for request is run and acquired by the user.
	Access boruta.AccessInfo
	// Tunnel is a connection to Dryad for the user.
	Tunnel tunnels.Tunneler
	// Req is ID of the worked request.
	Req boruta.ReqID
}

Job describes worker job.

type WorkerChange

type WorkerChange interface {
	// OnWorkerIdle notifies about available idle worker.
	OnWorkerIdle(boruta.WorkerUUID)
	// OnWorkerFail notifies about breaking execution of job by a running worker and
	// putting it into FAIL or MAINTENANCE state.
	OnWorkerFail(boruta.WorkerUUID)
}

WorkerChange defines API for implementation to be informed about changes in workers.

type WorkerList

type WorkerList struct {
	boruta.Superviser
	boruta.Workers
	// contains filtered or unexported fields
}

WorkerList implements Superviser and Workers interfaces. It manages a list of Workers. It implements also WorkersManager from matcher package making it usable as interface for acquiring workers by Matcher. The implemnetation requires changeListener, which is notified after Worker's state changes. The dryad.ClientManager allows managing Dryads' clients for key generation. One can be created using newDryadClient function.

func NewWorkerList

func NewWorkerList() *WorkerList

NewWorkerList returns a new WorkerList with all fields set.

func (*WorkerList) Deregister

func (wl *WorkerList) Deregister(uuid boruta.WorkerUUID) error

Deregister is an implementation of Deregister from Workers interface.

func (*WorkerList) GetWorkerInfo

func (wl *WorkerList) GetWorkerInfo(uuid boruta.WorkerUUID) (boruta.WorkerInfo, error)

GetWorkerInfo is an implementation of GetWorkerInfo from Workers interface.

func (*WorkerList) GetWorkerKey

func (wl *WorkerList) GetWorkerKey(uuid boruta.WorkerUUID) (rsa.PrivateKey, error)

GetWorkerKey retrieves key from the internal structure.

func (*WorkerList) GetWorkerSSHAddr

func (wl *WorkerList) GetWorkerSSHAddr(uuid boruta.WorkerUUID) (net.TCPAddr, error)

GetWorkerSSHAddr retrieves address of worker's ssh daemon from the internal structure.

func (*WorkerList) ListWorkers

func (wl *WorkerList) ListWorkers(filter boruta.ListFilter, info *boruta.SortInfo,
	paginator *boruta.WorkersPaginator) ([]boruta.WorkerInfo, *boruta.ListInfo, error)

ListWorkers is an implementation of ListWorkers from Workers interface.

func (*WorkerList) PrepareWorker

func (wl *WorkerList) PrepareWorker(uuid boruta.WorkerUUID, withKeyGeneration bool) error

PrepareWorker brings worker into IDLE state and prepares it to be ready for running a job. In some of the situations if a worker has been matched for a job, but has not been used, there is no need for regeneration of the key. Caller of this method can decide (with 2nd parameter) if key generation is required for preparing worker.

As key creation can take some time, the method is asynchronous and the worker's state might not be changed when it returns. It is a part of WorkersManager interface implementation by WorkerList.

func (*WorkerList) Register

func (wl *WorkerList) Register(caps boruta.Capabilities, dryadAddress string,
	sshAddress string) error

Register is an implementation of Register from Superviser interface. UUID, which identifies Worker, must be present in caps. Both dryadAddress and sshAddress must resolve and parse to net.TCPAddr. Neither IP address nor port number can not be ommited.

func (*WorkerList) SetChangeListener

func (wl *WorkerList) SetChangeListener(listener WorkerChange)

SetChangeListener sets change listener object in WorkerList. Listener should be notified in case of changes of workers' states, when worker becomes IDLE or must break its job because of fail or maintenance. It is a part of WorkersManager interface implementation by WorkerList.

func (*WorkerList) SetFail

func (wl *WorkerList) SetFail(uuid boruta.WorkerUUID, reason string) error

SetFail is an implementation of SetFail from Superviser interface.

TODO(amistewicz): WorkerList should process the reason and store it.

func (*WorkerList) SetGroups

func (wl *WorkerList) SetGroups(uuid boruta.WorkerUUID, groups boruta.Groups) error

SetGroups is an implementation of SetGroups from Workers interface.

func (*WorkerList) SetState

func (wl *WorkerList) SetState(uuid boruta.WorkerUUID, state boruta.WorkerState) error

SetState is an implementation of SetState from Workers interface. Nil return means that there were no formal issues to change the state of the worker. Error may occur while communicating with Dryad via RPC. In such case state of the worker will be changed to FAIL. It's responsibility of the caller to check if state was changed to requested value.

func (*WorkerList) TakeBestMatchingWorker

func (wl *WorkerList) TakeBestMatchingWorker(groups boruta.Groups, caps boruta.Capabilities) (bestWorker boruta.WorkerUUID, err error)

TakeBestMatchingWorker verifies which IDLE workers can satisfy Groups and Capabilities required by the request. Among all matched workers a best worker is choosen (least capable worker still fitting request). If a worker is found it is put into RUN state and its UUID is returned. An error is returned if no matching IDLE worker is found. It is a part of WorkersManager interface implementation by WorkerList.

Jump to

Keyboard shortcuts

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