Documentation
¶
Index ¶
- Constants
- Variables
- type ConfigProvider
- type Handler
- func (h *Handler) API() batchpb.BatchServiceServer
- func (h *Handler) Addr() string
- func (h *Handler) ExtractOperation(*echo.Context) string
- func (h *Handler) ExtractResource(*echo.Context) string
- func (h *Handler) GetSupportedOperations() []string
- func (h *Handler) Handler() echo.HandlerFunc
- func (h *Handler) MatchPriority() int
- func (h *Handler) Name() string
- func (h *Handler) OperationsAPI() longrunningpb.OperationsServer
- func (h *Handler) Reset()
- func (h *Handler) Restore(ctx context.Context, data []byte) error
- func (h *Handler) RouteMatcher() service.Matcher
- func (h *Handler) Shutdown(ctx context.Context)
- func (h *Handler) Snapshot(ctx context.Context) []byte
- func (h *Handler) StartWorker(ctx context.Context) error
- type InMemoryBackend
- func (b *InMemoryBackend) CancelJob(in *batchpb.CancelJobRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) Close()
- func (b *InMemoryBackend) CreateJob(in *batchpb.CreateJobRequest) (*batchpb.Job, error)
- func (b *InMemoryBackend) DeleteJob(in *batchpb.DeleteJobRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) DeleteOperation(name string) (*emptypb.Empty, error)
- func (b *InMemoryBackend) GetJob(name string) (*batchpb.Job, error)
- func (b *InMemoryBackend) GetOperation(name string) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) GetTask(name string) (*batchpb.Task, error)
- func (b *InMemoryBackend) ListJobs(in *batchpb.ListJobsRequest) (*batchpb.ListJobsResponse, error)
- func (b *InMemoryBackend) ListOperations(in *longrunningpb.ListOperationsRequest) (*longrunningpb.ListOperationsResponse, error)
- func (b *InMemoryBackend) ListTasks(in *batchpb.ListTasksRequest) (*batchpb.ListTasksResponse, error)
- func (b *InMemoryBackend) ProjectIDs() []string
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) SetClock(now func() time.Time)
- func (b *InMemoryBackend) SetContext(ctx context.Context)
- func (b *InMemoryBackend) SetRuntime(rt Runtime, scriptImage string)
- func (b *InMemoryBackend) SetServices(s Services)
- func (b *InMemoryBackend) SetTimer(t func(d time.Duration) (<-chan time.Time, func() bool))
- func (b *InMemoryBackend) SetTiming(t Timing)
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- func (b *InMemoryBackend) WaitIdle()
- func (b *InMemoryBackend) WaitOperation(ctx context.Context, in *longrunningpb.WaitOperationRequest) (*longrunningpb.Operation, error)
- type Provider
- type Runtime
- type SecretResolver
- type Services
- type Settings
- type Timing
Constants ¶
const ( // DefaultPort is the dedicated gRPC and REST listener's default TCP port. DefaultPort = 8147 // EngineNone records jobs and progresses them on the clock without running any container. EngineNone = "none" // EngineDocker runs every task's runnables as containers. EngineDocker = "docker" // DefaultScriptImage runs script runnables, which Batch executes on the VM host. DefaultScriptImage = "debian:bookworm-slim" )
const (
// HostsFilePath is where BATCH_HOSTS_FILE points when require_hosts_file is set.
HostsFilePath = "/etc/cloudbatch-taskgroup-hosts"
)
Variables ¶
var ErrNilAppContext = errors.New("gcpbatch: nil app context")
ErrNilAppContext is returned when Init is called with a nil AppContext.
Functions ¶
This section is empty.
Types ¶
type ConfigProvider ¶
type ConfigProvider interface {
GetGCPBatchSettings() Settings
}
ConfigProvider extracts Batch configuration from the AppContext Config.
type Handler ¶
type Handler struct {
Backend *InMemoryBackend
Port int
// contains filtered or unexported fields
}
Handler serves the Batch API (gRPC and REST) on a dedicated listener.
func NewHandler ¶
func NewHandler(backend *InMemoryBackend) *Handler
NewHandler creates a Handler; callers override Port from Settings.
func (*Handler) API ¶
func (h *Handler) API() batchpb.BatchServiceServer
API returns the Batch service server for in-process callers.
func (*Handler) ExtractOperation ¶
ExtractOperation is unused: requests never reach the shared router.
func (*Handler) ExtractResource ¶
ExtractResource is unused: requests never reach the shared router.
func (*Handler) GetSupportedOperations ¶
GetSupportedOperations lists the supported gRPC methods.
func (*Handler) Handler ¶
func (h *Handler) Handler() echo.HandlerFunc
Handler returns a 404 handler; the real API is on the dedicated port.
func (*Handler) MatchPriority ¶
MatchPriority is irrelevant because RouteMatcher never matches.
func (*Handler) OperationsAPI ¶
func (h *Handler) OperationsAPI() longrunningpb.OperationsServer
OperationsAPI returns the long-running operations server for in-process callers.
func (*Handler) RouteMatcher ¶
RouteMatcher never matches: Batch runs on its own listener.
type InMemoryBackend ¶
type InMemoryBackend struct {
// contains filtered or unexported fields
}
InMemoryBackend holds all Batch state under one lock.
func NewInMemoryBackend ¶
func NewInMemoryBackend() *InMemoryBackend
NewInMemoryBackend creates an empty state-only backend on the wall clock.
func (*InMemoryBackend) CancelJob ¶
func (b *InMemoryBackend) CancelJob(in *batchpb.CancelJobRequest) (*longrunningpb.Operation, error)
CancelJob starts cancellation: the job reads CANCELLATION_IN_PROGRESS, then CANCELLED.
func (*InMemoryBackend) Close ¶
func (b *InMemoryBackend) Close()
Close cancels every running job and waits for the runners to stop.
func (*InMemoryBackend) CreateJob ¶
func (b *InMemoryBackend) CreateJob(in *batchpb.CreateJobRequest) (*batchpb.Job, error)
CreateJob validates and records a job. It returns the job without a long-running operation, as the API does.
func (*InMemoryBackend) DeleteJob ¶
func (b *InMemoryBackend) DeleteJob(in *batchpb.DeleteJobRequest) (*longrunningpb.Operation, error)
DeleteJob starts deletion: the job reads DELETION_IN_PROGRESS until the operation ends, then is gone.
func (*InMemoryBackend) DeleteOperation ¶
func (b *InMemoryBackend) DeleteOperation(name string) (*emptypb.Empty, error)
DeleteOperation removes a finished operation.
func (*InMemoryBackend) GetJob ¶
func (b *InMemoryBackend) GetJob(name string) (*batchpb.Job, error)
GetJob returns one job.
func (*InMemoryBackend) GetOperation ¶
func (b *InMemoryBackend) GetOperation(name string) (*longrunningpb.Operation, error)
GetOperation returns one operation.
func (*InMemoryBackend) GetTask ¶
func (b *InMemoryBackend) GetTask(name string) (*batchpb.Task, error)
GetTask returns one task.
func (*InMemoryBackend) ListJobs ¶
func (b *InMemoryBackend) ListJobs(in *batchpb.ListJobsRequest) (*batchpb.ListJobsResponse, error)
ListJobs lists the jobs of a location, or of every location for "-".
func (*InMemoryBackend) ListOperations ¶
func (b *InMemoryBackend) ListOperations(in *longrunningpb.ListOperationsRequest) ( *longrunningpb.ListOperationsResponse, error, )
ListOperations lists the operations of one location, ordered by name.
func (*InMemoryBackend) ListTasks ¶
func (b *InMemoryBackend) ListTasks(in *batchpb.ListTasksRequest) (*batchpb.ListTasksResponse, error)
ListTasks lists the tasks of a task group, optionally filtered by State=....
func (*InMemoryBackend) ProjectIDs ¶
func (b *InMemoryBackend) ProjectIDs() []string
ProjectIDs lists the projects that own at least one job, sorted.
func (*InMemoryBackend) Reset ¶
func (b *InMemoryBackend) Reset()
Reset stops every runner and clears all state.
func (*InMemoryBackend) Restore ¶
func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
Restore loads a snapshot, replacing all state.
func (*InMemoryBackend) SetClock ¶
func (b *InMemoryBackend) SetClock(now func() time.Time)
SetClock replaces the clock lifecycle states and timestamps derive from.
func (*InMemoryBackend) SetContext ¶
func (b *InMemoryBackend) SetContext(ctx context.Context)
SetContext sets the parent context of job runners; cancelling it stops them.
func (*InMemoryBackend) SetRuntime ¶
func (b *InMemoryBackend) SetRuntime(rt Runtime, scriptImage string)
SetRuntime turns the container engine on: new jobs run their runnables as containers.
func (*InMemoryBackend) SetServices ¶
func (b *InMemoryBackend) SetServices(s Services)
SetServices connects Secret Manager and Cloud Logging.
func (*InMemoryBackend) SetTimer ¶
SetTimer replaces the timer behind max_run_duration and runnable timeouts.
func (*InMemoryBackend) SetTiming ¶
func (b *InMemoryBackend) SetTiming(t Timing)
SetTiming replaces the state-only durations.
func (*InMemoryBackend) Snapshot ¶
func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
Snapshot serialises jobs, tasks, operations and request ids. Running containers are not kept.
func (*InMemoryBackend) WaitIdle ¶
func (b *InMemoryBackend) WaitIdle()
WaitIdle blocks until every job runner has finished.
func (*InMemoryBackend) WaitOperation ¶
func (b *InMemoryBackend) WaitOperation(ctx context.Context, in *longrunningpb.WaitOperationRequest) ( *longrunningpb.Operation, error, )
WaitOperation returns once the operation is done or the timeout passes, whichever comes first.
type Provider ¶
type Provider struct{}
Provider implements service.Provider for Batch. It serves gRPC, REST and the gateway data plane on its own listener (see Handler.StartWorker) and never matches on the shared AWS router.
func (*Provider) Init ¶
func (p *Provider) Init(ctx *service.AppContext) (service.Registerable, error)
Init creates the backend and handler; the port is bound in StartWorker.
type Runtime ¶
type Runtime interface {
CreateAndStart(ctx context.Context, spec container.Spec) (string, error)
StopAndRemove(ctx context.Context, containerID string) error
}
Runtime is the slice of the container runtime a task needs. The runtime must also implement container.ExitWaiter; it should implement container.LogStreamer (Cloud Logging output).
type SecretResolver ¶
SecretResolver reads a Secret Manager secret version ("projects/p/secrets/s/versions/v").
type Services ¶
type Services struct {
Secrets SecretResolver
Logs gcpserve.LogSink
}
Services are the emulator backends a job reads from and writes to; absent ones stay nil.
type Settings ¶
type Settings struct {
Engine string `` //nolint:lll // config struct tags are intentionally verbose
/* 290-byte string literal not displayed */
ScriptImage string `` //nolint:lll // config struct tags are intentionally verbose
/* 234-byte string literal not displayed */
Port int `` //nolint:lll // config struct tags are intentionally verbose
/* 223-byte string literal not displayed */
}
Settings holds service-level configuration, embedded in the root CLI command as CLI.GCPBatch.
func DefaultSettings ¶
func DefaultSettings() Settings
DefaultSettings returns the settings used when no ConfigProvider is available.
type Timing ¶
type Timing struct {
Schedule time.Duration
Start time.Duration
TaskRun time.Duration
Cancel time.Duration
Delete time.Duration
}
Timing sets how long a state-only job takes on the backend clock. Every task runs for TaskRun and at most parallelism tasks run at once.
func DefaultTiming ¶
func DefaultTiming() Timing
DefaultTiming returns the durations used unless a test overrides them.