clients

package
v0.0.0-...-e560ebb Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: BSD-3-Clause Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxConcurrentSwarmingCalls is the maximum number of concurrent swarming
	// calls made within the context of a single RPC call to this app.
	//
	// There is no per-instance limit (yet).
	MaxConcurrentSwarmingCalls = 20

	// BotIDDimensionKey identifies the swarming dimension containing
	// the ID of BOT
	BotIDDimensionKey = "id"
	// DutIDDimensionKey identifies the swarming dimension containing the ID for
	// the DUT corresponding to a bot.
	DutIDDimensionKey = "dut_id"
	// DutModelDimensionKey identifies the swarming dimension containing the
	// Autotest model label for the DUT.
	DutModelDimensionKey = "label-model"
	// DutPoolDimensionKey identifies the swarming dimension containing the
	// Autotest pool label for the DUT.
	DutPoolDimensionKey = "label-pool"
	// DutOSDimensionKey identifies the swarming dimension containing the
	// OS label for the DUT.
	DutOSDimensionKey = "label-os_type"
	// DutNameDimensionKey identifies the swarming dimension
	// containing the DUT name.
	DutNameDimensionKey = "dut_name"
	// DutStateDimensionKey identifies the swarming dimension containing the
	// autotest DUT state for a bot.
	DutStateDimensionKey = "dut_state"

	// PoolDimensionKey identifies the swarming pool dimension.
	PoolDimensionKey = "pool"
	// SwarmingTimeLayout is the layout used by swarming RPCs to specify timestamps.
	SwarmingTimeLayout = "2006-01-02T15:04:05.999999999"
)

Variables

View Source
var DutStateRevMap = map[fleet.DutState]string{
	fleet.DutState_Ready:             "ready",
	fleet.DutState_NeedsCleanup:      "needs_cleanup",
	fleet.DutState_NeedsRepair:       "needs_repair",
	fleet.DutState_NeedsReset:        "needs_reset",
	fleet.DutState_RepairFailed:      "repair_failed",
	fleet.DutState_NeedsManualRepair: "needs_manual_repair",
	fleet.DutState_NeedsReplacement:  "needs_replacement",
	fleet.DutState_NeedsDeploy:       "needs_deploy",
}

DutStateRevMap mapping DutState to swarming value representation

HealthyDutStates is the set of healthy DUT states.

Functions

func GetStateDimension

func GetStateDimension(dims []*swarming.SwarmingRpcsStringListPair) fleet.DutState

GetStateDimension gets the dut_state value from a dimension slice.

func NewGerritClient

func NewGerritClient(c context.Context, host string) (gerrit.GerritClient, error)

NewGerritClient returns a new gerrit client.

This function is intended to be used within the context of an RPC to this app. The returned gerrit client forwards the oauth token used for the original RPC. In particular, this means that the original oauth credentials must include the gerrit OAuth 2.0 scope.

func NewGerritClientAsSelf

func NewGerritClientAsSelf(ctx context.Context, host string) (gerrit.GerritClient, error)

NewGerritClientAsSelf returns a new gerrit client using oauth tokens for the current service itself.

This function is intended to be used from cron calls that are not part of a user session. For normal RPC users, see NewGerritClient.

func NewGitilesClient

func NewGitilesClient(c context.Context, host string) (gitiles.GitilesClient, error)

NewGitilesClient returns a new gitiles client.

This function is intended to be used within the context of an RPC to this app. The returned gitiles client forwards the oauth token used for the original RPC. In particular, this means that the original oauth credentials must include the gerrit OAuth 2.0 scope.

func NewGitilesClientAsSelf

func NewGitilesClientAsSelf(ctx context.Context, host string) (gitiles.GitilesClient, error)

NewGitilesClientAsSelf returns a new gitiles client using oauth tokens for the current service itself.

This function is intended to be used from cron calls that are not part of a user session. For normal RPC users, see NewGitilesClient.

func PushAuditDUTs

func PushAuditDUTs(ctx context.Context, botIDs, actions []string, taskname string) error

PushAuditDUTs pushes BOT ids to taskqueue auditBotsQueue for upcoming audit jobs.

func PushRepairDUTs

func PushRepairDUTs(ctx context.Context, botIDs []string, expectedState string) error

PushRepairDUTs pushes BOT ids to taskqueue repairBotsQueue for upcoming repair jobs.

func PushRepairLabstations

func PushRepairLabstations(ctx context.Context, botIDs []string) error

PushRepairLabstations pushes BOT ids to taskqueue repairLabstationQueue for upcoming repair jobs.

func TaskDoneTime

func TaskDoneTime(tr *swarming.SwarmingRpcsTaskResult) (time.Time, error)

TaskDoneTime returns the time when the given task completed on a bot. If the task was never run or is still running, this function returns a zero time.

func TimeSinceBotTask

func TimeSinceBotTask(tr *swarming.SwarmingRpcsTaskResult) (*duration.Duration, error)

TimeSinceBotTask calls TimeSinceBotTaskN with time.Now().

func TimeSinceBotTaskN

func TimeSinceBotTaskN(tr *swarming.SwarmingRpcsTaskResult, now time.Time) (*duration.Duration, error)

TimeSinceBotTaskN returns the duration.Duration elapsed since the given task completed on a bot.

This function only considers tasks that were executed by Swarming to a specific bot. For tasks that were never executed on a bot, this function returns nil duration.

Types

type BotTasksCursor

type BotTasksCursor interface {
	Next(context.Context, int64) ([]*swarming.SwarmingRpcsTaskResult, error)
}

BotTasksCursor tracks a paginated query for Swarming bot tasks.

type Pager

type Pager struct {
	// Remaining is set to the number of items to retrieve.  This
	// can be modified after Pager has been used, but not
	// concurrently.
	Remaining int
}

Pager manages pagination of API calls.

func (*Pager) Next

func (p *Pager) Next() int

Next returns the number of items to request. If there are no more items to request, returns 0.

func (*Pager) Record

func (p *Pager) Record(n int)

Record records that items have been received (since a request may not return the exact number of items requested).

type SwarmingClient

type SwarmingClient interface {
	ListAliveIdleBotsInPool(c context.Context, pool string, dims strpair.Map) ([]*swarming.SwarmingRpcsBotInfo, error)
	ListAliveBotsInPool(context.Context, string, strpair.Map) ([]*swarming.SwarmingRpcsBotInfo, error)
	ListBotTasks(id string) BotTasksCursor
	ListRecentTasks(c context.Context, tags []string, state string, limit int) ([]*swarming.SwarmingRpcsTaskResult, error)
	ListSortedRecentTasksForBot(c context.Context, botID string, limit int) ([]*swarming.SwarmingRpcsTaskResult, error)
	CreateTask(c context.Context, name string, args *SwarmingCreateTaskArgs) (string, error)
	GetTaskResult(ctx context.Context, tid string) (*swarming.SwarmingRpcsTaskResult, error)
}

SwarmingClient exposes Swarming client API used by this package.

In prod, a SwarmingClient for interacting with the Swarming service will be used. Tests should use a fake.

func NewSwarmingClient

func NewSwarmingClient(c context.Context, host string) (SwarmingClient, error)

NewSwarmingClient returns a SwarmingClient for interaction with the Swarming service.

type SwarmingCreateTaskArgs

type SwarmingCreateTaskArgs struct {
	Cmd []string
	// The task targets a dut with the given bot id.
	BotID string
	// The task targets a dut with the given dut id.
	DutID string
	// If non-empty, the task targets a dut in the given state.
	DutState             string
	DutName              string
	ExecutionTimeoutSecs int64
	ExpirationSecs       int64
	Pool                 string
	Priority             int64
	Tags                 []string
	User                 string
	Realm                string
	ServiceAccount       string
}

SwarmingCreateTaskArgs contains the arguments to SwarmingClient.CreateTask.

This struct contains only a small subset of the Swarming task arguments that is needed by this app.

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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