client

package
v0.0.0-...-29e6843 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2018 License: Apache-2.0 Imports: 36 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) (*version.Version, 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) LoggerProducer

	// Sends a group of log messages to the API Server
	SendLogMessages(context.Context, TaskData, []apimodels.LogMessage) error
	SendProcessInfo(context.Context, TaskData, []*message.ProcessInfo) error
	SendSystemInfo(context.Context, TaskData, *message.SystemInfo) 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) 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

	// Spawn-hosts for tasks methods
	CreateHost(context.Context, TaskData, apimodels.CreateHost) error
	ListHosts(context.Context, TaskData) ([]restmodel.APIHost, 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, string, string) (*restmodel.APIHost, 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)
}

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 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

	// The writer functions return an io.Writer for use with
	// exec.Cmd operations for capturing standard output and standard
	// error from sbprocesses.
	TaskWriter(level.Priority) io.WriteCloser
	SystemWriter(level.Priority) io.WriteCloser

	// Close releases all resources by calling Close on all underlying senders.
	Close() error
}

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 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
	TaskExecution        int
	GetSubscriptionsFail bool

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

	// metrics collection
	ProcInfo map[string][]*message.ProcessInfo
	SysInfo  map[string]*message.SystemInfo

	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) error

func (*Mock) CreateSpawnHost

func (*Mock) CreateSpawnHost(ctx context.Context, distroID string, keyName string) (*model.APIHost, error)

CreateSpawnHost will return a mock host that would have been intended

func (*Mock) DeletePublicKey

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

func (*Mock) EndTask

EndTask returns a mock EndTaskResponse.

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) 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) 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) 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) 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) GetLoggerProducer

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

GetLoggerProducer constructs a single channel log producer.

func (*Mock) GetManifest

func (c *Mock) GetManifest(ctx context.Context, td TaskData) (*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) GetProcessInfoLength

func (c *Mock) GetProcessInfoLength(id string) int

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) GetSystemInfoLength

func (c *Mock) GetSystemInfoLength() int

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) GetVersion

func (c *Mock) GetVersion(ctx context.Context, td TaskData) (*version.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.APIHost, 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) 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) SendProcessInfo

func (c *Mock) SendProcessInfo(ctx context.Context, td TaskData, procs []*message.ProcessInfo) error

func (*Mock) SendSystemInfo

func (c *Mock) SendSystemInfo(ctx context.Context, td TaskData, sysinfo *message.SystemInfo) 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