miner

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2018 License: Apache-2.0 Imports: 52 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrListenerClosed is returned to clients and servers is the listener closed
	ErrListenerClosed = errors.New("inmemory listener closed")
)

Functions

func SortedIPs added in v0.3.0

func SortedIPs(ips []string) []string

Types

type BackoffTimer

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

BackoffTimer implementation

func NewBackoffTimer

func NewBackoffTimer(sleep, maxsleep time.Duration) *BackoffTimer

NewBackoffTimer implementations one direction backoff policy

func (*BackoffTimer) C

func (b *BackoffTimer) C() <-chan time.Time

C resets Timer and returns Timer.C

func (*BackoffTimer) Stop

func (b *BackoffTimer) Stop() bool

Stop frees the Timer

type Config added in v0.3.0

type Config interface {
	// HubEndpoints returns a string representation of a Hub endpoint to communicate with.
	HubEndpoints() []string
	// HubEthAddr returns hub's ethereum address.
	HubEthAddr() string
	// HubResolveEndpoints returns `true` if we need to resolve hub's endpoints via locator.
	HubResolveEndpoints() bool
	// HubResources returns resources allocated for a Hub.
	HubResources() *ResourcesConfig
	// Firewall returns firewall detection settings.
	Firewall() *FirewallConfig
	// PublicIPs returns all IPs that can be used to communicate with the miner.
	PublicIPs() []string
	// SSH returns settings for built-in ssh server
	SSH() *SSHConfig
	// Logging returns logging settings.
	Logging() LoggingConfig
	// Path to store Miner uuid
	UUIDPath() string
	// ETH returns ethereum configuration
	ETH() *accounts.EthConfig
	// LocatorEndpoint returns locator endpoint.
	LocatorEndpoint() string
	// MetricsListenAddr returns the address that can be used by Prometheus to get
	// metrics.
	MetricsListenAddr() string
	// Plugins returns plugins settings.
	Plugins() plugin.Config
}

Config represents a Miner configuration interface.

func NewConfig

func NewConfig(path string) (Config, error)

NewConfig creates a new Miner config from the specified YAML file.

type ContainerInfo

type ContainerInfo struct {
	ID           string
	ImageName    string
	StartAt      time.Time
	Ports        nat.PortMap
	Resources    resource.Resources
	PublicKey    ssh.PublicKey
	Cgroup       string
	CgroupParent string
	// contains filtered or unexported fields
}

ContainerInfo is a brief information about containers

type ContainerMetrics

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

ContainerMetrics are metrics collected from Docker about running containers

func (*ContainerMetrics) Marshal added in v0.3.0

func (m *ContainerMetrics) Marshal() *pb.ResourceUsage

type Description

type Description struct {
	Registry      string
	Image         string
	Auth          string
	RestartPolicy container.RestartPolicy
	Resources     container.Resources
	Cmd           []string
	Env           map[string]string
	TaskId        string
	DealId        string
	CommitOnStop  bool

	GPURequired bool
	// contains filtered or unexported fields
}

Description for a target application.

func (*Description) FormatEnv added in v0.3.0

func (d *Description) FormatEnv() []string

func (*Description) GPU added in v0.3.2

func (d *Description) GPU() bool

func (*Description) ID added in v0.3.2

func (d *Description) ID() string

func (*Description) Mounts added in v0.3.2

func (d *Description) Mounts(source string) []volume.Mount

func (*Description) Volumes added in v0.3.2

func (d *Description) Volumes() map[string]*pb.Volume

type ExecConnection added in v0.3.0

type ExecConnection types.HijackedResponse

type FirewallConfig added in v0.3.0

type FirewallConfig struct {
	// STUN server endpoint (with port).
	Server string `yaml:"server"`
}

FirewallConfig describes firewall detection settings.

type HubConfig added in v0.3.0

type HubConfig struct {
	EthAddr          string           `required:"true" yaml:"eth_addr"`
	ResolveEndpoints bool             `required:"false" yaml:"resolve_endpoints"`
	Endpoints        []string         `required:"false" yaml:"endpoints"`
	CGroups          *ResourcesConfig `required:"false" yaml:"resources"`
}

HubConfig describes Hub configuration.

type LocatorConfig added in v0.3.0

type LocatorConfig struct {
	Endpoint string `required:"true" yaml:"endpoint"`
}

type LoggingConfig added in v0.3.0

type LoggingConfig struct {
	Level int `required:"true" default:"1"`
}

type Miner

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

Miner holds information about jobs, make orders to Observer and communicates with Hub

func NewMiner added in v0.3.2

func NewMiner(cfg Config, opts ...Option) (m *Miner, err error)

func (*Miner) Close

func (m *Miner) Close()

Close disposes all resources related to the Miner

func (*Miner) DiscoverHub added in v0.3.0

func (m *Miner) DiscoverHub(ctx context.Context, request *pb.DiscoverHubRequest) (*pb.Empty, error)

func (*Miner) GetContainerInfo added in v0.3.0

func (m *Miner) GetContainerInfo(id string) (*ContainerInfo, bool)

func (*Miner) Handshake

func (m *Miner) Handshake(ctx context.Context, request *pb.MinerHandshakeRequest) (*pb.MinerHandshakeReply, error)

Handshake is the first frame received from a Hub.

This is a self representation about initial resources this Miner provides. TODO: May be useful to register a channel to cover runtime resource changes.

func (*Miner) Info

func (m *Miner) Info(ctx context.Context, request *pb.Empty) (*pb.InfoReply, error)

Info returns runtime statistics collected from all containers working on this miner.

This works the following way: a miner periodically collects various runtime statistics from all spawned containers that it knows about. For running containers metrics map the immediate state, for dead containers - their last memento.

func (*Miner) Load added in v0.3.0

func (m *Miner) Load(stream pb.Miner_LoadServer) error

func (*Miner) Ping

func (m *Miner) Ping(ctx context.Context, _ *pb.Empty) (*pb.PingReply, error)

Ping works as Healthcheck for the Hub

func (*Miner) Save added in v0.3.0

func (m *Miner) Save(request *pb.SaveRequest, stream pb.Miner_SaveServer) error

func (*Miner) Serve

func (m *Miner) Serve() error

Serve starts discovery of Hubs, accepts incoming connections from a Hub

func (*Miner) Start

func (m *Miner) Start(ctx context.Context, request *pb.MinerStartRequest) (*pb.MinerStartReply, error)

Start request from Hub makes Miner start a container

func (*Miner) Stop

func (m *Miner) Stop(ctx context.Context, request *pb.ID) (*pb.Empty, error)

Stop request forces to kill container

func (*Miner) TaskDetails added in v0.3.0

func (m *Miner) TaskDetails(ctx context.Context, req *pb.ID) (*pb.TaskStatusReply, error)

func (*Miner) TaskLogs added in v0.3.0

func (m *Miner) TaskLogs(request *pb.TaskLogsRequest, server pb.Miner_TaskLogsServer) error

TaskLogs returns logs from container

func (*Miner) TasksStatus

func (m *Miner) TasksStatus(server pb.Miner_TasksStatusServer) error

TasksStatus returns the status of a task

type Option added in v0.3.2

type Option func(*options)

func WithContext added in v0.3.2

func WithContext(ctx context.Context) Option

func WithHardware added in v0.3.2

func WithHardware(hardwareInfo hardware.HardwareInfo) Option

func WithKey added in v0.3.2

func WithKey(key *ecdsa.PrivateKey) Option

func WithLocatorClient added in v0.3.2

func WithLocatorClient(locatorClient pb.LocatorClient) Option

func WithNat added in v0.3.2

func WithNat(nat stun.NATType) Option

func WithOverseer added in v0.3.2

func WithOverseer(ovs Overseer) Option

func WithSSH added in v0.3.2

func WithSSH(ssh SSH) Option

func WithUUID added in v0.3.2

func WithUUID(uuid string) Option

type Overseer

type Overseer interface {
	// Load loads an image from the specified reader to the Docker.
	Load(ctx context.Context, rd io.Reader) (imageLoadStatus, error)

	// Save saves an image from the Docker into the returned reader.
	Save(ctx context.Context, imageID string) (types.ImageInspect, io.ReadCloser, error)

	// Spool prepares an application for its further start.
	//
	// For Docker containers this is an equivalent of pulling from the registry.
	Spool(ctx context.Context, d Description) error

	// Start attempts to start an application using the specified description.
	//
	// After successful starting an application becomes a target for accepting request, but not guarantees
	// to complete them.
	Start(ctx context.Context, description Description) (chan pb.TaskStatusReply_Status, ContainerInfo, error)

	// Exec a given command in running container
	Exec(ctx context.Context, Id string, cmd []string, env []string, isTty bool, wCh <-chan ssh.Window) (types.HijackedResponse, error)

	// Stop terminates the container.
	Stop(ctx context.Context, containerID string) error

	// Info returns runtime statistics collected from all running containers.
	//
	// Depending on the implementation this can be cached.
	Info(ctx context.Context) (map[string]ContainerMetrics, error)

	// Fetch logs of the container
	Logs(ctx context.Context, id string, opts types.ContainerLogsOptions) (io.ReadCloser, error)

	// Close terminates all associated asynchronous operations and prepares the Overseer for shutting down.
	Close() error
}

Overseer watches all miner's applications.

func NewOverseer

func NewOverseer(ctx context.Context, plugins *plugin.Repository) (Overseer, error)

NewOverseer creates new overseer

type Resources added in v0.3.0

type Resources specs.LinuxResources

CGroups is a type alias for OCI CGroups spec

func (*Resources) SetYAML added in v0.3.0

func (r *Resources) SetYAML(tag string, value interface{}) bool

SetYAML implements goyaml.Setter

type ResourcesConfig added in v0.3.0

type ResourcesConfig struct {
	Cgroup    string                `required:"true" yaml:"cgroup"`
	Resources *specs.LinuxResources `required:"false" yaml:"resources"`
}

type SSH added in v0.3.0

type SSH interface {
	Run() error
	Close()
}

func NewSSH added in v0.3.0

func NewSSH(miner *Miner, config *SSHConfig) (SSH, error)

type SSHConfig added in v0.3.0

type SSHConfig struct {
	BindEndpoint   string `required:"true" yaml:"bind"`
	PrivateKeyPath string `required:"true" yaml:"private_key_path"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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