quantum

package module
v0.0.0-...-a08e549 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2015 License: MIT Imports: 18 Imported by: 4

README

Quantum Build Status

Library for building distributed, composable services.

Documentation

Index

Constants

View Source
const (
	// RequestType is a mux type for requests
	RequestType = uint8(67)
)

Variables

View Source
var (
	// ErrInvalidAddr = error resolving TCP addr
	ErrInvalidAddr = errors.New("Invalid Address")
	// ErrListen = error listening on TCP port
	ErrListen = errors.New("Unable to listen on specified port")
)
View Source
var (
	// ErrInvalidLager = nil Lager
	ErrInvalidLager = errors.New("Invalid Config Lager")
	// ErrInvalidPool = nil Pool
	ErrInvalidPool = errors.New("Invalid Config Pool")
)
View Source
var (
	// ErrNoConfigs occurs when there are no configs to work with
	ErrNoConfigs = errors.New("no configs provided")
)
View Source
var (
	// ErrSigReceived is used when a signal is received while running a job
	ErrSigReceived = errors.New("Signal Received")
)

Functions

func IsNoAgentsErr

func IsNoAgentsErr(err error) bool

IsNoAgentsErr returns whether this error is a no agents responded error

func ListenAndServe

func ListenAndServe(a Acceptor, port string, lgr lager.Lager) error

ListenAndServe is a common function for listening on a port and accepting connections

func NewRequestReceiver

func NewRequestReceiver(ch chan Request) mux.Receiver

NewRequestReceiver creates a new request receiver

func NoAgentsErr

func NoAgentsErr(t string) error

NoAgentsErr creates an error for no agents that responded with type

func NoAgentsFromRequest

func NoAgentsFromRequest(request ResolveRequest) (err error)

NoAgentsFromRequest creates an error for no agents that responded from a request

func NoAgentsWithNameErr

func NoAgentsWithNameErr(t string, name string) error

NoAgentsWithNameErr creates an error for no agents that responded with type and name

func ToMultiStep

func ToMultiStep(s Step) multistep.Step

ToMultiStep converts Step to multistep.Step

Types

type Acceptor

type Acceptor interface {
	Accept(net.Listener) error
	IsShutdown() chan struct{}
	io.Closer
}

Acceptor defines an interface for accepting requests from a net.Listener

type Agent

type Agent interface {
	Acceptor
	Registry
	Start() error
}

Agent routes job requests to jobs, and runs the jobs with the request

type AgentConn

type AgentConn interface {
	mux.Server
	Logs() chan string
	Signals() chan os.Signal
	Lager() lager.Lager
}

AgentConn is a connection created on an agent

type BasicCommunicator

type BasicCommunicator struct {
	sync.WaitGroup
	// contains filtered or unexported fields
}

BasicCommunicator is a basic implementation of Communicator

func (*BasicCommunicator) Communicate

func (c *BasicCommunicator) Communicate(exitCh chan struct{})

Communicate faciliates communication the parent and child

func (*BasicCommunicator) DrainLogs

func (c *BasicCommunicator) DrainLogs()

DrainLogs drains logs from the child and sends them to the parent.

func (*BasicCommunicator) ForwardSignals

func (c *BasicCommunicator) ForwardSignals(exit chan struct{})

ForwardSignals forwards signals from the parent to the child. Forwarding stops when exit closes

type BasicExecutor

type BasicExecutor struct {
	Steps []Step
}

BasicExecutor implements Executor

func (*BasicExecutor) Run

func (r *BasicExecutor) Run(state StateBag) error

Run steps

type BasicJob

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

BasicJob executes a StepsJob on Run

func NewBasicJob

func NewBasicJob(job StepsJob) *BasicJob

NewBasicJob creates a new BasicJob

func (*BasicJob) Run

func (basic *BasicJob) Run(conn AgentConn) error

Run runs the basic job

type BasicRunner

type BasicRunner struct{}

BasicRunner is a basic implementation of Runner

func (*BasicRunner) Run

func (r *BasicRunner) Run(cmd string,
	outCh chan<- string,
	sigCh <-chan os.Signal) error

Run runs a command and captures the output of the command, while listening for and sending signals to the process.

type BasicUI

type BasicUI struct {
	lager.Lager
	// contains filtered or unexported fields
}

BasicUI is a simple implementation of UI

func (*BasicUI) Both

func (ui *BasicUI) Both(log string)

Both logs to both the agent and the client

func (*BasicUI) Client

func (ui *BasicUI) Client(log string)

Client logs to the client

type Client

type Client interface {
	Dial(address string) (ClientConn, error)
	DialTimeout(address string, time time.Duration) (ClientConn, error)
}

Client creates ClientConns

type ClientConn

type ClientConn interface {
	mux.Client
	Run(request Request) error
	Logs() <-chan string
	Signals() chan<- os.Signal
}

ClientConn is a connection to an AgentConn

type ClientResolver

type ClientResolver interface {
	Resolve(request ResolveRequest) (ClientConn, error)
}

ClientResolver defines the interface for a resolver client.

type ClientResolverConfig

type ClientResolverConfig struct {
	Config *Config
	Server string
}

ClientResolverConfig defines the parameters for ClientResolver

type Communicator

type Communicator interface {
	Communicate(exitCh chan struct{})
	Add(num int)
	Done()
	Wait()
}

Communicator defines an interface for communicating quantum connections

func NewBasicCommunicator

func NewBasicCommunicator(parent AgentConn, child ClientConn) Communicator

NewBasicCommunicator creates a new basic communicator between parent and child

func NewCommunicator

func NewCommunicator(parent AgentConn, child ClientConn) Communicator

NewCommunicator creates a default communicator

type Config

type Config struct {
	Lager lager.Lager
	Pool  mux.Pool
}

Config represents components required by all quantum components

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig is the default config

func (*Config) Verify

func (c *Config) Verify() error

Verify validates a Config, checking for nil components

type ConnConfig

type ConnConfig struct {
	Timeout time.Duration
	*Config
}

ConnConfig are configuration settings needed for Conn

func DefaultConnConfig

func DefaultConnConfig() *ConnConfig

DefaultConnConfig is the default ConnConfig

func (*ConnConfig) ToMux

func (c *ConnConfig) ToMux() *mux.Config

ToMux creates a mux.Config from ConnConfig

type Executor

type Executor interface {
	Execute(statebag StateBag) error
}

Executor executes steps

type Job

type Job interface {
	// Used to match requests to jobs
	Routable
	Configure([]byte) error
	Run(AgentConn) error
}

Job is executed by Quantum

type MultiClientResolver

type MultiClientResolver struct {
	Resolvers []ClientResolver
}

MultiClientResolver implements ClientResolver by trying to resolve a client be iterating through provided ClientResolvers.

func (*MultiClientResolver) Resolve

func (r *MultiClientResolver) Resolve(request ResolveRequest) (conn ClientConn, err error)

Resolve resolves a ResolveRequest by iterating through r.Resolvers

type MultiRegistrator

type MultiRegistrator struct {
	Registrators []Registrator
}

MultiRegistrator holds multiple Registry instances

func (*MultiRegistrator) Deregister

func (r *MultiRegistrator) Deregister() error

Deregister calls Deregister on Registries

func (*MultiRegistrator) Register

func (r *MultiRegistrator) Register(port int, reg Registry) error

Register calls Register on Registries

type Registrator

type Registrator interface {
	Register(port int, reg Registry) error
	Deregister() error
}

Registrator registers and deregisters services

type Registry

type Registry interface {
	Add(job Job)
	Get(request Request) (Job, error)
	Types() (types []string)
}

Registry adds jobs, provides access to jobs by type, and all job types.

type Request

type Request struct {
	Type string
	Data []byte
}

Request contains Type and Data. Type is the ID, Data is the request data

func NewRequest

func NewRequest(rt, rd string) Request

NewRequest creates a request using the request type and request data as strings

func RoutableRequest

func RoutableRequest(r Routable) Request

RoutableRequest creates a Request

type RequestReceiver

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

RequestReceiver receives Request

type ResolveRequest

type ResolveRequest struct {
	Agent string
	Type  string
}

ResolveRequest describes the parameters for client resolution

type Routable

type Routable interface {
	Type() string
}

Routable defines an interface for routing an object

type Runner

type Runner interface {
	Run(string, chan<- string, <-chan os.Signal) error
}

Runner defines an interface for running commands

func NewBasicRunner

func NewBasicRunner() (r Runner)

NewBasicRunner returns a basic runner

type StateBag

type StateBag struct {
	multistep.StateBag
}

StateBag defines a statebag

func NewStateBag

func NewStateBag() StateBag

NewStateBag creates a new StateBag

type Step

type Step interface {
	Run(state StateBag) error
	Cleanup(state StateBag)
}

Step defines a step that can run and clean up

type StepsJob

type StepsJob interface {
	Job
	Steps() []Step
}

StepsJob is a superset of Job, providing Steps so this job can by ran by BasicRun. This could be a StepJob with a BasicImplementation.

type UI

type UI interface {
	lager.Lager
	Client(log string)
	Both(log string)
}

UI handles sending logs to the client and agent

func NewUI

func NewUI(conn AgentConn) UI

NewUI creates a new UI

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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