client

package
v0.0.0-...-c8ce297 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Communicator

type Communicator interface {
	SharedCommunicator

	// The following operations are not implemented at the base level
	// and require either a host or pod-specific implementation.
	// EndTask marks the task as finished with the given status
	EndTask(context.Context, *apimodels.TaskEndDetail, TaskData) (*apimodels.EndTaskResponse, error)
	// GetNextTask returns a next task response by getting the next task for a given host.
	GetNextTask(context.Context, *apimodels.GetNextTaskDetails) (*apimodels.NextTaskResponse, error)
	// GetAgentSetupData populates an agent with the necessary data, including secrets.
	GetAgentSetupData(context.Context) (*apimodels.AgentSetupData, error)
}

func NewHostCommunicator

func NewHostCommunicator(serverURL, hostID, hostSecret string) Communicator

NewHostCommunicator returns a Communicator capable of making HTTP REST requests against the API server for an agent running on a host. To change the default retry behavior, use the SetTimeoutStart, SetTimeoutMax, and SetMaxAttempts methods.

func NewPodCommunicator

func NewPodCommunicator(serverURL, podID, podSecret string) Communicator

NewPodCommunicator returns a Communicator capable of making HTTP requests against the API server for an agent running in a pod.

type EndTaskResult

type EndTaskResult struct {
	Detail   *apimodels.TaskEndDetail
	TaskData TaskData
}

type LogOpts

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

type LoggerConfig

type LoggerConfig struct {
	System             []LogOpts
	Agent              []LogOpts
	Task               []LogOpts
	SendToGlobalSender bool
	AWSCredentials     *credentials.Credentials
	RedactorOpts       redactor.RedactionOptions
}

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

	// Flush flushes the underlying senders.
	Flush(context.Context) error

	// 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 plugins) 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
	GetPatchFileShouldFail bool
	TaskShouldRetryOnFail  bool

	NextTaskResponse              *apimodels.NextTaskResponse
	NextTaskIsNil                 bool
	StartTaskShouldFail           bool
	GetTaskResponse               *task.Task
	GetProjectResponse            *serviceModel.Project
	EndTaskResponse               *apimodels.EndTaskResponse
	EndTaskShouldFail             bool
	EndTaskResult                 EndTaskResult
	ShellExecFilename             string
	TimeoutFilename               string
	GenerateTasksShouldFail       bool
	HeartbeatShouldAbort          bool
	HeartbeatShouldConflict       bool
	HeartbeatShouldErr            bool
	HeartbeatShouldSometimesErr   bool
	HeartbeatCount                int
	TaskExecution                 int
	CreatedHost                   apimodels.CreateHost
	GetTaskPatchResponse          *patchmodel.Patch
	GetLoggerProducerShouldFail   bool
	CreateInstallationTokenFail   bool
	CreateInstallationTokenResult string

	CedarGRPCConn *grpc.ClientConn

	AttachedFiles    map[string][]*artifact.File
	LogID            string
	LocalTestResults []testresult.TestResult
	ResultsService   string
	ResultsFailed    bool
	TestLogs         []*testlog.TestLog
	TestLogCount     int

	PatchFiles map[string]string

	// Mock data returned from methods
	LastMessageSent  time.Time
	DownstreamParams []patchmodel.Parameter
	// contains filtered or unexported fields
}

Mock mocks the Communicator for testing.

func NewMock

func NewMock(serverURL string) *Mock

NewMock returns a Communicator for testing.

func (*Mock) AttachFiles

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

SendFiles attaches task files.

func (*Mock) Close

func (c *Mock) Close()

func (*Mock) ConcludeMerge

func (c *Mock) ConcludeMerge(ctx context.Context, patchId, status string, td TaskData) error

func (*Mock) CreateHost

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

func (*Mock) CreateInstallationToken

func (c *Mock) CreateInstallationToken(ctx context.Context, td TaskData, owner, repo string) (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) DisableHost

func (c *Mock) DisableHost(ctx context.Context, hostID string, info apimodels.DisableInfo) error

DisableHost signals to the app server that the host should be disabled.

func (*Mock) EndTask

EndTask returns a mock EndTaskResponse.

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

func (c *Mock) GetAdditionalPatches(ctx context.Context, patchId string, td TaskData) ([]string, error)

func (*Mock) GetAgentSetupData

func (c *Mock) GetAgentSetupData(ctx context.Context) (*apimodels.AgentSetupData, error)

func (*Mock) GetCedarConfig

func (c *Mock) GetCedarConfig(ctx context.Context) (*apimodels.CedarConfig, error)

GetCedarConfig returns a mock Cedar service configuration.

func (*Mock) GetCedarGRPCConn

func (c *Mock) GetCedarGRPCConn(ctx context.Context) (*grpc.ClientConn, error)

GetCedarGRPCConn returns gRPC connection if it is set.

func (*Mock) GetDisplayTaskInfoFromExecution

func (c *Mock) GetDisplayTaskInfoFromExecution(ctx context.Context, td TaskData) (*apimodels.DisplayTaskInfo, error)

func (*Mock) GetDistroAMI

func (c *Mock) GetDistroAMI(context.Context, string, string, TaskData) (string, error)

func (*Mock) GetDistroView

func (c *Mock) GetDistroView(context.Context, TaskData) (*apimodels.DistroView, 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) GetExpansions

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

func (*Mock) GetExpansionsAndVars

func (c *Mock) GetExpansionsAndVars(ctx context.Context, taskData TaskData) (*apimodels.ExpansionsAndVars, error)

GetExpansionsAndVars returns a mock ExpansionsAndVars.

func (*Mock) GetHeartbeatCount

func (c *Mock) GetHeartbeatCount() int

GetHeartbeatCount returns the current number of recorded heartbeats. This is thread-safe.

func (*Mock) GetLoggerProducer

func (c *Mock) GetLoggerProducer(ctx context.Context, tsk *task.Task, _ *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) 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) GetProject

func (c *Mock) GetProject(ctx context.Context, td TaskData) (*serviceModel.Project, error)

GetProject returns the mock project. If an explicit GetProjectResponse is specified, it will return that. Otherwise, by default, it will load data from the agent's testdata directory, which contains project YAML files for testing. The task ID is used to identify the name of the YAML file it will load.

func (*Mock) GetProjectRef

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

GetProjectRef returns a mock ProjectRef.

func (*Mock) GetPullRequestInfo

func (c *Mock) GetPullRequestInfo(ctx context.Context, taskData TaskData, prNum int, owner, repo string, lastAttempt bool) (*apimodels.PullRequestInfo, error)

func (*Mock) GetTask

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

GetTask returns a mock Task.

func (*Mock) GetTaskLogs

func (c *Mock) GetTaskLogs(taskID string) []log.LogLine

func (*Mock) GetTaskPatch

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

func (*Mock) Heartbeat

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

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

func (c *Mock) ListHosts(_ context.Context, _ TaskData) (model.HostListResults, error)

func (*Mock) MarkFailedTaskToRestart

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

func (*Mock) NewPush

func (*Mock) SendTestLog

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

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

func (*Mock) SetDownstreamParams

func (c *Mock) SetDownstreamParams(ctx context.Context, downstreamParams []patchmodel.Parameter, taskData TaskData) error

func (*Mock) SetMaxAttempts

func (c *Mock) SetMaxAttempts(attempts int)

func (*Mock) SetResultsInfo

func (c *Mock) SetResultsInfo(ctx context.Context, _ TaskData, service string, failed bool) error

func (*Mock) SetTimeoutMax

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

func (*Mock) SetTimeoutStart

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

func (*Mock) StartTask

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

func (*Mock) UpdateLastMessageTime

func (c *Mock) UpdateLastMessageTime()

func (*Mock) UpdatePushStatus

func (c *Mock) UpdatePushStatus(ctx context.Context, td TaskData, pushLog *serviceModel.PushLog) error

func (*Mock) UpsertCheckRun

func (c *Mock) UpsertCheckRun(ctx context.Context, td TaskData, checkRunOutput apimodels.CheckRunOutput) error

type SharedCommunicator

type SharedCommunicator interface {
	// Close is a method to release resources used by the communicator.
	Close()
	// UpdateLastMessageTime Updates the clients local concept of it's last updated
	// time; used by agents to determine timeouts.
	UpdateLastMessageTime()
	LastMessageAt() time.Time

	// StartTask marks the task as started.
	StartTask(context.Context, TaskData) error
	// GetTask returns the active task.
	GetTask(context.Context, TaskData) (*task.Task, error)
	// GetDisplayTaskInfoFromExecution returns the display task info of an
	// execution task, if it exists. It will return an empty struct and no
	// error if the task is not part of a display task.
	GetDisplayTaskInfoFromExecution(context.Context, TaskData) (*apimodels.DisplayTaskInfo, error)
	// GetProjectRef loads the task's project ref.
	GetProjectRef(context.Context, TaskData) (*model.ProjectRef, error)
	// GetDistroView returns the view of the distro information for the task.
	GetDistroView(context.Context, TaskData) (*apimodels.DistroView, error)
	// GetDistroAMI gets the AMI for the given distro/region
	GetDistroAMI(context.Context, string, string, TaskData) (string, error)
	// GetProject loads the project using the task's version ID.
	GetProject(context.Context, TaskData) (*model.Project, error)
	// Heartbeat will return a non-empty task status if the agent should stop running the task.
	// Returning evergreen.TaskFailed means that the task has been aborted. An empty string
	// indicates the heartbeat has succeeded.
	Heartbeat(context.Context, TaskData) (string, error)
	// GetExpansionsAndVars returns the expansions, project variables, and
	// version parameters. For expansions, all expansions are loaded except for
	// the expansions defined for this task's build variant. For variables,
	// project variables, project private variables, and version parameters are
	// included, but not project parameters.
	GetExpansionsAndVars(context.Context, TaskData) (*apimodels.ExpansionsAndVars, error)
	// GetCedarConfig returns the Cedar service configuration.
	GetCedarConfig(context.Context) (*apimodels.CedarConfig, error)
	// GetCedarGRPCConn returns the client connection to cedar if it exists, or
	// creates it if it doesn't exist.
	GetCedarGRPCConn(context.Context) (*grpc.ClientConn, error)
	// SetResultsInfo sets the test results information in the task.
	SetResultsInfo(context.Context, TaskData, string, bool) error

	// GetPullRequestInfo takes in a PR number, owner, and repo and returns information from the corresponding pull request.
	GetPullRequestInfo(context.Context, TaskData, int, string, string, bool) (*apimodels.PullRequestInfo, error)

	// DisableHost signals to the app server that the host should be disabled.
	DisableHost(context.Context, string, apimodels.DisableInfo) error

	// GetLoggerProducer constructs a new LogProducer instance for use by tasks.
	GetLoggerProducer(context.Context, *task.Task, *LoggerConfig) (LoggerProducer, error)

	// The following operations are used by task commands.
	SendTestLog(context.Context, TaskData, *testlog.TestLog) (string, error)
	GetTaskPatch(context.Context, TaskData, string) (*patchmodel.Patch, error)
	GetPatchFile(context.Context, TaskData, string) (string, error)

	NewPush(context.Context, TaskData, *apimodels.S3CopyRequest) (*model.PushLog, error)
	UpdatePushStatus(context.Context, TaskData, *model.PushLog) error
	AttachFiles(context.Context, TaskData, []*artifact.File) error
	GetManifest(context.Context, TaskData) (*manifest.Manifest, error)
	KeyValInc(context.Context, TaskData, *model.KeyVal) 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.HostListResults, 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)

	// ConcludeMerge reports the status of a commit queue merge back to the server
	ConcludeMerge(ctx context.Context, patchId, status string, td TaskData) error
	GetAdditionalPatches(ctx context.Context, patchId string, td TaskData) ([]string, error)

	SetDownstreamParams(ctx context.Context, downstreamParams []patchmodel.Parameter, taskData TaskData) error

	// CreateInstallationToken creates an installation token for the given owner and repo if there is a GitHub app installed.
	CreateInstallationToken(ctx context.Context, td TaskData, owner, repo string) (string, error)

	// MarkFailedTaskToRestart marks the task as needing to be restarted
	MarkFailedTaskToRestart(ctx context.Context, td TaskData) error

	// UpsertCheckRun upserts a checkrun for a task
	UpsertCheckRun(ctx context.Context, td TaskData, checkRunOutput apimodels.CheckRunOutput) error
}

SharedCommunicator contains operations that do not depend on the task’s runtime environment (i.e. host or container). They will only have a single non-mock implementation.

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