Search in sources :

Example 1 with V1JobBuilder

use of io.kubernetes.client.openapi.models.V1JobBuilder in project cdap by caskdata.

the class KubeTwillPreparer method createJob.

/**
 * Deploys a {@link V1Job} to for runnable execution in Kubernetes.
 */
private V1ObjectMeta createJob(V1ObjectMeta metadata, Map<String, RuntimeSpecification> runtimeSpecs, Location runtimeConfigLocation) throws ApiException {
    int parallelism = getMainRuntimeSpecification(runtimeSpecs).getResourceSpecification().getInstances();
    V1Job job = new V1JobBuilder().withMetadata(metadata).withNewSpec().withManualSelector(true).withSelector(new V1LabelSelector().matchLabels(metadata.getLabels())).withParallelism(parallelism).withCompletions(parallelism).withBackoffLimit(0).withNewTemplate().withMetadata(metadata).withSpec(createPodSpec(runtimeConfigLocation, runtimeSpecs, "Never", Collections.singletonList(KubeMasterEnvironment.DISABLE_POD_DELETION))).endTemplate().endSpec().build();
    try {
        batchV1Api.createNamespacedJob(kubeNamespace, job, "true", null, null);
        LOG.trace("Created Job {} in Kubernetes.", metadata.getName());
    } catch (ApiException e) {
        if (e.getCode() == HttpURLConnection.HTTP_CONFLICT) {
            LOG.warn("The kubernetes job already exists : {}. Ignoring resubmission of the job.", e.getResponseBody());
        } else {
            throw e;
        }
    }
    return job.getMetadata();
}
Also used : V1Job(io.kubernetes.client.openapi.models.V1Job) V1JobBuilder(io.kubernetes.client.openapi.models.V1JobBuilder) V1LabelSelector(io.kubernetes.client.openapi.models.V1LabelSelector) ApiException(io.kubernetes.client.openapi.ApiException)

Aggregations

ApiException (io.kubernetes.client.openapi.ApiException)1 V1Job (io.kubernetes.client.openapi.models.V1Job)1 V1JobBuilder (io.kubernetes.client.openapi.models.V1JobBuilder)1 V1LabelSelector (io.kubernetes.client.openapi.models.V1LabelSelector)1