state

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2020 License: MPL-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package state manages the state that the singleprocess server has, providing operations to mutate that state safely as needed.

Index

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

func (*IndexTime) FromArgs

func (idx *IndexTime) FromArgs(args ...interface{}) ([]byte, error)

func (*IndexTime) FromObject

func (idx *IndexTime) FromObject(obj interface{}) (bool, []byte, error)

type Instance

type Instance struct {
	Id           string
	DeploymentId string
	Project      string
	Application  string
	Workspace    string
	LogBuffer    *logbuffer.Buffer
}

func (*Instance) Proto

func (i *Instance) Proto() *pb.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 New

func New(log hclog.Logger, db *bolt.DB) (*State, error)

New initializes a new State store.

func TestState

func TestState(t testing.T) *State

TestState returns an initialized State for testing.

func TestStateReinit

func TestStateReinit(t testing.T, s *State) *State

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) BuildGet

func (s *State) BuildGet(ref *pb.Ref_Operation) (*pb.Build, error)

BuildGet gets a build by ref.

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) BuildPut

func (s *State) BuildPut(update bool, b *pb.Build) error

BuildPut inserts or updates a build record.

func (*State) Close

func (s *State) Close() error

Close should be called to gracefully close any resources.

func (*State) ConfigGet

func (s *State) ConfigGet(req *pb.ConfigGetRequest) ([]*pb.ConfigVar, error)

ConfigGet gets all the configuration for the given request.

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) ConfigSet

func (s *State) ConfigSet(vs ...*pb.ConfigVar) error

ConfigSet writes a configuration variable to the data store.

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

func (s *State) HMACKeyCreateIfNotExist(id string, size int) (*pb.HMACKey, error)

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

func (s *State) HMACKeyEmpty() bool

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

func (s *State) HMACKeyGet(id string) (*pb.HMACKey, error)

HMACKeyGet gets an HMAC key by ID. This will return a nil value if it doesn't exist.

func (*State) InstanceById

func (s *State) InstanceById(id string) (*Instance, error)

func (*State) InstanceCreate

func (s *State) InstanceCreate(rec *Instance) error

func (*State) InstanceDelete

func (s *State) InstanceDelete(id string) error

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 (s *State) InstanceExecDelete(id int64) error

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 (s *State) InstancesByDeployment(id string, ws memdb.WatchSet) ([]*Instance, error)

func (*State) JobAck

func (s *State) JobAck(id string, ack bool) (*Job, error)

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

func (s *State) JobAssignForRunner(ctx context.Context, r *pb.Runner) (*Job, error)

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

func (s *State) JobById(id string, ws memdb.WatchSet) (*Job, error)

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

func (s *State) JobCancel(id string, force bool) error

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

func (s *State) JobComplete(id string, result *pb.Job_Result, cerr error) error

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) JobCreate

func (s *State) JobCreate(jobpb *pb.Job) error

JobCreate queues the given job.

func (*State) JobExpire

func (s *State) JobExpire(id string) error

JobExpire expires a job. This will cancel the job if it is still queued.

func (*State) JobHeartbeat

func (s *State) JobHeartbeat(id string) error

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

func (s *State) JobIsAssignable(ctx context.Context, jobpb *pb.Job) (bool, error)

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) JobList

func (s *State) JobList() ([]*pb.Job, error)

JobList returns the list of jobs.

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

func (s *State) ProjectGet(ref *pb.Ref_Project) (*pb.Project, error)

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

func (s *State) ProjectPut(p *pb.Project) error

ProjectPut creates or updates the given project.

func (*State) ReleaseGet

func (s *State) ReleaseGet(ref *pb.Ref_Operation) (*pb.Release, error)

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

func (s *State) ReleasePut(update bool, b *pb.Release) error

ReleasePut inserts or updates a release record.

func (*State) RunnerById

func (s *State) RunnerById(id string) (*pb.Runner, error)

func (*State) RunnerCreate

func (s *State) RunnerCreate(r *pb.Runner) error

func (*State) RunnerDelete

func (s *State) RunnerDelete(id string) error

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

func (s *State) ServerIdGet() (string, error)

ServerIdGet gets the server ID.

func (*State) ServerIdSet

func (s *State) ServerIdSet(id string) error

ServerIdSet writes the server ID.

func (*State) WorkspaceGet

func (s *State) WorkspaceGet(n string) (*pb.Workspace, error)

WorkspaceGet gets a workspace with a specific name. If it doesn't exist, this will return an error with codes.NotFound.

func (*State) WorkspaceList

func (s *State) WorkspaceList() ([]*pb.Workspace, error)

WorkspaceList lists all the workspaces.

Jump to

Keyboard shortcuts

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