cluster

package
v0.0.0-...-c283e9f Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2021 License: BSD-3-Clause Imports: 21 Imported by: 38

Documentation

Overview

Package cluster implements a client for the Flynn host service.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("cluster: resource not found")

ErrNotFound is returned when a resource is not found (HTTP status 404).

View Source
var ErrWouldWait = errors.New("cluster: attach would wait")

ErrWouldWait is returned when the Attach should not wait, but the job is not running.

Functions

func ExtractHostID

func ExtractHostID(id string) (string, error)

ExtractHostID returns the host ID component of a job ID, returning an error if the given ID is invalid.

func ExtractUUID

func ExtractUUID(id string) (string, error)

ExtractUUID returns the UUID component of a job ID, returning an error if the given ID is invalid.

func GenerateJobID

func GenerateJobID(hostID, uuid string) string

GenerateJobID returns a random job identifier, prefixed with the given host ID.

func HostTagsFromMeta

func HostTagsFromMeta(meta map[string]string) map[string]string

func WaitForHostStatus

func WaitForHostStatus(hostIP string, desired func(*host.HostStatus) bool) (*host.HostStatus, error)

Types

type AttachClient

type AttachClient interface {
	// Conn returns the underlying transport stream for the client.
	Conn() io.ReadWriteCloser

	// Receive reads stdout/stderr frames from the connection and writes them to
	// stdout and stderr. If the job exits, the return int will be set to the
	// exit code.
	Receive(stdout, stderr io.Writer) (int, error)

	// Wait waits for the job to start. It may optionally be called before
	// calling Receive.
	Wait() error

	// Signal sends a Unix signal to the job.
	Signal(int) error

	// ResizeTTY resizes the job's TTY.
	ResizeTTY(height, width uint16) error

	// CloseWrite sends an EOF to the stdin stream.
	CloseWrite() error

	// Writer allows writing to the stdin stream.
	io.Writer

	// Closer allows closing the underlying transport connection.
	io.Closer
}

An AttachClient provides access to the stdin/stdout/stderr streams of a job and allows sending UNIX signals to it.

func NewAttachClient

func NewAttachClient(conn io.ReadWriteCloser) AttachClient

NewAttachClient wraps conn in an implementation of AttachClient.

type Client

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

A Client is used to discover members of the flynn-host cluster.

func NewClient

func NewClient() *Client

NewClient uses the default discoverd configuration to create a cluster client.

func NewClientWithHTTP

func NewClientWithHTTP(services ServiceFunc, hc *http.Client) *Client

func NewClientWithServices

func NewClientWithServices(services ServiceFunc) *Client

NewClientWithServices uses the provided services to find cluster members. If services is nil, the default discoverd client is used.

func (*Client) Host

func (c *Client) Host(id string) (*Host, error)

Host returns the host identified by id.

func (*Client) Hosts

func (c *Client) Hosts() ([]*Host, error)

Hosts returns a list of hosts in the cluster.

func (*Client) StreamHostEvents

func (c *Client) StreamHostEvents(ch chan *discoverd.Event) (stream.Stream, error)

type Host

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

Host is a client for a host daemon.

func NewHost

func NewHost(id string, addr string, h *http.Client, tags map[string]string) *Host

NewHost creates a new Host that uses client to communicate with it. addr is used by Attach.

func (*Host) AddJob

func (c *Host) AddJob(job *host.Job) error

AddJob runs a job on the host.

func (*Host) AddSink

func (c *Host) AddSink(info *ct.Sink) error

func (*Host) Addr

func (c *Host) Addr() string

Addr returns the IP/port that the host API is listening on.

func (*Host) Attach

func (c *Host) Attach(req *host.AttachReq, wait bool) (AttachClient, error)

Attach attaches to the job specified in req and returns an attach client. If wait is true, the client will wait for the job to start before returning the first bytes. If wait is false and the job is not running, ErrWouldWait is returned.

func (*Host) CreateSnapshot

func (c *Host) CreateSnapshot(volumeID string) (*volume.Info, error)

Create snapshot creates a snapshot of a volume on a host.

func (*Host) CreateVolume

func (c *Host) CreateVolume(providerId string, info *volume.Info) error

CreateVolume a new volume with the given configuration. When in doubt, use a providerId of "default".

func (*Host) DestroyVolume

func (c *Host) DestroyVolume(volumeID string) error

DestroyVolume deletes a volume by ID

func (*Host) DiscoverdDeregisterJob

func (c *Host) DiscoverdDeregisterJob(id string) error

DiscoverdDeregisterJob requests a job to deregister from service discovery.

func (*Host) GetJob

func (c *Host) GetJob(id string) (*host.ActiveJob, error)

GetJob retrieves job details by ID.

func (*Host) GetSinks

func (c *Host) GetSinks() ([]*ct.Sink, error)

func (*Host) GetStatus

func (c *Host) GetStatus() (*host.HostStatus, error)

func (*Host) GetVolume

func (c *Host) GetVolume(volumeID string) (*volume.Info, error)

GetVolume gets a volume by ID

func (*Host) ID

func (c *Host) ID() string

ID returns the ID of the host this client communicates with.

func (*Host) ListActiveJobs

func (c *Host) ListActiveJobs() (map[string]host.ActiveJob, error)

ListActiveJobs lists starting or running jobs on the host.

func (*Host) ListJobs

func (c *Host) ListJobs() (map[string]host.ActiveJob, error)

ListJobs lists all jobs on the host.

func (*Host) ListVolumes

func (c *Host) ListVolumes() ([]*volume.Info, error)

ListVolume returns a list of volume IDs

func (*Host) PullBinariesAndConfig

func (c *Host) PullBinariesAndConfig(repository, binDir, configDir, version string, tufDB io.Reader) (map[string]string, error)

PullBinariesAndConfig pulls binaries and config from a TUF repository using the local TUF file in tufDB

func (*Host) PullImages

func (c *Host) PullImages(repository, configDir, version string, tufDB io.Reader, ch chan *ct.ImagePullInfo) (stream.Stream, error)

PullImages pulls images from a TUF repository using the local TUF file in tufDB

func (*Host) PullSnapshot

func (c *Host) PullSnapshot(receiveVolID string, sourceHostID string, sourceSnapID string) (*volume.Info, error)

PullSnapshot requests the host pull a snapshot from another host onto one of its volumes. Returns the info for the new snapshot.

func (*Host) RemoveSink

func (c *Host) RemoveSink(id string) error

func (*Host) ResourceCheck

func (c *Host) ResourceCheck(request host.ResourceCheck) error

func (*Host) SendSnapshot

func (c *Host) SendSnapshot(snapID string, assumeHaves []json.RawMessage) (io.ReadCloser, error)

SendSnapshot requests transfer of volume snapshot data (this is used by other hosts in service of the PullSnapshot request).

func (*Host) SignalJob

func (c *Host) SignalJob(id string, sig int) error

SignalJob sends a signal to a running job.

func (*Host) StopJob

func (c *Host) StopJob(id string) error

StopJob stops a running job.

func (*Host) StreamEvents

func (c *Host) StreamEvents(id string, ch chan *host.Event) (stream.Stream, error)

StreamEvents about job state changes to ch. id may be "all" or a single job ID.

func (*Host) StreamVolumes

func (c *Host) StreamVolumes(ch chan *volume.Event) (stream.Stream, error)

StreamVolumes streams volume events to the given channel

func (*Host) Tags

func (c *Host) Tags() map[string]string

Tags returns the hosts tags

func (*Host) Update

func (c *Host) Update(name string, args ...string) (pid int, err error)

func (*Host) UpdateTags

func (c *Host) UpdateTags(tags map[string]string) error

func (*Host) UpdateWithShutdownDelay

func (c *Host) UpdateWithShutdownDelay(name string, delay time.Duration, args ...string) (pid int, err error)

type ServiceFunc

type ServiceFunc func(name string) discoverd.Service

A ServiceFunc is a function that takes a service name and returns a discoverd.Service.

Jump to

Keyboard shortcuts

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