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();
}
Aggregations