wire

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MessageTypeToTypeMap = map[MessageType]reflect.Type{}

MessageTypeToTypeMap is the reverse of TypeToMessageTypeMap to translate in reverse, and is generated at runtime from the TypeToMessageTypeMap

TypeToMessageTypeMap helps translate from type (reflect.Type) to MessageType (int16)

Functions

func GetMessageHeaderID

func GetMessageHeaderID(m Msg, fieldName string) int

GetMessageHeaderID returns the message ID in the header, if the underlying type has a header and a value for the message ID. If it doesn't have a header , or the ID is not set, this method will return 0

func SetMessageHeaderID

func SetMessageHeaderID(m Msg, fieldName string, id int)

SetMessageHeaderID uses reflection to set the message ID in the header, regardless of the underlying type of message. If the underlying type does not have a header, nothing happens

Types

type AckMsg

type AckMsg struct {
	Header MsgHeader
}

AckMsg can be sent from agent to controller or vice versa to indicate the message was received in scenarios where there is no information needed in the return path

type BreakCommandRequestMsg

type BreakCommandRequestMsg struct {
	Header MsgHeader
	// The ID of the command to send an os.Interrupt signal to
	CommandID []byte
}

BreakCommandRequestMsg is sent from the controller to the agent to have it send an os.Interrupt signal to a running command identified by CommandID. The agent will respond with an AckMsg or ErrorMsg

type CommandStatus

type CommandStatus int8

CommandStatus is an enumeration of the status in which commands can be

const (
	// The command has yielded an error
	CommandStatusError CommandStatus = -1
	// There is no status known yet
	CommandStatusUnknown CommandStatus = 0
	// The command is pending startup
	CommandStatusPending CommandStatus = 1
	// The command is running
	CommandStatusRunning CommandStatus = 2
	// The command completed running
	CommandStatusFinished CommandStatus = 3
)

type Conn

type Conn struct {
	Tag string
	// contains filtered or unexported fields
}

Conn describes a connection between agent and coordinator

func NewClient

func NewClient(host string, port int) (*Conn, error)

NewClient will open a TCP connection to the given host and port and return an instance of Conn for the connection that's open

func (*Conn) Close

func (c *Conn) Close() error

Close will close the connection

func (*Conn) Recv

func (c *Conn) Recv() (Msg, error)

Recv will try to read a Msg from the wire connection or return an error if it is unable to do so. The method call will block until either a message or error is available

func (*Conn) Send

func (c *Conn) Send(msg Msg) error

Send will encode a message into bytes and send it over the wire

func (*Conn) SetMessageID

func (c *Conn) SetMessageID(msg Msg)

SetMessageID uses an atomic message ID counter kept in the connection to assign a sequential message ID to the instance of a Msg, which is required to have a MsgHeader

type DeployFileFromS3RequestMsg

type DeployFileFromS3RequestMsg struct {
	Header        MsgHeader
	EnvironmentID []byte
	// The target path to download the file to, relative to the environment
	// folder
	TargetPath   string
	SourceBucket string
	SourcePath   string
	// Unpack the file if it is either a TAR or TAR.GZ
	Unpack bool
	// Ignore directory information in the archive
	FlatUnpack   bool
	SourceRegion string
	// Do not create a folder with the base name of the archive
	UnpackNoDir bool
}

DeployFileFromS3RequestMsg is sent from controller to agent to ask the agent to download a particular object from an S3 bucket and optionally unpack it in the given directory within a certain environment

type DeployFileFromS3ResponseMsg

type DeployFileFromS3ResponseMsg struct {
	Header  MsgHeader
	Success bool
}

DeployFileFromS3ResponseMsg is sent from agent to controller to inform the controller about the success state of the deploy request

type DeployFileRequestMsg

type DeployFileRequestMsg struct {
	Header        MsgHeader
	EnvironmentID []byte
	File          common.File
	Unpack        bool
	Offset        int64
	ExpectMore    bool
	FlatUnpack    bool
}

DeployFileRequestMsg is sent from controller to agent to deploy (smaller) files directly over the wire protocol without first having to upload it to S3. This is specifically used for deploying the configuration files which are a few KB in size

type DeployFileResponseMsg

type DeployFileResponseMsg struct {
	Header   MsgHeader
	FileHash []byte
}

DeployFileResponseMsg is sent from agent to controller to inform the controller about the success state of the deploy request

type DestroyEnvironmentMsg

type DestroyEnvironmentMsg struct {
	Header        MsgHeader
	EnvironmentID []byte
}

DestroyEnvironmentMsg is sent from controller to agent to request it to destroy the contents of a given environment

type ErrorMsg

type ErrorMsg struct {
	Header MsgHeader
	Error  string
}

ErrorMsg can be sent from agent to controller or vice versa to indicate an error occurred while processing the message

type ExecuteCommandRequestMsg

type ExecuteCommandRequestMsg struct {
	Header MsgHeader
	// The environment in which to execute the command
	EnvironmentID []byte
	// The directory, relative to the environment folder to use as working
	// folder
	Dir string
	// Environment variables to set (on top of the os.Environ)
	Env []string
	// The command (executable) to run
	Command string
	// The command line parameters to give to the command
	Parameters []string
	// Gather performance profiling while the command is running
	Profile bool
	// Run the command using `perf` to gather additional performance counters
	PerfProfile bool
	// The sample rate when running in perf (PerfProfile = true)
	PerfSampleRate int
	// Run in `gdb`
	Debug bool
	// The region in which the outputs bucket is
	S3OutputRegion string
	// The bucket in which to upload command outputs
	S3OutputBucket string
	// Gather bandwidth stats
	RecordNetworkTraffic bool
}

ExecuteCommandRequestMsg is sent from controller to agent to start a process on the agent

type ExecuteCommandResponseMsg

type ExecuteCommandResponseMsg struct {
	Header MsgHeader
	// The ID under which the command is running - will also match subsequent
	// ExecyteCommandStatusMsg messages
	CommandID []byte
	// Indicates if the command was started succesfully
	Success bool
	// If Success is false, this indicates what went wrong
	Error string
}

ExecuteCommandResponseMsg is sent by the agent to the controller in response to a ExecuteCommandRequestMsg to inform the controller wether the command has been executed succesfully. Note that this does not indicate that the command has finished running - only that it has been started. The agent will continue sending ExecuteCommandStatusMsg updates, which will eventually report the status CommandStatusFinished when the command has finished execution.

type ExecuteCommandStatusMsg

type ExecuteCommandStatusMsg struct {
	Header MsgHeader
	// The ID of the command for which an update is sent
	CommandID []byte
	// The current status of the command
	Status CommandStatus
	// If Status is CommandStatusFinished, this will contain the exit code of
	// the process
	ExitCode int
}

ExecuteCommandStatusMsg is sent by the agent to the controller to inform it of status changes

type HelloMsg

type HelloMsg struct {
	Header       MsgHeader
	SystemInfo   common.AgentSystemInfo
	AgentVersion string
}

HelloMsg is sent from agent to controller upon first connection. It identifies which version the agent is running and provides the initial system information of the agent

type HelloResponseMsg

type HelloResponseMsg struct {
	Header      MsgHeader
	YourAgentID int32
}

HelloResponseMsg is sent from controller to agent in response to HelloMsg and both acknowledges to the agent that the coordinator has accepted the HelloMsg, and tells the agent which AgentID it has on the coordinator

type Listener

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

Listener describes a server that can accept new connections

func NewServer

func NewServer(port int) (*Listener, error)

NewServer will return a new instance of Listener, which is listening on the port given in the `port` parameter

func (*Listener) Accept

func (l *Listener) Accept() (*Conn, error)

Accept will block until a new client connects, and returns an instance of Conn for that connection

type MessageType

type MessageType int16

func GetMessageType

func GetMessageType(m Msg) MessageType

GetMessageType inspects a message to determine its type and returns a MessageType (int16)

type Msg

type Msg interface {
}

func NewMessage

func NewMessage(mt MessageType) Msg

NewMessage instantiates a new message of the passed MessageType (int16)

func Receive

func Receive(rc chan Msg) (Msg, error)

Receive is a utilty function to read one message from a chan of wire messages with a timeout of 15 seconds

func ReceiveWithTimeout

func ReceiveWithTimeout(rc chan Msg, timeout time.Duration) (Msg, error)

ReceiveWithTimeout is a utilty function to read one message from a chan of wire messages with a configurable timeout

type MsgHeader

type MsgHeader struct {
	ID     int
	YourID int
}

type PingMsg

type PingMsg struct {
	Header MsgHeader
}

PingMsg is sent from the controller to the agent, which responds with an AckMsg. This message is used to see if the connection to the agent is still alive, and how long the roundtrip of the message takes

type PrepareEnvironmentReplyMsg

type PrepareEnvironmentReplyMsg struct {
	Header        MsgHeader
	EnvironmentID []byte
}

PrepareEnvironmentReplyMsg is sent from agent to controller to confirm the succesful creation of an environment, and to inform the controller about the environment's unique ID under which it can be referenced in future calls that require an environment

type PrepareEnvironmentRequestMsg

type PrepareEnvironmentRequestMsg struct {
	Header MsgHeader
}

PrepareEnvironmentRequestMsg is sent from controller to agent to request a fresh environment folder on the agent in which the agent can deploy a binary set and execute a test run

type RenameFileRequestMsg

type RenameFileRequestMsg struct {
	Header        MsgHeader
	EnvironmentID []byte
	SourcePath    string
	TargetPath    string
}

RenameFileRequestMsg is send from controller to agent and used to rename a file on the agent. The agent will respond with an RenameFileResponseMsg. Currently only used for renaming shard preseed files

type RenameFileResponseMsg

type RenameFileResponseMsg struct {
	Header  MsgHeader
	Success bool
}

RenameFileResponseMsg is sent from agent to controller to communicate the result of a Rename action

type TerminateCommandRequestMsg

type TerminateCommandRequestMsg struct {
	Header MsgHeader
	// The ID of the command to send an os.Kill signal to
	CommandID []byte
}

TerminateCommandRequestMsg is sent from the controller to the agent to have it send an os.Kill signal to a running command identified by CommandID. The agent will respond with an AckMsg or ErrorMsg

type UpdateSystemInfoMsg

type UpdateSystemInfoMsg struct {
	Header     MsgHeader
	SystemInfo common.AgentSystemInfo
}

UpdateSystemInfoMsg is sent from the agent to the controller to let the controller know the up-to-date system information of the agent. The controller will respond with an AckMsg

type UploadFileToS3RequestMsg

type UploadFileToS3RequestMsg struct {
	Header        MsgHeader
	EnvironmentID []byte
	// The source path, relative to the environment's folder, to upload the file
	// from
	SourcePath   string
	TargetBucket string
	TargetPath   string
	TargetRegion string
}

UploadFileToS3RequestMsg is sent from controller to agent to request it to upload a file from its file system to an S3 bucket such that the controller can later retrieve it. The transfer via S3 is much more efficient for many agents transferring files at once (as upposed to bottlenecking the built-in wireprotocol for this data transfer). The client sends a UploadFileToS3ResponseMsg in response to this request

type UploadFileToS3ResponseMsg

type UploadFileToS3ResponseMsg struct {
	Header  MsgHeader
	Success bool
}

UploadFileToS3ResponseMsg is a response to UploadFileToS3RequestMsg to indicate the success or failure of the S3 upload

Jump to

Keyboard shortcuts

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