miner

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2017 License: Apache-2.0 Imports: 50 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 {
	// HubEndpoint returns a string representation of a Hub endpoint to communicate with.
	HubEndpoint() string
	// 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
	// GPU returns options about NVIDIA GPU support via nvidia-docker-plugin
	GPU() *gpu.Config
	// 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
}

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
}

Description for a target application.

func (*Description) FormatEnv added in v0.3.0

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

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 GPUConfig added in v0.3.0

type GPUConfig struct {
	NvidiaDockerDriver string `yaml:"nvidiadockerdriver"`
}

GPUConfig contains options related to NVIDIA GPU support

type HubConfig added in v0.3.0

type HubConfig struct {
	Endpoint string           `required:"true" yaml:"endpoint"`
	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 (*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 MinerBuilder added in v0.3.0

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

func NewMinerBuilder added in v0.3.0

func NewMinerBuilder(cfg Config, key *ecdsa.PrivateKey) (*MinerBuilder, error)

func (*MinerBuilder) Build added in v0.3.0

func (b *MinerBuilder) Build() (miner *Miner, err error)

func (*MinerBuilder) Config added in v0.3.0

func (b *MinerBuilder) Config(config Config) *MinerBuilder

func (*MinerBuilder) Context added in v0.3.0

func (b *MinerBuilder) Context(ctx context.Context) *MinerBuilder

func (*MinerBuilder) Hardware added in v0.3.0

func (b *MinerBuilder) Hardware(hardware hardware.HardwareInfo) *MinerBuilder

func (*MinerBuilder) Overseer added in v0.3.0

func (b *MinerBuilder) Overseer(ovs Overseer) *MinerBuilder

func (*MinerBuilder) SSH added in v0.3.0

func (b *MinerBuilder) SSH(ssh SSH) *MinerBuilder

func (*MinerBuilder) UUID added in v0.3.0

func (b *MinerBuilder) UUID(uuid string) *MinerBuilder

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

	// 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, gpuCfg *gpu.Config) (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(miner *Miner) error
	Close()
}

func NewSSH added in v0.3.0

func NewSSH(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