io.fabric8.kubernetes.api.model.batch.DoneableJob Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.batch.DoneableJob. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PatchService.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private static EntityPatcher<Job> jobPatcher() {
    return (KubernetesClient client, String namespace, Job newObj, Job oldObj) -> {
        if (UserConfigurationCompare.configEqual(newObj, oldObj)) {
            return oldObj;
        }

        DoneableJob entity = client.batch().jobs().withName(oldObj.getMetadata().getName()).edit();

        if (!UserConfigurationCompare.configEqual(newObj.getMetadata(), oldObj.getMetadata())) {
            entity.withMetadata(newObj.getMetadata());
        }

        if (!UserConfigurationCompare.configEqual(newObj.getSpec().getSelector(), oldObj.getSpec().getSelector())) {
            entity.editSpec().withSelector(newObj.getSpec().getSelector());
        }

        if (!UserConfigurationCompare.configEqual(newObj.getSpec().getTemplate(), oldObj.getSpec().getSelector())) {
            entity.editSpec().withTemplate(newObj.getSpec().getTemplate());
        }

        return entity.done();
    };
}
 
Example #2
Source File: KubernetesResource.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
public static DoneableJob deployNewJob(Job job) {
    return new DoneableJob(job, kubernetesJob -> {
        TestUtils.waitFor("Job creation " + job.getMetadata().getName(), Constants.POLL_INTERVAL_FOR_RESOURCE_CREATION, Constants.TIMEOUT_FOR_CR_CREATION,
            () -> {
                try {
                    ResourceManager.kubeClient().getClient().batch().jobs().inNamespace(kubeClient().getNamespace()).createOrReplace(kubernetesJob);
                    return true;
                } catch (KubernetesClientException e) {
                    if (e.getMessage().contains("object is being deleted")) {
                        return false;
                    } else {
                        throw e;
                    }
                }
            }
        );
        return deleteLater(kubernetesJob);
    });
}
 
Example #3
Source File: JobOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
public JobOperationsImpl(OperationContext context) {
  super(context.withApiGroupName("batch")
    .withApiGroupVersion("v1")
    .withPlural("jobs"));

  this.type = Job.class;
  this.listType = JobList.class;
  this.doneableType = DoneableJob.class;
}
 
Example #4
Source File: JobOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Override
public ScalableResource<Job, DoneableJob> load(InputStream is) {
  try {
    Job item = unmarshal(is, Job.class);
    return new JobOperationsImpl(context.withItem(item));
  } catch (Throwable t) {
    throw KubernetesClientException.launderThrowable(t);
  }
}
 
Example #5
Source File: KafkaClientsResource.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static DoneableJob producerStrimzi(String producerName, String bootstrapServer, String topicName, int messageCount) {
    return producerStrimzi(producerName, bootstrapServer, topicName, messageCount, "");
}
 
Example #6
Source File: KafkaClientsResource.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static DoneableJob producerStrimzi(String producerName, String bootstrapServer, String topicName, int messageCount, String additionalConfig) {
    Map<String, String> producerLabels = new HashMap<>();
    producerLabels.put("app", producerName);
    producerLabels.put(Constants.KAFKA_CLIENTS_LABEL_KEY, Constants.KAFKA_CLIENTS_LABEL_VALUE);

    return KubernetesResource.deployNewJob(new JobBuilder()
        .withNewMetadata()
            .withNamespace(ResourceManager.kubeClient().getNamespace())
            .withLabels(producerLabels)
            .withName(producerName)
        .endMetadata()
        .withNewSpec()
            .withNewTemplate()
                .withNewMetadata()
                    .withLabels(producerLabels)
                .endMetadata()
                .withNewSpec()
                    .withRestartPolicy("OnFailure")
                    .withContainers()
                        .addNewContainer()
                        .withName(producerName)
                            .withImage("strimzi/hello-world-producer:latest")
                                .addNewEnv()
                                    .withName("BOOTSTRAP_SERVERS")
                                    .withValue(bootstrapServer)
                                .endEnv()
                                .addNewEnv()
                                    .withName("TOPIC")
                                    .withValue(topicName)
                                .endEnv()
                                .addNewEnv()
                                    .withName("DELAY_MS")
                                    .withValue("1000")
                                .endEnv()
                                .addNewEnv()
                                    .withName("LOG_LEVEL")
                                    .withValue("DEBUG")
                                .endEnv()
                                .addNewEnv()
                                    .withName("MESSAGE_COUNT")
                                    .withValue(String.valueOf(messageCount))
                                .endEnv()
                                .addNewEnv()
                                    .withName("PRODUCER_ACKS")
                                    .withValue("all")
                                .endEnv()
                                .addNewEnv()
                                    .withName("ADDITIONAL_CONFIG")
                                    .withValue(additionalConfig)
                                .endEnv()
                        .endContainer()
                    .endSpec()
                .endTemplate()
            .endSpec()
            .build());
}
 
Example #7
Source File: KafkaClientsResource.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static DoneableJob consumerStrimzi(String consumerName, String bootstrapServer, String topicName, int messageCount) {
    return consumerStrimzi(consumerName, bootstrapServer, topicName, messageCount, "", generateRandomConsumerGroup());
}
 
Example #8
Source File: KafkaClientsResource.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static DoneableJob consumerStrimzi(String consumerName, String bootstrapServer, String topicName, int messageCount, String additionalConfig, String consumerGroup) {
    Map<String, String> consumerLabels = new HashMap<>();
    consumerLabels.put("app", consumerName);
    consumerLabels.put(Constants.KAFKA_CLIENTS_LABEL_KEY, Constants.KAFKA_CLIENTS_LABEL_VALUE);

    return KubernetesResource.deployNewJob(new JobBuilder()
        .withNewMetadata()
            .withNamespace(ResourceManager.kubeClient().getNamespace())
            .withLabels(consumerLabels)
            .withName(consumerName)
        .endMetadata()
        .withNewSpec()
            .withNewTemplate()
                .withNewMetadata()
                    .withLabels(consumerLabels)
                .endMetadata()
                .withNewSpec()
                    .withRestartPolicy("OnFailure")
                    .withContainers()
                        .addNewContainer()
                        .withName(consumerName)
                            .withImage("strimzi/hello-world-consumer:latest")
                                .addNewEnv()
                                    .withName("BOOTSTRAP_SERVERS")
                                    .withValue(bootstrapServer)
                                .endEnv()
                                .addNewEnv()
                                    .withName("TOPIC")
                                    .withValue(topicName)
                                .endEnv()
                                .addNewEnv()
                                    .withName("DELAY_MS")
                                    .withValue("1000")
                                .endEnv()
                                .addNewEnv()
                                    .withName("LOG_LEVEL")
                                    .withValue("DEBUG")
                                .endEnv()
                                .addNewEnv()
                                    .withName("MESSAGE_COUNT")
                                    .withValue(String.valueOf(messageCount))
                                .endEnv()
                               .addNewEnv()
                                    .withName("GROUP_ID")
                                    .withValue(consumerGroup)
                                .endEnv()
                                .addNewEnv()
                                    .withName("ADDITIONAL_CONFIG")
                                    .withValue(additionalConfig)
                                .endEnv()
                        .endContainer()
                    .endSpec()
                .endTemplate()
            .endSpec()
            .build());
}
 
Example #9
Source File: ExtensionsAPIGroupDSL.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Deprecated
MixedOperation<Job, JobList, DoneableJob, ScalableResource<Job, DoneableJob>> jobs();
 
Example #10
Source File: JobOperationsImpl.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public ScalableResource<Job, DoneableJob> fromServer() {
  return new JobOperationsImpl(context.withReloadingFromServer(true));
}
 
Example #11
Source File: ExtensionsAPIGroupClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
@Deprecated
public MixedOperation<Job, JobList, DoneableJob, ScalableResource<Job, DoneableJob>> jobs() {
  return new JobOperationsImpl(httpClient, getConfiguration());
}
 
Example #12
Source File: BatchAPIGroupClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public MixedOperation<Job, JobList, DoneableJob, ScalableResource<Job, DoneableJob>> jobs() {
  return new JobOperationsImpl(httpClient, getConfiguration());
}
 
Example #13
Source File: BatchAPIGroupDSL.java    From kubernetes-client with Apache License 2.0 votes vote down vote up
MixedOperation<Job, JobList, DoneableJob, ScalableResource<Job, DoneableJob>> jobs();