Search in sources :

Example 1 with JobCondition

use of io.fabric8.kubernetes.api.model.batch.v1.JobCondition in project pipelite by enasequence.

the class KubernetesExecutorTest method describeJobsStateSuccess.

@Test
public void describeJobsStateSuccess() {
    JobStatus jobStatus = new JobStatus();
    jobStatus.setCompletionTime("test");
    assertThat(KubernetesExecutor.describeJobsResultFromStatus(jobStatus).isSuccess()).isTrue();
    jobStatus = new JobStatus();
    JobCondition jobCondition = new JobCondition();
    jobCondition.setType("Complete");
    jobCondition.setStatus("true");
    jobStatus.setConditions(Arrays.asList(jobCondition));
    assertThat(KubernetesExecutor.describeJobsResultFromStatus(jobStatus).isSuccess()).isTrue();
}
Also used : JobStatus(io.fabric8.kubernetes.api.model.batch.v1.JobStatus) JobCondition(io.fabric8.kubernetes.api.model.batch.v1.JobCondition) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with JobCondition

use of io.fabric8.kubernetes.api.model.batch.v1.JobCondition in project strimzi-kafka-operator by strimzi.

the class JobUtils method logCurrentJobStatus.

/**
 * Log actual status of Job with pods.
 * @param jobName - name of the job, for which we should scrape status
 * @param namespace - namespace/project where is job running
 */
public static void logCurrentJobStatus(String jobName, String namespace) {
    Job currentJob = kubeClient().getJob(namespace, jobName);
    if (currentJob != null && currentJob.getStatus() != null) {
        List<String> log = new ArrayList<>(asList(Constants.JOB, " status:\n"));
        List<JobCondition> conditions = currentJob.getStatus().getConditions();
        log.add("\tActive: " + currentJob.getStatus().getActive());
        log.add("\n\tFailed: " + currentJob.getStatus().getFailed());
        log.add("\n\tReady: " + currentJob.getStatus().getReady());
        log.add("\n\tSucceeded: " + currentJob.getStatus().getSucceeded());
        if (conditions != null) {
            List<String> conditionList = new ArrayList<>();
            for (JobCondition condition : conditions) {
                if (condition.getMessage() != null) {
                    conditionList.add("\t\tType: " + condition.getType() + "\n");
                    conditionList.add("\t\tMessage: " + condition.getMessage() + "\n");
                }
            }
            if (!conditionList.isEmpty()) {
                log.add("\n\tConditions:\n");
                log.addAll(conditionList);
            }
        }
        log.add("\n\nPods with conditions and messages:\n\n");
        for (Pod pod : kubeClient().namespace(currentJob.getMetadata().getNamespace()).listPodsByPrefixInName(jobName)) {
            log.add(pod.getMetadata().getName() + ":");
            List<String> podConditions = new ArrayList<>();
            for (PodCondition podCondition : pod.getStatus().getConditions()) {
                if (podCondition.getMessage() != null) {
                    podConditions.add("\n\tType: " + podCondition.getType() + "\n");
                    podConditions.add("\tMessage: " + podCondition.getMessage() + "\n");
                }
            }
            if (podConditions.isEmpty()) {
                log.add("\n\t<EMPTY>");
            } else {
                log.addAll(podConditions);
            }
            log.add("\n\n");
        }
        LOGGER.info("{}", String.join("", log).strip());
    }
}
Also used : JobCondition(io.fabric8.kubernetes.api.model.batch.v1.JobCondition) Pod(io.fabric8.kubernetes.api.model.Pod) ArrayList(java.util.ArrayList) Job(io.fabric8.kubernetes.api.model.batch.v1.Job) PodCondition(io.fabric8.kubernetes.api.model.PodCondition)

Example 3 with JobCondition

use of io.fabric8.kubernetes.api.model.batch.v1.JobCondition in project strimzi by strimzi.

the class JobUtils method logCurrentJobStatus.

/**
 * Log actual status of Job with pods.
 * @param jobName - name of the job, for which we should scrape status
 * @param namespace - namespace/project where is job running
 */
public static void logCurrentJobStatus(String jobName, String namespace) {
    Job currentJob = kubeClient().getJob(namespace, jobName);
    if (currentJob != null && currentJob.getStatus() != null) {
        List<String> log = new ArrayList<>(asList(Constants.JOB, " status:\n"));
        List<JobCondition> conditions = currentJob.getStatus().getConditions();
        log.add("\tActive: " + currentJob.getStatus().getActive());
        log.add("\n\tFailed: " + currentJob.getStatus().getFailed());
        log.add("\n\tReady: " + currentJob.getStatus().getReady());
        log.add("\n\tSucceeded: " + currentJob.getStatus().getSucceeded());
        if (conditions != null) {
            List<String> conditionList = new ArrayList<>();
            for (JobCondition condition : conditions) {
                if (condition.getMessage() != null) {
                    conditionList.add("\t\tType: " + condition.getType() + "\n");
                    conditionList.add("\t\tMessage: " + condition.getMessage() + "\n");
                }
            }
            if (!conditionList.isEmpty()) {
                log.add("\n\tConditions:\n");
                log.addAll(conditionList);
            }
        }
        log.add("\n\nPods with conditions and messages:\n\n");
        for (Pod pod : kubeClient().namespace(currentJob.getMetadata().getNamespace()).listPodsByPrefixInName(jobName)) {
            log.add(pod.getMetadata().getName() + ":");
            List<String> podConditions = new ArrayList<>();
            for (PodCondition podCondition : pod.getStatus().getConditions()) {
                if (podCondition.getMessage() != null) {
                    podConditions.add("\n\tType: " + podCondition.getType() + "\n");
                    podConditions.add("\tMessage: " + podCondition.getMessage() + "\n");
                }
            }
            if (podConditions.isEmpty()) {
                log.add("\n\t<EMPTY>");
            } else {
                log.addAll(podConditions);
            }
            log.add("\n\n");
        }
        LOGGER.info("{}", String.join("", log).strip());
    }
}
Also used : JobCondition(io.fabric8.kubernetes.api.model.batch.v1.JobCondition) Pod(io.fabric8.kubernetes.api.model.Pod) ArrayList(java.util.ArrayList) Job(io.fabric8.kubernetes.api.model.batch.v1.Job) PodCondition(io.fabric8.kubernetes.api.model.PodCondition)

Example 4 with JobCondition

use of io.fabric8.kubernetes.api.model.batch.v1.JobCondition in project pipelite by enasequence.

the class KubernetesExecutorTest method describeJobsStateError.

@Test
public void describeJobsStateError() {
    JobStatus jobStatus = new JobStatus();
    JobCondition jobCondition = new JobCondition();
    jobCondition.setType("Failed");
    jobCondition.setStatus("true");
    jobStatus.setConditions(Arrays.asList(jobCondition));
    assertThat(KubernetesExecutor.describeJobsResultFromStatus(jobStatus).isError()).isTrue();
}
Also used : JobStatus(io.fabric8.kubernetes.api.model.batch.v1.JobStatus) JobCondition(io.fabric8.kubernetes.api.model.batch.v1.JobCondition) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

JobCondition (io.fabric8.kubernetes.api.model.batch.v1.JobCondition)4 Pod (io.fabric8.kubernetes.api.model.Pod)2 PodCondition (io.fabric8.kubernetes.api.model.PodCondition)2 Job (io.fabric8.kubernetes.api.model.batch.v1.Job)2 JobStatus (io.fabric8.kubernetes.api.model.batch.v1.JobStatus)2 ArrayList (java.util.ArrayList)2 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2