util

package
v0.0.0-...-9796e91 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// MgmtOpServerStateRead is a JBoss CLI command for reading WFLY server
	MgmtOpServerStateRead = ":read-attribute(name=server-state)"
	// MgmtOpListSubsystems is a JBoss CLI command to read names of available subsystems
	MgmtOpListSubsystems = ":read-children-names(child-type=subsystem)"
	// MgmtOpReload is a JBoss CLI command for reloading WFLY server
	MgmtOpReload = ":reload()"
	// MgmtOpRestart is a JBoss CLI command for restarting WFLY server
	MgmtOpRestart = ":shutdown(restart=true)"
	// MgmtOpTxnCheckJdbcStore is a JBoss CLI command to verify if txn log is saved in a database
	MgmtOpTxnCheckJdbcStore = "/subsystem=transactions:read-attribute(name=use-jdbc-store)"
	// MgmtOpTxnCheckRecoveryListener is a JBoss CLI command to verify if recovery listener is active
	MgmtOpTxnCheckRecoveryListener = "/subsystem=transactions:read-attribute(name=recovery-listener)"
	// MgmtOpTxnProbe is a JBoss CLI command for probing transaction log store
	MgmtOpTxnProbe = "/subsystem=transactions/log-store=log-store:probe()"
	// MgmtOpTxnRead is a JBoss CLI command for reading transaction log store
	MgmtOpTxnRead = "" /* 128-byte string literal not displayed */
	// MgmtOpTxnRecoverySocketBindingRead is a JBoss CLI command for reading name of recovery socket binding
	MgmtOpTxnRecoverySocketBindingRead = "/subsystem=transactions:read-attribute(name=socket-binding)"
	// MgmtOpSocketBindingRead is a JBoss CLI command for reading all data on the socket binding group
	MgmtOpSocketBindingRead = "/socket-binding-group=standard-sockets:read-resource(recursive=true,resolve-expressions=true,include-runtime=true)"
	// MgmtOpSystemPropertyRecoveryBackoffPeriod is a JBoss CLI command to set system property of recovery backoff period
	MgmtOpSystemPropertyRecoveryBackoffPeriod = "/system-property=com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean.recoveryBackoffPeriod:add(value=%s)"
	// MgmtOpSystemPropertyPeriodicRecoveryPeriod is a JBoss CLI command to set system property of periodic recovery period
	MgmtOpSystemPropertyPeriodicRecoveryPeriod = "/system-property=com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean.periodicRecoveryPeriod:add(value=%s)"
	// MgmtOpSystemPropertyOrphanSafetyInterval is a JBoss CLI command to set system property of orphan safety interval
	MgmtOpSystemPropertyOrphanSafetyInterval = "/system-property=com.arjuna.ats.jta.common.JTAEnvironmentBean.orphanSafetyInterval:add(value=%s)"
	// MgmtOpSystemPropertyTransactionManagerDisabled is a JBoss CLI command to set system property to disable/enable transaction manager
	MgmtOpSystemPropertyTransactionManagerDisabled = "/system-property=com.arjuna.ats.arjuna.common.CoordinatorEnvironmentBean.startDisabled:add(value=%s)"
)

Functions

func ContainsInList

func ContainsInList(list []string, s string) bool

ContainsInList returns true if the string s is included in the list,

otherwise false is returned

func ContainsInMap

func ContainsInMap(m map[string]string, vals ...string) bool

ContainsInMap returns true if the map m contains at least one of the string

presented as argument `vals`, otherwise false is returned

func ConvertToArrayString

func ConvertToArrayString(intf interface{}) ([]string, error)

ConvertToArrayString takes interface type and tries to convert it to array of strings

func ConvertToInt

func ConvertToInt(intf interface{}) (int32, error)

ConvertToInt takes interface type and tries to convert it to int32

func ConvertToString

func ConvertToString(intf interface{}) (string, error)

ConvertToString takes interface type and tries to convert it to string

func CopyMap

func CopyMap(originalMap map[string]string) map[string]string

CopyMap duplicates map as it creates new map and puts there all the

key value pairs that were included in the first map

func ExecuteAndGetResult

func ExecuteAndGetResult(pod *corev1.Pod, managementOperation string) (interface{}, error)

ExecuteAndGetResult executes the JBoss CLI operation provided as the string in parameter 'managementOperation'

It will be executed by call of 'jboss-cli.sh' at the particular pod.
When succesful it returns the result part of the returned json, otherwise it returns nil with error describing failure details.

func ExecuteMgmtOp

func ExecuteMgmtOp(pod *corev1.Pod, mgmtOpString string) (map[string]interface{}, error)

ExecuteMgmtOp executes WildFly managemnt operation represented as a string

the execution runs as shh remote command with jboss-cli.sh executed on the pod
returns the JSON as the return value from the operation

func ExecuteOpAndWaitForServerBeingReady

func ExecuteOpAndWaitForServerBeingReady(reqLogger logr.Logger, mgmtOp string, pod *corev1.Pod) error

ExecuteOpAndWaitForServerBeingReady executes WildFly management operation on the pod

this operation is checked to succeed and then waits for the container is ready
this method is assumed to be used for reload/restart operations
returns error if execution was not processed successfully

func GetEnvAsDuration

func GetEnvAsDuration(key string, fallbackDurationAmount int64, durationType time.Duration) time.Duration

GetEnvAsDuration returns defined environment variable as duration

while it expects the environment variable contains the number defined in duration type
defined as a third parameter. The result will be returned as duration.
If env variable is not found then the default value as duration is returned (defined by the duration type)
e.g. call 'GetEnvAsDuration("TIMEOUT", 10, time.Second)' means
 search for the TIMEOUT env variable and the value is expected being defined in seconds,
 if the env var is not found then returns duration of 10 seconds

func GetEnvAsInt

func GetEnvAsInt(key string, fallbackInteger int64) int64

GetEnvAsInt returns defined environment variable as an integer

or default value is returned if the env var is not configured

func GetTransactionRecoveryPort

func GetTransactionRecoveryPort(pod *corev1.Pod) (int32, error)

GetTransactionRecoveryPort reads management to find out the recovery port

func IsAppServerRunningViaJBossCli

func IsAppServerRunningViaJBossCli(pod *corev1.Pod) (bool, error)

IsAppServerRunningViaJBossCli runs JBoss CLI call to app server to find out if is in state 'running'

if 'running' then returns true, otherwise false
when false is returned then error contains a message with app server's state

func IsMgmtOutcomeSuccesful

func IsMgmtOutcomeSuccesful(jsonBody map[string]interface{}) bool

IsMgmtOutcomeSuccesful verifies if the management operation was succcesfull

func ListSubsystems

func ListSubsystems(pod *corev1.Pod) ([]string, error)

ListSubsystems list the available subsystems in the application server at the po

func MapMerge

func MapMerge(firstMap map[string]string, secondOverwritingMap map[string]string) map[string]string

MapMerge merges the two maps together and returns the result. If one of them is nil then is ommitted from the merged result If both maps are null then an empty initialized map is returned The second map rewrites data of the first map in the result if there are such

func ReadJSONDataByIndex

func ReadJSONDataByIndex(json interface{}, indexes ...string) interface{}

ReadJSONDataByIndex iterates over the JSON object to return

data saved at the provided index. It returns json data as interface{}.

func RemoveFromList

func RemoveFromList(list []string, s string) []string

RemoveFromList iterates over the list and removes all occurences

of the string s. The list without the s strings is returned.

func SanitizeVolumeName

func SanitizeVolumeName(name string) string

SanitizeVolumeName ensures that the given volume name is a valid DNS-1123 label accepted by Kubernetes.

func SortPodListByName

func SortPodListByName(podList *corev1.PodList) *corev1.PodList

SortPodListByName sorts the pod list by number in the name

expecting the format which the StatefulSet works with which is `<podname>-<number>`

Types

type RemoteOperationsInterface

type RemoteOperationsInterface interface {
	Execute(pod *corev1.Pod, command string) (string, error)
	SocketConnect(hostname string, port int32, command string) (string, error)
	VerifyLogContainsRegexp(pod *corev1.Pod, logFromTime *time.Time, regexpLineCheck *regexp.Regexp) (string, error)
	ObtainLogLatestTimestamp(pod *corev1.Pod) (*time.Time, error)
}
var (
	RemoteOps RemoteOperationsInterface
)

type RemoteOperationsStruct

type RemoteOperationsStruct struct{}

func (RemoteOperationsStruct) Execute

func (RemoteOperationsStruct) Execute(pod *corev1.Pod, command string) (string, error)

Execute executes a command inside the remote pod

func (RemoteOperationsStruct) ObtainLogLatestTimestamp

func (RemoteOperationsStruct) ObtainLogLatestTimestamp(pod *corev1.Pod) (*time.Time, error)

ObtainLogLatestTimestamp reads log from pod and find out

what is the latest log record at the time
and returns time stamp of the record

func (RemoteOperationsStruct) SocketConnect

func (RemoteOperationsStruct) SocketConnect(hostname string, port int32, command string) (string, error)

SocketConnect send a command (a string) to the defined hostname and port

where it connects to with 'net.Dial' tcp connection

func (RemoteOperationsStruct) VerifyLogContainsRegexp

func (RemoteOperationsStruct) VerifyLogContainsRegexp(pod *corev1.Pod, logFromTime *time.Time, regexpLineCheck *regexp.Regexp) (string, error)

VerifyLogContainsRegexp checks if a line in the log from the pod matches the provided regexp

the log could be limited to be taken from particular time further, when no time defined the log is not limited by time

Jump to

Keyboard shortcuts

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