environment

package
v0.0.0-...-d6c69f2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrScaleDown = errors.New("cannot scale down the environment")

Functions

This section is empty.

Types

type AWSEnvironment

type AWSEnvironment struct {
	// contains filtered or unexported fields
}

func NewAWSEnvironment

func NewAWSEnvironment(onDestroyRunner runner.DestroyRunnerHandler) *AWSEnvironment

func (*AWSEnvironment) AddRunner

func (a *AWSEnvironment) AddRunner(_ runner.Runner)

func (*AWSEnvironment) ApplyPrewarmingPoolSize

func (a *AWSEnvironment) ApplyPrewarmingPoolSize() error

ApplyPrewarmingPoolSize is neither supported nor required. It is handled transparently by AWS.

func (*AWSEnvironment) CPULimit

func (a *AWSEnvironment) CPULimit() uint

CPULimit is disabled as one can only set the memory limit with AWS Lambda.

func (*AWSEnvironment) Delete

func (*AWSEnvironment) DeleteRunner

func (a *AWSEnvironment) DeleteRunner(_ string) (r runner.Runner, ok bool)

func (*AWSEnvironment) ID

func (*AWSEnvironment) IdleRunnerCount

func (a *AWSEnvironment) IdleRunnerCount() uint

IdleRunnerCount is not supported as we have no information about the AWS managed prewarming pool. For the Poseidon Health check we default to 1.

func (*AWSEnvironment) Image

func (a *AWSEnvironment) Image() string

Image is used to specify the AWS Endpoint Poseidon is connecting to.

func (*AWSEnvironment) MarshalJSON

func (a *AWSEnvironment) MarshalJSON() ([]byte, error)

func (*AWSEnvironment) MemoryLimit

func (a *AWSEnvironment) MemoryLimit() uint

func (*AWSEnvironment) NetworkAccess

func (a *AWSEnvironment) NetworkAccess() (enabled bool, mappedPorts []uint16)

func (*AWSEnvironment) PrewarmingPoolSize

func (a *AWSEnvironment) PrewarmingPoolSize() uint

PrewarmingPoolSize is neither supported nor required. It is handled transparently by AWS. For easy compatibility with CodeOcean, 1 is the static value.

func (*AWSEnvironment) Register

func (a *AWSEnvironment) Register() error

func (*AWSEnvironment) Sample

func (a *AWSEnvironment) Sample() (r runner.Runner, ok bool)

func (*AWSEnvironment) SetCPULimit

func (a *AWSEnvironment) SetCPULimit(_ uint) error

SetCPULimit is disabled as one can only set the memory limit with AWS Lambda.

func (*AWSEnvironment) SetConfigFrom

func (a *AWSEnvironment) SetConfigFrom(_ runner.ExecutionEnvironment)

func (*AWSEnvironment) SetID

func (a *AWSEnvironment) SetID(id dto.EnvironmentID)

func (*AWSEnvironment) SetImage

func (a *AWSEnvironment) SetImage(awsEndpoint string)

func (*AWSEnvironment) SetMemoryLimit

func (a *AWSEnvironment) SetMemoryLimit(_ uint) error

func (*AWSEnvironment) SetNetworkAccess

func (a *AWSEnvironment) SetNetworkAccess(_ bool, _ []uint16)

func (*AWSEnvironment) SetPrewarmingPoolSize

func (a *AWSEnvironment) SetPrewarmingPoolSize(_ uint)

SetPrewarmingPoolSize is neither supported nor required. It is handled transparently by AWS.

type AWSEnvironmentManager

type AWSEnvironmentManager struct {
	*AbstractManager
}

AWSEnvironmentManager contains no functionality at the moment. IMPROVE: Create Lambda functions dynamically.

func NewAWSEnvironmentManager

func NewAWSEnvironmentManager(runnerManager runner.Manager) *AWSEnvironmentManager

func (*AWSEnvironmentManager) CreateOrUpdate

func (*AWSEnvironmentManager) Get

func (*AWSEnvironmentManager) List

type AbstractManager

type AbstractManager struct {
	// contains filtered or unexported fields
}

AbstractManager is used to have a fallback environment manager in the chain of responsibility following the null object pattern.

func NewAbstractManager

func NewAbstractManager(runnerManager runner.Manager) *AbstractManager

NewAbstractManager creates a new abstract runner manager that keeps track of all environments of one kind.

func (*AbstractManager) CreateOrUpdate

func (*AbstractManager) Delete

func (n *AbstractManager) Delete(environmentID dto.EnvironmentID) (bool, error)

func (*AbstractManager) Get

func (*AbstractManager) HasNextHandler

func (n *AbstractManager) HasNextHandler() bool

func (*AbstractManager) List

func (*AbstractManager) NextHandler

func (n *AbstractManager) NextHandler() ManagerHandler

func (*AbstractManager) SetNextHandler

func (n *AbstractManager) SetNextHandler(next ManagerHandler)

func (*AbstractManager) Statistics

type Manager

type Manager interface {
	// List returns all environments known by Poseidon.
	// When `fetch` is set the environments are fetched from the executor before returning.
	List(ctx context.Context, fetch bool) ([]runner.ExecutionEnvironment, error)

	// Get returns the details of the requested environment.
	// When `fetch` is set the requested environment is fetched from the executor before returning.
	Get(ctx context.Context, id dto.EnvironmentID, fetch bool) (runner.ExecutionEnvironment, error)

	// CreateOrUpdate creates/updates an execution environment on the executor.
	// If the job was created, the returned boolean is true, if it was updated, it is false.
	// If err is not nil, that means the environment was neither created nor updated.
	CreateOrUpdate(
		ctx context.Context,
		id dto.EnvironmentID,
		request dto.ExecutionEnvironmentRequest,
	) (bool, error)

	// Delete removes the specified execution environment.
	// Iff the specified environment could not be found Delete returns false.
	Delete(id dto.EnvironmentID) (bool, error)

	// Statistics returns statistical data for each execution environment.
	Statistics() map[dto.EnvironmentID]*dto.StatisticalExecutionEnvironmentData
}

Manager encapsulates API calls to the executor API for creation and deletion of execution environments.

type ManagerHandler

type ManagerHandler interface {
	Manager
	SetNextHandler(next ManagerHandler)
	NextHandler() ManagerHandler
	HasNextHandler() bool
}

ManagerHandler is one handler in the chain of responsibility of environment managers. Each manager can handle different requests.

type ManagerHandlerMock

type ManagerHandlerMock struct {
	mock.Mock
}

ManagerHandlerMock is an autogenerated mock type for the ManagerHandler type

func NewManagerHandlerMock

func NewManagerHandlerMock(t interface {
	mock.TestingT
	Cleanup(func())
}) *ManagerHandlerMock

NewManagerHandlerMock creates a new instance of ManagerHandlerMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*ManagerHandlerMock) CreateOrUpdate

CreateOrUpdate provides a mock function with given fields: ctx, id, request

func (*ManagerHandlerMock) Delete

func (_m *ManagerHandlerMock) Delete(id dto.EnvironmentID) (bool, error)

Delete provides a mock function with given fields: id

func (*ManagerHandlerMock) Get

Get provides a mock function with given fields: ctx, id, fetch

func (*ManagerHandlerMock) HasNextHandler

func (_m *ManagerHandlerMock) HasNextHandler() bool

HasNextHandler provides a mock function with given fields:

func (*ManagerHandlerMock) List

List provides a mock function with given fields: ctx, fetch

func (*ManagerHandlerMock) NextHandler

func (_m *ManagerHandlerMock) NextHandler() ManagerHandler

NextHandler provides a mock function with given fields:

func (*ManagerHandlerMock) SetNextHandler

func (_m *ManagerHandlerMock) SetNextHandler(next ManagerHandler)

SetNextHandler provides a mock function with given fields: next

func (*ManagerHandlerMock) Statistics

Statistics provides a mock function with given fields:

type NomadEnvironment

type NomadEnvironment struct {
	// contains filtered or unexported fields
}

func NewNomadEnvironment

func NewNomadEnvironment(ctx context.Context, environmentID dto.EnvironmentID, apiClient nomad.ExecutorAPI,
	jobHCL string,
) (*NomadEnvironment, error)

NewNomadEnvironment creates a new Nomad environment based on the passed Nomad Job HCL. The passed context does not determine the lifespan of the environment, use Delete instead.

func NewNomadEnvironmentFromRequest

func NewNomadEnvironmentFromRequest(ctx context.Context,
	apiClient nomad.ExecutorAPI, jobHCL string, environmentID dto.EnvironmentID, request dto.ExecutionEnvironmentRequest) (
	*NomadEnvironment, error,
)

func (*NomadEnvironment) AddRunner

func (n *NomadEnvironment) AddRunner(object runner.Runner)

func (*NomadEnvironment) ApplyPrewarmingPoolSize

func (n *NomadEnvironment) ApplyPrewarmingPoolSize() error

func (*NomadEnvironment) CPULimit

func (n *NomadEnvironment) CPULimit() uint

func (*NomadEnvironment) DeepCopyJob

func (n *NomadEnvironment) DeepCopyJob() *nomadApi.Job

DeepCopyJob clones the native Nomad job in a way that it can be used as Runner job.

func (*NomadEnvironment) Delete

func (n *NomadEnvironment) Delete(reason runner.DestroyReason) error

func (*NomadEnvironment) DeleteRunner

func (n *NomadEnvironment) DeleteRunner(id string) (r runner.Runner, ok bool)

func (*NomadEnvironment) ID

func (*NomadEnvironment) IdleRunnerCount

func (n *NomadEnvironment) IdleRunnerCount() uint

func (*NomadEnvironment) Image

func (n *NomadEnvironment) Image() string

func (*NomadEnvironment) MarshalJSON

func (n *NomadEnvironment) MarshalJSON() (res []byte, err error)

MarshalJSON implements the json.Marshaler interface. This converts the NomadEnvironment into the expected schema for dto.ExecutionEnvironmentData.

func (*NomadEnvironment) MemoryLimit

func (n *NomadEnvironment) MemoryLimit() uint

func (*NomadEnvironment) NetworkAccess

func (n *NomadEnvironment) NetworkAccess() (allowed bool, ports []uint16)

func (*NomadEnvironment) PrewarmingPoolSize

func (n *NomadEnvironment) PrewarmingPoolSize() uint

func (*NomadEnvironment) Register

func (n *NomadEnvironment) Register() error

Register creates a Nomad job based on the default job configuration and the given parameters. It registers the job with Nomad and waits until the registration completes.

func (*NomadEnvironment) Sample

func (n *NomadEnvironment) Sample() (runner.Runner, bool)

func (*NomadEnvironment) SetCPULimit

func (n *NomadEnvironment) SetCPULimit(limit uint) error

func (*NomadEnvironment) SetConfigFrom

func (n *NomadEnvironment) SetConfigFrom(environment runner.ExecutionEnvironment)

SetConfigFrom gets the options from the environment job and saves it into another temporary job. IMPROVE: The getters use a validation function that theoretically could edit the environment job. But this modification might never been saved to Nomad.

func (*NomadEnvironment) SetID

func (n *NomadEnvironment) SetID(id dto.EnvironmentID)

func (*NomadEnvironment) SetImage

func (n *NomadEnvironment) SetImage(image string)

func (*NomadEnvironment) SetMemoryLimit

func (n *NomadEnvironment) SetMemoryLimit(limit uint) error

func (*NomadEnvironment) SetNetworkAccess

func (n *NomadEnvironment) SetNetworkAccess(allow bool, exposedPorts []uint16)

func (*NomadEnvironment) SetPrewarmingPoolSize

func (n *NomadEnvironment) SetPrewarmingPoolSize(count uint)

type NomadEnvironmentManager

type NomadEnvironmentManager struct {
	*AbstractManager
	// contains filtered or unexported fields
}

func NewNomadEnvironmentManager

func NewNomadEnvironmentManager(
	runnerManager runner.Manager,
	apiClient nomad.ExecutorAPI,
	templateJobFile string,
) (*NomadEnvironmentManager, error)

func (*NomadEnvironmentManager) CreateOrUpdate

func (m *NomadEnvironmentManager) CreateOrUpdate(
	ctx context.Context, id dto.EnvironmentID, request dto.ExecutionEnvironmentRequest,
) (created bool, err error)

func (*NomadEnvironmentManager) Get

func (m *NomadEnvironmentManager) Get(ctx context.Context, environmentID dto.EnvironmentID, fetch bool) (
	executionEnvironment runner.ExecutionEnvironment, err error,
)

func (*NomadEnvironmentManager) KeepEnvironmentsSynced

func (m *NomadEnvironmentManager) KeepEnvironmentsSynced(ctx context.Context, synchronizeRunners func(ctx context.Context) error)

KeepEnvironmentsSynced loads all environments, runner existing at Nomad, and watches Nomad events to handle further changes.

func (*NomadEnvironmentManager) List

Jump to

Keyboard shortcuts

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