util

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

README

util/

The util directory contains code that

  1. Provides useful functionality that could be used by more than one library in this module
  2. Doesn't fall into an existing specialized category, like logging
  3. Has a relatively limited scope. "Limited scope" is a subjective criteria. If there are many objects and functions that all interact together, consider placing the code in its own top-level directory and not here.

Documentation

Index

Constants

View Source
const (
	DefaultClientPort                = 5433
	DefaultHTTPPortOffset            = 3010
	DefaultHTTPPort                  = DefaultClientPort + DefaultHTTPPortOffset
	DefaultControlAddressFamily      = "ipv4"
	IPv6ControlAddressFamily         = "ipv6"
	DefaultRestartPolicy             = "ksafe"
	DefaultDBDir                     = "/opt/vertica"
	DefaultShareDir                  = DefaultDBDir + "/share"
	DefaultLicenseKey                = DefaultShareDir + "/license.key"
	DefaultConfigDir                 = DefaultDBDir + "/config"
	DefaultRetryCount                = 3
	DefaultTimeoutSeconds            = 300
	DefaultLoadCatalogTimeoutSeconds = 3600
	DefaultStatePollingTimeout       = 1200
	DefaultLargeCluster              = -1
	MaxLargeCluster                  = 120
	MinDepotSize                     = 0
	MaxDepotSize                     = 100
	DefaultDrainSeconds              = 60
	NodeUpState                      = "UP"
	NodeDownState                    = "DOWN"
	SuppressHelp                     = "SUPPRESS_HELP"
)

this file defines basic default values

View Source
const (
	FileExist    = 0
	FileNotExist = 1
	NoWritePerm  = 2
)
View Source
const (
	AWSAuthKey = "awsauth"
)
View Source
const DefaultDateOnlyFormat = time.DateOnly

default date only format: this omits time within a date

View Source
const DefaultDateTimeFormat = time.DateTime

default date time format: this omits nanoseconds but is still able to parse those out

View Source
const DefaultDateTimeNanoSecFormat = time.DateTime + ".000000000"

default date time format: this includes nanoseconds

Variables

View Source
var RestartPolicyList = []string{"never", DefaultRestartPolicy, "always"}

Functions

func AbsPathCheck

func AbsPathCheck(dirPath string) error

func AddressCheck

func AddressCheck(address string, ipv6 bool) error

func ArrayToString

func ArrayToString(arr []string, delimiter string) string

convert an array to a string by joining the elements in the array using the given delimiter

func CanReadAccessDir

func CanReadAccessDir(dirPath string) error

Check whether the directory is read accessible by trying to open the file

func CanWriteAccessDir added in v1.0.0

func CanWriteAccessDir(dirPath string) int

Check whether the directory is read accessible

func CheckAllEmptyOrNonEmpty

func CheckAllEmptyOrNonEmpty(vars ...string) bool

func CheckMissingFields

func CheckMissingFields(object any) error

func CheckNotEmpty

func CheckNotEmpty(a string) bool

func CheckPathExist

func CheckPathExist(filePath string) bool

func CopyFile

func CopyFile(sourcePath, destinationPath string, perm fs.FileMode) error

copy file from a source path to a destination path

func CopyMap

func CopyMap[K comparable, V any](original map[K]V) map[K]V

CopyMap returns a copy of a map.

func CopySlice

func CopySlice[T any](original []T) []T

CopySlice returns a copy of a slice.

func FillInDefaultTimeForEndTimestamp

func FillInDefaultTimeForEndTimestamp(dateonly *string) *time.Time

Read date only string from argument, fill in time, overwrite argument by date time string, and return parsed time, the filled in time will indicate the end of a day (right before the beginning of the following day)

func FillInDefaultTimeForStartTimestamp

func FillInDefaultTimeForStartTimestamp(dateonly *string) *time.Time

Read date only string from argument, fill in time, overwrite argument by date time string, and return parsed time, the filled in time will indicate the beginning of a day

func FilterMapByKey

func FilterMapByKey[M ~map[K]V, K comparable, V any](m M, n []K) M

FilterMapByKey, given a map and a slice of keys, returns a map, which is a subset of the original, that contains only keys in from the given slice.

func GenVNodeName

func GenVNodeName(vnodes map[string]string, dbName string, hostCount int) (string, bool)

GenVNodeName generates a vnode and returns it after checking it is not already taken by an existing node.

func GetCleanPath

func GetCleanPath(path string) string

replace all '//' to be '/', trim the path string

func GetCurrentUsername

func GetCurrentUsername() (string, error)

func GetEnv

func GetEnv(key, fallback string) string

get env var with a fallback value

func GetEonFlagMsg

func GetEonFlagMsg(message string) string

func GetJSONLogErrors

func GetJSONLogErrors(responseContent string, responseObj any, opName string, logger vlog.Printer) error

func GetOptionalFlagMsg added in v1.0.0

func GetOptionalFlagMsg(message string) string

func GetPathPrefix

func GetPathPrefix(path string) string

GetPathPrefix returns a path prefix for a (catalog/data/depot) path of a node

func IsAbsPath

func IsAbsPath(path string) bool

have this util function so no need to import file/path for every command that needs check file path

func IsEmptyOrValidTimeStr

func IsEmptyOrValidTimeStr(layout string, value *string) (*time.Time, error)

import time package in this util file so other files don't need to import time wrapper function to handle empty input string, returns an error if the time is invalid caller responsible for passing in correct layout

func IsIPv4

func IsIPv4(ip string) bool

IP util functions

func IsIPv6

func IsIPv6(ip string) bool

func IsOptionSet

func IsOptionSet(f *flag.FlagSet, optionName string) bool

check if an option is passed in

func IsTimeEqualOrAfter

func IsTimeEqualOrAfter(start, end time.Time) bool

func MapKeyDiff

func MapKeyDiff[M ~map[K]V, K comparable, V any](m, n M) []K

calculate diff of map keys: m-n

func Max

func Max[T constraints.Ordered](a, b T) T

Max works on all sane types, not just float64 like the math package funcs. Can be removed after upgrade to go 1.21 (VER-90410) as min/max become builtins.

func NmaCertsLookup

func NmaCertsLookup(f FetchAllEnvVars)

NmaCertsLookup retrieves kubernetes certs.

func NmaSecretLookup

func NmaSecretLookup(f FetchAllEnvVars)

NmaSecretLookup retrieves kubernetes secrets.

func ParamNotSetErrorMsg

func ParamNotSetErrorMsg(param string) error

func ParseConfigParams added in v1.0.0

func ParseConfigParams(configParamListStr string) (map[string]string, error)

ParseConfigParams builds and returns a map from a comma-separated list of params.

func ParseKeyValueListStr added in v1.0.0

func ParseKeyValueListStr(listStr, opt string) (map[string]string, error)

ParseKeyValueListStr converts a comma-separated list of key-value pairs into a map. Ex: key1=val1,key2=val2 ---> map[string]string{key1: val1, key2: val2}

func ResolveRawHostsToAddresses

func ResolveRawHostsToAddresses(rawHosts []string, ipv6 bool) ([]string, error)

resolve RawHosts to be IP addresses

func ResolveToAbsPath

func ResolveToAbsPath(path string) (string, error)

func ResolveToIPAddrs

func ResolveToIPAddrs(hostname string, ipv6 bool) ([]string, error)

func ResolveToOneIP

func ResolveToOneIP(hostname string, ipv6 bool) (string, error)

func SetParserUsage

func SetParserUsage(parser *flag.FlagSet, op string)

suppress help message for hidden options

func SliceDiff

func SliceDiff[K comparable](m, n []K) []K

calculate array diff: m-n

func SplitHosts added in v1.0.0

func SplitHosts(hosts string) ([]string, error)

func StringInArray

func StringInArray(str string, list []string) bool

func TrimSpace

func TrimSpace(str string) string

avoid import strings in every operation

func ValidateAbsPath

func ValidateAbsPath(path *string, pathName string) error

func ValidateCommunalStorageLocation

func ValidateCommunalStorageLocation(location string) error

ValidateCommunalStorageLocation can identify some invalid communal storage locations

func ValidateDBName

func ValidateDBName(dbName string) error

func ValidateName

func ValidateName(name, obj string) error

ValidateName will validate the name of an obj, the obj can be database, subcluster, etc. when a name is provided, make sure no special chars are in it

func ValidateRequiredAbsPath

func ValidateRequiredAbsPath(path *string, pathName string) error

ValidateRequiredAbsPath check whether a required path is set then validate it

func ValidateUsernameAndPassword

func ValidateUsernameAndPassword(opName string, useHTTPPassword bool, userName string) error

when password is given, the user name cannot be empty

Types

type FetchAllEnvVars

type FetchAllEnvVars interface {
	SetK8Secrets(port, secretNameSpace, secretName string)
	SetK8Certs(rootCAPath, certPath, keyPath string)
	TypeName() string
}

Jump to

Keyboard shortcuts

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