Documentation ¶
Overview ¶
Package state implements the agent state. This is a separate package to enforce access to a limited public API.
Index ¶
- Constants
- type Controller
- func (c *Controller) ActiveDUTs() []string
- func (c *Controller) AddDUT(dutID string)
- func (c *Controller) BlockDUTs()
- func (c *Controller) DrainAll()
- func (c *Controller) DrainDUT(dutID string)
- func (c *Controller) TerminateAll()
- func (c *Controller) TerminateDUT(dutID string)
- func (c *Controller) Wait()
- type ControllerHook
- type State
Constants ¶
const GraceInterval = 3 * time.Minute
GraceInterval is the amount of time to provide for bots to terminate gracefully.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller provides running bots for DUTs. Callers tell Controller what DUTs to add, drain, or terminate, and Controller makes sure there are bots running or not running for those DUTs.
func NewController ¶
func NewController(h ControllerHook) *Controller
NewController creates a new Controller.
func (*Controller) ActiveDUTs ¶
func (c *Controller) ActiveDUTs() []string
ActiveDUTs returns a slice of all DUTs the controller is keeping alive. This includes DUTs that are draining or terminated but not exited yet. This method is safe to call concurrently.
func (*Controller) AddDUT ¶
func (c *Controller) AddDUT(dutID string)
AddDUT adds a DUT to the Controller. The controller ensures that a Swarming bot is running for the DUT. If the DUT was already added or if the controller is blocked, do nothing. This method is concurrency safe.
func (*Controller) BlockDUTs ¶
func (c *Controller) BlockDUTs()
BlockDUTs marks the controller to not accept new DUTs. This method is safe to call concurrently.
func (*Controller) DrainAll ¶
func (c *Controller) DrainAll()
DrainAll drains all DUTs. You almost certainly want to call Block first to make sure DUTs don't get added right after calling this.
func (*Controller) DrainDUT ¶
func (c *Controller) DrainDUT(dutID string)
DrainDUT removes a DUT to no longer have bots running for it and drains its current bot. This method can be called repeatedly. If the controller does not have the DUT, just call ReleaseDUT on the controller's hook. This method is concurrency safe.
func (*Controller) TerminateAll ¶
func (c *Controller) TerminateAll()
TerminateAll terminates all DUTs. You almost certainly want to call Block first to make sure DUTs don't get added right after calling this.
func (*Controller) TerminateDUT ¶
func (c *Controller) TerminateDUT(dutID string)
TerminateDUT removes a DUT to no longer have bots running for it and terminates its current bot. This method can be called repeatedly. If the controller does not have the DUT, just call ReleaseDUT on the controller's hook. This method is concurrency safe.
func (*Controller) Wait ¶
func (c *Controller) Wait()
Wait for all Swarming bots to finish. It is the caller's responsibility to make sure all bots are terminated or drained, else this call will hang.
type ControllerHook ¶
type ControllerHook interface { // StartBot starts a bot process for the DUT. // This method should be safe to call concurrently. StartBot(dutID string) (bot.Bot, error) // ReleaseDUT is called to release the DUT for a bot process // that has finished. This method should be idempotent. ReleaseDUT(dutID string) }
ControllerHook defines the interface that a Controller uses to interact with the external world.
type State ¶
type State struct { *Controller // contains filtered or unexported fields }
State contains the agent state for the lifetime of one drone UUID assignment.
func New ¶
func New(uuid string, h ControllerHook) *State
New creates a new instance of agent state.
func (*State) SetExpiration ¶
SetExpiration sets a new expiration time. Note that if the expiration already fired, this does nothing.