hostman

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2016 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package hostman provides utilities for managing Lever instances and Lever resources running on the same node. It also provides a service so that the capabilities are accessible to other services as well.

Package hostman is a generated protocol buffer package.

It is generated from these files:

manager.proto

It has these top-level messages:

InstanceInfo
InitReply
InstanceKey
StopReply

Index

Constants

View Source
const ManagerService = "leverhostmanager"

ManagerService is the name of the host manager internal service.

View Source
const PackageName = "hostman"

PackageName is the name of this package.

Variables

View Source
var (
	// InstanceIDFlag is the instance ID of the manager. Note: This is
	// a different instance ID than leverutil.InstanceIDFlag because they
	// serve different things.
	InstanceIDFlag = config.DeclareString(
		PackageName, "managerInstanceID", leverutil.RandomID())

	// RegionalNetworkFlag is the name of the Docker network that the proxy
	// uses internally.
	RegionalNetworkFlag = config.DeclareString(
		PackageName, "regionalNetwork", "leveros_default")
)
View Source
var (
	// InstanceExpiryTimeFlag is the expiry time after its last use after which
	// a instance instance is evicted from the host.
	InstanceExpiryTimeFlag = config.DeclareDuration(
		PackageName, "instanceExpiryTime", 5*time.Minute)
)
View Source
var (
	// ResourceExpiryTimeFlag is the expiry time after its last use after which
	// a resource is evicted from the host.
	ResourceExpiryTimeFlag = config.DeclareDuration(
		PackageName, "resourceExpiryTime", 3*time.Minute)
)

Functions

func InitializeInstance

func InitializeInstance(
	grpcPool *scale.GRPCPool, info *InstanceInfo, node string) error

InitializeInstance initializes the infrastructure necessary for instance to start serving.

func RegisterManagerServer

func RegisterManagerServer(s *grpc.Server, srv ManagerServer)

func StopInstance

func StopInstance(
	grpcPool *scale.GRPCPool, key *InstanceKey, node string) error

StopInstance stops a given Lever instance.

Types

type InitReply

type InitReply struct {
}

func (*InitReply) Descriptor

func (*InitReply) Descriptor() ([]byte, []int)

func (*InitReply) ProtoMessage

func (*InitReply) ProtoMessage()

func (*InitReply) Reset

func (m *InitReply) Reset()

func (*InitReply) String

func (m *InitReply) String() string

type InstanceInfo

type InstanceInfo struct {
	Environment       string `protobuf:"bytes,1,opt,name=environment" json:"environment,omitempty"`
	Service           string `protobuf:"bytes,2,opt,name=service" json:"service,omitempty"`
	InstanceID        string `protobuf:"bytes,3,opt,name=instanceID" json:"instanceID,omitempty"`
	ContainerID       string `protobuf:"bytes,4,opt,name=containerID" json:"containerID,omitempty"`
	ServingID         string `protobuf:"bytes,5,opt,name=servingID" json:"servingID,omitempty"`
	LevInstResourceID string `protobuf:"bytes,6,opt,name=levInstResourceID" json:"levInstResourceID,omitempty"`
	LevInstSessionID  string `protobuf:"bytes,7,opt,name=levInstSessionID" json:"levInstSessionID,omitempty"`
}

func (*InstanceInfo) Descriptor

func (*InstanceInfo) Descriptor() ([]byte, []int)

func (*InstanceInfo) ProtoMessage

func (*InstanceInfo) ProtoMessage()

func (*InstanceInfo) Reset

func (m *InstanceInfo) Reset()

func (*InstanceInfo) String

func (m *InstanceInfo) String() string

type InstanceKey

type InstanceKey struct {
	Environment string `protobuf:"bytes,1,opt,name=environment" json:"environment,omitempty"`
	Service     string `protobuf:"bytes,2,opt,name=service" json:"service,omitempty"`
	InstanceID  string `protobuf:"bytes,3,opt,name=instanceID" json:"instanceID,omitempty"`
	ServingID   string `protobuf:"bytes,4,opt,name=servingID" json:"servingID,omitempty"`
}

func (*InstanceKey) Descriptor

func (*InstanceKey) Descriptor() ([]byte, []int)

func (*InstanceKey) ProtoMessage

func (*InstanceKey) ProtoMessage()

func (*InstanceKey) Reset

func (m *InstanceKey) Reset()

func (*InstanceKey) String

func (m *InstanceKey) String() string

type KeepAliveFun

type KeepAliveFun func(resourceName, levResResourceID, levResSessionID string)

KeepAliveFun is a function that should be called on every event on a stream to signal the manager that the unerlying infrastructure is still being used.

type LeverInstance

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

LeverInstance represents a Lever instance running on a Lever host. It takes care of monitoring the Docker container and the Consul lock associated with the instance and manages the instance's lifecycle. It also keeps track of the resources hosted on it and sends them keep alive's where appropriate.

func NewLeverInstance

func NewLeverInstance(
	info *InstanceInfo, instanceAddr string, proxyInAddr string,
	conns *scale.GRPCPool, docker *dockerapi.Client,
	onCloseFun OnCloseFun) *LeverInstance

NewLeverInstance returns a new instance of LeverInstance.

func (*LeverInstance) Close

func (instance *LeverInstance) Close(kill bool)

Close shuts down the instance.

func (*LeverInstance) InstanceAddr

func (instance *LeverInstance) InstanceAddr() string

InstanceAddr returns the IP + port the instance is accessible at for Lever RPCs.

func (*LeverInstance) KeepAlive

func (instance *LeverInstance) KeepAlive(
	leverResource, leverResResourceID, leverResSessionID string) error

KeepAlive resets the instance's TTL expiry along with any resource being accessed.

type LeverResource

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

LeverResource represents an instance of a Lever resource within a Lever service, that is hosted on a Lever instance. It takes care of monitoring the Consul lock associated with the resource and manages the resource's lifecycle.

func NewLeverResource

func NewLeverResource(
	leverEnv, leverService, instanceID, leverResource, levResResourceID,
	levResSessionID, instanceAddr string,
	conns *scale.GRPCPool, onCloseFun OnCloseFun) (*LeverResource, error)

NewLeverResource returns a new instance of LeverResource.

func (*LeverResource) Close

func (resource *LeverResource) Close()

Close closes down the resource.

func (*LeverResource) KeepAlive

func (resource *LeverResource) KeepAlive() error

KeepAlive resets the resource's TTL expiry.

func (*LeverResource) SoftClose

func (resource *LeverResource) SoftClose()

SoftClose closes down the resource but does not send RPC to container.

type Manager

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

Manager manages the instances and resources available on this host.

func NewManager

func NewManager(
	grpcServer *grpc.Server, grpcPool *scale.GRPCPool,
	docker *dockerapi.Client, grpcAddr string, proxyInAddr string) (
	manager *Manager, err error)

NewManager returns a new Manager.

func (*Manager) Close

func (manager *Manager) Close()

Close stops the manager.

func (*Manager) EnsureInfrastructureInitialized

func (manager *Manager) EnsureInfrastructureInitialized(
	info *InstanceInfo) (
	envNetworkIP string, ownIP string, instanceAddr string,
	keepAlive KeepAliveFun, err error)

EnsureInfrastructureInitialized verifies that all the necessary infrastructure is registered, managed and ready to be used.

func (*Manager) InitializeInstance

func (manager *Manager) InitializeInstance(
	ctx context.Context, info *InstanceInfo) (
	reply *InitReply, err error)

InitializeInstance implements the ManagerService interface.

func (*Manager) IsInstanceAlive

func (manager *Manager) IsInstanceAlive(
	servingID string, instanceID string) bool

IsInstanceAlive verifies whether an instance is still alive.

func (*Manager) RandomInstaceID

func (manager *Manager) RandomInstaceID(
	servingID string) (instanceID string, err error)

RandomInstaceID returns a random instanceID that serves provided servingID.

func (*Manager) StopInstance

func (manager *Manager) StopInstance(
	ctx context.Context, instanceKey *InstanceKey) (
	reply *StopReply, err error)

StopInstance implements the ManagerService interface.

type ManagerClient

type ManagerClient interface {
	InitializeInstance(ctx context.Context, in *InstanceInfo, opts ...grpc.CallOption) (*InitReply, error)
	StopInstance(ctx context.Context, in *InstanceKey, opts ...grpc.CallOption) (*StopReply, error)
}

func NewManagerClient

func NewManagerClient(cc *grpc.ClientConn) ManagerClient

type ManagerServer

type ManagerServer interface {
	InitializeInstance(context.Context, *InstanceInfo) (*InitReply, error)
	StopInstance(context.Context, *InstanceKey) (*StopReply, error)
}

type OnCloseFun

type OnCloseFun func(identifier string, err error)

OnCloseFun is a function that is called when an instance or a resource is closed.

type StopReply

type StopReply struct {
}

func (*StopReply) Descriptor

func (*StopReply) Descriptor() ([]byte, []int)

func (*StopReply) ProtoMessage

func (*StopReply) ProtoMessage()

func (*StopReply) Reset

func (m *StopReply) Reset()

func (*StopReply) String

func (m *StopReply) String() string

Jump to

Keyboard shortcuts

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