common

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2019 License: Apache-2.0 Imports: 21 Imported by: 12

Documentation

Overview

DBDeployer - The MySQL Sandbox Copyright © 2006-2019 Giuseppe Maxia

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	// Tarball flavors
	MySQLFlavor         = "mysql"
	PerconaServerFlavor = "percona"
	MariaDbFlavor       = "mariadb"
	NDBFlavor           = "ndb"
	TiDbFlavor          = "tidb"

	// Feature names
	InstallDb        = "installdb"
	DynVariables     = "dynVars"
	SemiSynch        = "semiSync"
	CrashSafe        = "crashSafe"
	GTID             = "GTID"
	EnhancedGTID     = "enhancedGTID"
	Initialize       = "initialize"
	CreateUser       = "createUser"
	SuperReadOnly    = "superReadOnly"
	MySQLX           = "mysqlx"
	MySQLXDefault    = "mysqlxDefault"
	MultiSource      = "multiSource"
	GroupReplication = "groupReplication"
	SetPersist       = "setPersist"
	Roles            = "roles"
	NativeAuth       = "nativeAuth"
	DataDict         = "datadict"
)

Variables

View Source
var CommandLineArgs []string
View Source
var CompatibleVersion string = "1.19.0" // 2019-02-17

Compatible version is the version used to mark compatible archives (templates, configuration). It is usually major.minor.0, except when we are at version 0.x, when every revision may bring incompatibility

View Source
var MariadbCapabilities = Capabilities{
	Flavor: MariaDbFlavor,
	Features: FeatureList{
		InstallDb: {
			Description: "uses mysql_install_db",
			Since:       globals.MinimumMySQLInstallDb,
			Until:       nil,
		},
		DynVariables: MySQLCapabilities.Features[DynVariables],
		SemiSynch:    MySQLCapabilities.Features[SemiSynch],
	},
}

NOTE: We only list the capabilities for which dbdeployer needs to take action

View Source
var MySQLCapabilities = Capabilities{
	Flavor: MySQLFlavor,
	Features: FeatureList{
		InstallDb: {
			Description: "uses mysql_install_db",
			Since:       globals.MinimumMySQLInstallDb,
			Until:       globals.MaximumMySQLInstallDb,
		},
		DynVariables: {
			Description: "dynamic variables",
			Since:       globals.MinimumDynVariablesVersion,
		},
		SemiSynch: {
			Description: "semi-synchronous replication",
			Since:       globals.MinimumSemiSyncVersion,
		},
		CrashSafe: {
			Description: "crash-safe replication",
			Since:       globals.MinimumCrashSafeVersion,
		},
		GTID: {
			Description: "Global transaction identifiers",
			Since:       globals.MinimumGtidVersion,
		},
		EnhancedGTID: {
			Description: "Enhanced Global transaction identifiers",
			Since:       globals.MinimumEnhancedGtidVersion,
		},
		Initialize: {
			Description: "mysqld --initialize as default",
			Since:       globals.MinimumDefaultInitializeVersion,
		},
		CreateUser: {
			Description: "Create user mandatory",
			Since:       globals.MinimumCreateUserVersion,
		},
		SuperReadOnly: {
			Description: "super-read-only support",
			Since:       globals.MinimumSuperReadOnly,
		},
		MySQLX: {
			Description: "MySQLX supported",
			Since:       globals.MinimumMysqlxVersion,
		},
		MySQLXDefault: {
			Description: "MySQLX enabled by default",
			Since:       globals.MinimumMysqlxDefaultVersion,
		},
		MultiSource: {
			Description: "multi-source replication",
			Since:       globals.MinimumMultiSourceReplVersion,
		},
		GroupReplication: {
			Description: "group replication",
			Since:       globals.MinimumGroupReplVersion,
		},
		SetPersist: {
			Description: "Set persist supported",
			Since:       globals.MinimumPersistVersion,
		},
		Roles: {
			Description: "Roles supported",
			Since:       globals.MinimumRolesVersion,
		},
		NativeAuth: {
			Description: "Native Authentication plugin",
			Since:       globals.MinimumNativeAuthPluginVersion,
		},
		DataDict: {
			Description: "data dictionary",
			Since:       globals.MinimumDataDictionaryVersion,
		},
	},
}
View Source
var NDBCapabilities = Capabilities{}
View Source
var PerconaCapabilities = Capabilities{
	Flavor:   PerconaServerFlavor,
	Features: MySQLCapabilities.Features,
}
View Source
var TiDBCapabilities = Capabilities{}
View Source
var VersionDef string = "1.19.0" // 2019-02-17

Functions

func AbsolutePath

func AbsolutePath(value string) (string, error)

Returns the absolute path of a file

func AddToCleanupStack

func AddToCleanupStack(cf CleanupFunc, funcName, arg string)

Adds an action to the list of clean-up operations to run before aborting the program

func AppendStrings

func AppendStrings(lines []string, filename string, termination string) error

append a string slice into an existing file

func Atoi

func Atoi(val string) int

Converts a string to an integer. Exits on error

func BaseName

func BaseName(filename string) string

Returns the base name of a file

func CheckFlavorSupport added in v1.19.0

func CheckFlavorSupport(flavor string) error

func CheckOrigin

func CheckOrigin(args []string)

Checks the initial argument for a sandbox deployment

func CheckSandboxDir

func CheckSandboxDir(sandboxHome string) error

Creates a sandbox directory if it does not exist

func CheckTarballOperatingSystem

func CheckTarballOperatingSystem(basedir string) error

Checks that the extracted tarball directory

contains one or more files expected for the current
operating system.
It prevents simple errors like :
* using a Linux tarball on a Mac or vice-versa
* using a source or test tarball instead of a binaries one.

func CondPrintf

func CondPrintf(format string, args ...interface{})

func CondPrintln

func CondPrintln(args ...interface{})

func CopyFile

func CopyFile(source, destination string) error

Copies a file

func DetectBinaryFlavor added in v1.19.0

func DetectBinaryFlavor(basedir string) string

Tries to detect the database flavor from files in the tarball directory

func DirExists

func DirExists(filename string) bool

returns true if a given directory exists

func DirName

func DirName(filename string) string

Returns the directory name of a file

func ErrCheckExitf

func ErrCheckExitf(err error, exitCode int, format string, args ...interface{})

Checks the status of error variable and exit with custom message if it is not nil.

func ExecExists

func ExecExists(filename string) bool

returns true if a given executable exists

func Exit

func Exit(exitCode int, messages ...string)

Exit with custom set of messages Runs cleanup actions before aborting the program

func Exitf

func Exitf(exitCode int, format string, args ...interface{})

Exit with formatted message Runs cleanup actions before aborting the program

func FileExists

func FileExists(filename string) bool

returns true if a given file exists

func FindFreePort

func FindFreePort(basePort int, installedPorts []int, howMany int) (int, error)

Finds the a range of howMany free ports available, starting at basePort. installedPorts is a slice of ports already used by other sandboxes. Calls either findFreePortRange or findFreePortSingle, depending on the amount of ports requested. Returns the first port of the requested range

func FindInPath

func FindInPath(filename string) string

Same as Which

func GetAvailableVersions

func GetAvailableVersions() ([]string, error)

func GetInstalledPorts

func GetInstalledPorts(sandboxHome string) ([]int, error)

Collects a list of used ports from deployed sandboxes

func GetVersionsFromDir

func GetVersionsFromDir(basedir string) ([]string, error)

Returns the list of versions available for deployment

func GreaterOrEqualVersion

func GreaterOrEqualVersion(version string, comparedTo []int) (bool, error)

Checks if a version string is greater or equal a given numeric version "5.6.33" >= []int{5,7,0} = false "5.7.21" >= []int{5,7,0} = true "10.1.21" >= []int{5,7,0} = false (!) Note: MariaDB versions are skipped. The function returns false for MariaDB 10+. So far (2018-02-19) this comparison holds, because MariaDB behaves like 5.5+ for the purposes of sandbox deployment

DEPRECATED as of 1.18.0 Use GreaterOrEqualVersionList and flavors instead

func GreaterOrEqualVersionList added in v1.19.0

func GreaterOrEqualVersionList(verList, comparedTo []int) (bool, error)

func HasCapability added in v1.19.0

func HasCapability(flavor, feature, version string) (bool, error)

func Includes

func Includes(mainString, contained string) bool

Return true is `contained` is a sub-string of `mainString`

func IntSliceToDottedString

func IntSliceToDottedString(val []int) string

Given an array of integers, returns a string containing the numbers separated by a dot. For example: an input of []int{1, 2, 3} returns "1.2.3"

func IsATarball

func IsATarball(fileName string) bool

Returns true if the file name has a recognized tarball extension for use with dbdeployer

func IsEnvSet

func IsEnvSet(envVar string) bool

Checks whether a given environment variable is set

func IsIPV4 added in v1.17.0

func IsIPV4(ip string) bool

Returns true if a given string looks like an IPV4

func IsVersion

func IsVersion(version string) bool

Returns true if a given string looks contains a version number (major.minor.rev)

func LatestVersion

func LatestVersion(searchDir, pattern string) string

Returns the latest version among the ones found in a Sandbox binary directory

func LogDirName

func LogDirName() string

Returns the name of the log directory

func MakeCustomizedUuid

func MakeCustomizedUuid(port, nodeNum int) (string, error)

Creates a "human readable" and predictable UUID using some pre-defined elements. Used to replace the random UUID created by MySQL 5.6+, with the purpose of returning easy to read server identifiers that can be processed visually.

func Mkdir

func Mkdir(dirName string)

Creates a directory, and exits if an error occurs

func RemoveTrailingSlash

func RemoveTrailingSlash(s string) string

Removes a slash (if any) at the end of a given string

func ReplaceEnvVar

func ReplaceEnvVar(name string, envVar string) string

Replaces the environment variable `envVar` with its value for example, if "$HOME" resolves to "/home/goofy" the string "$HOME/some/path" would become "/home/goofy/some/path"

func ReplaceHomeVar

func ReplaceHomeVar(path string) string

Given a path with the variable "$HOME" at the start, returns a string with the value of HOME expanded

func ReplaceLiteralEnvVar

func ReplaceLiteralEnvVar(name string, envVar string) string

Replaces the literal value of an environment variable with its name for example, if "$HOME" resolves to "/home/goofy" the string "/home/goofy/some/path" would become "$HOME/some/path"

func ReplaceLiteralHome

func ReplaceLiteralHome(path string) string

Given a path starting at the HOME directory returns a string where the literal value for $HOME is replaced by the string "$HOME"

func Rmdir

func Rmdir(dirName string)

Removes a directory, and exits if an error occurs

func RmdirAll

func RmdirAll(dirName string)

Removes a directory with its contents, and exits if an error occurs

func RunCleanupActions

func RunCleanupActions()

Runs the cleanup actions (usually before Exit)

func RunCmd

func RunCmd(c string) (string, error)

Runs a command

func RunCmdCtrl

func RunCmdCtrl(c string, silent bool) (string, error)

Runs a command, with optional quiet output

func RunCmdWithArgs

func RunCmdWithArgs(c string, args []string) (string, error)

Runs a command with arguments

func SandboxInfoToFileNames

func SandboxInfoToFileNames(sbList []SandboxInfo) (fileNames []string)

Returns a list of inner sandboxes

func SlurpAsBytes

func SlurpAsBytes(filename string) ([]byte, error)

reads a file and returns its contents as a byte slice

func SlurpAsLines

func SlurpAsLines(filename string) ([]string, error)

Reads a file and returns its lines as a string slice

func SlurpAsString

func SlurpAsString(filename string) (string, error)

Reads a file and returns its contents as a single string

func SortVersions

func SortVersions(versions []string) []string

func SortVersionsSubset

func SortVersionsSubset(versions []string, wanted string) (sorted []string)

Given a list of version strings (in the format x.x.x) this function returns an ordered list, taking into account the components of the versions, so that 5.6.2 sorts lower than 5.6.11 while a text sort would put 5.6.11 before 5.6.2 If wanted is not empty, it will be interpreted as a short version to match. For example, when wanted is "5.6", only the versions starting with '5.6' will be considered.

func StringToIntSlice

func StringToIntSlice(val string) (numberList []int, err error)

Given a string containing comma-separated integers, returns an array of integers Example: an input of "1,2,3" returns []int{1, 2, 3}

func TemplateFill

func TemplateFill(tmpl string, data StringMap) string

TemplateFill passed template string is formatted using its operands and returns the resulting string. Spaces are added between operands when neither is a string. Based on code from https://play.golang.org/p/COHKlB2RML

func TextToBool

func TextToBool(value string) (result bool)

Returns true if the input value is either of "true", "yes", "1"

func TrimmedLines

func TrimmedLines(s string) string

Given a multi-line string, this function removes leading spaces from every line. It also removes the first line, if it is empty

func VersionToList

func VersionToList(version string) ([]int, error)

Gets three integers for a version string Converts "1.2.3" into []int{1, 2, 3}

func VersionToName

func VersionToName(version string) string

Converts a version string into a name. Replaces dots with underscores. "1.2.3" -> "1_2_3"

func VersionToPort

func VersionToPort(version string) (int, error)

Converts a version string into a port number e.g. "5.6.33" -> 5633

func Which

func Which(filename string) string

Returns the full path of an executable, or an empty string if the executable is not found

func WriteSandboxDescription

func WriteSandboxDescription(destination string, sd SandboxDescription) error

Writes the description of a sandbox in the appropriate directory

func WriteString

func WriteString(line string, filename string) error

append a string into an existing file

func WriteStrings

func WriteStrings(lines []string, filename string, termination string) error

Writes a string slice into a file The file is created

Types

type Capabilities added in v1.19.0

type Capabilities struct {
	Flavor   string      `json:"flavor"`
	Features FeatureList `json:"features"`
}

type Capability added in v1.19.0

type Capability struct {
	Description string         `json:"description"`
	Since       MinimumVersion `json:"since"`
	Until       MinimumVersion `json:"until"`
}

type CleanupFunc

type CleanupFunc func(target string)

type CleanupRec

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

type ConfigOptions

type ConfigOptions map[string][]KeyValue

func ParseConfigFile

func ParseConfigFile(filename string) (ConfigOptions, error)

Reads a MySQL configuration file and returns its structured contents

type FeatureList added in v1.19.0

type FeatureList map[string]Capability

type KeyValue

type KeyValue struct {
	Key   string
	Value string
}

type MinimumVersion added in v1.19.0

type MinimumVersion []int

type PortMap

type PortMap map[int]bool

type SandboxDescription

type SandboxDescription struct {
	Basedir           string `json:"basedir"`
	ClientBasedir     string `json:"client_basedir,omitempty"`
	SBType            string `json:"type"` // single multi master-slave group
	Version           string `json:"version"`
	Flavor            string `json:"flavor,omitempty"`
	Port              []int  `json:"port"`
	Nodes             int    `json:"nodes"`
	NodeNum           int    `json:"node_num"`
	DbDeployerVersion string `json:"dbdeployer-version"`
	Timestamp         string `json:"timestamp"`
	CommandLine       string `json:"command-line"`
	LogFile           string `json:"log-file,omitempty"`
}

func ReadSandboxDescription

func ReadSandboxDescription(sandboxDirectory string) (SandboxDescription, error)

Reads sandbox description from a given directory

type SandboxInfo

type SandboxInfo struct {
	SandboxName string
	Locked      bool
}

func GetInstalledSandboxes

func GetInstalledSandboxes(sandboxHome string) (installedSandboxes []SandboxInfo, err error)

Gets a list of installed sandboxes from the $SANDBOX_HOME directory

type SandboxUser

type SandboxUser struct {
	Description string `json:"description"`
	Username    string `json:"username"`
	Password    string `json:"password"`
	Privileges  string `json:"privileges"`
}

type Stack

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

The stack is implemented using a double-linked list from Go standard library

func NewStack

func NewStack() (stack Stack)

NewStack returns a new stack

func (*Stack) Bottom

func (stack *Stack) Bottom() interface{}

Bottom() returns the object stored as .Value in the bottom list element The object is NOT removed from the list

func (*Stack) Len

func (stack *Stack) Len() int

The length of the stack is that of the underlying list

func (*Stack) Pop

func (stack *Stack) Pop() interface{}

Pop() returns the object stored as .Value in the top list element Client calls will need to cast the object to the expected type. The object is removed from the list e.g.:

type MyType struct { ... }
var lastOne MyType
lastOne = stack.Pop().(MyType)

func (*Stack) Push

func (stack *Stack) Push(item interface{})

Push() inserts an item to the front of the stack. The item can be of any type

func (*Stack) Reset

func (stack *Stack) Reset()

Removes all items from the stack

func (*Stack) Top

func (stack *Stack) Top() interface{}

Top() returns the object stored as .Value in the top list element The object is NOT removed from the list

type StringMap

type StringMap map[string]interface{}

StringMap defines the map of variable types, for brevity

Jump to

Keyboard shortcuts

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