Documentation ¶
Overview ¶
Package state manages the state that the singleprocess server has, providing operations to mutate that state safely as needed.
Index ¶
- type IndexTime
- type Instance
- type InstanceExec
- type Job
- type ListOperationOption
- type State
- func (s *State) AppDelete(ref *pb.Ref_Application) error
- func (s *State) AppGet(ref *pb.Ref_Application) (*pb.Application, error)
- func (s *State) AppPut(app *pb.Application) (*pb.Application, error)
- func (s *State) ArtifactGet(ref *pb.Ref_Operation) (*pb.PushedArtifact, error)
- func (s *State) ArtifactLatest(ref *pb.Ref_Application, ws *pb.Ref_Workspace) (*pb.PushedArtifact, error)
- func (s *State) ArtifactList(ref *pb.Ref_Application, opts ...ListOperationOption) ([]*pb.PushedArtifact, error)
- func (s *State) ArtifactPut(update bool, b *pb.PushedArtifact) error
- func (s *State) BuildGet(ref *pb.Ref_Operation) (*pb.Build, error)
- func (s *State) BuildLatest(ref *pb.Ref_Application, ws *pb.Ref_Workspace) (*pb.Build, error)
- func (s *State) BuildList(ref *pb.Ref_Application, opts ...ListOperationOption) ([]*pb.Build, error)
- func (s *State) BuildPut(update bool, b *pb.Build) error
- func (s *State) Close() error
- func (s *State) ConfigGet(req *pb.ConfigGetRequest) ([]*pb.ConfigVar, error)
- func (s *State) ConfigGetWatch(req *pb.ConfigGetRequest, ws memdb.WatchSet) ([]*pb.ConfigVar, error)
- func (s *State) ConfigSet(vs ...*pb.ConfigVar) error
- func (s *State) DeploymentGet(ref *pb.Ref_Operation) (*pb.Deployment, error)
- func (s *State) DeploymentLatest(ref *pb.Ref_Application, ws *pb.Ref_Workspace) (*pb.Deployment, error)
- func (s *State) DeploymentList(ref *pb.Ref_Application, opts ...ListOperationOption) ([]*pb.Deployment, error)
- func (s *State) DeploymentPut(update bool, b *pb.Deployment) error
- func (s *State) HMACKeyCreateIfNotExist(id string, size int) (*pb.HMACKey, error)
- func (s *State) HMACKeyEmpty() bool
- func (s *State) HMACKeyGet(id string) (*pb.HMACKey, error)
- func (s *State) InstanceById(id string) (*Instance, error)
- func (s *State) InstanceCreate(rec *Instance) error
- func (s *State) InstanceDelete(id string) error
- func (s *State) InstanceExecById(id int64) (*InstanceExec, error)
- func (s *State) InstanceExecCreateByDeployment(did string, exec *InstanceExec) error
- func (s *State) InstanceExecDelete(id int64) error
- func (s *State) InstanceExecListByInstanceId(id string, ws memdb.WatchSet) ([]*InstanceExec, error)
- func (s *State) InstancesByApp(ref *pb.Ref_Application, refws *pb.Ref_Workspace, ws memdb.WatchSet) ([]*Instance, error)
- func (s *State) InstancesByDeployment(id string, ws memdb.WatchSet) ([]*Instance, error)
- func (s *State) JobAck(id string, ack bool) (*Job, error)
- func (s *State) JobAssignForRunner(ctx context.Context, r *pb.Runner) (*Job, error)
- func (s *State) JobById(id string, ws memdb.WatchSet) (*Job, error)
- func (s *State) JobCancel(id string, force bool) error
- func (s *State) JobComplete(id string, result *pb.Job_Result, cerr error) error
- func (s *State) JobCreate(jobpb *pb.Job) error
- func (s *State) JobExpire(id string) error
- func (s *State) JobHeartbeat(id string) error
- func (s *State) JobIsAssignable(ctx context.Context, jobpb *pb.Job) (bool, error)
- func (s *State) JobList() ([]*pb.Job, error)
- func (s *State) ProjectDelete(ref *pb.Ref_Project) error
- func (s *State) ProjectGet(ref *pb.Ref_Project) (*pb.Project, error)
- func (s *State) ProjectList() ([]*pb.Ref_Project, error)
- func (s *State) ProjectPut(p *pb.Project) error
- func (s *State) ReleaseGet(ref *pb.Ref_Operation) (*pb.Release, error)
- func (s *State) ReleaseLatest(ref *pb.Ref_Application, ws *pb.Ref_Workspace) (*pb.Release, error)
- func (s *State) ReleaseList(ref *pb.Ref_Application, opts ...ListOperationOption) ([]*pb.Release, error)
- func (s *State) ReleasePut(update bool, b *pb.Release) error
- func (s *State) RunnerById(id string) (*pb.Runner, error)
- func (s *State) RunnerCreate(r *pb.Runner) error
- func (s *State) RunnerDelete(id string) error
- func (s *State) ServerConfigGet() (*pb.ServerConfig, error)
- func (s *State) ServerConfigSet(c *pb.ServerConfig) error
- func (s *State) ServerIdGet() (string, error)
- func (s *State) ServerIdSet(id string) error
- func (s *State) WorkspaceGet(n string) (*pb.Workspace, error)
- func (s *State) WorkspaceList() ([]*pb.Workspace, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IndexTime ¶
type IndexTime struct { Field string // Asc if true will index with ascending order. Usually you want to // find the most recent data so this is false by default. Asc bool }
IndexTime indexes a time.Time field of a struct. TODO(mitchellh): test
type Instance ¶
type InstanceExec ¶
type InstanceExec struct { Id int64 InstanceId string Args []string Pty *pb.ExecStreamRequest_PTY ClientEventCh <-chan *pb.ExecStreamRequest EntrypointEventCh chan<- *pb.EntrypointExecRequest Connected uint32 }
type Job ¶
type Job struct { // Full job structure. *pb.Job // OutputBuffer is the terminal output for this job. This is a buffer // that may not contain the full amount of output depending on the // time of connection. OutputBuffer *logbuffer.Buffer // Blocked is true if this job is blocked on another job for the same // project/app/workspace. Blocked bool }
Job is the exported structure that is returned for most state APIs and gives callers access to more information than the pure job structure.
type ListOperationOption ¶
type ListOperationOption func(opts *listOperationsOptions)
ListOperationOption is an exported type to set configuration for listing operations.
func ListWithOrder ¶
func ListWithOrder(f *pb.OperationOrder) ListOperationOption
ListWithOrder sets ordering on the list operation.
func ListWithPhysicalState ¶
func ListWithPhysicalState(f pb.Operation_PhysicalState) ListOperationOption
ListWithPhysicalState sets ordering on the list operation.
func ListWithStatusFilter ¶
func ListWithStatusFilter(f ...*pb.StatusFilter) ListOperationOption
ListWithStatusFilter sets a status filter.
func ListWithWorkspace ¶
func ListWithWorkspace(f *pb.Ref_Workspace) ListOperationOption
ListWithWorkspace sets ordering on the list operation.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State is the primary API for state mutation for the server.
func TestState ¶
func TestState(t testing.T) *State
TestState returns an initialized State for testing.
func TestStateReinit ¶
TestStateReinit reinitializes the state by pretending to restart the server with the database associated with this state. This can be used to test index init logic.
This safely copies the entire DB so the old state can continue running with zero impact.
func (*State) AppDelete ¶
func (s *State) AppDelete(ref *pb.Ref_Application) error
AppDelete deletes an application from a project. This will also delete all the operations associated with this application.
func (*State) AppGet ¶
func (s *State) AppGet(ref *pb.Ref_Application) (*pb.Application, error)
AppGet retrieves the application..
func (*State) AppPut ¶
func (s *State) AppPut(app *pb.Application) (*pb.Application, error)
AppPut creates or updates the application.
func (*State) ArtifactGet ¶
func (s *State) ArtifactGet(ref *pb.Ref_Operation) (*pb.PushedArtifact, error)
ArtifactGet gets a artifact by ref.
func (*State) ArtifactLatest ¶
func (s *State) ArtifactLatest( ref *pb.Ref_Application, ws *pb.Ref_Workspace, ) (*pb.PushedArtifact, error)
ArtifactLatest gets the latest artifact that was completed successfully.
func (*State) ArtifactList ¶
func (s *State) ArtifactList( ref *pb.Ref_Application, opts ...ListOperationOption, ) ([]*pb.PushedArtifact, error)
func (*State) ArtifactPut ¶
func (s *State) ArtifactPut(update bool, b *pb.PushedArtifact) error
ArtifactPut inserts or updates a artifact record.
func (*State) BuildLatest ¶
func (s *State) BuildLatest( ref *pb.Ref_Application, ws *pb.Ref_Workspace, ) (*pb.Build, error)
BuildLatest gets the latest build that was completed successfully.
func (*State) BuildList ¶
func (s *State) BuildList( ref *pb.Ref_Application, opts ...ListOperationOption, ) ([]*pb.Build, error)
func (*State) ConfigGetWatch ¶
func (s *State) ConfigGetWatch(req *pb.ConfigGetRequest, ws memdb.WatchSet) ([]*pb.ConfigVar, error)
ConfigGetWatch gets all the configuration for the given request. If a non-nil WatchSet is given, this can be watched for potential changes in the config.
func (*State) DeploymentGet ¶
func (s *State) DeploymentGet(ref *pb.Ref_Operation) (*pb.Deployment, error)
DeploymentGet gets a deployment by ref.
func (*State) DeploymentLatest ¶
func (s *State) DeploymentLatest( ref *pb.Ref_Application, ws *pb.Ref_Workspace, ) (*pb.Deployment, error)
DeploymentLatest gets the latest deployment that was completed successfully.
func (*State) DeploymentList ¶
func (s *State) DeploymentList( ref *pb.Ref_Application, opts ...ListOperationOption, ) ([]*pb.Deployment, error)
func (*State) DeploymentPut ¶
func (s *State) DeploymentPut(update bool, b *pb.Deployment) error
DeploymentPut inserts or updates a deployment record.
func (*State) HMACKeyCreateIfNotExist ¶
HMACKeyCreateIfNotExist creates a new HMAC key with the given ID and size. If a key with the given ID exists already it will be returned.
func (*State) HMACKeyEmpty ¶
HMACKeyEmpty returns true if no HMAC keys have been created. This will be true only when the server is in a bootstrap state.
func (*State) HMACKeyGet ¶
HMACKeyGet gets an HMAC key by ID. This will return a nil value if it doesn't exist.
func (*State) InstanceCreate ¶
func (*State) InstanceDelete ¶
func (*State) InstanceExecById ¶
func (s *State) InstanceExecById(id int64) (*InstanceExec, error)
func (*State) InstanceExecCreateByDeployment ¶
func (s *State) InstanceExecCreateByDeployment(did string, exec *InstanceExec) error
func (*State) InstanceExecDelete ¶
func (*State) InstanceExecListByInstanceId ¶
func (s *State) InstanceExecListByInstanceId(id string, ws memdb.WatchSet) ([]*InstanceExec, error)
func (*State) InstancesByApp ¶
func (s *State) InstancesByApp( ref *pb.Ref_Application, refws *pb.Ref_Workspace, ws memdb.WatchSet, ) ([]*Instance, error)
func (*State) InstancesByDeployment ¶
func (*State) JobAck ¶
JobAck acknowledges that a job has been accepted or rejected by the runner. If ack is false, then this will move the job back to the queued state and be eligible for assignment.
func (*State) JobAssignForRunner ¶
JobAssignForRunner will wait for and assign a job to a specific runner. This will automatically evaluate any conditions that the runner and/or job may have on assignability.
The assigned job is put into a "waiting" state until the runner acks the assignment which can be set with JobAck.
If ctx is provided and assignment has to block waiting for new jobs, this will cancel when the context is done.
func (*State) JobById ¶
JobById looks up a job by ID. The returned Job will be a deep copy of the job so it is safe to read/write. If the job can't be found, a nil result with no error is returned.
func (*State) JobCancel ¶
JobCancel marks a job as cancelled. This will set the internal state and request the cancel but if the job is running then it is up to downstream to listen for and react to Job changes for cancellation.
func (*State) JobComplete ¶
JobComplete marks a running job as complete. If an error is given, the job is marked as failed (a completed state). If no error is given, the job is marked as successful.
func (*State) JobHeartbeat ¶
JobHeartbeat resets the heartbeat timer for a running job. If the job is not currently running this does nothing, it will not return an error. If the job doesn't exist then this will return an error.
func (*State) JobIsAssignable ¶
JobIsAssignable returns whether there is a registered runner that meets the requirements to run this job.
If this returns true, the job if queued should eventually be assigned successfully to a runner. An assignable result does NOT mean that it will be in queue a short amount of time.
Note the result is a point-in-time result. If the only candidate runners deregister between this returning true and queueing, the job may still sit in a queue indefinitely.
func (*State) ProjectDelete ¶
func (s *State) ProjectDelete(ref *pb.Ref_Project) error
ProjectDelete deletes a project by reference. This is a complete data delete. This will delete all operations associated with this project as well.
func (*State) ProjectGet ¶
ProjectGet gets a project by reference.
func (*State) ProjectList ¶
func (s *State) ProjectList() ([]*pb.Ref_Project, error)
ProjectList returns the list of projects.
func (*State) ProjectPut ¶
ProjectPut creates or updates the given project.
func (*State) ReleaseGet ¶
ReleaseGet gets a release by ref.
func (*State) ReleaseLatest ¶
func (s *State) ReleaseLatest( ref *pb.Ref_Application, ws *pb.Ref_Workspace, ) (*pb.Release, error)
ReleaseLatest gets the latest release that was completed successfully.
func (*State) ReleaseList ¶
func (s *State) ReleaseList( ref *pb.Ref_Application, opts ...ListOperationOption, ) ([]*pb.Release, error)
func (*State) ReleasePut ¶
ReleasePut inserts or updates a release record.
func (*State) RunnerDelete ¶
func (*State) ServerConfigGet ¶
func (s *State) ServerConfigGet() (*pb.ServerConfig, error)
ServerConfigGet gets the server configuration.
func (*State) ServerConfigSet ¶
func (s *State) ServerConfigSet(c *pb.ServerConfig) error
ServerConfigSet writes the server configuration.
func (*State) ServerIdGet ¶
ServerIdGet gets the server ID.
func (*State) ServerIdSet ¶
ServerIdSet writes the server ID.
func (*State) WorkspaceGet ¶
WorkspaceGet gets a workspace with a specific name. If it doesn't exist, this will return an error with codes.NotFound.