model

package
v0.0.0-...-f985571 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const DeadAfter = 10 * time.Minute

DeadAfter is the amount of time after which a bot is considered dead.

Variables

This section is empty.

Functions

func FromTaskID

func FromTaskID(t TaskID) int64

FromTaskID converts an external key to the internal DB format.

Types

type Bot

type Bot struct {
	Key             string              `json:"a,omitempty"`
	SchemaVersion   int                 `json:"b,omitempty"`
	Created         time.Time           `json:"c,omitempty"`
	LastSeen        time.Time           `json:"d,omitempty"`
	Version         string              `json:"e,omitempty"`
	Deleted         bool                `json:"f,omitempty"`
	Dead            bool                `json:"g,omitempty"`
	QuarantinedMsg  string              `json:"h,omitempty"`
	MaintenanceMsg  string              `json:"i,omitempty"`
	TaskID          int64               `json:"j,omitempty"`
	AuthenticatedAs string              `json:"k,omitempty"`
	Dimensions      map[string][]string `json:"l,omitempty"`
	State           []byte              `json:"m,omitempty"`
	ExternalIP      string              `json:"n,omitempty"`
}

Bot represents a bot as known by the server.

type BotEvent

type BotEvent struct {
	Key           int64  `json:"a,omitempty"`
	SchemaVersion int    `json:"b,omitempty"`
	BotID         string `json:"c,omitempty"`
	// Information about the event.
	Time    time.Time `json:"d,omitempty"`
	Event   string    `json:"e,omitempty"`
	Message string    `json:"f,omitempty"`
	// Information copied for the bot.
	Version         string              `json:"g,omitempty"`
	AuthenticatedAs string              `json:"h,omitempty"`
	Dimensions      map[string][]string `json:"i,omitempty"`
	State           []byte              `json:"j,omitempty"`
	ExternalIP      string              `json:"k,omitempty"`
	TaskID          int64               `json:"l,omitempty"`
	QuarantinedMsg  string              `json:"m,omitempty"`
	MaintenanceMsg  string              `json:"n,omitempty"`
}

BotEvent is an event on a bot.

func (*BotEvent) InitFrom

func (e *BotEvent) InitFrom(b *Bot, now time.Time, event, msg string)

InitFrom initializes a BotEvent from a bot.

type BuildToken

type BuildToken struct {
	BuildID         int64  `json:"a,omitempty"`
	Token           string `json:"b,omitempty"`
	BuildbucketHost string `json:"c,omitempty"`
}

BuildToken is a LUCI Buildbucket token.

type CIPDPackage

type CIPDPackage struct {
	PkgName string `json:"a,omitempty"`
	Version string `json:"b,omitempty"`
	Path    string `json:"c,omitempty"`
}

CIPDPackage declares a LUCI CIPD package.

type Cache

type Cache struct {
	Name string `json:"a,omitempty"`
	Path string `json:"b,omitempty"`
}

Cache is a named cache that survives across tasks.

type Containment

type Containment struct {
	ContainmentType ContainmentType `json:"a,omitempty"`
}

Containment declares the type of process containment the bot shall do.

type ContainmentType

type ContainmentType int

ContainmentType declares the type of process containment the bot shall do.

const (
	ContainmentNotSpecified ContainmentType = iota
	ContainmentNone
	ContainmentAuto
	ContainmentJobObject
)

Valid ContainmentType.

type DB

type DB interface {
	Tables
	io.Closer
	// Snapshot ensures there's a copy on disk in case of a crash.
	Snapshot() error
}

DB is a database backend.

func NewDBJSON

func NewDBJSON(p string) (DB, error)

NewDBJSON opens file p.

Use "db.json.zst".

func NewDBSqlite3

func NewDBSqlite3(p string) (DB, error)

NewDBSqlite3 creates or opens a sqlite3 DB.

type Digest

type Digest struct {
	Size int64    `json:"a,omitempty"`
	Hash [32]byte `json:"b,omitempty"`
}

Digest is a more memory efficient version of rbe.Digest.

func (*Digest) FromProto

func (d *Digest) FromProto(p *rbe.Digest) error

FromProto converts from RBE's digest message.

func (*Digest) ToProto

func (d *Digest) ToProto(p *rbe.Digest)

ToProto converts to RBE's digest message.

type Filter

type Filter struct {
	Cursor   string
	Limit    int
	Earliest time.Time
	Latest   time.Time
}

Filter is a set of typical filters

type ResultDB

type ResultDB struct {
	Host       string `json:"a,omitempty"`
	Invocation string `json:"b,omitempty"`
}

ResultDB declares the LUCI ResultDB information.

type Tables

type Tables interface {
	TaskRequestGet(id int64, r *TaskRequest)
	// TaskRequestAdd adds a new TaskRequest. It is immutable so it is an error
	// to add two TaskRequest with the same key.
	TaskRequestAdd(r *TaskRequest)
	TaskRequestCount() int64
	TaskRequestSlice(f Filter) ([]TaskRequest, string)

	TaskResultGet(id int64, r *TaskResult)
	TaskResultSet(r *TaskResult)
	TaskResultCount() int64
	TaskResultSlice(botid string, f Filter, state TaskStateQuery, sort TaskSort) ([]TaskResult, string)

	BotGet(id string, b *Bot)
	BotSet(b *Bot)
	BotCount(dims map[string]string) (total, quarantined, maintenance, dead, busy int64)
	BotGetSlice(cursor string, limit int) ([]Bot, string)

	BotEventAdd(e *BotEvent)
	BotEventGetSlice(botid string, f Filter) ([]BotEvent, string)
}

Tables is the functions to access Swarming DB tables.

type TaskID

type TaskID string

TaskID is a task ID as presented to the user.

func ToTaskID

func ToTaskID(key int64) TaskID

ToTaskID converts an internal DB key to a external format.

type TaskOutput

type TaskOutput struct {
	Size int64 `json:"a,omitempty"`
}

TaskOutput stores the task's output.

type TaskOutputs

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

TaskOutputs is a good enough task outputs manager.

It uses a files backed store.

TODO: Implement compression.

func NewTaskOutputs

func NewTaskOutputs(root string) (*TaskOutputs, error)

NewTaskOutputs returns an initialized TaskOutputs.

func (*TaskOutputs) Loop

func (t *TaskOutputs) Loop(ctx context.Context, max int, cutoff time.Duration)

Loop should be run to lazily close file handles.

func (*TaskOutputs) ReadOutput

func (t *TaskOutputs) ReadOutput(key, offset int64, max int) ([]byte, error)

ReadOutput reads the task output from a file at the specified offset.

func (*TaskOutputs) SetOutput

func (t *TaskOutputs) SetOutput(key, offset int64, content []byte) error

SetOutput sets the output for a task at the specified offset.

type TaskProperties

type TaskProperties struct {
	Caches       []Cache             `json:"a,omitempty"`
	Command      []string            `json:"b,omitempty"`
	RelativeWD   string              `json:"c,omitempty"`
	CASHost      string              `json:"d,omitempty"`
	Input        Digest              `json:"e,omitempty"`
	CIPDHost     string              `json:"f,omitempty"`
	CIPDClient   CIPDPackage         `json:"g,omitempty"`
	CIPDPackages []CIPDPackage       `json:"h,omitempty"`
	Dimensions   map[string]string   `json:"i,omitempty"`
	Env          map[string]string   `json:"j,omitempty"`
	EnvPrefixes  map[string][]string `json:"k,omitempty"`
	HardTimeout  time.Duration       `json:"l,omitempty"`
	GracePeriod  time.Duration       `json:"m,omitempty"`
	IOTimeout    time.Duration       `json:"n,omitempty"`
	SecretBytes  []byte              `json:"o,omitempty"`
	Idempotent   bool                `json:"p,omitempty"`
	Outputs      []string            `json:"q,omitempty"`
	Containment  Containment         `json:"r,omitempty"`
}

TaskProperties declares what the task runs.

func (*TaskProperties) ValidateAndSetDefaults

func (t *TaskProperties) ValidateAndSetDefaults() error

ValidateAndSetDefaults set default values and returns an error if the task request is invalid.

type TaskRequest

type TaskRequest struct {
	Key                 int64       `json:"a,omitempty"`
	SchemaVersion       int64       `json:"b,omitempty"`
	Created             time.Time   `json:"c,omitempty"`
	Priority            int32       `json:"d,omitempty"`
	ParentTask          int64       `json:"e,omitempty"`
	Tags                []string    `json:"f,omitempty"`
	TaskSlices          []TaskSlice `json:"g,omitempty"`
	Name                string      `json:"h,omitempty"`
	ManualTags          []string    `json:"i,omitempty"`
	Authenticated       string      `json:"j,omitempty"`
	User                string      `json:"k,omitempty"`
	ServiceAccount      string      `json:"l,omitempty"`
	PubSubTopic         string      `json:"m,omitempty"`
	PubSubAuthToken     string      `json:"n,omitempty"`
	PubSubUserData      string      `json:"o,omitempty"`
	ResultDBUpdateToken string      `json:"p,omitempty"`
	Realm               string      `json:"q,omitempty"`
	ResultDB            bool        `json:"r,omitempty"`
	BuildToken          BuildToken  `json:"s,omitempty"`
}

TaskRequest is a single requested task by a client. It is immutable.

func (*TaskRequest) ValidateAndSetDefaults

func (t *TaskRequest) ValidateAndSetDefaults() error

ValidateAndSetDefaults set default values and returns an error if the task request is invalid.

type TaskResult

type TaskResult struct {
	Key              int64               `json:"a,omitempty"`
	SchemaVersion    int                 `json:"b,omitempty"`
	BotID            string              `json:"c,omitempty"`
	BotVersion       string              `json:"d,omitempty"`
	BotDimensions    map[string][]string `json:"e,omitempty"`
	BotIdleSince     time.Duration       `json:"f,omitempty"`
	ServerVersions   []string            `json:"g,omitempty"`
	CurrentTaskSlice int32               `json:"h,omitempty"`
	DedupedFrom      int64               `json:"i,omitempty"`
	PropertiesHash   string              `json:"j,omitempty"`
	TaskOutput       TaskOutput          `json:"k,omitempty"`
	ExitCode         int32               `json:"l,omitempty"`
	InternalFailure  string              `json:"m,omitempty"`
	State            TaskState           `json:"n,omitempty"`
	Children         []int64             `json:"o,omitempty"`
	Output           Digest              `json:"p,omitempty"`
	CIPDClientUsed   CIPDPackage         `json:"q,omitempty"`
	CIPDPins         []CIPDPackage       `json:"r,omitempty"`
	ResultDB         ResultDB            `json:"s,omitempty"`
	Duration         time.Duration       `json:"t,omitempty"`
	Started          time.Time           `json:"u,omitempty"`
	Completed        time.Time           `json:"v,omitempty"`
	Abandoned        time.Time           `json:"w,omitempty"`
	Modified         time.Time           `json:"x,omitempty"`
	Cost             float64             `json:"y,omitempty"`
	Killing          bool                `json:"z,omitempty"`
	DeadAfter        time.Time           `json:"aa,omitempty"`
}

TaskResult is the result of running a TaskRequest.

type TaskSlice

type TaskSlice struct {
	Properties      TaskProperties `json:"a,omitempty"`
	Expiration      time.Duration  `json:"b,omitempty"`
	WaitForCapacity bool           `json:"c,omitempty"`
}

TaskSlice defines one "option" to run the task.

func (*TaskSlice) ValidateAndSetDefaults

func (t *TaskSlice) ValidateAndSetDefaults() error

ValidateAndSetDefaults set default values and returns an error if the task request is invalid.

type TaskSort

type TaskSort int

TaskSort is a way to sort tasks.

const (
	TaskSortCreated TaskSort = iota
	TaskSortModified
	TaskSortCompleted
	TaskSortAbandoned
	TaskSortStarted
)

Valid TaskSort.

type TaskState

type TaskState int64

TaskState is the state of the task request.

const (
	Running TaskState = iota
	Pending
	Expired
	Timedout
	BotDied
	Canceled
	Completed
	Killed
	NoResource
)

Valid TaskState.

type TaskStateQuery

type TaskStateQuery int

TaskStateQuery filters on different kinds of tasks.

const (
	TaskStateQueryPending TaskStateQuery = iota
	TaskStateQueryRunning
	TaskStateQueryPendingRunning
	TaskStateQueryCompleted
	TaskStateQueryCompletedSuccess
	TaskStateQueryCompletedFailure
	TaskStateQueryExpired
	TaskStateQueryTimedOut
	TaskStateQueryBotDied
	TaskStateQueryCanceled
	TaskStateQueryAll
	TaskStateQueryDeduped
	TaskStateQueryKilled
	TaskStateQueryNoResource
)

Valid TaskStateQuery.

Jump to

Keyboard shortcuts

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