boltdbstate

package
v0.11.4 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: MPL-2.0 Imports: 53 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 InstanceLogs

type InstanceLogs struct {
	Id         int64
	InstanceId string

	LogBuffer *logbuffer.Buffer
}

InstanceLogs is a value that can be created to assist in coordination log writers and readers. It is a lighter weight version of an Instance used to manage virtual CEBs sending logs.

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 TestStateRestart

func TestStateRestart(t testing.T, s *State) (*State, error)

TestStateRestart closes the given state and restarts it against the same DB file.

func (*State) AppDelete

func (s *State) AppDelete(ctx context.Context, 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(ctx context.Context, ref *pb.Ref_Application) (*pb.Application, error)

AppGet retrieves the application..

func (*State) AppPut

func (s *State) AppPut(ctx context.Context, app *pb.Application) (*pb.Application, error)

AppPut creates or updates the application.

func (*State) ApplicationPollComplete

func (s *State) ApplicationPollComplete(
	ctx context.Context,
	project *pb.Project,
	t time.Time,
) error

ApplicationPollComplete sets the next poll time for a given project given the app reference along with the time interval "t".

func (*State) ApplicationPollPeek

func (s *State) ApplicationPollPeek(
	ctx context.Context,
	ws memdb.WatchSet,
) (*pb.Project, time.Time, error)

ApplicationPollPeek peeks at the next available project that will be polled against, and returns the project as the result along with the poll time. The poll queuer will queue a job against every defined application for the given project. For more information on how ProjectPollPeek works, refer to the ProjectPollPeek docs.

func (*State) ArtifactGet

func (s *State) ArtifactGet(ctx context.Context, ref *pb.Ref_Operation) (*pb.PushedArtifact, error)

ArtifactGet gets a artifact by ref.

func (*State) ArtifactLatest

func (s *State) ArtifactLatest(
	ctx context.Context,
	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(
	ctx context.Context,
	ref *pb.Ref_Application,
	opts ...serverstate.ListOperationOption,
) ([]*pb.PushedArtifact, error)

func (*State) ArtifactPut

func (s *State) ArtifactPut(ctx context.Context, update bool, b *pb.PushedArtifact) error

ArtifactPut inserts or updates a artifact record.

func (*State) AuthMethodDelete

func (s *State) AuthMethodDelete(ctx context.Context, ref *pb.Ref_AuthMethod) error

AuthMethodDelete deletes an auth method by reference.

func (*State) AuthMethodGet

func (s *State) AuthMethodGet(ctx context.Context, ref *pb.Ref_AuthMethod) (*pb.AuthMethod, error)

AuthMethodGet gets a auth method by reference.

func (*State) AuthMethodList

func (s *State) AuthMethodList(ctx context.Context) ([]*pb.AuthMethod, error)

AuthMethodList returns the list of projects.

func (*State) AuthMethodPut

func (s *State) AuthMethodPut(ctx context.Context, v *pb.AuthMethod) error

AuthMethodPut creates or updates the given auth method. .

func (*State) BuildGet

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

BuildGet gets a build by ref.

func (*State) BuildLatest

func (s *State) BuildLatest(
	ctx context.Context,
	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(
	ctx context.Context,
	ref *pb.Ref_Application,
	opts ...serverstate.ListOperationOption,
) ([]*pb.Build, error)

func (*State) BuildPut

func (s *State) BuildPut(ctx context.Context, 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) ConfigDelete added in v0.11.2

func (s *State) ConfigDelete(ctx context.Context, vs ...*pb.ConfigVar) error

ConfigDelete looks at each passed in ConfigVar and checks to see if it has been properly set for deletion either through ConfigVar_Unset or when its static value i.e. ConfigVar_Static is empty string. It then calls through to configSet to delete it.

func (*State) ConfigGet

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

ConfigGet gets all the configuration for the given request.

func (*State) ConfigGetWatch

func (s *State) ConfigGetWatch(ctx context.Context, 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(ctx context.Context, vs ...*pb.ConfigVar) error

ConfigSet writes a configuration variable to the data store. Deletes are always ordered before writes so that you can't delete a new value in a single ConfigSet (you should never want to do this).

func (*State) ConfigSourceDelete added in v0.11.2

func (s *State) ConfigSourceDelete(ctx context.Context, vs ...*pb.ConfigSource) error

ConfigSourceDelete deletes the config sourcer value from the db

func (*State) ConfigSourceGet

func (s *State) ConfigSourceGet(ctx context.Context, req *pb.GetConfigSourceRequest) ([]*pb.ConfigSource, error)

ConfigSourceGet gets all the configuration sources for the given request.

func (*State) ConfigSourceGetWatch

func (s *State) ConfigSourceGetWatch(ctx context.Context, req *pb.GetConfigSourceRequest, ws memdb.WatchSet) ([]*pb.ConfigSource, error)

ConfigSourceGetWatch gets all the configuration sources for the given request. If a non-nil WatchSet is given, this can be watched for potential changes in the config source settings.

func (*State) ConfigSourceSet

func (s *State) ConfigSourceSet(ctx context.Context, vs ...*pb.ConfigSource) error

ConfigSourceSet writes a set of config source values to the database.

func (*State) CreateSnapshot

func (s *State) CreateSnapshot(ctx context.Context, w io.Writer) error

CreateSnapshot creates a database snapshot and writes it to the given writer.

This will NOT buffer data to w, so you should wrap w in a bufio.Writer if you want buffering.

func (*State) DeploymentGet

func (s *State) DeploymentGet(ctx context.Context, ref *pb.Ref_Operation) (*pb.Deployment, error)

DeploymentGet gets a deployment by ref.

func (*State) DeploymentLatest

func (s *State) DeploymentLatest(
	ctx context.Context,
	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(
	ctx context.Context,
	ref *pb.Ref_Application,
	opts ...serverstate.ListOperationOption,
) ([]*pb.Deployment, error)

func (*State) DeploymentPut

func (s *State) DeploymentPut(ctx context.Context, update bool, b *pb.Deployment) error

DeploymentPut inserts or updates a deployment record.

func (*State) GetFileChangeSignal

func (s *State) GetFileChangeSignal(ctx context.Context, scope *pb.Ref_Application) (string, error)

GetFileChangeSignal checks the metadata for the given application and its project, returning the value of FileChangeSignal that is most relevent.

func (*State) HMACKeyCreateIfNotExist

func (s *State) HMACKeyCreateIfNotExist(ctx context.Context, 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(ctx context.Context) 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(ctx context.Context, 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(ctx context.Context, id string) (*serverstate.Instance, error)

func (*State) InstanceCreate

func (s *State) InstanceCreate(ctx context.Context, rec *serverstate.Instance) error

func (*State) InstanceDelete

func (s *State) InstanceDelete(ctx context.Context, id string) error

func (*State) InstanceExecById

func (s *State) InstanceExecById(ctx context.Context, id int64) (*serverstate.InstanceExec, error)

func (*State) InstanceExecConnect added in v0.9.0

func (s *State) InstanceExecConnect(ctx context.Context, id int64) (*serverstate.InstanceExec, error)

func (*State) InstanceExecCreateByDeployment

func (s *State) InstanceExecCreateByDeployment(ctx context.Context, did string, exec *serverstate.InstanceExec) error

func (*State) InstanceExecCreateByTargetedInstance

func (s *State) InstanceExecCreateByTargetedInstance(ctx context.Context, id string, exec *serverstate.InstanceExec) error

func (*State) InstanceExecCreateForVirtualInstance

func (s *State) InstanceExecCreateForVirtualInstance(ctx context.Context, id string, exec *serverstate.InstanceExec) error

InstanceExecCreateForVirtualInstance registers the given InstanceExec record on the instance specified. The instance does not yet have to be known (as it may not yet have connected to the server) so this code will use memdb watchers to detect the instance as it connects and then register the exec.

func (*State) InstanceExecDelete

func (s *State) InstanceExecDelete(ctx context.Context, id int64) error

func (*State) InstanceExecListByInstanceId

func (s *State) InstanceExecListByInstanceId(ctx context.Context, id string, ws memdb.WatchSet) ([]*serverstate.InstanceExec, error)

func (*State) InstanceExecWaitConnected added in v0.9.0

func (s *State) InstanceExecWaitConnected(ctx context.Context, exec *serverstate.InstanceExec) error

func (*State) InstanceLogsById

func (s *State) InstanceLogsById(ctx context.Context, id int64) (*InstanceLogs, error)

func (*State) InstanceLogsByInstanceId

func (s *State) InstanceLogsByInstanceId(ctx context.Context, id string) (*InstanceLogs, error)

func (*State) InstanceLogsCreate

func (s *State) InstanceLogsCreate(ctx context.Context, id string, logs *InstanceLogs) error

func (*State) InstanceLogsDelete

func (s *State) InstanceLogsDelete(ctx context.Context, id int64) error

func (*State) InstanceLogsListByInstanceId

func (s *State) InstanceLogsListByInstanceId(ctx context.Context, id string, ws memdb.WatchSet) ([]*InstanceLogs, error)

func (*State) InstancesByApp

func (s *State) InstancesByApp(
	ctx context.Context,
	ref *pb.Ref_Application,
	refws *pb.Ref_Workspace,
	ws memdb.WatchSet,
) ([]*serverstate.Instance, error)

func (*State) InstancesByDeployment

func (s *State) InstancesByDeployment(ctx context.Context, id string, ws memdb.WatchSet) ([]*serverstate.Instance, error)

func (*State) JobAck

func (s *State) JobAck(ctx context.Context, id string, ack bool) (*serverstate.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. Additionally, if a job is associated with an on-demand runner task and/or pipeline, this func will progress the Tasks and Pipeline state machines depending on which job has currently been acked.

func (*State) JobAssignForRunner

func (s *State) JobAssignForRunner(ctx context.Context, r *pb.Runner) (*serverstate.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(ctx context.Context, id string, ws memdb.WatchSet) (*serverstate.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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, jobs ...*pb.Job) error

JobCreate queues the given jobs. If any job fails to queue, no jobs are queued. If partial failures are acceptable, call this multiple times with a single job.

func (*State) JobExpire

func (s *State) JobExpire(ctx context.Context, id string) error

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

func (*State) JobHeartbeat

func (s *State) JobHeartbeat(ctx context.Context, 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) JobLatestInit added in v0.11.0

func (s *State) JobLatestInit(ctx context.Context, proj *pb.Ref_Project) (*pb.Job, error)

JobLatestInit looks up the latest init job for the given project. 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) JobList

func (s *State) JobList(
	ctx context.Context,
	req *pb.ListJobsRequest,
) ([]*pb.Job, *pb.PaginationResponse, error)

JobList returns the list of jobs.

func (*State) JobPeekForRunner

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

JobPeekForRunner effectively simulates JobAssignForRunner with two changes: (1) jobs are not actually assigned (they remain queued) and (2) this will not block if a job isn't available. If a job isn't available, this will return (nil, nil).

func (*State) JobProjectScopedRequest

func (s *State) JobProjectScopedRequest(
	ctx context.Context,
	pRef *pb.Ref_Project,
	jobTemplate *pb.Job,
) ([]*pb.QueueJobRequest, error)

Given a Project Ref and a Job Template, this function will generate a slice of QueueJobRequests for every application inside the requested Project

func (*State) JobUpdate

func (s *State) JobUpdate(ctx context.Context, id string, cb func(jobpb *pb.Job) error) error

JobUpdate calls the given callback to update fields on the job data. The callback is called in the context of a database write lock so it should NOT compute anything and should be fast. The callback can return an error to abort the transaction.

Job states should NOT be modified using this, only metadata.

func (*State) JobUpdateExpiry added in v0.10.0

func (s *State) JobUpdateExpiry(ctx context.Context, id string, newExpire *timestamppb.Timestamp) error

JobUpdateExpiry will update the jobs expiration time with the new value. This method is used when a runner has accepted a job and peeks at its runner config. By this point, we know the runner has accepted a job to work on, so the runner should handle the job soon.

func (*State) JobUpdateRef

func (s *State) JobUpdateRef(ctx context.Context, id string, ref *pb.Job_DataSource_Ref) error

JobUpdateRef sets the data_source_ref field for a job. This job can be in any state.

func (*State) JobsByTaskRef added in v0.9.0

func (s *State) JobsByTaskRef(
	ctx context.Context,
	task *pb.Task,
) (startJob *pb.Job, taskJob *pb.Job, stopJob *pb.Job, watchJob *pb.Job, err error)

GetJobsByTaskRef will look up every job triple by Task ref in a single memdb transaction. This is often used via the API for building out a complete picture of a task beyond the job ID refs.

func (*State) OnDemandRunnerConfigDefault

func (s *State) OnDemandRunnerConfigDefault(ctx context.Context) ([]*pb.Ref_OnDemandRunnerConfig, error)

OnDemandRunnerConfigDefault returns the list of ondemandRunners that are defaults.

func (*State) OnDemandRunnerConfigDelete

func (s *State) OnDemandRunnerConfigDelete(ctx context.Context, ref *pb.Ref_OnDemandRunnerConfig) error

OnDemandRunnerConfigDelete deletes a ondemandRunner by reference. This is a complete data delete. This will delete all operations associated with this ondemandRunner as well.

func (*State) OnDemandRunnerConfigGet

func (s *State) OnDemandRunnerConfigGet(ctx context.Context, ref *pb.Ref_OnDemandRunnerConfig) (*pb.OnDemandRunnerConfig, error)

OnDemandRunnerConfigGet gets a ondemandRunner by reference.

func (*State) OnDemandRunnerConfigList

func (s *State) OnDemandRunnerConfigList(ctx context.Context) ([]*pb.OnDemandRunnerConfig, error)

OnDemandRunnerConfigList returns the list of ondemandRunners.

func (*State) OnDemandRunnerConfigPut

func (s *State) OnDemandRunnerConfigPut(ctx context.Context, o *pb.OnDemandRunnerConfig) (*pb.OnDemandRunnerConfig, error)

OnDemandRunnerConfigPut creates or updates the given ondemandRunner.

Application changes will be ignored, you must use the Application APIs.

func (*State) PipelineDelete added in v0.10.0

func (s *State) PipelineDelete(ctx context.Context, ref *pb.Ref_Pipeline) error

PipelineDelete deletes a pipeline by reference.

func (*State) PipelineGet added in v0.10.0

func (s *State) PipelineGet(ctx context.Context, ref *pb.Ref_Pipeline) (*pb.Pipeline, error)

PipelineGet gets a pipeline by reference.

func (*State) PipelineList added in v0.10.0

func (s *State) PipelineList(ctx context.Context, pRef *pb.Ref_Project) ([]*pb.Pipeline, error)

func (*State) PipelinePut added in v0.10.0

func (s *State) PipelinePut(ctx context.Context, p *pb.Pipeline) error

PipelinePut creates or updates the given Pipeline.

func (*State) PipelineRunGet added in v0.10.0

func (s *State) PipelineRunGet(ctx context.Context, ref *pb.Ref_Pipeline, seq uint64) (*pb.PipelineRun, error)

PipelineRunGet gets a PipelineRun by pipeline and sequence.

func (*State) PipelineRunGetById added in v0.10.0

func (s *State) PipelineRunGetById(ctx context.Context, id string) (*pb.PipelineRun, error)

PipelineRunGetById gets a PipelineRun by pipeline run ID.

func (*State) PipelineRunGetByJobId added in v0.10.0

func (s *State) PipelineRunGetByJobId(ctx context.Context, jobId string) (*pb.PipelineRun, error)

func (*State) PipelineRunGetLatest added in v0.10.0

func (s *State) PipelineRunGetLatest(ctx context.Context, pId string) (*pb.PipelineRun, error)

PipelineRunGetLatest gets the latest PipelineRun by pipeline ID.

func (*State) PipelineRunList added in v0.10.0

func (s *State) PipelineRunList(ctx context.Context, pRef *pb.Ref_Pipeline) ([]*pb.PipelineRun, error)

func (*State) PipelineRunPut added in v0.10.0

func (s *State) PipelineRunPut(ctx context.Context, pr *pb.PipelineRun) error

PipelineRunPut creates or updates the given PipelineRun.

func (*State) ProjectCount added in v0.11.0

func (s *State) ProjectCount(ctx context.Context) (uint64, error)

func (*State) ProjectDelete

func (s *State) ProjectDelete(ctx context.Context, 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(ctx context.Context, ref *pb.Ref_Project) (*pb.Project, error)

ProjectGet gets a project by reference.

func (*State) ProjectList

func (s *State) ProjectList(ctx context.Context, paginationRequest *pb.PaginationRequest) ([]*pb.Ref_Project, *pb.PaginationResponse, error)

ProjectList returns the list of projects.

func (*State) ProjectListBundles added in v0.11.0

func (s *State) ProjectListBundles(ctx context.Context, paginationRequest *pb.PaginationRequest) ([]*pb.UI_ProjectBundle, *pb.PaginationResponse, error)

ProjectListFull returns the list of full projects (rather than refs).

func (*State) ProjectListWorkspaces

func (s *State) ProjectListWorkspaces(ctx context.Context, ref *pb.Ref_Project) ([]*pb.Workspace_Project, error)

ProjectListWorkspaces returns the list of workspaces that a project is in.

func (*State) ProjectPollComplete

func (s *State) ProjectPollComplete(ctx context.Context, p *pb.Project, t time.Time) error

ProjectPollComplete sets the next poll time for the given project to the time "t" plus the interval time for the project.

func (*State) ProjectPollPeek

func (s *State) ProjectPollPeek(ctx context.Context, ws memdb.WatchSet) (*pb.Project, time.Time, error)

ProjectPollPeek returns the next project that should be polled. This will return (nil,nil) if there are no projects to poll currently.

This is a "peek" operation so it does not update the project's next poll time. Therefore, calling this multiple times should return the same result unless a function like ProjectPollComplete is called.

If ws is non-nil, the WatchSet can be watched for any changes to projects to poll. This can be watched, for example, to detect when projects to poll are added. This is important functionality since callers may be sleeping on a deadline for awhile when a new project is inserted to poll immediately.

func (*State) ProjectPut

func (s *State) ProjectPut(ctx context.Context, p *pb.Project) error

ProjectPut creates or updates the given project.

Application changes will be ignored, you must use the Application APIs.

func (*State) ProjectUpdateDataRef

func (s *State) ProjectUpdateDataRef(
	ctx context.Context,
	ref *pb.Ref_Project,
	ws *pb.Ref_Workspace,
	dataRef *pb.Job_DataSource_Ref,
) error

ProjectUpdateDataRef updates the latest data ref used for a project. This data is available via the APIs for querying workspaces.

func (*State) Prune

func (s *State) Prune() error

Prune should be called in a on a regular interval to allow State to prune out old data.

func (*State) ReleaseGet

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

ReleaseGet gets a release by ref.

func (*State) ReleaseLatest

func (s *State) ReleaseLatest(
	ctx context.Context,
	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(
	ctx context.Context,
	ref *pb.Ref_Application,
	opts ...serverstate.ListOperationOption,
) ([]*pb.Release, error)

func (*State) ReleasePut

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

ReleasePut inserts or updates a release record.

func (*State) RunnerAdopt

func (s *State) RunnerAdopt(ctx context.Context, id string, implicit bool) error

RunnerAdopt marks a runner as adopted.

If "implicit" is true, then this runner is implicitly adopted and the state goes to "PREADOPTED". This means that the runner instance itself was never explicitly adopted, but it already has a valid token so it is accepted.

func (*State) RunnerById

func (s *State) RunnerById(ctx context.Context, id string, ws memdb.WatchSet) (*pb.Runner, error)

func (*State) RunnerCreate

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

func (*State) RunnerDelete

func (s *State) RunnerDelete(ctx context.Context, id string) error

RunnerDelete permanently deletes the runner record including any on-disk state such as adoption state. This effectively "forgets" the runner.

func (*State) RunnerList

func (s *State) RunnerList(ctx context.Context) ([]*pb.Runner, error)

RunnerList lists all the runners. This isn't a list of only online runners; this is ALL runners the database currently knows about.

func (*State) RunnerOffline

func (s *State) RunnerOffline(ctx context.Context, id string) error

RunnerOffline marks that a runner has gone offline. This is the preferred approach to deregistering a runner, since this will keep the adoption state around.

func (*State) RunnerReject

func (s *State) RunnerReject(ctx context.Context, id string) error

RunnerReject marks a runner as rejected.

func (*State) ServerConfigGet

func (s *State) ServerConfigGet(ctx context.Context) (*pb.ServerConfig, error)

ServerConfigGet gets the server configuration.

func (*State) ServerConfigSet

func (s *State) ServerConfigSet(ctx context.Context, c *pb.ServerConfig) error

ServerConfigSet writes the server configuration.

func (*State) ServerIdGet

func (s *State) ServerIdGet(ctx context.Context) (string, error)

ServerIdGet gets the server ID.

func (*State) ServerIdSet

func (s *State) ServerIdSet(ctx context.Context, id string) error

ServerIdSet writes the server ID.

func (*State) ServerURLTokenGet

func (s *State) ServerURLTokenGet(ctx context.Context) (string, error)

ServerURLTokenGet gets the server URL token.

func (*State) ServerURLTokenSet

func (s *State) ServerURLTokenSet(ctx context.Context, token string) error

ServerURLTokenSet writes the server URL token.

func (*State) StageRestoreSnapshot

func (s *State) StageRestoreSnapshot(ctx context.Context, r io.Reader) error

StageRestoreSnapshot stages a database restore for the next server restart. This will create a temporary file alongside the data file so we must have write access to the directory containing the database.

func (*State) StatusReportGet

func (s *State) StatusReportGet(ctx context.Context, ref *pb.Ref_Operation) (*pb.StatusReport, error)

get status report by referenced operation

func (*State) StatusReportLatest

func (s *State) StatusReportLatest(
	ctx context.Context,
	ref *pb.Ref_Application,
	ws *pb.Ref_Workspace,
	filter func(*pb.StatusReport) (bool, error),
) (*pb.StatusReport, error)

StatusReportLatest gets the latest generated status report

func (*State) StatusReportList

func (s *State) StatusReportList(
	ctx context.Context,
	ref *pb.Ref_Application,
	opts ...serverstate.ListOperationOption,
) ([]*pb.StatusReport, error)

func (*State) StatusReportPut

func (s *State) StatusReportPut(ctx context.Context, update bool, report *pb.StatusReport) error

create or update the latest status report

func (*State) TaskCancel added in v0.9.0

func (s *State) TaskCancel(ctx context.Context, ref *pb.Ref_Task) error

TaskCancel cancels a tasks jobs by task id or run job id reference. NOTE(briancain): this way means each cancel is its own transaction and commit, not the greatest. Previously I attempted to implement this with taskCancel where the entire job triple was canceled inside a single transaction. This ended up deadlocking because when we cancel a job, we also call a `db.Update` on each job when we update its state in the database. This caused a deadlock. For now we cancel each job separately.

func (*State) TaskDelete

func (s *State) TaskDelete(ctx context.Context, ref *pb.Ref_Task) error

TaskDelete deletes a task by reference.

func (*State) TaskGet

func (s *State) TaskGet(ctx context.Context, ref *pb.Ref_Task) (*pb.Task, error)

TaskGet gets a task by reference.

func (*State) TaskList

func (s *State) TaskList(ctx context.Context, req *pb.ListTaskRequest) ([]*pb.Task, error)

TaskList returns the list of tasks.

func (*State) TaskPut

func (s *State) TaskPut(ctx context.Context, t *pb.Task) error

TaskPut creates or updates the given Task.

func (*State) TokenSignature added in v0.10.0

func (s *State) TokenSignature(ctx context.Context, tokenBody []byte, keyId string) (signature []byte, err error)

TokenSignature generates a secure hash signature for the given token body, using the given keyId. In this implementation of TokenSignature, if a key with the given ID doesn't exist, it will be created. The token, keyId, and signature can later be presented to TokenSignatureVerify to determine if the signature was produced by us, using this method.

func (*State) TokenSignatureVerify added in v0.10.0

func (s *State) TokenSignatureVerify(ctx context.Context, tokenBody []byte, signature []byte, keyId string) (isValid bool, err error)

TokenSignatureVerify verifies that a given token body + signature was produced by us, using the given key id. Expected to be a signature generated by TokenSignature

func (*State) TriggerDelete

func (s *State) TriggerDelete(ctx context.Context, ref *pb.Ref_Trigger) error

TriggerDelete deletes a trigger by reference.

func (*State) TriggerGet

func (s *State) TriggerGet(ctx context.Context, ref *pb.Ref_Trigger) (*pb.Trigger, error)

TriggerGet gets a trigger by reference.

func (*State) TriggerList

func (s *State) TriggerList(
	ctx context.Context,
	refws *pb.Ref_Workspace,
	refproj *pb.Ref_Project,
	refapp *pb.Ref_Application,
	tagFilter []string,
) ([]*pb.Trigger, error)

TriggerList returns the list of triggers.

func (*State) TriggerPut

func (s *State) TriggerPut(ctx context.Context, t *pb.Trigger) error

TriggerPut creates or updates the given Trigger.

func (*State) UserDelete

func (s *State) UserDelete(ctx context.Context, ref *pb.Ref_User) error

UserDelete deletes a user by reference.

func (*State) UserEmpty

func (s *State) UserEmpty(ctx context.Context) (bool, error)

UserEmpty returns true if there are no users yet (bootstrap state).

func (*State) UserGet

func (s *State) UserGet(ctx context.Context, ref *pb.Ref_User) (*pb.User, error)

UserGet gets a user by reference.

func (*State) UserGetEmail

func (s *State) UserGetEmail(ctx context.Context, email string) (*pb.User, error)

UserGetEmail gets a user by by email lookup. This will return a codes.NotFound error if the user is not found.

func (*State) UserGetOIDC

func (s *State) UserGetOIDC(ctx context.Context, iss, sub string) (*pb.User, error)

UserGetOIDC gets a user by by OIDC link lookup. This will return a codes.NotFound error if the user is not found.

func (*State) UserList

func (s *State) UserList(ctx context.Context) ([]*pb.User, error)

UserList returns the list of projects.

func (*State) UserPut

func (s *State) UserPut(ctx context.Context, user *pb.User) error

UserPut creates or updates the given user. If the user has no ID set then an ID will be written directly to the parameter.

func (*State) WorkspaceDelete added in v0.10.0

func (s *State) WorkspaceDelete(ctx context.Context, n string) error

func (*State) WorkspaceGet

func (s *State) WorkspaceGet(ctx context.Context, 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(ctx context.Context) ([]*pb.Workspace, error)

WorkspaceList lists all the workspaces.

func (*State) WorkspaceListByApp

func (s *State) WorkspaceListByApp(ctx context.Context, ref *pb.Ref_Application) ([]*pb.Workspace, error)

WorkspaceListByApp lists all the workspaces used by a specific application.

func (*State) WorkspaceListByProject

func (s *State) WorkspaceListByProject(ctx context.Context, ref *pb.Ref_Project) ([]*pb.Workspace, error)

WorkspaceListByProject lists all the workspaces used by a project.

func (*State) WorkspacePut

func (s *State) WorkspacePut(ctx context.Context, workspace *pb.Workspace) error

WorkspacePut creates or updates the given Workspace.

Project changes will be ignored

Jump to

Keyboard shortcuts

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