manager

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WorkerRole = "worker"

	DbFilemode = os.FileMode(0600)
)

Variables

View Source
var (
	MaxRestarts = 3

	LoopInterval = 10 * time.Second

	DbFile = "philharmonic.db"

	DbTaskBucket       = "tasks"
	DbEventBucket      = "events"
	DbAssignmentBucket = "assignments"
)
View Source
var (
	RestartBackoffBase = 10 * time.Second
	RestartBackoffMax  = 5 * time.Minute
)

exponential restart backoff bounds restart attempt n = base * 2^(n-1), capped at max

View Source
var ApiShutdownTimeout = 10 * time.Second

Functions

This section is empty.

Types

type Api

type Api struct {
	Address string
	Port    int
	Manager *Manager
	Router  *chi.Mux

	// enables HTTPS when non-nil
	// a non-nil config with ClientCAs set additionally requires
	// callers to authenticate with a cluster certificate via mTLS
	TLSConfig *tls.Config

	// auth enables bearer-token user authentication when non-nil
	// When nil, the API accepts unauthenticated requests
	Auth *auth.TokenStore
	// contains filtered or unexported fields
}

func (*Api) GetNodesHandler

func (a *Api) GetNodesHandler(w http.ResponseWriter, r *http.Request)

func (*Api) GetTaskLogsHandler

func (a *Api) GetTaskLogsHandler(w http.ResponseWriter, r *http.Request)

proxies a logs request to the worker that owns the task

{taskID} may be a UUID or a task name

the response is text/plain with X-Task-State and X-Exit-Code headers

func (*Api) GetTasksHandler

func (a *Api) GetTasksHandler(w http.ResponseWriter, r *http.Request)

func (*Api) PullImageHandler

func (a *Api) PullImageHandler(w http.ResponseWriter, r *http.Request)

pulls the requested image on every configured worker, or on the subset named in the body. workers are pulled concurrently, the response always carries a per-worker result, so a partial failure is reported with a 200 and per-worker errors

func (*Api) Shutdown

func (a *Api) Shutdown() error

func (*Api) Start

func (a *Api) Start() error

func (*Api) StartTaskHandler

func (a *Api) StartTaskHandler(w http.ResponseWriter, r *http.Request)

func (*Api) StopTaskHandler

func (a *Api) StopTaskHandler(w http.ResponseWriter, r *http.Request)

type Assignment

type Assignment struct {
	TaskID uuid.UUID
	Worker string
}

func (Assignment) Key

func (a Assignment) Key() uuid.UUID

type HTTPResponse

type HTTPResponse struct {
	HTTPStatusCode int
	Message        string
}

type ImagePullReport

type ImagePullReport struct {
	Image   string            `json:"image"`
	Results []ImagePullResult `json:"results"`
}

type ImagePullResult

type ImagePullResult struct {
	Worker string `json:"worker"`
	OK     bool   `json:"ok"`
	// pulled is false both when the image was already present on the worker
	// and when the pull failed
	Pulled bool   `json:"pulled"`
	Error  string `json:"error,omitempty"`
}

type Manager

type Manager struct {
	TaskDb       store.Store[task.Task]
	EventDb      store.Store[task.TaskEvent]
	Assignments  store.Store[Assignment]
	Reservations ReservationStore

	WorkerNodes []*node.Node
	Scheduler   scheduler.Scheduler
	// contains filtered or unexported fields
}

func New

func New(workers []string, schedulerType, dbType string) (*Manager, error)

func (*Manager) AddTask

func (m *Manager) AddTask(te task.TaskEvent) error

func (*Manager) Close

func (m *Manager) Close() error

func (*Manager) DoHealthChecks

func (m *Manager) DoHealthChecks(ctx context.Context)

func (*Manager) ProcessTasks

func (m *Manager) ProcessTasks(ctx context.Context)

func (*Manager) RefreshNodeStats

func (m *Manager) RefreshNodeStats(ctx context.Context)

func (*Manager) SelectWorker

func (m *Manager) SelectWorker(t *task.Task) (*node.Node, error)

func (*Manager) SendWork

func (m *Manager) SendWork()

func (*Manager) UpdateTasks

func (m *Manager) UpdateTasks(ctx context.Context)

type NodeView

type NodeView struct {
	node.Snapshot
	Address string `json:",omitempty"`
	Role    string `json:",omitempty"`
}

type PullImagesRequest

type PullImagesRequest struct {
	Image string `json:"image"`

	// workers to pull the image on, addressed by host:port
	// an empty or omitted list selects every configured worker
	Workers []string `json:"workers,omitempty"`
}

the body of POST /images.

type ReservationStore

type ReservationStore interface {
	Lock()
	Unlock()

	TryReserve(workerAddress string, t *task.Task) bool
	Release(workerAddress string, t *task.Task)
	Conflicts(workerAddress string, t *task.Task, allowOwn bool) bool
	ConflictsLocked(workerAddress string, t *task.Task, allowOwn bool) bool
	TryReserveLocked(workerAddress string, t *task.Task) bool
}

type ReservationTable

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

per worker, a map from "proto:port" to the owning task ID

func NewReservationTable

func NewReservationTable() *ReservationTable

func (*ReservationTable) Conflicts

func (rt *ReservationTable) Conflicts(workerAddress string, t *task.Task, allowOwn bool) bool

func (*ReservationTable) ConflictsLocked

func (rt *ReservationTable) ConflictsLocked(workerAddress string, t *task.Task, allowOwn bool) bool

func (*ReservationTable) Lock

func (rt *ReservationTable) Lock()

func (*ReservationTable) Release

func (rt *ReservationTable) Release(workerAddress string, t *task.Task)

func (*ReservationTable) TryReserve

func (rt *ReservationTable) TryReserve(workerAddress string, t *task.Task) bool

func (*ReservationTable) TryReserveLocked

func (rt *ReservationTable) TryReserveLocked(workerAddress string, t *task.Task) bool

func (*ReservationTable) Unlock

func (rt *ReservationTable) Unlock()

type TaskView

type TaskView struct {
	task.Task
	Worker string `json:",omitempty"`
}

type WorkerLogsResponse

type WorkerLogsResponse struct {
	StatusCode int
	Header     http.Header
	Body       []byte
}

Jump to

Keyboard shortcuts

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