command

package
v0.38.0-rc4 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

AuthZProvider is the authz registry for Notebooks, Shells, and Commands.

Functions

func GetCommandOwnerID

func GetCommandOwnerID(ctx context.Context, taskID model.TaskID) (model.UserID, error)

GetCommandOwnerID gets a command's ownerID from a taskID. Uses persisted command state. Returns db.ErrNotFound if a command with given taskID does not exist.

func SetDefaultService

func SetDefaultService(cs *CommandService)

SetDefaultService initializes & returns a new CommandService.

Types

type Command

type Command struct {
	tasks.GenericCommandSpec
	// contains filtered or unexported fields
}

Command is executed in a containerized environment on a Determined cluster. Locking in: Start, OnExit, DeleteIfInWorkspace, ToV1Command/Shell/Notebook/Tensorboard.

func (*Command) DeleteIfInWorkspace

func (c *Command) DeleteIfInWorkspace(req *apiv1.DeleteWorkspaceRequest)

DeleteIfInWorkspace deletes a command's allocation matching a workspaceID.

func (*Command) OnExit

func (c *Command) OnExit(ae *task.AllocationExited)

OnExit runs when an command's allocation exits. It marks the command task as complete, and unregisters where needed. OnExit locks ahead of gc -> unregisterCommand.

func (*Command) ResourcePool

func (c *Command) ResourcePool() string

ResourcePool gets the command's resource pool.

func (*Command) SetJobPriority

func (c *Command) SetJobPriority(priority int) error

SetJobPriority sets a command's job priority.

func (*Command) SetResourcePool

func (c *Command) SetResourcePool(resourcePool string) error

SetResourcePool is not implemented for commands.

func (*Command) SetWeight

func (c *Command) SetWeight(weight float64) error

SetWeight sets the command's group weight.

func (*Command) Start

func (c *Command) Start(ctx context.Context) error

Start starts the command & its respective allocation. Once started, it persists to the db.

func (*Command) ToV1Command

func (c *Command) ToV1Command() *commandv1.Command

ToV1Command takes a *Command from the command service registry & returns a *commandv1.Command.

func (*Command) ToV1Job

func (c *Command) ToV1Job() (*jobv1.Job, error)

ToV1Job takes a command and returns a job.

func (*Command) ToV1Notebook

func (c *Command) ToV1Notebook() *notebookv1.Notebook

ToV1Notebook takes a *Command from the command service registry & returns a *notebookv1.Notebook.

func (*Command) ToV1Shell

func (c *Command) ToV1Shell() *shellv1.Shell

ToV1Shell takes a *Command from the command service registry & returns a *shellv1.Shell.

func (*Command) ToV1Tensorboard

func (c *Command) ToV1Tensorboard() *tensorboardv1.Tensorboard

ToV1Tensorboard takes a *Command from the command service registry & returns a *tensorboardv1.Tensorboard.

type CommandService

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

CommandService tracks the different NTSC commands in the system.

var DefaultCmdService *CommandService

DefaultCmdService is the global command service singleton.

func NewService

func NewService(db *db.PgDB, rm rm.ResourceManager) (*CommandService, error)

NewService returns a new CommandService.

func (*CommandService) DeleteWorkspaceNTSC

func (cs *CommandService) DeleteWorkspaceNTSC(req *apiv1.DeleteWorkspaceRequest)

DeleteWorkspaceNTSC deletes all NTSC associated with a workspace ID.

func (*CommandService) GetCommand

GetCommand looks up a command by ID returns a summary of the its state and configuration.

func (*CommandService) GetCommands

GetCommands returns all commands in the command service registry matching the workspace ID.

func (*CommandService) GetNotebook

GetNotebook looks up a notebook by ID returns a summary of the its state and configuration.

func (*CommandService) GetNotebooks

GetNotebooks returns all notebooks in the command service registry matching the workspace ID.

func (*CommandService) GetShell

GetShell looks up a shell by ID returns a summary of the its state and configuration.

func (*CommandService) GetShells

GetShells returns all shells in the command service registry matching the workspace ID.

func (*CommandService) GetTensorboard

GetTensorboard looks up a tensorboard by ID returns a summary of the its state and configuration.

func (*CommandService) GetTensorboards

GetTensorboards returns all tbs in the command service registry matching the workspace ID.

func (*CommandService) KillNTSC

func (cs *CommandService) KillNTSC(id string, taskType model.TaskType) (*Command, error)

KillNTSC sends a kill signal to the command's allocation.

func (*CommandService) LaunchGenericCommand

func (cs *CommandService) LaunchGenericCommand(
	taskType model.TaskType,
	jobType model.JobType,
	req *CreateGeneric,
) (*Command, error)

LaunchGenericCommand creates NTSC commands and persists them to the database.

func (*CommandService) LaunchNotebookCommand

func (cs *CommandService) LaunchNotebookCommand(
	req *CreateGeneric,
	user *model.User,
) (*Command, error)

LaunchNotebookCommand creates notebook commands and persists them to the database.

func (*CommandService) RestoreAllCommands

func (cs *CommandService) RestoreAllCommands(
	ctx context.Context,
) error

RestoreAllCommands restores all terminated commands whose end time isn't set.

func (*CommandService) SetNTSCPriority

func (cs *CommandService) SetNTSCPriority(
	id string, priority int, taskType model.TaskType,
) (*Command, error)

SetNTSCPriority sets the NTSC's resource manager group priority.

type CommandSnapshot

type CommandSnapshot struct {
	bun.BaseModel `bun:"table:command_state"`

	TaskID         model.TaskID `bun:"task_id"`
	RegisteredTime time.Time    `bun:"registered_time"`
	// taskType can be obtained from related task.
	// jobType can be obtained from task -> job_id -> job_type
	// jobId can be obtained from task -> job_id
	AllocationID model.AllocationID `bun:"allocation_id"`

	// GenericCommandSpec
	GenericCommandSpec tasks.GenericCommandSpec `bun:"generic_command_spec"`

	// GenericTaskSpec
	GenericTaskSpec *tasks.GenericTaskSpec `bun:"generic_task_spec"`

	// Relations
	Task       model.Task       `bun:"rel:belongs-to,join:task_id=task_id"`
	Allocation model.Allocation `bun:"rel:belongs-to,join:allocation_id=allocation_id"`
}

CommandSnapshot is a db representation of a generic command.

type CreateGeneric

type CreateGeneric struct {
	ContextDirectory []byte
	Spec             *tasks.GenericCommandSpec
}

CreateGeneric is a request to the CommandService to create a generic command.

type NSCAuthZ

type NSCAuthZ interface {
	// NSC functions
	// GET /api/v1/NSCs/:nsc_id
	// GET /tasks
	CanGetNSC(
		ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
	) error

	// GET /api/v1/tasks/count
	CanGetActiveTasksCount(ctx context.Context, curUser model.User) error

	// POST /api/v1/NSCs/:nsc_id/kill
	CanTerminateNSC(
		ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
	) error

	// POST /api/v1/NSCs
	CanCreateNSC(
		ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
	) error

	// PATCH /NSCs/:nsc_id
	// POST /api/v1/tensorboards/:tb_id/set_priority
	CanSetNSCsPriority(
		ctx context.Context, curUser model.User, workspaceID model.AccessScopeID, priority int,
	) error

	// GET /api/v1/NSCs
	AccessibleScopes(
		ctx context.Context, curUser model.User, requestedScope model.AccessScopeID,
	) (model.AccessScopeSet, error)

	FilterTensorboards(
		ctx context.Context, curUser model.User, requestedScope model.AccessScopeID,
		tensorboards []*tensorboardv1.Tensorboard,
	) ([]*tensorboardv1.Tensorboard, error)

	// Tensorboard functions
	// GET /api/v1/tensorboards/:tb_id
	CanGetTensorboard(
		ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
		experimentIDs []int32, trialIDs []int32,
	) error

	// POST /api/v1/tensorboards/:tb_id/kill
	CanTerminateTensorboard(
		ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
	) error

	CanCreateGenericTask(
		ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
	) error
}

NSCAuthZ describes authz methods for Notebooks, Shells, and Commands.

type NSCAuthZBasic

type NSCAuthZBasic struct{}

NSCAuthZBasic is basic OSS controls.

func (*NSCAuthZBasic) AccessibleScopes

func (a *NSCAuthZBasic) AccessibleScopes(
	ctx context.Context, curUser model.User, requestedScope model.AccessScopeID,
) (model.AccessScopeSet, error)

AccessibleScopes returns the set of scopes that the user should be limited to.

func (*NSCAuthZBasic) CanCreateGenericTask

func (a *NSCAuthZBasic) CanCreateGenericTask(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
) error

CanCreateGenericTask always returns nil.

func (*NSCAuthZBasic) CanCreateNSC

func (a *NSCAuthZBasic) CanCreateNSC(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
) error

CanCreateNSC always returns a nil error.

func (*NSCAuthZBasic) CanGetActiveTasksCount

func (a *NSCAuthZBasic) CanGetActiveTasksCount(ctx context.Context, curUser model.User) error

CanGetActiveTasksCount always returns a nil error.

func (*NSCAuthZBasic) CanGetNSC

func (a *NSCAuthZBasic) CanGetNSC(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
) error

CanGetNSC returns true and nil error.

func (*NSCAuthZBasic) CanGetTensorboard

func (a *NSCAuthZBasic) CanGetTensorboard(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
	experimentIDs []int32, trialIDs []int32,
) error

CanGetTensorboard returns true and nil error.

func (*NSCAuthZBasic) CanSetNSCsPriority

func (a *NSCAuthZBasic) CanSetNSCsPriority(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID, priority int,
) error

CanSetNSCsPriority always returns a nil error.

func (*NSCAuthZBasic) CanTerminateNSC

func (a *NSCAuthZBasic) CanTerminateNSC(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
) error

CanTerminateNSC always returns a nil error.

func (*NSCAuthZBasic) CanTerminateTensorboard

func (a *NSCAuthZBasic) CanTerminateTensorboard(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
) error

CanTerminateTensorboard always returns nil.

func (*NSCAuthZBasic) FilterTensorboards

func (a *NSCAuthZBasic) FilterTensorboards(
	ctx context.Context,
	curUser model.User,
	requestedScope model.AccessScopeID,
	tensorboards []*tensorboardv1.Tensorboard,
) ([]*tensorboardv1.Tensorboard, error)

FilterTensorboards returns the tensorboards that the user has access to.

type NSCAuthZPermissive

type NSCAuthZPermissive struct{}

NSCAuthZPermissive is permissive implementation of the NSCAuthZ interface.

func (*NSCAuthZPermissive) AccessibleScopes

func (a *NSCAuthZPermissive) AccessibleScopes(
	ctx context.Context, curUser model.User, requestedScope model.AccessScopeID,
) (model.AccessScopeSet, error)

AccessibleScopes returns the set of scopes that the user should be limited to.

func (*NSCAuthZPermissive) CanCreateGenericTask

func (a *NSCAuthZPermissive) CanCreateGenericTask(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
) error

CanCreateGenericTask always returns nil.

func (*NSCAuthZPermissive) CanCreateNSC

func (a *NSCAuthZPermissive) CanCreateNSC(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
) error

CanCreateNSC always returns a nil error.

func (*NSCAuthZPermissive) CanGetActiveTasksCount

func (a *NSCAuthZPermissive) CanGetActiveTasksCount(ctx context.Context, curUser model.User) error

CanGetActiveTasksCount always returns a nil error.

func (*NSCAuthZPermissive) CanGetNSC

func (a *NSCAuthZPermissive) CanGetNSC(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
) error

CanGetNSC returns nil error unless the developer master config option security.authz._strict_ntsc_enabled is true then it returns a boolean if the user is an admin or if the user owns the task and a nil error.

func (*NSCAuthZPermissive) CanGetTensorboard

func (a *NSCAuthZPermissive) CanGetTensorboard(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
	experimentIDs []int32, trialIDs []int32,
) error

CanGetTensorboard always returns true and nil error.

func (*NSCAuthZPermissive) CanSetNSCsPriority

func (a *NSCAuthZPermissive) CanSetNSCsPriority(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID, priority int,
) error

CanSetNSCsPriority always returns a nil error.

func (*NSCAuthZPermissive) CanTerminateNSC

func (a *NSCAuthZPermissive) CanTerminateNSC(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
) error

CanTerminateNSC always returns a nil error.

func (*NSCAuthZPermissive) CanTerminateTensorboard

func (a *NSCAuthZPermissive) CanTerminateTensorboard(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
) error

CanTerminateTensorboard always returns nil.

func (*NSCAuthZPermissive) FilterTensorboards

func (a *NSCAuthZPermissive) FilterTensorboards(
	ctx context.Context, curUser model.User, requestedScope model.AccessScopeID,
	tensorboards []*tensorboardv1.Tensorboard,
) ([]*tensorboardv1.Tensorboard, error)

FilterTensorboards returns the tensorboards the user has access to.

type NSCAuthZRBAC

type NSCAuthZRBAC struct{}

NSCAuthZRBAC is the RBAC implementation of the NSCAuthZ interface.

func (*NSCAuthZRBAC) AccessibleScopes

func (a *NSCAuthZRBAC) AccessibleScopes(
	ctx context.Context, curUser model.User, requestedScope model.AccessScopeID,
) (model.AccessScopeSet, error)

AccessibleScopes returns the set of scopes that the user should be limited to.

func (*NSCAuthZRBAC) CanCreateGenericTask

func (a *NSCAuthZRBAC) CanCreateGenericTask(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
) error

CanCreateGenericTask returns whether or not a user can create a generic task.

func (*NSCAuthZRBAC) CanCreateNSC

func (a *NSCAuthZRBAC) CanCreateNSC(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
) error

CanCreateNSC checks if the user is authorized to create NSCs in the workspace.

func (*NSCAuthZRBAC) CanGetActiveTasksCount

func (a *NSCAuthZRBAC) CanGetActiveTasksCount(ctx context.Context, curUser model.User) (err error)

CanGetActiveTasksCount always returns a nil error.

func (*NSCAuthZRBAC) CanGetNSC

func (a *NSCAuthZRBAC) CanGetNSC(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
) error

CanGetNSC checks if the user is authorized to view NSCs in the specified workspace.

func (*NSCAuthZRBAC) CanGetTensorboard

func (a *NSCAuthZRBAC) CanGetTensorboard(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
	experimentIDs []int32, trialIDs []int32,
) error

CanGetTensorboard returns whether or not a user owns the tensorboard or can access it.

func (*NSCAuthZRBAC) CanSetNSCsPriority

func (a *NSCAuthZRBAC) CanSetNSCsPriority(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID, priority int,
) error

CanSetNSCsPriority checks if the user is authorized to set NSCs priority in the workspace.

func (*NSCAuthZRBAC) CanTerminateNSC

func (a *NSCAuthZRBAC) CanTerminateNSC(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
) (err error)

CanTerminateNSC checks if the user is authorized to terminate NSCs in the workspace.

func (*NSCAuthZRBAC) CanTerminateTensorboard

func (a *NSCAuthZRBAC) CanTerminateTensorboard(
	ctx context.Context, curUser model.User, workspaceID model.AccessScopeID,
) error

CanTerminateTensorboard always returns nil.

func (*NSCAuthZRBAC) FilterTensorboards

func (a *NSCAuthZRBAC) FilterTensorboards(
	ctx context.Context, curUser model.User, requestedScope model.AccessScopeID,
	tensorboards []*tensorboardv1.Tensorboard,
) ([]*tensorboardv1.Tensorboard, error)

FilterTensorboards returns the tensorboards that the user has access to.

type TaskMetadata

type TaskMetadata struct {
	bun.BaseModel `bun:"table:command_state"`
	WorkspaceID   model.AccessScopeID `bun:"workspace_id"`
	TaskType      model.TaskType      `bun:"task_type"`
	ExperimentIDs []int32             `bun:"experiment_ids"`
	TrialIDs      []int32             `bun:"trial_ids"`
}

TaskMetadata captures minimal metadata about a task.

func IdentifyTask

func IdentifyTask(ctx context.Context, taskID model.TaskID) (TaskMetadata, error)

IdentifyTask returns the task metadata for a given task ID. Returns db.ErrNotFound if a command with given taskID does not exist.

Jump to

Keyboard shortcuts

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