Class StUtils


  • public class StUtils
    extends Object
    • 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
      • changeOrgAndTagInImageMap

        public static String changeOrgAndTagInImageMap​(String imageMap)
      • createContainerEnvVarsFromMap

        public static List<io.strimzi.api.kafka.model.ContainerEnvVar> createContainerEnvVarsFromMap​(Map<String,​String> envVars)
      • checkEnvVarInPod

        public static String checkEnvVarInPod​(String podName,
                                              String envVarName)
      • 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 container
        json - The json from which to extract properties
        envVar - 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 container
        envVar - 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 encryption
        tlsEncryption - tls listener encryption
        plainTlsAuth - plain listener authentication
        tlsTlsAuth - 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 the pods Steps: 1. get log from pod 2. find every occurrence of `}\n{` which will be replaced with `}, {` - by BETWEEN_JSON_OBJECTS_PATTERN 3. replace everything from beginning to the first proper JSON object with `{`- by ALL_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 checked
        containerName - 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 last timeSince
        Parameters:
        podName - name of pod to take a log from
        containerName - name of container
        timeSince - 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 file
        namespace - namespace where Strimzi should be installed
        Returns:
        deployment file content as String