matcher

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: 8 Imported by: 2

Documentation

Overview

Package matcher provides interface and implementation for taking actions related to assigning requests to workers and reacting to requests time events.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrJobAlreadyExists is returned during job creation if previous job
	// run by the worker was not released properly.
	ErrJobAlreadyExists = errors.New("job already exists")
)

Functions

This section is empty.

Types

type DeadlineMatcher

type DeadlineMatcher struct {
	Matcher
	// contains filtered or unexported fields
}

DeadlineMatcher implements Matcher interface for handling pending requests timeout.

func NewDeadlineMatcher

func NewDeadlineMatcher(r RequestsManager) *DeadlineMatcher

NewDeadlineMatcher creates a new DeadlineMatcher structure.

func (DeadlineMatcher) Notify

func (m DeadlineMatcher) Notify(dead []boruta.ReqID)

Notify implements Matcher interface. This method reacts on events passed to matcher. Timeout method is called on RequestsManager for each request. Some of the timeouts might be invalid, because the request's state has been changed to CANCEL or INPROGRESS; or the Deadline time itself has been changed. Verification if timeout conditions are met is done in Timeout() method. If changing state to TIMEOUT is not possible Timeout returns an error. Any errors are ignored as they are false negatives cases from DeadlineMatcher point of view.

type JobsManager

type JobsManager interface {
	// Create prepares a new job for the worker.
	Create(boruta.ReqID, boruta.WorkerUUID) error
	// Get returns pointer to a Job from JobsManager or error if no job for
	// the worker is found.
	Get(boruta.WorkerUUID) (*workers.Job, error)
	// Finish cleans up after job is done. The second parameter defines
	// if worker should be prepared for next job.
	Finish(boruta.WorkerUUID, bool) error
}

JobsManager defines API for internal boruta management of jobs.

func NewJobsManager

func NewJobsManager(w WorkersManager) JobsManager

NewJobsManager creates and returns new JobsManagerImpl structure.

type JobsManagerImpl

type JobsManagerImpl struct {
	JobsManager
	// contains filtered or unexported fields
}

JobsManagerImpl manages jobs. It is an implementation of JobsManager interface. It provides methods for creation of new jobs, getting their data and finishing them.

func (*JobsManagerImpl) Create

func (m *JobsManagerImpl) Create(req boruta.ReqID, worker boruta.WorkerUUID) error

Create method creates a new job for the request and the worker. It also prepares communication to Dryad by creating a tunnel. It is a part of JobsManager interface implementation.

func (*JobsManagerImpl) Finish

func (m *JobsManagerImpl) Finish(worker boruta.WorkerUUID, prepare bool) error

Finish closes the job execution, breaks the tunnel to Dryad and removes job from jobs collection. The Dryad should be notified and prepared for next job with key regeneration if prepare is true. If prepare is false, Dryad should not be prepared. This can happen when Dryad failed or is brought to MAINTENANCE state. It is a part of JobsManager interface implementation.

func (*JobsManagerImpl) Get

func (m *JobsManagerImpl) Get(worker boruta.WorkerUUID) (*workers.Job, error)

Get returns job information related to the worker ID or error if no job for that worker was found. It is a part of JobsManager interface implementation.

type Matcher

type Matcher interface {
	// Notify triggers action in the matcher. The ReqID slice contain set
	// of requests' IDs related to the event. The slice can be empty if the event
	// requires generic actions on all requests.
	Notify([]boruta.ReqID)
}

Matcher defines interface for objects that can be notified about events.

type RequestsManager

type RequestsManager interface {
	// InitIteration starts iteration over requests pending in queue.
	// Method returns error if iterations are already started and have not been
	// terminated with TerminateIteration()
	InitIteration() error
	// TerminateIteration finishes iterating over requests formerly started with InitIteration.
	TerminateIteration()
	// Next gets next ID from request queue.
	// Method returns {ID, true} if there is pending request
	// or {ReqID(0), false} if queue's end has been reached.
	Next() (boruta.ReqID, bool)
	// VerifyIfReady checks if the request is ready to be run on worker.
	VerifyIfReady(boruta.ReqID, time.Time) bool
	// Get retrieves full request information or error if no request is found.
	Get(boruta.ReqID) (boruta.ReqInfo, error)
	// Timeout sets request to TIMEOUT state after Deadline time is exceeded.
	Timeout(boruta.ReqID) error
	// Close closes request setting it in DONE state, closing job
	// and releasing worker after run time of the request has been exceeded.
	Close(boruta.ReqID) error
	// Run starts job performing the request on the worker.
	Run(boruta.ReqID, boruta.WorkerUUID) error
}

RequestsManager interface defines API for internal boruta management of requests.

type TimeoutMatcher

type TimeoutMatcher struct {
	Matcher
	// contains filtered or unexported fields
}

TimeoutMatcher implements Matcher interface for handling running requests timeout.

func NewTimeoutMatcher

func NewTimeoutMatcher(r RequestsManager) *TimeoutMatcher

NewTimeoutMatcher creates a new TimeoutMatcher structure.

func (TimeoutMatcher) Notify

func (m TimeoutMatcher) Notify(out []boruta.ReqID)

Notify implements Matcher interface. This method reacts to events passed to matcher. Close method is called on RequestsManager for each request. Some of the cases might be invalid, because the request's state has been changed to DONE or FAILED. Verification of closing conditions is done inside Close method.

type ValidMatcher

type ValidMatcher struct {
	Matcher
	// contains filtered or unexported fields
}

ValidMatcher implements Matcher interface for handling requests validation.

func NewValidMatcher

func NewValidMatcher(r RequestsManager, w WorkersManager, j JobsManager) *ValidMatcher

NewValidMatcher creates a new ValidMatcher structure.

func (ValidMatcher) Notify

func (m ValidMatcher) Notify([]boruta.ReqID)

Notify implements Matcher interface. This method reacts on events passed to matcher. In this implementation requests' IDs are ignored as requests must be matched in order they are placed in requests priority queue.

type WorkersManager

type WorkersManager interface {
	// TakeBestMatchingWorker returns best matching worker that meets a criteria.
	// An error is returned if no matching worker is found.
	TakeBestMatchingWorker(boruta.Groups, boruta.Capabilities) (boruta.WorkerUUID, error)

	// PrepareWorker makes it ready for running a job.
	// Caller of this method can decide (with 2nd parameter) if key generation
	// is required for preparing worker.
	PrepareWorker(worker boruta.WorkerUUID, withKeyGeneration bool) error

	// GetWorkerSSHAddr returns address of the ssh daemon on the worker that can
	// be used for setting up tunnel to the worker. If there is no worker with
	// given WorkerUUID an error is returned.
	GetWorkerSSHAddr(boruta.WorkerUUID) (net.TCPAddr, error)

	// GetWorkerKey returns private RSA key of the worker that can be used for
	// accessing the worker. If there is no worker with given WorkerUUID an error
	// is returned.
	GetWorkerKey(boruta.WorkerUUID) (rsa.PrivateKey, error)

	// SetChangeListener stores reference to object, which should be notified
	// in case of changes of workers' states.
	SetChangeListener(workers.WorkerChange)
}

WorkersManager defines API for internal boruta management of workers.

Jump to

Keyboard shortcuts

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