serverstate

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: 7 Imported by: 0

Documentation

Overview

Package serverstate exports the interface and verification harness for implementing a new state storage backend for the server.

Additional state storage backends is not an officially supported extension of Waypoint, so you do this at your own peril. It will not be supported. However, this package is exported because we maintain our own private state backends for other use cases of Waypoint.

Index

Constants

View Source
const (
	DefaultUser   = "waypoint"
	DefaultUserId = "00000000000000000000000001"
)

See the docs in singleprocess.

Variables

View Source
var (
	JobWaitingTimeout   = 2 * time.Minute
	JobHeartbeatTimeout = 2 * time.Minute
)

These variables control the timeouts associated with the job system. The job system implementaions MUST use them. They are GUARANTEED to be written only when the state implementation is NOT running. Therefore, no lock is needed to read them.

These MUST be used because the tests in statetest will manipulate these to verify various behaviors.

Functions

This section is empty.

Types

type Instance

type Instance struct {
	Id           string
	DeploymentId string
	Project      string
	Application  string
	Workspace    string
	LogBuffer    *logbuffer.Buffer
	Type         pb.Instance_Type
	DisableExec  bool
}

Instance represents a running deployment instance for an application.

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

	// This is the context that the client side is running inside.
	// It is used by the entrypoint side to detect if the client is still
	// around or not.
	Context context.Context
}

InstanceExec represents a single exec session.

type InstanceExecHandler added in v0.9.0

type InstanceExecHandler interface {
	// InstanceExecCreateByTargetedInstance registers an exec request for a specific instance,
	// identified by it's database id.
	InstanceExecCreateByTargetedInstance(ctx context.Context, id string, exec *InstanceExec) error

	// InstanceExecCreateByDeployment looks up the instances running the given deployment,
	// picks an instance, and assigns the exec to that instance.
	InstanceExecCreateByDeployment(ctx context.Context, did string, exec *InstanceExec) error

	// InstanceExecCreateForVirtualInstance is used for plugins that require instances to be
	// created just to handle exec requests. The given instance id doesn't have to exist yet,
	// the code will wait for the instance to come online, then assign the exec request to it.
	InstanceExecCreateForVirtualInstance(ctx context.Context, id string, exec *InstanceExec) error

	// InstanceExecDelete deletes an exec request, identified by it's numeric id (InstanceExec.Id)
	InstanceExecDelete(ctx context.Context, id int64) error

	// InstanceExecById retrieves an exec request, identified by it's numeric id (InstanceExec.Id)
	InstanceExecById(ctx context.Context, id int64) (*InstanceExec, error)

	// InstanceExecListByInstanceId returns any exec requests for the given instance id.
	InstanceExecListByInstanceId(ctx context.Context, id string, ws memdb.WatchSet) ([]*InstanceExec, error)

	// InstanceExecById retrieves an exec request, identified by it's numeric id (InstanceExec.Id).
	// The implementer also can use this opertunity to do any sychronization of state, such as
	// connecting to external systems.
	InstanceExecConnect(ctx context.Context, id int64) (*InstanceExec, error)

	// InstanceExecWaitConnected is run to allow the implementation to sync up with a call to
	// InstanceExecConnect run elsewhere.
	InstanceExecWaitConnected(ctx context.Context, exec *InstanceExec) error
}

InstanceExecHandler is an optional interface that the state interface can implement. When it does, the functionality associated with `waypoint exec` will be available.

type Interface

type Interface interface {
	// Close is always called when the server is shutting down or reloading
	// the state store. This should clean up any resources (file handles, etc.)
	// that the state storage is using.
	io.Closer

	HMACKeyEmpty(context.Context) bool
	HMACKeyCreateIfNotExist(ctx context.Context, id string, size int) (*pb.HMACKey, error)
	HMACKeyGet(ctx context.Context, id string) (*pb.HMACKey, error)
	TokenSignature(ctx context.Context, tokenBody []byte, keyId string) (signature []byte, err error)
	TokenSignatureVerify(ctx context.Context, tokenBody []byte, signature []byte, keyId string) (isValid bool, err error)

	ServerConfigSet(context.Context, *pb.ServerConfig) error
	ServerConfigGet(context.Context) (*pb.ServerConfig, error)

	UserPut(context.Context, *pb.User) error
	UserGet(context.Context, *pb.Ref_User) (*pb.User, error)
	UserDelete(context.Context, *pb.Ref_User) error
	UserList(context.Context) ([]*pb.User, error)
	UserEmpty(context.Context) (bool, error)
	UserGetOIDC(ctx context.Context, iss, sub string) (*pb.User, error)
	UserGetEmail(context.Context, string) (*pb.User, error)

	AuthMethodPut(context.Context, *pb.AuthMethod) error
	AuthMethodGet(context.Context, *pb.Ref_AuthMethod) (*pb.AuthMethod, error)
	AuthMethodDelete(context.Context, *pb.Ref_AuthMethod) error
	AuthMethodList(context.Context) ([]*pb.AuthMethod, error)

	RunnerCreate(context.Context, *pb.Runner) error
	RunnerDelete(context.Context, string) error
	RunnerOffline(context.Context, string) error
	RunnerAdopt(context.Context, string, bool) error
	RunnerReject(context.Context, string) error
	RunnerById(context.Context, string, memdb.WatchSet) (*pb.Runner, error)
	RunnerList(context.Context) ([]*pb.Runner, error)

	OnDemandRunnerConfigPut(context.Context, *pb.OnDemandRunnerConfig) (*pb.OnDemandRunnerConfig, error)
	OnDemandRunnerConfigGet(context.Context, *pb.Ref_OnDemandRunnerConfig) (*pb.OnDemandRunnerConfig, error)
	OnDemandRunnerConfigDelete(context.Context, *pb.Ref_OnDemandRunnerConfig) error
	OnDemandRunnerConfigList(context.Context) ([]*pb.OnDemandRunnerConfig, error)
	OnDemandRunnerConfigDefault(context.Context) ([]*pb.Ref_OnDemandRunnerConfig, error)

	ServerURLTokenSet(context.Context, string) error
	ServerURLTokenGet(context.Context) (string, error)

	ServerIdSet(ctx context.Context, id string) error
	ServerIdGet(context.Context) (string, error)

	CreateSnapshot(context.Context, io.Writer) error
	StageRestoreSnapshot(context.Context, io.Reader) error

	ConfigSet(context.Context, ...*pb.ConfigVar) error
	ConfigDelete(context.Context, ...*pb.ConfigVar) error
	ConfigGet(context.Context, *pb.ConfigGetRequest) ([]*pb.ConfigVar, error)
	ConfigGetWatch(context.Context, *pb.ConfigGetRequest, memdb.WatchSet) ([]*pb.ConfigVar, error)

	ConfigSourceSet(context.Context, ...*pb.ConfigSource) error
	ConfigSourceDelete(context.Context, ...*pb.ConfigSource) error
	ConfigSourceGet(context.Context, *pb.GetConfigSourceRequest) ([]*pb.ConfigSource, error)
	ConfigSourceGetWatch(context.Context, *pb.GetConfigSourceRequest, memdb.WatchSet) ([]*pb.ConfigSource, error)

	InstanceCreate(context.Context, *Instance) error
	InstanceDelete(context.Context, string) error
	InstanceById(context.Context, string) (*Instance, error)
	InstancesByApp(context.Context, *pb.Ref_Application, *pb.Ref_Workspace, memdb.WatchSet) ([]*Instance, error)
	InstancesByDeployment(context.Context, string, memdb.WatchSet) ([]*Instance, error)

	WorkspaceList(context.Context) ([]*pb.Workspace, error)
	WorkspaceListByProject(context.Context, *pb.Ref_Project) ([]*pb.Workspace, error)
	WorkspaceListByApp(context.Context, *pb.Ref_Application) ([]*pb.Workspace, error)
	WorkspaceGet(context.Context, string) (*pb.Workspace, error)
	WorkspacePut(context.Context, *pb.Workspace) error
	WorkspaceDelete(context.Context, string) error

	ProjectPut(context.Context, *pb.Project) error
	ProjectGet(context.Context, *pb.Ref_Project) (*pb.Project, error)
	ProjectDelete(context.Context, *pb.Ref_Project) error
	ProjectUpdateDataRef(context.Context, *pb.Ref_Project, *pb.Ref_Workspace, *pb.Job_DataSource_Ref) error
	ProjectCount(context.Context) (uint64, error)
	ProjectList(context.Context, *pb.PaginationRequest) ([]*pb.Ref_Project, *pb.PaginationResponse, error)
	ProjectListBundles(context.Context, *pb.PaginationRequest) ([]*pb.UI_ProjectBundle, *pb.PaginationResponse, error)
	ProjectListWorkspaces(context.Context, *pb.Ref_Project) ([]*pb.Workspace_Project, error)
	ProjectPollPeek(context.Context, memdb.WatchSet) (*pb.Project, time.Time, error)
	ProjectPollComplete(context.Context, *pb.Project, time.Time) error

	AppPut(context.Context, *pb.Application) (*pb.Application, error)
	AppDelete(context.Context, *pb.Ref_Application) error
	AppGet(context.Context, *pb.Ref_Application) (*pb.Application, error)
	ApplicationPollPeek(context.Context, memdb.WatchSet) (*pb.Project, time.Time, error)
	ApplicationPollComplete(context.Context, *pb.Project, time.Time) error
	GetFileChangeSignal(context.Context, *pb.Ref_Application) (string, error)

	ArtifactPut(context.Context, bool, *pb.PushedArtifact) error
	ArtifactGet(context.Context, *pb.Ref_Operation) (*pb.PushedArtifact, error)
	ArtifactLatest(context.Context, *pb.Ref_Application, *pb.Ref_Workspace) (*pb.PushedArtifact, error)
	ArtifactList(context.Context, *pb.Ref_Application, ...ListOperationOption) ([]*pb.PushedArtifact, error)

	BuildPut(context.Context, bool, *pb.Build) error
	BuildGet(context.Context, *pb.Ref_Operation) (*pb.Build, error)
	BuildLatest(context.Context, *pb.Ref_Application, *pb.Ref_Workspace) (*pb.Build, error)
	BuildList(context.Context, *pb.Ref_Application, ...ListOperationOption) ([]*pb.Build, error)

	DeploymentPut(context.Context, bool, *pb.Deployment) error
	DeploymentGet(context.Context, *pb.Ref_Operation) (*pb.Deployment, error)
	DeploymentLatest(context.Context, *pb.Ref_Application, *pb.Ref_Workspace) (*pb.Deployment, error)
	DeploymentList(context.Context, *pb.Ref_Application, ...ListOperationOption) ([]*pb.Deployment, error)

	ReleasePut(context.Context, bool, *pb.Release) error
	ReleaseGet(context.Context, *pb.Ref_Operation) (*pb.Release, error)
	ReleaseLatest(context.Context, *pb.Ref_Application, *pb.Ref_Workspace) (*pb.Release, error)
	ReleaseList(context.Context, *pb.Ref_Application, ...ListOperationOption) ([]*pb.Release, error)

	StatusReportPut(context.Context, bool, *pb.StatusReport) error
	StatusReportGet(context.Context, *pb.Ref_Operation) (*pb.StatusReport, error)
	StatusReportLatest(
		context.Context,
		*pb.Ref_Application,
		*pb.Ref_Workspace,
		func(*pb.StatusReport) (bool, error),
	) (*pb.StatusReport, error)
	StatusReportList(context.Context, *pb.Ref_Application, ...ListOperationOption) ([]*pb.StatusReport, error)

	TriggerPut(context.Context, *pb.Trigger) error
	TriggerGet(context.Context, *pb.Ref_Trigger) (*pb.Trigger, error)
	TriggerDelete(context.Context, *pb.Ref_Trigger) error
	TriggerList(context.Context, *pb.Ref_Workspace, *pb.Ref_Project, *pb.Ref_Application, []string) ([]*pb.Trigger, error)

	JobCreate(context.Context, ...*pb.Job) error
	JobProjectScopedRequest(context.Context, *pb.Ref_Project, *pb.Job) ([]*pb.QueueJobRequest, error)
	JobList(context.Context, *pb.ListJobsRequest) ([]*pb.Job, *pb.PaginationResponse, error)
	JobLatestInit(context.Context, *pb.Ref_Project) (*pb.Job, error)
	JobById(context.Context, string, memdb.WatchSet) (*Job, error)
	JobPeekForRunner(context.Context, *pb.Runner) (*Job, error)
	JobAssignForRunner(context.Context, *pb.Runner) (*Job, error)
	JobAck(context.Context, string, bool) (*Job, error)
	JobUpdateRef(context.Context, string, *pb.Job_DataSource_Ref) error
	JobUpdateExpiry(context.Context, string, *timestamppb.Timestamp) error
	JobUpdate(context.Context, string, func(*pb.Job) error) error
	JobComplete(context.Context, string, *pb.Job_Result, error) error
	JobCancel(context.Context, string, bool) error
	JobHeartbeat(context.Context, string) error
	JobExpire(context.Context, string) error
	JobIsAssignable(context.Context, *pb.Job) (bool, error)

	TaskPut(context.Context, *pb.Task) error
	TaskGet(context.Context, *pb.Ref_Task) (*pb.Task, error)
	TaskDelete(context.Context, *pb.Ref_Task) error
	TaskCancel(context.Context, *pb.Ref_Task) error
	TaskList(context.Context, *pb.ListTaskRequest) ([]*pb.Task, error)
	JobsByTaskRef(context.Context, *pb.Task) (*pb.Job, *pb.Job, *pb.Job, *pb.Job, error)

	PipelinePut(context.Context, *pb.Pipeline) error
	PipelineGet(context.Context, *pb.Ref_Pipeline) (*pb.Pipeline, error)
	PipelineDelete(context.Context, *pb.Ref_Pipeline) error
	PipelineList(context.Context, *pb.Ref_Project) ([]*pb.Pipeline, error)

	PipelineRunPut(context.Context, *pb.PipelineRun) error
	PipelineRunGet(context.Context, *pb.Ref_Pipeline, uint64) (*pb.PipelineRun, error)
	PipelineRunGetLatest(context.Context, string) (*pb.PipelineRun, error)
	PipelineRunGetById(context.Context, string) (*pb.PipelineRun, error)
	PipelineRunList(context.Context, *pb.Ref_Pipeline) ([]*pb.PipelineRun, error)
}

Interface is the primary interface implemented by an implementation.

Any changes to this interface will require changes to all implementations in all projects.

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 for some reason. The reasons
	// a job may be blocked:
	//  - another job for the same project/app/workspace.
	//  - a dependent job hasn't completed yet
	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 *ListOperationOptions)

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 ListWithWatchSet

func ListWithWatchSet(ws memdb.WatchSet) ListOperationOption

ListWithWatchSet registers watches for the listing, allowing the watcher to detect if new items are added.

func ListWithWorkspace

func ListWithWorkspace(f *pb.Ref_Workspace) ListOperationOption

ListWithWorkspace sets ordering on the list operation.

type ListOperationOptions

type ListOperationOptions struct {
	Application   *pb.Ref_Application
	Workspace     *pb.Ref_Workspace
	Status        []*pb.StatusFilter
	Order         *pb.OperationOrder
	PhysicalState pb.Operation_PhysicalState
	WatchSet      memdb.WatchSet
}

ListOperationOptions are options that can be set for List calls on operations for filtering and limiting the response.

func BuildListOperationOptions

func BuildListOperationOptions(ref *pb.Ref_Application, opts ...ListOperationOption) *ListOperationOptions

BuildListOperationOptions is a helper for implementations to create a ListOperationOptions from an app ref and a set of options.

type Pruner

type Pruner interface {
	Interface

	Prune() error
}

Pruner is implemented by state storage implementations that require a periodic prune. The implementation can't control when this is called, but it will be called roughly every hour or shorter.

During pruning, other operations are still allowed to come in. It is up to the state implementation to handle safe concurrency.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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