Package io.strimzi.systemtest.utils
Class StUtils
- java.lang.Object
-
- io.strimzi.systemtest.utils.StUtils
-
public class StUtils extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
changeDeploymentNamespace(File deploymentFile, String namespace)
Change Deployment configuration before applying it.static String
changeOrgAndTag(String image)
The method to configure docker image to use proper docker registry, docker org and docker tag.static String
changeOrgAndTagInImageMap(String imageMap)
static String
checkEnvVarInPod(String podName, String envVarName)
static boolean
checkLogForJSONFormat(Map<String,String> pods, String containerName)
Method for checking if JSON format logging is set for thepods
Steps: 1.static Properties
configMap2Properties(io.fabric8.kubernetes.api.model.ConfigMap cm)
static List<io.strimzi.api.kafka.model.ContainerEnvVar>
createContainerEnvVarsFromMap(Map<String,String> envVars)
static io.vertx.core.json.JsonArray
expectedServiceDiscoveryInfo(int port, String protocol, String auth, boolean tls)
static io.vertx.core.json.JsonArray
expectedServiceDiscoveryInfo(String plainEcryption, String tlsEncryption, boolean plainTlsAuth, boolean tlsTlsAuth)
Build jsonArray with data about service discovery based on pass configurationstatic List<String>
getLinesWithoutCommentsAndEmptyLines(String config)
static String
getLogFromPodByTime(String podName, String containerName, String timeSince)
Method which returns log from lasttimeSince
static Map<String,Object>
getPropertiesFromJson(int containerIndex, String json, String envVar)
Get a Map of properties from an environment variable in json.static String
globalVariableJsonPathBuilder(int containerIndex, String envVar)
Get a jsonPath which can be used to extract envariable variables from a specstatic boolean
isAllowedOnCurrentK8sVersion(String maxKubernetesVersion)
Method for check if test is allowed on current Kubernetes versionstatic boolean
isAllowOnCurrentEnvironment(String envVariableForCheck)
Method for check if test is allowed on specific testing environmentstatic Map<String,Object>
loadProperties(String keyValuePairs)
Translate key/value pairs formatted like properties into a Mapstatic Properties
stringToProperties(String str)
-
-
-
Method Detail
-
isAllowOnCurrentEnvironment
public static boolean isAllowOnCurrentEnvironment(String envVariableForCheck)
Method for check if test is allowed on specific testing environment- Parameters:
envVariableForCheck
- environment variable which is specific for a specific environment- Returns:
- true if test is allowed, false if not
-
changeOrgAndTag
public static String changeOrgAndTag(String image)
The method to configure docker image to use proper docker registry, docker org and docker tag.- Parameters:
image
- Image that needs to be changed- Returns:
- Updated docker image with a proper registry, org, tag
-
createContainerEnvVarsFromMap
public static List<io.strimzi.api.kafka.model.ContainerEnvVar> createContainerEnvVarsFromMap(Map<String,String> envVars)
-
loadProperties
public static Map<String,Object> loadProperties(String keyValuePairs)
Translate key/value pairs formatted like properties into a Map- Parameters:
keyValuePairs
- Pairs in key=value format; pairs are separated by newlines- Returns:
- THe map of key/values
-
getPropertiesFromJson
public static Map<String,Object> getPropertiesFromJson(int containerIndex, String json, String envVar)
Get a Map of properties from an environment variable in json.- Parameters:
containerIndex
- name of the containerjson
- The json from which to extract propertiesenvVar
- The environment variable name- Returns:
- The properties which the variable contains
-
globalVariableJsonPathBuilder
public static String globalVariableJsonPathBuilder(int containerIndex, String envVar)
Get a jsonPath which can be used to extract envariable variables from a spec- Parameters:
containerIndex
- index of the containerenvVar
- The environment variable name- Returns:
- The json path
-
stringToProperties
public static Properties stringToProperties(String str)
-
configMap2Properties
public static Properties configMap2Properties(io.fabric8.kubernetes.api.model.ConfigMap cm)
-
getLinesWithoutCommentsAndEmptyLines
public static List<String> getLinesWithoutCommentsAndEmptyLines(String config)
-
expectedServiceDiscoveryInfo
public static io.vertx.core.json.JsonArray expectedServiceDiscoveryInfo(int port, String protocol, String auth, boolean tls)
-
expectedServiceDiscoveryInfo
public static io.vertx.core.json.JsonArray expectedServiceDiscoveryInfo(String plainEcryption, String tlsEncryption, boolean plainTlsAuth, boolean tlsTlsAuth)
Build jsonArray with data about service discovery based on pass configuration- Parameters:
plainEcryption
- plain listener encryptiontlsEncryption
- tls listener encryptionplainTlsAuth
- plain listener authenticationtlsTlsAuth
- tls listener authentication- Returns:
- builded jsonArray
-
checkLogForJSONFormat
public static boolean checkLogForJSONFormat(Map<String,String> pods, String containerName)
Method for checking if JSON format logging is set for thepods
Steps: 1. get log from pod 2. find every occurrence of `}\n{` which will be replaced with `}, {` - byBETWEEN_JSON_OBJECTS_PATTERN
3. replace everything from beginning to the first proper JSON object with `{`- byALL_BEFORE_JSON_PATTERN
4. also add `[` to beginning and `]` to the end of String to create proper JsonArray 5. try to parse the JsonArray- Parameters:
pods
- snapshot of pods to be checkedcontainerName
- name of container from which to take the log- Returns:
- if JSON format was set up or not
-
isAllowedOnCurrentK8sVersion
public static boolean isAllowedOnCurrentK8sVersion(String maxKubernetesVersion)
Method for check if test is allowed on current Kubernetes version- Parameters:
maxKubernetesVersion
- kubernetes version which test needs- Returns:
- true if test is allowed, false if not
-
getLogFromPodByTime
public static String getLogFromPodByTime(String podName, String containerName, String timeSince)
Method which returns log from lasttimeSince
- Parameters:
podName
- name of pod to take a log fromcontainerName
- name of containertimeSince
- time from which the log should be taken - 3s, 5m, 2h -- back- Returns:
- log from the pod
-
changeDeploymentNamespace
public static String changeDeploymentNamespace(File deploymentFile, String namespace)
Change Deployment configuration before applying it. We set different namespace, log level and image pull policy. It's mostly used for use cases where we use direct kubectl command instead of fabric8 calls to api.- Parameters:
deploymentFile
- loaded Strimzi deployment filenamespace
- namespace where Strimzi should be installed- Returns:
- deployment file content as String
-
-