state

package
v1.8.4 Latest Latest
Warning

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

Go to latest
Published: May 29, 2019 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package state provides utilities to manage state

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcquireBuilding

func AcquireBuilding(servers []int, buildID string) error

AcquireBuilding acquires a build lock. Any function which modifies the nodes in a testnet should only do so after calling this function and ensuring that the returned value is nil

func ForceUnlockServers added in v1.8.1

func ForceUnlockServers(serverIDs []int)

ForceUnlockServers forcefully stops builds on the given servers to unlock the given servers

func SignalStop

func SignalStop(buildID string) error

SignalStop flags that the current build should be stopped, if there is a current build. Returns an error if there is no build in progress. Signal the build to stop by the build id.

func Stop

func Stop(serverID int) bool

Stop checks if the stop signal has been sent. If this returns true, a building process should return. The ssh client checks this for you. This is fairly naive and will need to be changed for multi-tenancy

Types

type BuildState

type BuildState struct {
	ExternExtras map[string]interface{} //will be exported
	Extras       map[string]interface{}

	Servers []int
	BuildID string

	BuildError CustomError
	BuildStage string

	DeployProgress uint64
	DeployTotal    uint64

	BuildProgress uint64
	BuildTotal    uint64

	SideCars        uint64 //The number of side cars
	SideCarProgress uint64
	SideCarTotal    uint64
	// contains filtered or unexported fields
}

BuildState packages the build state nicely into an object

func GetBuildStateByID added in v1.6.5

func GetBuildStateByID(buildID string) (*BuildState, error)

GetBuildStateByID gets the current build state based off the build id. Will given an error if the build is not found

func GetBuildStateByServerID added in v1.6.5

func GetBuildStateByServerID(serverID int) *BuildState

GetBuildStateByServerID gets the current build state on a server. DEPRECATED, use GetBuildStateByID instead.

func NewBuildState

func NewBuildState(servers []int, buildID string) *BuildState

NewBuildState creates a new build state for the given servers with the given buildID

func RestoreBuildState

func RestoreBuildState(buildID string) (*BuildState, error)

RestoreBuildState creates a BuildState from the previous BuildState with the same BuildID. If one does not exist, it returns an error.

func (*BuildState) AddFreezePoint

func (bs *BuildState) AddFreezePoint(freezePoint float64)

AddFreezePoint adds a point at which the build will freeze in the future

func (*BuildState) Async

func (bs *BuildState) Async(fn func())

Async Set a function to be executed at some point during the build. All these functions must complete before the build is considered finished.

func (*BuildState) Defer

func (bs *BuildState) Defer(fn func())

Defer adds a function to be executed asynchronously after the build is completed.

func (*BuildState) Destroy

func (bs *BuildState) Destroy() error

Destroy deletes all storage of the BuildState

func (*BuildState) Done

func (bs *BuildState) Done() bool

Done checks if the build is done

func (*BuildState) DoneBuilding

func (bs *BuildState) DoneBuilding()

DoneBuilding signals that the building process has finished and releases the build lock.

func (*BuildState) ErrorFree

func (bs *BuildState) ErrorFree() bool

ErrorFree checks that there has not been an error reported with ReportError

func (*BuildState) FinishDeploy

func (bs *BuildState) FinishDeploy()

FinishDeploy signals that the deployment process has finished and the blockchain specific process will begin.

func (*BuildState) FinishMainBuild added in v1.8.4

func (bs *BuildState) FinishMainBuild()

FinishMainBuild sets the main build as finished, and signals the start of the side car build

func (*BuildState) Freeze

func (bs *BuildState) Freeze() error

Freeze freezes the build

func (*BuildState) Get

func (bs *BuildState) Get(key string) (interface{}, bool)

Get fetches a value as interface from the given key

func (*BuildState) GetError

func (bs *BuildState) GetError() error

GetError gets the currently stored error

func (*BuildState) GetExt

func (bs *BuildState) GetExt(key string) (interface{}, bool)

GetExt gets a value based on the given key from the external state store

func (*BuildState) GetExtExtras

func (bs *BuildState) GetExtExtras() ([]byte, error)

GetExtExtras gets the entire external state store as JSON

func (*BuildState) GetExtras

func (bs *BuildState) GetExtras() map[string]interface{}

GetExtras returns the internal state store as a map[string]interface

func (*BuildState) GetP

func (bs *BuildState) GetP(key string, out interface{}) bool

GetP gets the value for key and puts it in the object that out is pointing to

func (*BuildState) GetProgress

func (bs *BuildState) GetProgress() float64

GetProgress gets the progress as a percentage, within the range 0.0% - 100.0%

func (*BuildState) IncrementBuildProgress

func (bs *BuildState) IncrementBuildProgress()

IncrementBuildProgress increments the build progress by one step.

func (*BuildState) IncrementDeployProgress

func (bs *BuildState) IncrementDeployProgress()

IncrementDeployProgress increments the deploy process by one step. This is thread safe.

func (*BuildState) IncrementSideCarProgress added in v1.8.4

func (bs *BuildState) IncrementSideCarProgress()

IncrementSideCarProgress increments the sidecar build progress by one step.

func (*BuildState) IsFrozen added in v1.7.1

func (bs *BuildState) IsFrozen() bool

IsFrozen check if the build is currently frozen

func (*BuildState) Marshal

func (bs *BuildState) Marshal() string

Marshal turns the BuildState into json representing the current progress of the build

func (*BuildState) OnError

func (bs *BuildState) OnError(fn func())

OnError adds a function to be executed upon a build finishing in the error state

func (*BuildState) ReportError

func (bs *BuildState) ReportError(err error)

ReportError stores the given error to be passed onto any who query the build status.

func (*BuildState) Reset

func (bs *BuildState) Reset()

Reset sets the build state back the beginning. Used for when additional nodes are being added, as the stores may want to be reused

func (*BuildState) Set

func (bs *BuildState) Set(key string, value interface{})

Set stores a key value pair

func (*BuildState) SetBuildStage

func (bs *BuildState) SetBuildStage(stage string)

SetBuildStage updates the text which will be displayed along with the build progress percentage when the status of the build is queried.

func (*BuildState) SetBuildSteps

func (bs *BuildState) SetBuildSteps(steps int)

SetBuildSteps sets the number of steps in the blockchain specific build process. Must be equivalent to the number of times IncrementBuildProgress() will be called.

func (*BuildState) SetDeploySteps

func (bs *BuildState) SetDeploySteps(steps int)

SetDeploySteps sets the number of steps in the deployment process. Should be given a number equivalent to the number of times IncrementDeployProgress will be called.

func (*BuildState) SetExt

func (bs *BuildState) SetExt(key string, value interface{})

SetExt inserts a key value pair into the external state store, currently only supports string and []string on the other side

func (*BuildState) SetSidecarSteps added in v1.8.4

func (bs *BuildState) SetSidecarSteps(steps int)

SetSidecarSteps sets the number of steps in the sidecar specific build process. Must be equivalent to the number of times IncrementBuildProgress() will be called.

func (*BuildState) SetSidecars added in v1.8.4

func (bs *BuildState) SetSidecars(sidecars int)

SetSidecars sets the number of sidecars

func (*BuildState) SignalStop

func (bs *BuildState) SignalStop() error

SignalStop flags that the current build should be stopped, if there is a current build. Returns an error if there is no build in progress

func (*BuildState) Stop

func (bs *BuildState) Stop() bool

Stop checks if the stop signal has been sent. If bs returns true, a building process should return. The ssh client checks bs for you.

func (*BuildState) Store

func (bs *BuildState) Store() error

Store saves the BuildState for later retrieval

func (*BuildState) Unfreeze

func (bs *BuildState) Unfreeze() error

Unfreeze unfreezes the build

func (*BuildState) Write

func (bs *BuildState) Write(file string, data string) error

Write writes data to a file, creating it if it doesn't exist, deleting and recreating it if it does, should be used instead of golangs internal io library as bs one provides automatic file cleanup and separation of files among different builds.

type CustomError

type CustomError struct {
	What string `json:"what"`
	// contains filtered or unexported fields
}

CustomError is a custom wrapper for a go error, which has What containing error.Error()

Jump to

Keyboard shortcuts

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