servicestatemanager

package
v0.0.0-...-1c5d739 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadTenantID occurs when the tenant ID is not contained in the service state manager
	ErrBadTenantID = errors.New("Unrecognized tenant ID")
	// ErrDuplicateTenantID occurs when the tenant ID is already contained in the service state manager
	ErrDuplicateTenantID = errors.New("A tenant with this ID already exists")
	// ErrBatchQueueEmpty occurs when the tenant's queue is empty
	ErrBatchQueueEmpty = errors.New("Tenant service state queue is empty")
	// ErrMismatchedDesiredStates occurs when to batches try to merge with different desired states
	ErrMismatchedDesiredStates = errors.New("Can't merge batches with different desired states")
	// ErrMissingQueue occurs when queue doesn't exist for the tenant with the desired state of a batch
	ErrMissingQueue = errors.New("No queue found for tenant ID and desired state")
	// ErrWaitTimeout occurs when we timeout waiting for a batch of services to reach the desired state
	ErrWaitTimeout = errors.New("Timeout waiting for services")
	// ErrNotRunning occurs when you try to perform an operation on a service state manager that is not running
	ErrNotRunning = errors.New("Service state manager is not running")
	// ErrAlreadyStarted occurs when you try to start a service state manager that has already been started
	ErrAlreadyStarted = errors.New("Service state manager has already been started")
)

Functions

This section is empty.

Types

type BatchServiceStateManager

type BatchServiceStateManager struct {
	Facade Facade

	ServiceRunLevelTimeout time.Duration
	TenantQueues           map[string]map[service.DesiredState]*ServiceStateQueue
	TenantShutDowns        map[string]chan<- int
	// contains filtered or unexported fields
}

BatchServiceStateManager schedules batches of services to start/stop/restart according to

StartLevel

func NewBatchServiceStateManager

func NewBatchServiceStateManager(facade Facade, ctx datastore.Context, runLevelTimeout time.Duration) *BatchServiceStateManager

NewBatchServiceStateManager creates a new, initialized ServiceStateManager

func (*BatchServiceStateManager) AddTenant

func (s *BatchServiceStateManager) AddTenant(tenantID string) error

AddTenant adds a queue for a tenant and starts the processing loop for it

func (*BatchServiceStateManager) RemoveTenant

func (s *BatchServiceStateManager) RemoveTenant(tenantID string) error

RemoveTenant cancels the pending batches in queue for the tenant and deletes it from the service state manager

func (*BatchServiceStateManager) ScheduleServices

func (s *BatchServiceStateManager) ScheduleServices(svcs []*service.Service, tenantID string, desiredState service.DesiredState, emergency bool) error

ScheduleServices merges and reconciles a slice of services with the ServiceStateChangeBatches in the ServiceStateManager's queue

func (*BatchServiceStateManager) Shutdown

func (s *BatchServiceStateManager) Shutdown()

Shutdown properly cancels pending services in queueLoop

func (*BatchServiceStateManager) Start

func (s *BatchServiceStateManager) Start() error

Start gets tenants from the facade and adds them to the service state manager

func (*BatchServiceStateManager) SyncCurrentStates

func (s *BatchServiceStateManager) SyncCurrentStates(svcIDs []string)

func (*BatchServiceStateManager) Wait

func (s *BatchServiceStateManager) Wait(tenantID string)

Wait blocks until the queues are empty for tenantID

func (*BatchServiceStateManager) WaitScheduled

func (s *BatchServiceStateManager) WaitScheduled(tenantID string, serviceIDs ...string)

WaitScheduled blocks until every service has been scheduled or moved/removed from the queue

type ByEmergencyShutdown

type ByEmergencyShutdown struct{ CancellableServices }

func (ByEmergencyShutdown) Less

func (s ByEmergencyShutdown) Less(i, j int) bool

Sort by EmergencyShutdownLevel - 1, to ensure level of 0 is last

type ByReverseStartLevel

type ByReverseStartLevel struct{ CancellableServices }

func (ByReverseStartLevel) Less

func (s ByReverseStartLevel) Less(i, j int) bool

type ByStartLevel

type ByStartLevel struct{ CancellableServices }

func (ByStartLevel) Less

func (s ByStartLevel) Less(i, j int) bool

type CancellableService

type CancellableService struct {
	*service.Service

	C <-chan interface{}
	// contains filtered or unexported fields
}

CancellableService is a service whose scheduling may be canceled by a channel

func NewCancellableService

func NewCancellableService(svc *service.Service) *CancellableService

func (*CancellableService) Cancel

func (s *CancellableService) Cancel()

type CancellableServices

type CancellableServices []*CancellableService

Types for sorting

func (CancellableServices) Len

func (s CancellableServices) Len() int

func (CancellableServices) Swap

func (s CancellableServices) Swap(i, j int)

type CurrentStateWait

type CurrentStateWait struct {
	WaitingState service.DesiredState
	Done         <-chan struct{}
	// contains filtered or unexported fields
}

func (*CurrentStateWait) Cancel

func (w *CurrentStateWait) Cancel()

type Facade

type Facade interface {
	// WaitSingleService blocks until the service has reached the desired state, or the channel is closed
	WaitSingleService(*service.Service, service.DesiredState, <-chan interface{}) error
	// ScheduleServiceBatch changes the desired state of a set of services, and returns a list of IDs of services that could not be scheduled
	ScheduleServiceBatch(datastore.Context, []*CancellableService, string, service.DesiredState) ([]string, error)
	// UpdateService modifies a service
	UpdateService(ctx datastore.Context, svc service.Service) error
	// GetTenantIDs gets a list of all tenant IDs
	GetTenantIDs(ctx datastore.Context) ([]string, error)
	// GetServiceLite looks up the latest service object with all of the information necessary to schedule it
	GetServicesForScheduling(ctx datastore.Context, ids []string) []*service.Service
	// SetServicesCurrentState updates the service's current state in the service store
	SetServicesCurrentState(ctx datastore.Context, currentState service.ServiceCurrentState, serviceIDs ...string)
}

Facade provides access to functions for scheduling

type ServiceStateChangeBatch

type ServiceStateChangeBatch struct {
	Services     map[string]*CancellableService
	DesiredState service.DesiredState
	Emergency    bool
}

ServiceStateChangeBatch represents a batch of services with the same desired state that will be operated on by a ServiceStateManager

func MergeBatches

func MergeBatches(batches []ServiceStateChangeBatch) ([]ServiceStateChangeBatch, error)

MergeBatches sorts the services is batches by StartLevel, desiredState, and emergency, creates a new batch from the services and returns is

func (ServiceStateChangeBatch) Cancel

func (b ServiceStateChangeBatch) Cancel()

func (ServiceStateChangeBatch) String

func (b ServiceStateChangeBatch) String() string

type ServiceStateManager

type ServiceStateManager interface {
	// ScheduleServices schedules a set of services to change their desired state
	ScheduleServices(svcs []*service.Service, tenantID string, desiredState service.DesiredState, emergency bool) error
	// AddTenant prepares the service state manager to receive requests for a new tenant
	AddTenant(tenantID string) error
	// RemoveTenant notifies the service state manager that a tenant no longer exists
	RemoveTenant(tenantID string) error
	// WaitScheduled blocks until all requested services have been scheduled or cancelled
	WaitScheduled(tenantID string, serviceIDs ...string)
	// Wait blocks until all processing for the current tenant has completed
	Wait(tenantID string)
	// SyncCurrentStates will try to determine the current state of services and update the service store
	SyncCurrentStates(svcIDs []string)
}

ServiceStateManager provides a way to organize and manage services before scheduling them

type ServiceStateQueue

type ServiceStateQueue struct {
	BatchQueue   []ServiceStateChangeBatch
	CurrentBatch ServiceStateChangeBatch
	Changed      chan bool
	Facade       Facade
	// contains filtered or unexported fields
}

ServiceStateQueue is a queue with a queueLoop processing it's batches

func NewServiceStateQueue

func NewServiceStateQueue(facade Facade) *ServiceStateQueue

func (*ServiceStateQueue) Cancel

func (q *ServiceStateQueue) Cancel()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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