updateutil

package
v0.0.0-...-7638cb1 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2017 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package updateutil contains updater specific utilities.

Package updateutil contains updater specific utilities.

Package updateutil contains updater specific utilities.

Package updateutil contains updater specific utilities.

Package updateutil contains updater specific utilities.

Index

Constants

View Source
const (
	// UpdaterPackageNamePrefix represents the name of Updater Package
	UpdaterPackageNamePrefix = "-updater"

	// HashType represents the default hash type
	HashType = "sha256"

	// Updater represents Updater name
	Updater = "updater"

	// UpdateContextFileName represents Update context json file
	UpdateContextFileName = "updatecontext.json"

	// UpdatePluginResultFileName represents Update plugin result file name
	UpdatePluginResultFileName = "updatepluginresult.json"

	// DefaultOutputFolder represents default location for storing output files
	DefaultOutputFolder = "output"

	// DefaultStandOut represents the default file name for update stand output
	DefaultStandOut = "stdout"

	// DefaultStandErr represents the default file name for update stand error
	DefaultStandErr = "stderr"

	// RegionHolder represents Place holder for Region
	RegionHolder = "{Region}"

	// PackageNameHolder represents Place holder for package name
	PackageNameHolder = "{PackageName}"

	// PackageVersionHolder represents Place holder for package version
	PackageVersionHolder = "{PackageVersion}"

	// FileNameHolder represents Place holder for file name
	FileNameHolder = "{FileName}"

	// PlatformHolder represents Place holder for platform
	PlatformHolder = "{Platform}"

	// ArchHolder represents Place holder for Arch
	ArchHolder = "{Arch}"

	// CompressedHolder represents Place holder for compress format
	CompressedHolder = "{Compressed}"

	// PlatformLinux represents linux
	PlatformLinux = "linux"

	// PlatformAmazonLinux represents amazon linux
	PlatformAmazonLinux = "amazon"

	// PlatformRedHat represents RedHat
	PlatformRedHat = "red hat"

	// PlatformUbuntu represents Ubuntu
	PlatformUbuntu = "ubuntu"

	// PlatformCentOS represents CentOS
	PlatformCentOS = "centos"

	// PlatformWindows represents windows
	PlatformWindows = "windows"

	//PlatformWindowsNano represents windows nano
	PlatformWindowsNano = "windows-nano"

	// DefaultUpdateExecutionTimeoutInSeconds represents default timeout time for execution update related scripts in seconds
	DefaultUpdateExecutionTimeoutInSeconds = 150

	// PipelineTestVersion represents fake version for pipeline tests
	PipelineTestVersion = "255.0.0.0"
)
View Source
const (
	// UpdateCmd represents the command argument for update
	UpdateCmd = "update"

	// SourceVersionCmd represents the command argument for source version
	SourceVersionCmd = "source.version"

	// SourceLocationCmd represents the command argument for source location
	SourceLocationCmd = "source.location"

	// SourceHashCmd represents the command argument for source hash value
	SourceHashCmd = "source.hash"

	// TargetVersionCmd represents the command argument for target version
	TargetVersionCmd = "target.version"

	// TargetLocationCmd represents the command argument for target location
	TargetLocationCmd = "target.location"

	// TargetHashCmd represents the command argument for target hash value
	TargetHashCmd = "target.hash"

	// PackageNameCmd represents the command argument for package name
	PackageNameCmd = "package.name"

	// MessageIDCmd represents the command argument for message id
	MessageIDCmd = "messageid"

	// StdoutFileName represents the command argument for standard output file
	StdoutFileName = "stdout"

	// StderrFileName represents the command argument for standard error file
	StderrFileName = "stderr"

	// OutputKeyPrefixCmd represents the command argument for output key prefix
	OutputKeyPrefixCmd = "output.key"

	// OutputBucketNameCmd represents the command argument for output bucket name
	OutputBucketNameCmd = "output.bucket"
)
View Source
const (
	// Installer represents Install shell script
	Installer = "install.sh"

	// UnInstaller represents Uninstall shell script
	UnInstaller = "uninstall.sh"
)
View Source
const (
	// CompressFormat represents the compress format for linux platform
	CompressFormat = "tar.gz"
)
View Source
const MinimumDiskSpaceForUpdate int64 = 104857600

MinimumDiskSpaceForUpdate represents 100 Mb in bytes

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 InstallerFilePath

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

InstallerFilePath returns Installer file path

func UnInstallerFilePath

func UnInstallerFilePath(updateRoot string, packageName string, version 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

func VersionCompare

func VersionCompare(versionl string, versionr string) (result int, err error)

VersionCompare compares two version strings

Types

type ErrorCode

type ErrorCode string

ErrorCode is types of Error Codes

const (
	// ErrorInvalidSourceVersion represents Source version is not supported
	ErrorInvalidSourceVersion ErrorCode = "ErrorInvalidSourceVersion"

	// ErrorInvalidTargetVersion represents Target version is not supported
	ErrorInvalidTargetVersion ErrorCode = "ErrorInvalidTargetVersion"

	// ErrorAttemptToDowngrade represents An update is attempting to downgrade Ec2Config to a lower version
	ErrorAttemptToDowngrade ErrorCode = "ErrorAttempToDowngrade"

	// ErrorInitializationFailed represents An update is failed to initialize
	ErrorInitializationFailed ErrorCode = "ErrorInitializationFailed"

	// ErrorInvalidPackage represents Installation package file is invalid
	ErrorInvalidPackage ErrorCode = "ErrorInvalidPackage"

	// ErrorPackageNotAccessible represents Installation package file is not accessible
	ErrorPackageNotAccessible ErrorCode = "ErrorPackageNotAccessible"

	// ErrorInvalidCertificate represents Installation package file doesn't contain valid certificate
	ErrorInvalidCertificate ErrorCode = "ErrorInvalidCertificate"

	// ErrorInvalidManifest represents Invalid manifest file
	ErrorInvalidManifest ErrorCode = "ErrorInvalidManifest"

	// ErrorInvalidManifestLocation represents Invalid manifest file location
	ErrorInvalidManifestLocation ErrorCode = "ErrorInvalidManifestLocation"

	// ErrorUninstallFailed represents Uninstall failed
	ErrorUninstallFailed ErrorCode = "ErrorUninstallFailed"

	// ErrorInstallFailed represents Install failed
	ErrorInstallFailed ErrorCode = "ErrorInstallFailed"

	// ErrorCannotStartService represents Cannot start Ec2Config service
	ErrorCannotStartService ErrorCode = "ErrorCannotStartService"

	// ErrorCannotStopService represents Cannot stop Ec2Config service
	ErrorCannotStopService ErrorCode = "ErrorCannotStopService"

	// ErrorTimeout represents Installation time-out
	ErrorTimeout ErrorCode = "ErrorTimeout"

	// ErrorUnexpected represents Unexpected Error
	ErrorUnexpected ErrorCode = "ErrorUnexpected"

	// ErrorEnvironmentIssue represents Unexpected Error
	ErrorEnvironmentIssue ErrorCode = "ErrorEnvironmentIssue"

	// ErrorLoadingAgentVersion represents failed for loading agent version
	ErrorLoadingAgentVersion ErrorCode = "ErrorLoadingAgentVersion"
)

type InstanceContext

type InstanceContext struct {
	Region          string
	Platform        string
	PlatformVersion string
	InstallerName   string
	Arch            string
	CompressFormat  string
}

InstanceContext holds information for the instance

func (*InstanceContext) FileName

func (i *InstanceContext) FileName(packageName string) string

FileName generates downloadable file name base on agreed convension

func (*InstanceContext) IsPlatformUsingSystemD

func (i *InstanceContext) IsPlatformUsingSystemD(log log.T) (result bool, err error)

IsPlatformUsingSystemD returns if SystemD is the default Init for the Linux platform

type Mock

type Mock struct {
	mock.Mock
}

Mock stands for a mocked updateutil.

func NewMockDefault

func NewMockDefault() *Mock

NewMockDefault returns an instance of Mock with default expectations set.

func (*Mock) CreateInstanceContext

func (m *Mock) CreateInstanceContext(log log.T) (context *InstanceContext, err error)

CreateInstanceContext mocks the CreateInstanceContext function.

func (*Mock) CreateUpdateDownloadFolder

func (m *Mock) CreateUpdateDownloadFolder() (folder string, err error)

CreateUpdateDownloadFolder mocks the CreateUpdateDownloadFolder function.

func (*Mock) ExeCommand

func (m *Mock) ExeCommand(log log.T, cmd string, workingDir string, updaterRoot string, stdOut string, stdErr string, isAsync bool) (err error)

ExeCommand mocks the ExeCommand function.

func (*Mock) SaveUpdatePluginResult

func (m *Mock) SaveUpdatePluginResult(log log.T, updaterRoot string, updateResult *UpdatePluginResult) (err error)

SaveUpdatePluginResult mocks the SaveUpdatePluginResult function.

type T

type T interface {
	CreateInstanceContext(log log.T) (context *InstanceContext, err error)
	CreateUpdateDownloadFolder() (folder string, err error)
	ExeCommand(log log.T, cmd string, workingDir string, updaterRoot string, stdOut string, stdErr string, isAsync bool) (err error)
	IsServiceRunning(log log.T, i *InstanceContext) (result bool, err error)
	SaveUpdatePluginResult(log log.T, updaterRoot string, updateResult *UpdatePluginResult) (err error)
	IsDiskSpaceSufficientForUpdate(log log.T) (bool, error)
}

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 {
	CustomUpdateExecutionTimeoutInSeconds int
}

Utility implements interface T

func (*Utility) CreateInstanceContext

func (util *Utility) CreateInstanceContext(log log.T) (context *InstanceContext, err error)

CreateInstanceContext 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) (err 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) 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 *InstanceContext) (result bool, err error)

IsServiceRunning returns is service running

func (*Utility) SaveUpdatePluginResult

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

SaveUpdatePluginResult saves UpdatePluginResult to the local storage

Jump to

Keyboard shortcuts

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