hub

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: 53 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMinerNotFound = status.Errorf(codes.NotFound, "miner not found")
)

Functions

This section is empty.

Types

type ACLStorage added in v0.3.0

type ACLStorage interface {
	// Insert inserts the given worker credentials to the storage.
	Insert(credentials string)
	// Remove removes the given worker credentials from the storage.
	// Returns true if it was actually removed.
	Remove(credentials string) bool
	// Has checks whether the given worker credentials contains in the
	// storage.
	Has(credentials string) bool
	// Each applies the specified function to each credentials in the storage.
	// Traversal will continue until all items in the Set have been visited,
	// or if the closure returns false.
	Each(fn func(string) bool)
}

ACLStorage describes an ACL storage for workers.

A worker connection can be accepted only and the only if its credentials provided with the certificate contains in this storage.

func NewACLStorage added in v0.3.0

func NewACLStorage() ACLStorage

type AllocationStatus added in v0.3.0

type AllocationStatus int
const (
	FREE AllocationStatus = iota
	RESERVED
	ALLOCATED
)

type Cluster added in v0.3.0

type Cluster interface {
	// Starts synchronization process. Can be called multiple times after error is received in EventChannel
	Run() error

	Close()

	// IsLeader returns true if this cluster is a leader, i.e. we rule the
	// synchronization process.
	IsLeader() bool

	LeaderClient() (pb.HubClient, error)

	RegisterAndLoadEntity(name string, prototype interface{}) error

	Synchronize(entity interface{}) error

	// Fetch current cluster members
	Members() ([]NewMemberEvent, error)
}

func NewCluster added in v0.3.0

Returns a cluster writer interface if this node is a master, event channel otherwise. Should be recalled when a cluster's master/slave state changes. The channel is closed when the specified context is canceled.

type ClusterConfig added in v0.3.0

type ClusterConfig struct {
	Store                        StoreConfig `yaml:"store"`
	Failover                     bool        `yaml:"failover"`
	Endpoint                     string      `yaml:"endpoint"`
	AnnounceEndpoint             string      `yaml:"announce_endpoint"`
	LeaderKey                    string      `yaml:"leader_key" default:"sonm/hub/leader"`
	MemberListKey                string      `yaml:"member_list_key" default:"sonm/hub/list"`
	SynchronizableEntitiesPrefix string      `yaml:"sync_prefix" default:"sonm/hub/sync"`
	LeaderTTL                    uint64      `yaml:"leader_ttl" default:"20"`
	AnnouncePeriod               uint64      `yaml:"announce_period" default:"10"`
	AnnounceTTL                  uint64      `yaml:"announce_ttl" default:"20"`
	MemberGCPeriod               uint64      `yaml:"member_gc_period" default:"60"`
}

type ClusterEvent added in v0.3.0

type ClusterEvent interface{}

type Config added in v0.3.0

type Config struct {
	Endpoint      string             `required:"true" yaml:"endpoint"`
	GatewayConfig *GatewayConfig     `yaml:"gateway"`
	Logging       LoggingConfig      `yaml:"logging"`
	Eth           accounts.EthConfig `yaml:"ethereum"`
	Locator       LocatorConfig      `yaml:"locator"`
	Market        MarketConfig       `yaml:"market"`
	Cluster       ClusterConfig      `yaml:"cluster"`
	Whitelist     WhitelistConfig    `yaml:"whitelist"`
}

func NewConfig

func NewConfig(path string) (*Config, error)

NewConfig loads a hub config from the specified YAML file.

func (*Config) EndpointIP added in v0.3.0

func (c *Config) EndpointIP() string

type DealID added in v0.3.0

type DealID string

func (DealID) String added in v0.3.0

func (id DealID) String() string

type DealMeta added in v0.3.0

type DealMeta struct {
	ID      DealID
	BidID   string
	MinerID string
	Order   structs.Order
	Usage   *resource.Resources
	Tasks   []*TaskInfo
	// contains filtered or unexported fields
}

type DealMetaData added in v0.3.0

type DealMetaData interface {
	// Deal extracts deal ID from the request.
	Deal(ctx context.Context, request interface{}) (DealID, error)
	// Wallet extracts self-signed wallet from the request.
	Wallet(ctx context.Context, request interface{}) (string, error)
}

DealMetaData allows to extract deal-specific parameters for authorization. We implement this interface for all methods that require wallet authorization.

type DeviceProperties added in v0.3.0

type DeviceProperties map[string]float64

type ETH added in v0.3.0

type ETH interface {
	// VerifyBuyerBalance verifies that the buyer specified under the given
	// order has enough balance to have a deal.
	VerifyBuyerBalance(bidOrder *structs.Order) error
	// VerifyBuyerAllowance verifies that the buyer specified under the given
	// order has enough allowance to have a deal.
	VerifyBuyerAllowance(bidOrder *structs.Order) error
	// GetAcceptedDeals returns all currently accepted deals.
	GetAcceptedDeals(ctx context.Context) ([]*pb.Deal, error)
	// GetClosedDeals returns all currently closed deals.
	// Warning: use with caution: this may return significantly large amount
	// of data.
	GetClosedDeals(ctx context.Context) ([]*pb.Deal, error)
	// WaitForDealCreated waits for deal created on Buyer-side
	WaitForDealCreated(request *structs.DealRequest, buyerID string) (*pb.Deal, error)
	// WaitForDealClosed blocks the current execution context until the
	// specified deal is closed.
	WaitForDealClosed(ctx context.Context, dealID DealID, buyerID string) error
	// AcceptDeal approves deal on Hub-side.
	AcceptDeal(id string) error
	// CloseDeal closes the specified deal on Hub-side.
	CloseDeal(id DealID) error
	// GetDeal checks whether a given deal exists.
	GetDeal(id string) (*pb.Deal, error)
}

func NewETH added in v0.3.0

func NewETH(ctx context.Context, key *ecdsa.PrivateKey, bcr blockchain.Blockchainer, timeout time.Duration) (ETH, error)

NewETH constructs a new Ethereum client.

type EventAuthorization added in v0.3.0

type EventAuthorization interface {
	Authorize(ctx context.Context, request interface{}) error
}

type GatewayConfig added in v0.3.0

type GatewayConfig struct {
	Ports []uint16 `required:"true" yaml:"ports"`
}

type Hub

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

Hub collects miners, send them orders to spawn containers, etc.

func New

func New(ctx context.Context, cfg *Config, version string, opts ...Option) (*Hub, error)

New returns new Hub

func (*Hub) Close

func (h *Hub) Close()

Close disposes all resources attached to the Hub

func (*Hub) DeregisterWorker added in v0.3.0

func (h *Hub) DeregisterWorker(ctx context.Context, request *pb.ID) (*pb.Empty, error)

DeregisterWorkers deny Worker with given ID to connect to the Hub

func (*Hub) Devices added in v0.3.0

func (h *Hub) Devices(ctx context.Context, request *pb.Empty) (*pb.DevicesReply, error)

func (*Hub) DiscoverHub added in v0.3.0

func (h *Hub) DiscoverHub(ctx context.Context, request *pb.DiscoverHubRequest) (*pb.Empty, error)

func (*Hub) GetDealInfo added in v0.3.0

func (h *Hub) GetDealInfo(ctx context.Context, dealID *pb.ID) (*pb.DealInfoReply, error)

func (*Hub) GetDeviceProperties added in v0.3.0

func (h *Hub) GetDeviceProperties(ctx context.Context, request *pb.ID) (*pb.GetDevicePropertiesReply, error)

func (*Hub) GetRegisteredWorkers added in v0.3.0

func (h *Hub) GetRegisteredWorkers(ctx context.Context, empty *pb.Empty) (*pb.GetRegisteredWorkersReply, error)

GetRegisteredWorkers returns a list of Worker IDs that are allowed to connect to the Hub.

func (*Hub) Info

func (h *Hub) Info(ctx context.Context, request *pb.ID) (*pb.InfoReply, error)

Info returns aggregated runtime statistics for specified miners.

func (*Hub) InsertSlot added in v0.3.0

func (h *Hub) InsertSlot(ctx context.Context, request *pb.InsertSlotRequest) (*pb.ID, error)

func (*Hub) List

func (h *Hub) List(ctx context.Context, request *pb.Empty) (*pb.ListReply, error)

List returns attached miners

func (*Hub) MinerDevices added in v0.3.0

func (h *Hub) MinerDevices(ctx context.Context, request *pb.ID) (*pb.DevicesReply, error)

func (*Hub) MinerStatus

func (h *Hub) MinerStatus(ctx context.Context, request *pb.ID) (*pb.StatusMapReply, error)

func (*Hub) Ping

func (h *Hub) Ping(ctx context.Context, _ *pb.Empty) (*pb.PingReply, error)

Ping should be used as Healthcheck for Hub

func (*Hub) ProposeDeal added in v0.3.0

func (h *Hub) ProposeDeal(ctx context.Context, r *pb.DealRequest) (*pb.Empty, error)

func (*Hub) PullTask added in v0.3.0

func (h *Hub) PullTask(request *pb.PullTaskRequest, stream pb.Hub_PullTaskServer) error

func (*Hub) PushTask added in v0.3.0

func (h *Hub) PushTask(stream pb.Hub_PushTaskServer) error

func (*Hub) RegisterWorker added in v0.3.0

func (h *Hub) RegisterWorker(ctx context.Context, request *pb.ID) (*pb.Empty, error)

RegisterWorker allows Worker with given ID to connect to the Hub

func (*Hub) RemoveSlot added in v0.3.0

func (h *Hub) RemoveSlot(ctx context.Context, request *pb.ID) (*pb.Empty, error)

func (*Hub) Serve

func (h *Hub) Serve() error

Serve starts handling incoming API gRPC request and communicates with miners

func (*Hub) SetDeviceProperties added in v0.3.0

func (h *Hub) SetDeviceProperties(ctx context.Context, request *pb.SetDevicePropertiesRequest) (*pb.Empty, error)

func (*Hub) Slots added in v0.3.0

func (h *Hub) Slots(ctx context.Context, request *pb.Empty) (*pb.SlotsReply, error)

func (*Hub) StartTask

func (h *Hub) StartTask(ctx context.Context, request *pb.HubStartTaskRequest) (*pb.HubStartTaskReply, error)

func (*Hub) Status added in v0.3.0

func (h *Hub) Status(ctx context.Context, _ *pb.Empty) (*pb.HubStatusReply, error)

Status returns internal hub statistic

func (*Hub) StopTask

func (h *Hub) StopTask(ctx context.Context, request *pb.ID) (*pb.Empty, error)

StopTask sends termination request to a miner handling the task

func (*Hub) TaskList added in v0.3.0

func (h *Hub) TaskList(ctx context.Context, request *pb.Empty) (*pb.TaskListReply, error)

TODO: refactor - we can use h.tasks here

func (*Hub) TaskLogs added in v0.3.0

func (h *Hub) TaskLogs(request *pb.TaskLogsRequest, server pb.Hub_TaskLogsServer) error

func (*Hub) TaskStatus

func (h *Hub) TaskStatus(ctx context.Context, request *pb.ID) (*pb.TaskStatusReply, error)

type LeadershipEvent added in v0.3.0

type LeadershipEvent struct {
	Held            bool
	LeaderId        string
	LeaderEndpoints []string
}

Specific type of cluster event emited when leadership is transferred. It is not always loss or aquire of leadership of this specific node

type LocatorConfig added in v0.3.0

type LocatorConfig struct {
	Endpoint string `required:"true" yaml:"endpoint"`
	Period   int    `required:"true" default:"300" yaml:"period"`
}

type LoggingConfig added in v0.3.0

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

type Market added in v0.3.0

type Market interface {
	// OrderExists checks whether an order with the specified ID exists in the
	// marketplace.
	OrderExists(ID string) (bool, error)
	// CreateOrder creates order on marketplace
	CreateOrder(ord *pb.Order) (*pb.Order, error)
	// CancelOrder removes order from marketplace
	CancelOrder(ID string) error
}

func NewMarket added in v0.3.0

func NewMarket(ctx context.Context, addr string) (Market, error)

NewMarket constructs a new SONM marketplace client.

type MarketConfig added in v0.3.0

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

type MinerCtx

type MinerCtx struct {

	// gRPC Client
	Client pb.MinerClient
	// contains filtered or unexported fields
}

MinerCtx holds all the data related to a connected Miner

func (*MinerCtx) Close

func (m *MinerCtx) Close()

Close frees all connections related to a Miner

func (*MinerCtx) Consume added in v0.3.0

func (m *MinerCtx) Consume(Id OrderID, usage *resource.Resources) error

Consume consumes the specified resources from the miner.

func (*MinerCtx) ID added in v0.3.0

func (m *MinerCtx) ID() string

ID returns the miner id.

func (*MinerCtx) OrderUsage added in v0.3.0

func (m *MinerCtx) OrderUsage(id OrderID) (*resource.Resources, error)

func (*MinerCtx) Orders added in v0.3.0

func (m *MinerCtx) Orders() []OrderID

Orders returns a list of allocated orders. Useful for looking for a proper miner for starting tasks.

func (*MinerCtx) PollConsume added in v0.3.0

func (m *MinerCtx) PollConsume(usage *resource.Resources) error

func (*MinerCtx) Release added in v0.3.0

func (m *MinerCtx) Release(id OrderID)

Release returns back resources for the miner.

Should be called when a deal has finished no matter for what reason.

type NewMemberEvent added in v0.3.0

type NewMemberEvent struct {
	Id string
	// contains filtered or unexported fields
}

Specific type of cluster event emited when new member joins cluster

type Option added in v0.3.0

type Option func(options *options)

Option func is for applying any params to hub options

func WithBlockchain added in v0.3.0

func WithBlockchain(bcr blockchain.Blockchainer) Option

func WithCertRotator added in v0.3.0

func WithCertRotator(rot util.HitlessCertRotator) Option

func WithCluster added in v0.3.0

func WithCluster(cl Cluster, evt <-chan ClusterEvent) Option

func WithContext added in v0.3.0

func WithContext(ctx context.Context) Option

func WithCreds added in v0.3.0

func WithCreds(creds credentials.TransportCredentials) Option

func WithLocator added in v0.3.0

func WithLocator(loc pb.LocatorClient) Option

func WithMarket added in v0.3.0

func WithMarket(mp pb.MarketClient) Option

func WithPrivateKey added in v0.3.0

func WithPrivateKey(k *ecdsa.PrivateKey) Option

func WithVersion added in v0.3.0

func WithVersion(v string) Option

type OrderID added in v0.3.0

type OrderID string

func (OrderID) String added in v0.3.0

func (id OrderID) String() string

type Scheduler added in v0.3.0

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

func (*Scheduler) Add added in v0.3.0

func (s *Scheduler) Add(slot *structs.Slot) error

func (*Scheduler) All added in v0.3.0

func (s *Scheduler) All() []*structs.Slot

func (*Scheduler) Exists added in v0.3.0

func (s *Scheduler) Exists(slot *structs.Slot) bool

func (*Scheduler) Get added in v0.3.0

func (s *Scheduler) Get(slot *structs.Slot) *structs.Slot

func (*Scheduler) Reserve added in v0.3.0

func (s *Scheduler) Reserve(slot *structs.Slot) error

type StoreConfig added in v0.3.0

type StoreConfig struct {
	Type     string `required:"true" default:"boltdb" yaml:"type"`
	Endpoint string `required:"true" default:"/tmp/sonm/boltdb" yaml:"endpoint"`
	Bucket   string `required:"true" default:"sonm" yaml:"bucket"`
	KeyFile  string `yaml:"key_file"`
	CertFile string `yaml:"cert_file"`
}

type TaskInfo added in v0.3.0

type TaskInfo struct {
	structs.StartTaskRequest
	pb.MinerStartReply
	ID      string
	DealId  DealID
	MinerId string
	EndTime *time.Time
}

type Whitelist added in v0.3.0

type Whitelist interface {
	Allowed(ctx context.Context, registry string, image string, auth string) (bool, reference.Named, error)
}

func NewWhitelist added in v0.3.0

func NewWhitelist(ctx context.Context, config *WhitelistConfig) Whitelist

type WhitelistConfig added in v0.3.0

type WhitelistConfig struct {
	Url                 string   `yaml:"url"`
	Enabled             *bool    `yaml:"enabled" default:"true" required:"true"`
	PrivilegedAddresses []string `yaml:"privileged_addresses"`
	RefreshPeriod       uint     `yaml:"refresh_period" default:"60"`
}

type WhitelistRecord added in v0.3.0

type WhitelistRecord struct {
	AllowedHashes []string `json:"allowed_hashes"`
}

Jump to

Keyboard shortcuts

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