updateutil

package
v0.0.0-...-955c50f Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 29 Imported by: 18

Documentation

Overview

Package updateutil contains updater specific utilities.

Package updateutil contains updater specific utilities.

Package updateutil contains updater specific utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildMessage

func BuildMessage(err error, format string, params ...interface{}) (message string)

BuildMessage builds the messages with provided format, error and arguments

func BuildMessages

func BuildMessages(errs []error, format string, params ...interface{}) (message string)

BuildMessages builds the messages with provided format, error and arguments

func BuildUpdateCommand

func BuildUpdateCommand(cmd string, arg string, value string) string

BuildUpdateCommand builds command string with argument and value

func CompareVersion

func CompareVersion(versionOne string, versionTwo string) (int, error)

func ConvertToUpdateErrorCode

func ConvertToUpdateErrorCode(errorCodes ...string) updateconstants.ErrorCode

ConvertToUpdateErrorCode joins the error string array passed and converts to update error code

func GetCommandPid

func GetCommandPid(cmd *exec.Cmd) int

getCommandPid returns the pid of the process if present, defaults to pid -1

func GetManifestURLFromSourceUrl

func GetManifestURLFromSourceUrl(sourceURL string) (string, error)

GetManifestURLFromSourceUrl parses source url passed to the updater and generates the url for manifest

func GetStableURLFromManifestURL

func GetStableURLFromManifestURL(manifestURL string, identity identity.IAgentIdentity) (string, error)

func InstallerFilePath

func InstallerFilePath(updateRoot string, packageName string, version string, installer string) (file string)

InstallerFilePath returns Installer file path

func IsIdentityRuntimeConfigSupported

func IsIdentityRuntimeConfigSupported(sourceVersion string) bool

IsIdentityRuntimeConfigSupported returns true if source agent version is greater than 3.1.282.0, any error defaults to false this logic is required to ensure that updater does not rely on an old runtime config if an agent has been downgraded from a version that supported identity runtimeconfig and also to skip the runtimeconfig check when we know it does not exist

func IsV1UpdatePlugin

func IsV1UpdatePlugin(SourceVersion string) bool

IsV1UpdatePlugin returns true if source agent version is equal or below 3.0.882.0, any error defaults to false

this logic is required since moving logic from plugin to updater would otherwise lead
to duplicate aws console logging when upgrading from V1UpdatePlugin agents

func ResolveAgentReleaseBucketURL

func ResolveAgentReleaseBucketURL(region string, identity identity.IAgentIdentity) string

ResolveAgentReleaseBucketURL makes best effort to generate an url for the ssm agent bucket

func ResolveUpdateRoot

func ResolveUpdateRoot(sourceVersion string) (string, error)

ResolveUpdateRoot returns the platform specific path to update artifacts

func UnInstallerFilePath

func UnInstallerFilePath(updateRoot string, packageName string, version string, uninstaller string) (file string)

UnInstallerFilePath returns UnInstaller file path

func UpdateArtifactFolder

func UpdateArtifactFolder(updateRoot string, packageName string, version string) (folder string)

UpdateArtifactFolder returns the folder path for storing all the update artifacts

func UpdateContextFilePath

func UpdateContextFilePath(updateRoot string) (filePath string)

UpdateContextFilePath returns Context file path

func UpdateOutputDirectory

func UpdateOutputDirectory(updateRoot string) string

UpdateOutputDirectory returns output directory

func UpdatePluginResultFilePath

func UpdatePluginResultFilePath(updateRoot string) (filePath string)

UpdatePluginResultFilePath returns update plugin result file path

func UpdateStdErrPath

func UpdateStdErrPath(updateRoot string, fileName string) string

UpdateStdErrPath returns stand error file path

func UpdateStdOutPath

func UpdateStdOutPath(updateRoot string, fileName string) string

UpdateStdOutPath returns stand output file path

func UpdaterFilePath

func UpdaterFilePath(updateRoot string, updaterPackageName string, version string) (filePath string)

UpdaterFilePath returns updater file path

Types

type T

type T interface {
	CreateUpdateDownloadFolder() (folder string, err error)
	ExeCommand(log log.T, cmd string, workingDir string, updaterRoot string, stdOut string, stdErr string, isAsync bool) (pid int, exitCode updateconstants.UpdateScriptExitCode, err error)
	ExecCommandWithOutput(log log.T, cmd string, workingDir string, updaterRoot string, stdOut string, stdErr string) (pId int, updExitCode updateconstants.UpdateScriptExitCode, stdoutBytes *bytes.Buffer, errorBytes *bytes.Buffer, cmdErr error)
	IsServiceRunning(log log.T, i updateinfo.T) (result bool, err error)
	IsWorkerRunning(log log.T) (result bool, err error)
	WaitForServiceToStart(log log.T, i updateinfo.T, targetVersion string) (result bool, err error)
	SaveUpdatePluginResult(log log.T, updaterRoot string, updateResult *UpdatePluginResult) (err error)
	IsDiskSpaceSufficientForUpdate(log log.T) (bool, error)
	UpdateInstallDelayer(ctx context.T, updateRoot string) error
	LoadUpdateDocumentState(ctx context.T, commandId string) error
	UpdateExecutionTimeOut(int)
	GetExecutionTimeOut() int
}

T represents the interface for Update utility

type UpdatePluginResult

type UpdatePluginResult struct {
	StandOut      string    `json:"StandOut"`
	StartDateTime time.Time `json:"StartDateTime"`
}

UpdatePluginResult represents Agent update plugin result

func LoadUpdatePluginResult

func LoadUpdatePluginResult(
	log log.T, updateRoot string) (updateResult *UpdatePluginResult, err error)

LoadUpdatePluginResult loads UpdatePluginResult from local storage

type Utility

type Utility struct {
	Context                               context.T
	CustomUpdateExecutionTimeoutInSeconds int
	ProcessExecutor                       executor.IExecutor
	UpdateDocState                        contracts.DocumentState
}

Utility implements interface T

func NewUpdaterUtilWithLoadedDocContent

func NewUpdaterUtilWithLoadedDocContent(ctx context.T, commandId string) *Utility

func (*Utility) CreateInstanceInfo

func (util *Utility) CreateInstanceInfo(log log.T) (context updateinfo.T, err error)

CreateInstanceInfo create instance related information such as region, platform and arch

func (*Utility) CreateUpdateDownloadFolder

func (util *Utility) CreateUpdateDownloadFolder() (folder string, err error)

CreateUpdateDownloadFolder creates folder for storing update downloads

func (*Utility) ExeCommand

func (util *Utility) ExeCommand(
	log log.T,
	cmd string,
	workingDir string,
	outputRoot string,
	stdOut string,
	stdErr string,
	isAsync bool) (int, updateconstants.UpdateScriptExitCode, error)

ExeCommand executes shell command

func (*Utility) ExeCommandOutput

func (util *Utility) ExeCommandOutput(
	log log.T,
	cmd string,
	parameters []string,
	workingDir string,
	outputRoot string,
	stdOutFileName string,
	stdErrFileName string,
	usePlatformSpecificCommand bool) (output string, err error)

TODO move to commandUtil ExeCommandOutput executes shell command and returns the stdout

func (*Utility) ExecCommandWithOutput

func (util *Utility) ExecCommandWithOutput(
	log log.T,
	cmd string,
	workingDir string,
	outputRoot string,
	stdOut string,
	stdErr string) (pId int, updExitCode updateconstants.UpdateScriptExitCode, stdoutBytes *bytes.Buffer, errorBytes *bytes.Buffer, cmdErr error)

ExecCommandWithOutput executes shell command and returns output and error of command execution

func (*Utility) GetExecutionTimeOut

func (util *Utility) GetExecutionTimeOut() int

GetExecutionTimeOut returns the command execution timeout

func (*Utility) IsDiskSpaceSufficientForUpdate

func (util *Utility) IsDiskSpaceSufficientForUpdate(log log.T) (bool, error)

IsDiskSpaceSufficientForUpdate loads disk space info and checks the available bytes Returns true if the system has at least 100 Mb for available disk space or false if it is less than 100 Mb

func (*Utility) IsServiceRunning

func (util *Utility) IsServiceRunning(log log.T, i updateinfo.T) (result bool, err error)

IsServiceRunning returns is service running

func (*Utility) IsWorkerRunning

func (util *Utility) IsWorkerRunning(log log.T) (result bool, err error)

IsWorkerRunning returns true if ssm-agent-worker running

func (*Utility) LoadUpdateDocumentState

func (util *Utility) LoadUpdateDocumentState(ctx context.T, commandId string) error

LoadUpdateDocumentState loads the update document state from Pending queue

func (*Utility) NewExeCommandOutput

func (util *Utility) NewExeCommandOutput(
	log log.T,
	cmd string,
	parameters []string,
	workingDir string,
	outputRoot string,
	stdoutWriter io.Writer,
	stderrWriter io.Writer,
	usePlatformSpecificCommand bool) (output string, err error)

TODO move to commandUtil ExeCommandOutput executes shell command and returns the stdout

func (*Utility) SaveUpdatePluginResult

func (util *Utility) SaveUpdatePluginResult(
	log log.T, updateRoot string, updateResult *UpdatePluginResult) (err error)

SaveUpdatePluginResult saves UpdatePluginResult to the local storage

func (*Utility) UpdateExecutionTimeOut

func (util *Utility) UpdateExecutionTimeOut(timeout int)

UpdateExecutionTimeOut updates the command execution timeout

func (*Utility) UpdateInstallDelayer

func (util *Utility) UpdateInstallDelayer(ctx context.T, updateRoot string) error

UpdateInstallDelayer delays the agent install when domain join reboot doc found

func (*Utility) WaitForServiceToStart

func (util *Utility) WaitForServiceToStart(log log.T, i updateinfo.T, targetVersion string) (result bool, svcRunningErr error)

WaitForServiceToStart wait for service to start and returns is service started

Directories

Path Synopsis
Package updateconstants contains constants related to update
Package updateconstants contains constants related to update
Package updatemanifest implements the logic for the ssm agent s3 manifest.
Package updatemanifest implements the logic for the ssm agent s3 manifest.
Package updates3util implements the logic for s3 update download
Package updates3util implements the logic for s3 update download

Jump to

Keyboard shortcuts

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