autoscaler

package
v0.0.0-...-b95a7b5 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: BSD-3-Clause Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TestInstances = []string{"ct-gce-001", "ct-gce-002"}
)

Functions

func GetInstanceRange

func GetInstanceRange(min, max int, getInstance func(int) (*gce.Instance, error)) ([]*gce.Instance, error)

Helper function for creating lists of instances. The given range is inclusive.

func GetInstanceSet

func GetInstanceSet(intSet string, getInstance func(int) *gce.Instance) ([]*gce.Instance, error)

Helper function for creating lists of instances.

Types

type Autoscaler

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

Autoscaler is a struct used for autoscaling instances in GCE.

func NewAutoscaler

func NewAutoscaler(projectId, zone string, ts oauth2.TokenSource, instances []*gce.Instance) (*Autoscaler, error)

NewAutoscaler returns an Autoscaler instance which manages the given GCE instances. Automatically calls Update().

func (*Autoscaler) GetInstanceStatuses

func (a *Autoscaler) GetInstanceStatuses() map[string]bool

See documentation for IAutoscaler.

func (*Autoscaler) GetNamesOfManagedInstances

func (a *Autoscaler) GetNamesOfManagedInstances() []string

See documentation for IAutoscaler.

func (*Autoscaler) GetOnlineInstances

func (a *Autoscaler) GetOnlineInstances() []string

See documentation for IAutoscaler.

func (*Autoscaler) Start

func (a *Autoscaler) Start(instanceNames []string) error

See documentation for IAutoscaler.

func (*Autoscaler) StartAllInstances

func (a *Autoscaler) StartAllInstances() error

See documentation for IAutoscaler.

func (*Autoscaler) Stop

func (a *Autoscaler) Stop(instanceNames []string) error

See documentation for IAutoscaler.

func (*Autoscaler) StopAllInstances

func (a *Autoscaler) StopAllInstances() error

See documentation for IAutoscaler.

func (*Autoscaler) Update

func (a *Autoscaler) Update() error

See documentation for IAutoscaler.

type IAutoscaler

type IAutoscaler interface {
	// GetInstanceStatuses returns a map of instance names to booleans
	// indicating whether each instance is online as of the last Update().
	GetInstanceStatuses() map[string]bool

	// GetNamesOfManagedInstances returns names of all instances managed by
	// this autoscaler.
	GetNamesOfManagedInstances() []string

	// GetOnlineInstances returns a slice of all online instance names as of
	// the last Update().
	GetOnlineInstances() []string

	// Start the given instances.
	// Note: This method returns when all instances are in RUNNING state.
	// Does not check to see if they are ready (ssh-able).
	Start([]string) error

	// StartAllInstances starts all instances.
	// Note: This method returns when all instances are in RUNNING state.
	// Does not check to see if they are ready (ssh-able).
	StartAllInstances() error

	// Stop the given instances.
	Stop([]string) error

	// StopAllInstances stops all instances.
	StopAllInstances() error

	// Update determines which instances are online and caches that
	// information.
	Update() error
}

Interface useful for mocking. TODO(borenet): This doesn't really "auto" scale anything.

type MockAutoscaler

type MockAutoscaler struct {
	StopAllInstancesTimesCalled  int
	StartAllInstancesTimesCalled int
}

func (*MockAutoscaler) GetInstanceStatuses

func (m *MockAutoscaler) GetInstanceStatuses() map[string]bool

func (*MockAutoscaler) GetNamesOfManagedInstances

func (m *MockAutoscaler) GetNamesOfManagedInstances() []string

func (*MockAutoscaler) GetOnlineInstances

func (m *MockAutoscaler) GetOnlineInstances() []string

func (*MockAutoscaler) Start

func (m *MockAutoscaler) Start([]string) error

func (*MockAutoscaler) StartAllInstances

func (m *MockAutoscaler) StartAllInstances() error

func (*MockAutoscaler) Stop

func (m *MockAutoscaler) Stop([]string) error

func (*MockAutoscaler) StopAllInstances

func (m *MockAutoscaler) StopAllInstances() error

func (*MockAutoscaler) Update

func (m *MockAutoscaler) Update() error

Jump to

Keyboard shortcuts

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