client

package
v0.0.0-...-418c65a Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2019 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HTTPConflictError = errors.New(evergreen.TaskConflict)

Functions

This section is empty.

Types

type Communicator

type Communicator interface {
	// ---------------------------------------------------------------------
	// Begin legacy API methods
	// ---------------------------------------------------------------------
	//
	// Setters
	//
	// SetTimeoutStart sets the initial timeout for a request.
	SetTimeoutStart(time.Duration)
	// SetTimeoutMax sets the maximum timeout for a request.
	SetTimeoutMax(time.Duration)
	// SetMaxAttempts sets the number of attempts a request will be made.
	SetMaxAttempts(int)
	// SetHostID sets the host ID.
	SetHostID(string)
	// SetHostSecret sets the host secret.
	SetHostSecret(string)
	// GetHostID returns the host ID.
	GetHostID() string
	// GetHostSecret returns the host secret.
	GetHostSecret() string

	// Method to release resources used by the communicator.
	Close()

	// Updates the clients local concept of it's last updated
	// time; used by agents to determine timeouts.
	UpdateLastMessageTime()
	LastMessageAt() time.Time
	// Agent Operations
	//
	// StartTask marks the task as started.
	StartTask(context.Context, TaskData) error
	// EndTask marks the task as finished with the given status
	EndTask(context.Context, *apimodels.TaskEndDetail, TaskData) (*apimodels.EndTaskResponse, error)
	// GetTask returns the active task.
	GetTask(context.Context, TaskData) (*task.Task, error)
	// GetProjectRef loads the task's project.
	GetProjectRef(context.Context, TaskData) (*model.ProjectRef, error)
	// GetDistro returns the distro for the task.
	GetDistro(context.Context, TaskData) (*distro.Distro, error)
	// GetVersion loads the task's Version
	GetVersion(context.Context, TaskData) (*model.Version, error)
	// GetExpansions returns all expansions for the task known by the app server
	GetExpansions(context.Context, TaskData) (util.Expansions, error)
	// Heartbeat sends a heartbeat to the API server. The server can respond with
	// an "abort" response. This function returns true if the agent should abort.
	Heartbeat(context.Context, TaskData) (bool, error)
	// FetchExpansionVars loads expansions for a communicator's task from the API server.
	FetchExpansionVars(context.Context, TaskData) (*apimodels.ExpansionVars, error)
	// GetNextTask returns a next task response by getting the next task for a given host.
	GetNextTask(context.Context, *apimodels.GetNextTaskDetails) (*apimodels.NextTaskResponse, error)

	// Constructs a new LogProducer instance for use by tasks.
	GetLoggerProducer(context.Context, TaskData, *LoggerConfig) (LoggerProducer, error)
	GetLoggerMetadata() LoggerMetadata

	// Sends a group of log messages to the API Server
	SendLogMessages(context.Context, TaskData, []apimodels.LogMessage) error

	// The following operations use the legacy API server and are
	// used by task commands.
	SendTestResults(context.Context, TaskData, *task.LocalTestResults) error
	SendTestLog(context.Context, TaskData, *model.TestLog) (string, error)
	GetTaskPatch(context.Context, TaskData) (*patchmodel.Patch, error)
	GetPatchFile(context.Context, TaskData, string) (string, error)

	// The following operations are used by
	AttachFiles(context.Context, TaskData, []*artifact.File) error
	GetManifest(context.Context, TaskData) (*manifest.Manifest, error)
	S3Copy(context.Context, TaskData, *apimodels.S3CopyRequest) (string, error)
	KeyValInc(context.Context, TaskData, *model.KeyVal) error

	// these are for the taskdata/json plugin that saves perf data
	PostJSONData(context.Context, TaskData, string, interface{}) error
	GetJSONData(context.Context, TaskData, string, string, string) ([]byte, error)
	GetJSONHistory(context.Context, TaskData, bool, string, string) ([]byte, error)

	// GenerateTasks posts new tasks for the `generate.tasks` command.
	GenerateTasks(context.Context, TaskData, []json.RawMessage) error

	// GenerateTasksPoll polls for new tasks for the `generate.tasks` command.
	GenerateTasksPoll(context.Context, TaskData) (*apimodels.GeneratePollResponse, error)

	// Spawn-hosts for tasks methods
	CreateHost(context.Context, TaskData, apimodels.CreateHost) ([]string, error)
	ListHosts(context.Context, TaskData) ([]restmodel.CreateHost, error)

	// Client Configuration methods
	//
	SetAPIUser(string)
	SetAPIKey(string)

	// Admin methods
	//
	SetBannerMessage(context.Context, string, evergreen.BannerTheme) error
	GetBannerMessage(context.Context) (string, error)
	SetServiceFlags(context.Context, *restmodel.APIServiceFlags) error
	GetServiceFlags(context.Context) (*restmodel.APIServiceFlags, error)
	RestartRecentTasks(context.Context, time.Time, time.Time) error
	GetSettings(context.Context) (*evergreen.Settings, error)
	UpdateSettings(context.Context, *restmodel.APIAdminSettings) (*restmodel.APIAdminSettings, error)
	GetEvents(context.Context, time.Time, int) ([]interface{}, error)
	RevertSettings(context.Context, string) error

	// Host methods
	GetHostsByUser(context.Context, string) ([]*restmodel.APIHost, error)

	// Spawnhost methods
	//
	CreateSpawnHost(context.Context, *restmodel.HostRequestOptions) (*restmodel.APIHost, error)
	ModifySpawnHost(context.Context, string, host.HostModifyOptions) error
	TerminateSpawnHost(context.Context, string) error
	ChangeSpawnHostPassword(context.Context, string, string) error
	ExtendSpawnHostExpiration(context.Context, string, int) error
	GetHosts(context.Context, func([]*restmodel.APIHost) error) error

	// Fetch list of distributions evergreen can spawn
	GetDistrosList(context.Context) ([]restmodel.APIDistro, error)

	// Fetch the current authenticated user's public keys
	GetCurrentUsersKeys(context.Context) ([]restmodel.APIPubKey, error)

	AddPublicKey(context.Context, string, string) error

	// Delete a key with specified name from the current authenticated user
	DeletePublicKey(context.Context, string) error

	// List variant/task aliases
	ListAliases(context.Context, string) ([]model.ProjectAlias, error)

	// GetClientConfig fetches the ClientConfig for the evergreen server
	GetClientConfig(context.Context) (*evergreen.ClientConfig, error)

	// GetSubscriptions fetches the subscriptions for the user defined
	// in the local evergreen yaml
	GetSubscriptions(context.Context) ([]event.Subscription, error)

	// CreateVersionFromConfig takes an evergreen config and makes runnable tasks from it
	CreateVersionFromConfig(context.Context, string, string, bool, []byte) (*model.Version, error)

	// Commit Queue
	GetCommitQueue(ctx context.Context, projectID string) (*restmodel.APICommitQueue, error)
	GetCommitQueueItemAuthor(ctx context.Context, projectID, item string) (string, error)
	DeleteCommitQueueItem(ctx context.Context, projectID string, item string) error
	EnqueueItem(ctx context.Context, patchID string) (int, error)

	GetUserAuthorInfo(context.Context, TaskData, string) (*restmodel.APIUserAuthorInformation, error)

	// Notifications
	SendNotification(ctx context.Context, notificationType string, data interface{}) error

	// GetDockerLogs returns logs for the given docker container
	GetDockerLogs(ctx context.Context, hostID string, startTime time.Time, endTime time.Time, isError bool) ([]byte, error)
	GetDockerStatus(ctx context.Context, hostID string) (*cloud.ContainerStatus, error)

	// GetManifestByTask returns the manifest corresponding to the given task
	GetManifestByTask(ctx context.Context, taskId string) (*manifest.Manifest, error)
}

Communicator is an interface for communicating with the API server.

func NewCommunicator

func NewCommunicator(serverURL string) Communicator

NewCommunicator returns a Communicator capable of making HTTP REST requests against the API server. To change the default retry behavior, use the SetTimeoutStart, SetTimeoutMax, and SetMaxAttempts methods.

type LogOpts

type LogOpts struct {
	Sender            string
	SplunkServerURL   string
	SplunkToken       string
	Filepath          string
	LogkeeperURL      string
	LogkeeperBuilder  string
	LogkeeperBuildNum int
	BufferDuration    time.Duration
	BufferSize        int
}

type LoggerConfig

type LoggerConfig struct {
	System []LogOpts
	Agent  []LogOpts
	Task   []LogOpts
}

type LoggerMetadata

type LoggerMetadata struct {
	Agent  []LogkeeperMetadata
	System []LogkeeperMetadata
	Task   []LogkeeperMetadata
}

type LoggerProducer

type LoggerProducer interface {
	// The Execution/Task/System loggers provide a grip-like
	// logging interface for the distinct logging channels that the
	// Evergreen agent provides to tasks
	Execution() grip.Journaler
	Task() grip.Journaler
	System() grip.Journaler

	// Close releases all resources by calling Close on all underlying senders.
	Close() error
	// Closed returns true if this logger has been closed, false otherwise.
	Closed() bool
}

LoggerProducer provides a mechanism for agents (and command pluings) to access the process' logging facilities. The interfaces are all based on grip interfaces and abstractions, and the behavior of the interfaces is dependent on the configuration and implementation of the LoggerProducer instance.

func NewSingleChannelLogHarness

func NewSingleChannelLogHarness(name string, sender send.Sender) LoggerProducer

NewSingleChannelLogHarnness returns a log implementation that uses a LoggerProducer where Execution, Task, and System systems all use the same sender. The Local channel still wraps the default global sender.

This implementation is primarily for testing and should be used with the InternalSender, which permits introspection of log messages.

type LogkeeperMetadata

type LogkeeperMetadata struct {
	Build string
	Test  string
}

type Mock

type Mock struct {

	// mock behavior
	NextTaskShouldFail     bool
	NextTaskShouldConflict bool
	GetPatchFileShouldFail bool

	NextTaskResponse            *apimodels.NextTaskResponse
	NextTaskIsNil               bool
	EndTaskResponse             *apimodels.EndTaskResponse
	EndTaskShouldFail           bool
	EndTaskResult               endTaskResult
	ShellExecFilename           string
	TimeoutFilename             string
	HeartbeatShouldAbort        bool
	HeartbeatShouldErr          bool
	HeartbeatShouldSometimesErr bool
	TaskExecution               int
	GetSubscriptionsFail        bool
	CreatedHost                 apimodels.CreateHost

	AttachedFiles    map[string][]*artifact.File
	LogID            string
	LocalTestResults *task.LocalTestResults
	TestLogs         []*serviceModel.TestLog
	TestLogCount     int

	PatchFiles map[string]string

	LastMessageSent time.Time
	// contains filtered or unexported fields
}

Mock mocks EvergreenREST for testing.

func NewMock

func NewMock(serverURL string) *Mock

NewMock returns a Communicator for testing.

func (*Mock) AddPublicKey

func (c *Mock) AddPublicKey(ctx context.Context, keyName, keyValue string) error

func (*Mock) AttachFiles

func (c *Mock) AttachFiles(ctx context.Context, td TaskData, taskFiles []*artifact.File) error

SendFiles attaches task files.

func (*Mock) ChangeSpawnHostPassword

func (*Mock) ChangeSpawnHostPassword(context.Context, string, string) error

func (*Mock) Close

func (c *Mock) Close()

func (*Mock) CreateHost

func (c *Mock) CreateHost(ctx context.Context, td TaskData, options apimodels.CreateHost) ([]string, error)

func (*Mock) CreateSpawnHost

func (*Mock) CreateSpawnHost(ctx context.Context, spawnRequest *model.HostRequestOptions) (*model.APIHost, error)

CreateSpawnHost will return a mock host that would have been intended

func (*Mock) CreateVersionFromConfig

func (c *Mock) CreateVersionFromConfig(ctx context.Context, project, message string, active bool, config []byte) (*serviceModel.Version, error)

func (*Mock) DeleteCommitQueueItem

func (c *Mock) DeleteCommitQueueItem(ctx context.Context, projectID, item string) error

func (*Mock) DeletePublicKey

func (c *Mock) DeletePublicKey(ctx context.Context, keyName string) error

func (*Mock) EndTask

EndTask returns a mock EndTaskResponse.

func (*Mock) EnqueueItem

func (c *Mock) EnqueueItem(ctx context.Context, patchID string) (int, error)

func (*Mock) ExtendSpawnHostExpiration

func (*Mock) ExtendSpawnHostExpiration(context.Context, string, int) error

func (*Mock) FetchExpansionVars

func (c *Mock) FetchExpansionVars(ctx context.Context, td TaskData) (*apimodels.ExpansionVars, error)

FetchExpansionVars returns a mock ExpansionVars.

func (*Mock) GenerateTasks

func (c *Mock) GenerateTasks(ctx context.Context, td TaskData, jsonBytes []json.RawMessage) error

GenerateTasks posts new tasks for the `generate.tasks` command.

func (*Mock) GenerateTasksPoll

func (c *Mock) GenerateTasksPoll(ctx context.Context, td TaskData) (*apimodels.GeneratePollResponse, error)

func (*Mock) GetBannerMessage

func (c *Mock) GetBannerMessage(ctx context.Context) (string, error)

func (*Mock) GetClientConfig

func (c *Mock) GetClientConfig(ctx context.Context) (*evergreen.ClientConfig, error)

func (*Mock) GetCommitQueue

func (c *Mock) GetCommitQueue(ctx context.Context, projectID string) (*model.APICommitQueue, error)

func (*Mock) GetCommitQueueItemAuthor

func (c *Mock) GetCommitQueueItemAuthor(ctx context.Context, projectID, item string) (string, error)

func (*Mock) GetCurrentUsersKeys

func (c *Mock) GetCurrentUsersKeys(ctx context.Context) ([]model.APIPubKey, error)

func (*Mock) GetDistro

func (c *Mock) GetDistro(ctx context.Context, td TaskData) (*distro.Distro, error)

GetDistro returns a mock Distro.

func (*Mock) GetDistrosList

func (c *Mock) GetDistrosList(ctx context.Context) ([]model.APIDistro, error)

func (*Mock) GetDockerLogs

func (c *Mock) GetDockerLogs(context.Context, string, time.Time, time.Time, bool) ([]byte, error)

func (*Mock) GetDockerStatus

func (c *Mock) GetDockerStatus(context.Context, string) (*cloud.ContainerStatus, error)

func (*Mock) GetEndTaskDetail

func (c *Mock) GetEndTaskDetail() *apimodels.TaskEndDetail

GetEndTaskDetail returns the task end detail saved in the mock.

func (*Mock) GetEvents

func (c *Mock) GetEvents(ctx context.Context, ts time.Time, limit int) ([]interface{}, error)

func (*Mock) GetExpansions

func (c *Mock) GetExpansions(ctx context.Context, taskData TaskData) (util.Expansions, error)

func (*Mock) GetHostID

func (c *Mock) GetHostID() string

func (*Mock) GetHostSecret

func (c *Mock) GetHostSecret() string

func (*Mock) GetHosts

func (c *Mock) GetHosts(ctx context.Context, f func([]*model.APIHost) error) error

GetHosts will return an array with a single mock host

func (*Mock) GetHostsByUser

func (c *Mock) GetHostsByUser(ctx context.Context, user string) ([]*model.APIHost, error)

GetHostsByUser will return an array with a single mock host

func (*Mock) GetJSONData

func (c *Mock) GetJSONData(ctx context.Context, td TaskData, tn, dn, vn string) ([]byte, error)

func (*Mock) GetJSONHistory

func (c *Mock) GetJSONHistory(ctx context.Context, td TaskData, tags bool, tn, dn string) ([]byte, error)

func (*Mock) GetLoggerMetadata

func (c *Mock) GetLoggerMetadata() LoggerMetadata

func (*Mock) GetLoggerProducer

func (c *Mock) GetLoggerProducer(ctx context.Context, td TaskData, config *LoggerConfig) (LoggerProducer, error)

GetLoggerProducer constructs a single channel log producer.

func (*Mock) GetManifest

func (c *Mock) GetManifest(ctx context.Context, td TaskData) (*manifest.Manifest, error)

func (*Mock) GetManifestByTask

func (c *Mock) GetManifestByTask(context.Context, string) (*manifest.Manifest, error)

func (*Mock) GetMockMessages

func (c *Mock) GetMockMessages() map[string][]apimodels.LogMessage

GetMockMessages returns the mock's logs.

func (*Mock) GetNextTask

func (c *Mock) GetNextTask(ctx context.Context, details *apimodels.GetNextTaskDetails) (*apimodels.NextTaskResponse, error)

GetNextTask returns a mock NextTaskResponse.

func (*Mock) GetPatchFile

func (c *Mock) GetPatchFile(ctx context.Context, td TaskData, patchFileID string) (string, error)

func (*Mock) GetProjectRef

func (c *Mock) GetProjectRef(ctx context.Context, td TaskData) (*serviceModel.ProjectRef, error)

GetProjectRef returns a mock ProjectRef.

func (*Mock) GetServiceFlags

func (c *Mock) GetServiceFlags(ctx context.Context) (*model.APIServiceFlags, error)

func (*Mock) GetSettings

func (c *Mock) GetSettings(ctx context.Context) (*evergreen.Settings, error)

func (*Mock) GetSubscriptions

func (c *Mock) GetSubscriptions(_ context.Context) ([]event.Subscription, error)

func (*Mock) GetTask

func (c *Mock) GetTask(ctx context.Context, td TaskData) (*task.Task, error)

GetTask returns a mock Task.

func (*Mock) GetTaskPatch

func (c *Mock) GetTaskPatch(ctx context.Context, td TaskData) (*patchmodel.Patch, error)

func (*Mock) GetUserAuthorInfo

func (c *Mock) GetUserAuthorInfo(ctx context.Context, td TaskData, userID string) (*model.APIUserAuthorInformation, error)

func (*Mock) GetVersion

func (c *Mock) GetVersion(ctx context.Context, td TaskData) (*serviceModel.Version, error)

GetVersion return a mock Version.

func (*Mock) Heartbeat

func (c *Mock) Heartbeat(ctx context.Context, td TaskData) (bool, error)

Heartbeat returns false, which indicates the heartbeat has succeeded.

func (*Mock) KeyValInc

func (c *Mock) KeyValInc(ctx context.Context, td TaskData, kv *serviceModel.KeyVal) error

func (*Mock) LastMessageAt

func (c *Mock) LastMessageAt() time.Time

func (*Mock) ListAliases

func (c *Mock) ListAliases(ctx context.Context, keyName string) ([]serviceModel.ProjectAlias, error)

func (*Mock) ListHosts

func (c *Mock) ListHosts(_ context.Context, _ TaskData) ([]model.CreateHost, error)

func (*Mock) ModifySpawnHost

func (*Mock) ModifySpawnHost(ctx context.Context, hostID string, changes host.HostModifyOptions) error

func (*Mock) PostJSONData

func (c *Mock) PostJSONData(ctx context.Context, td TaskData, path string, data interface{}) error

func (*Mock) RestartRecentTasks

func (c *Mock) RestartRecentTasks(ctx context.Context, starAt, endAt time.Time) error

func (*Mock) RevertSettings

func (c *Mock) RevertSettings(ctx context.Context, guid string) error

func (*Mock) S3Copy

func (c *Mock) S3Copy(ctx context.Context, td TaskData, req *apimodels.S3CopyRequest) (string, error)

func (*Mock) SendLogMessages

func (c *Mock) SendLogMessages(ctx context.Context, td TaskData, msgs []apimodels.LogMessage) error

SendTaskLogMessages posts tasks messages to the api server

func (*Mock) SendNotification

func (c *Mock) SendNotification(_ context.Context, _ string, _ interface{}) error

func (*Mock) SendTestLog

func (c *Mock) SendTestLog(ctx context.Context, td TaskData, log *serviceModel.TestLog) (string, error)

SendTestLog posts a test log for a communicator's task. Is a noop if the test Log is nil.

func (*Mock) SendTestResults

func (c *Mock) SendTestResults(ctx context.Context, td TaskData, results *task.LocalTestResults) error

SendResults posts a set of test results for the communicator's task. If results are empty or nil, this operation is a noop.

func (*Mock) SetAPIKey

func (c *Mock) SetAPIKey(apiKey string)

func (*Mock) SetAPIUser

func (c *Mock) SetAPIUser(apiUser string)

func (*Mock) SetBannerMessage

func (c *Mock) SetBannerMessage(ctx context.Context, m string, t evergreen.BannerTheme) error

nolint

func (*Mock) SetHostID

func (c *Mock) SetHostID(hostID string)

func (*Mock) SetHostSecret

func (c *Mock) SetHostSecret(hostSecret string)

func (*Mock) SetMaxAttempts

func (c *Mock) SetMaxAttempts(attempts int)

func (*Mock) SetServiceFlags

func (c *Mock) SetServiceFlags(ctx context.Context, f *model.APIServiceFlags) error

func (*Mock) SetTimeoutMax

func (c *Mock) SetTimeoutMax(timeoutMax time.Duration)

func (*Mock) SetTimeoutStart

func (c *Mock) SetTimeoutStart(timeoutStart time.Duration)

nolint

func (*Mock) StartTask

func (c *Mock) StartTask(ctx context.Context, td TaskData) error

nolint

func (*Mock) TerminateSpawnHost

func (*Mock) TerminateSpawnHost(ctx context.Context, hostID string) error

func (*Mock) UpdateLastMessageTime

func (c *Mock) UpdateLastMessageTime()

func (*Mock) UpdateSettings

func (c *Mock) UpdateSettings(ctx context.Context, update *model.APIAdminSettings) (*model.APIAdminSettings, error)

type TaskData

type TaskData struct {
	ID                 string
	Secret             string
	OverrideValidation bool
}

TaskData contains the taskData.ID and taskData.Secret. It must be set for some client methods.

Jump to

Keyboard shortcuts

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