Search in sources :

Example 1 with Exec

use of io.strimzi.test.executor.Exec in project strimzi by strimzi.

the class OlmResource method parseExamplesFromCsv.

private static Map<String, JsonObject> parseExamplesFromCsv(String csvName, String namespace) {
    String csvString = ResourceManager.cmdKubeClient().exec(true, Level.DEBUG, "get", "csv", csvName, "-o", "json", "-n", namespace).out();
    JsonObject csv = new JsonObject(csvString);
    String almExamples = csv.getJsonObject("metadata").getJsonObject("annotations").getString("alm-examples");
    JsonArray examples = new JsonArray(almExamples);
    return examples.stream().map(o -> (JsonObject) o).collect(Collectors.toMap(object -> object.getString("kind"), object -> object));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Environment(io.strimzi.systemtest.Environment) OlmInstallationStrategy(io.strimzi.systemtest.enums.OlmInstallationStrategy) KubeClusterResource.cmdKubeClient(io.strimzi.test.k8s.KubeClusterResource.cmdKubeClient) Level(org.apache.logging.log4j.Level) HashMap(java.util.HashMap) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) OlmUtils(io.strimzi.systemtest.utils.specific.OlmUtils) Stack(java.util.Stack) StandardCopyOption(java.nio.file.StandardCopyOption) ByteArrayInputStream(java.io.ByteArrayInputStream) Charset(java.nio.charset.Charset) KubeClusterResource(io.strimzi.test.k8s.KubeClusterResource) CR_CREATION_TIMEOUT(io.strimzi.systemtest.resources.ResourceManager.CR_CREATION_TIMEOUT) Map(java.util.Map) TestUtils(io.strimzi.test.TestUtils) JsonObject(io.vertx.core.json.JsonObject) Files(java.nio.file.Files) Constants(io.strimzi.systemtest.Constants) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) KubeClusterResource.kubeClient(io.strimzi.test.k8s.KubeClusterResource.kubeClient) JsonArray(io.vertx.core.json.JsonArray) DeploymentUtils(io.strimzi.systemtest.utils.kubeUtils.controllers.DeploymentUtils) Exec(io.strimzi.test.executor.Exec) Logger(org.apache.logging.log4j.Logger) ResourceManager(io.strimzi.systemtest.resources.ResourceManager) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) JsonObject(io.vertx.core.json.JsonObject)

Example 2 with Exec

use of io.strimzi.test.executor.Exec in project strimzi by strimzi.

the class MetricsCollector method collectMetrics.

/**
 * Collect metrics from specific pod
 * @return collected metrics
 */
private String collectMetrics(String metricsPodIp) throws InterruptedException, ExecutionException, IOException {
    List<String> executableCommand = Arrays.asList(cmdKubeClient(namespaceName).toString(), "exec", scraperPodName, "-n", namespaceName, "--", "curl", metricsPodIp + ":" + metricsPort + metricsPath);
    Exec exec = new Exec();
    // 20 seconds should be enough for collect data from the pod
    int ret = exec.execute(null, executableCommand, 20_000);
    LOGGER.info("Metrics collection for PodIp {} from Pod {} finished with return code: {}", metricsPodIp, scraperPodName, ret);
    return exec.out();
}
Also used : Exec(io.strimzi.test.executor.Exec)

Example 3 with Exec

use of io.strimzi.test.executor.Exec in project strimzi by strimzi.

the class MetricsIsolatedST method getExporterRunScript.

private String getExporterRunScript(String podName) throws InterruptedException, ExecutionException, IOException {
    ArrayList<String> command = new ArrayList<>();
    command.add("cat");
    command.add("/tmp/run.sh");
    ArrayList<String> executableCommand = new ArrayList<>();
    executableCommand.addAll(Arrays.asList(cmdKubeClient().toString(), "exec", podName, "-n", INFRA_NAMESPACE, "--"));
    executableCommand.addAll(command);
    Exec exec = new Exec();
    // 20 seconds should be enough for collect data from the pod
    int ret = exec.execute(null, executableCommand, 20_000);
    synchronized (lock) {
        LOGGER.info("Metrics collection for pod {} return code - {}", podName, ret);
    }
    assertThat("Collected metrics should not be empty", exec.out(), not(emptyString()));
    return exec.out();
}
Also used : Exec(io.strimzi.test.executor.Exec) ArrayList(java.util.ArrayList) Matchers.emptyString(org.hamcrest.Matchers.emptyString)

Example 4 with Exec

use of io.strimzi.test.executor.Exec in project strimzi-kafka-operator by strimzi.

the class VerifiableClient method runClient.

/**
 * Run clients
 *
 * @param timeoutMs kill timeout in ms
 * @return true if command end with exit code 0
 */
private boolean runClient(long timeoutMs, boolean logToOutput) {
    messages.clear();
    try {
        executor = new Exec();
        ArrayList<String> command = prepareCommand();
        LOGGER.info("Client command: {}", String.join(" ", command));
        int ret = executor.execute(null, command, timeoutMs);
        synchronized (lock) {
            if (logToOutput) {
                if (ret == 0) {
                    parseToList(executor.out());
                } else {
                    LOGGER.info("{} RETURN code: {}", clientType, ret);
                    if (!executor.out().isEmpty()) {
                        LOGGER.info("======STDOUT START=======");
                        LOGGER.info("{}", Exec.cutExecutorLog(executor.out()));
                        LOGGER.info("======STDOUT END======");
                    }
                    if (!executor.err().isEmpty()) {
                        LOGGER.info("======STDERR START=======");
                        LOGGER.info("{}", Exec.cutExecutorLog(executor.err()));
                        LOGGER.info("======STDERR END======");
                    }
                }
            }
        }
        return ret == 0;
    } catch (InterruptedException | ExecutionException | IOException e) {
        e.printStackTrace();
        return false;
    }
}
Also used : Exec(io.strimzi.test.executor.Exec) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with Exec

use of io.strimzi.test.executor.Exec in project strimzi by strimzi.

the class VerifiableClient method runClient.

/**
 * Run clients
 *
 * @param timeoutMs kill timeout in ms
 * @return true if command end with exit code 0
 */
private boolean runClient(long timeoutMs, boolean logToOutput) {
    messages.clear();
    try {
        executor = new Exec();
        ArrayList<String> command = prepareCommand();
        LOGGER.info("Client command: {}", String.join(" ", command));
        int ret = executor.execute(null, command, timeoutMs);
        synchronized (lock) {
            if (logToOutput) {
                if (ret == 0) {
                    parseToList(executor.out());
                } else {
                    LOGGER.info("{} RETURN code: {}", clientType, ret);
                    if (!executor.out().isEmpty()) {
                        LOGGER.info("======STDOUT START=======");
                        LOGGER.info("{}", Exec.cutExecutorLog(executor.out()));
                        LOGGER.info("======STDOUT END======");
                    }
                    if (!executor.err().isEmpty()) {
                        LOGGER.info("======STDERR START=======");
                        LOGGER.info("{}", Exec.cutExecutorLog(executor.err()));
                        LOGGER.info("======STDERR END======");
                    }
                }
            }
        }
        return ret == 0;
    } catch (InterruptedException | ExecutionException | IOException e) {
        e.printStackTrace();
        return false;
    }
}
Also used : Exec(io.strimzi.test.executor.Exec) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Exec (io.strimzi.test.executor.Exec)8 IOException (java.io.IOException)4 Constants (io.strimzi.systemtest.Constants)2 Environment (io.strimzi.systemtest.Environment)2 OlmInstallationStrategy (io.strimzi.systemtest.enums.OlmInstallationStrategy)2 ResourceManager (io.strimzi.systemtest.resources.ResourceManager)2 CR_CREATION_TIMEOUT (io.strimzi.systemtest.resources.ResourceManager.CR_CREATION_TIMEOUT)2 DeploymentUtils (io.strimzi.systemtest.utils.kubeUtils.controllers.DeploymentUtils)2 OlmUtils (io.strimzi.systemtest.utils.specific.OlmUtils)2 TestUtils (io.strimzi.test.TestUtils)2 KubeClusterResource (io.strimzi.test.k8s.KubeClusterResource)2 KubeClusterResource.cmdKubeClient (io.strimzi.test.k8s.KubeClusterResource.cmdKubeClient)2 KubeClusterResource.kubeClient (io.strimzi.test.k8s.KubeClusterResource.kubeClient)2 JsonArray (io.vertx.core.json.JsonArray)2 JsonObject (io.vertx.core.json.JsonObject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 InputStream (java.io.InputStream)2 Charset (java.nio.charset.Charset)2 Files (java.nio.file.Files)2