Search in sources :

Example 16 with Job

use of com.google.cloud.scheduler.v1.Job in project kubernetes-client by fabric8io.

the class JobExample method main.

public static void main(String[] args) {
    final ConfigBuilder configBuilder = new ConfigBuilder();
    if (args.length > 0) {
        configBuilder.withMasterUrl(args[0]);
    }
    try (KubernetesClient client = new KubernetesClientBuilder().withConfig(configBuilder.build()).build()) {
        final String namespace = "default";
        final Job job = new JobBuilder().withApiVersion("batch/v1").withNewMetadata().withName("pi").withLabels(Collections.singletonMap("label1", "maximum-length-of-63-characters")).withAnnotations(Collections.singletonMap("annotation1", "some-very-long-annotation")).endMetadata().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().withName("pi").withImage("perl").withArgs("perl", "-Mbignum=bpi", "-wle", "print bpi(2000)").endContainer().withRestartPolicy("Never").endSpec().endTemplate().endSpec().build();
        logger.info("Creating job pi.");
        client.batch().v1().jobs().inNamespace(namespace).createOrReplace(job);
        // Get All pods created by the job
        PodList podList = client.pods().inNamespace(namespace).withLabel("job-name", job.getMetadata().getName()).list();
        // Wait for pod to complete
        client.pods().inNamespace(namespace).withName(podList.getItems().get(0).getMetadata().getName()).waitUntilCondition(pod -> pod.getStatus().getPhase().equals("Succeeded"), 2, TimeUnit.MINUTES);
        // Print Job's log
        String joblog = client.batch().v1().jobs().inNamespace(namespace).withName("pi").getLog();
        logger.info(joblog);
    } catch (KubernetesClientException e) {
        logger.error("Unable to create job", e);
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) PodList(io.fabric8.kubernetes.api.model.PodList) KubernetesClientBuilder(io.fabric8.kubernetes.client.KubernetesClientBuilder) JobBuilder(io.fabric8.kubernetes.api.model.batch.v1.JobBuilder) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) Job(io.fabric8.kubernetes.api.model.batch.v1.Job) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 17 with Job

use of com.google.cloud.scheduler.v1.Job in project kubernetes-client by fabric8io.

the class JobIT method testCreateWithGenerateName.

@Test
public void testCreateWithGenerateName() {
    // Given
    Job job = getJobBuilder().editMetadata().withName(null).withGenerateName("test-job-").endMetadata().build();
    // When
    Job jobCreated = client.batch().jobs().inNamespace(session.getNamespace()).create(job);
    // Then
    assertNotNull(jobCreated);
    assertTrue(jobCreated.getMetadata().getName().contains("test-job-"));
    assertEquals("test-job-", jobCreated.getMetadata().getGenerateName());
    assertNotNull(jobCreated.getMetadata().getName());
    assertNotEquals("test-job-", jobCreated.getMetadata().getName());
    assertTrue(client.batch().jobs().inNamespace(session.getNamespace()).withName(jobCreated.getMetadata().getName()).delete());
}
Also used : Job(io.fabric8.kubernetes.api.model.batch.v1.Job) Test(org.junit.Test)

Example 18 with Job

use of com.google.cloud.scheduler.v1.Job in project java-scheduler by googleapis.

the class ITSystemTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    /* The job will be delivered by publishing a message to the given Pub/Sub topic. */
    publisherClient = TopicAdminClient.create();
    publisherClient.createTopic(TOPIC_NAME);
    client = CloudSchedulerClient.create();
    Job createJob = Job.newBuilder().setName(JOB_NAME).setPubsubTarget(PUB_SUB_TARGET).setSchedule(SCHEDULE).setTimeZone(TIME_ZONE).build();
    client.createJob(PARENT, createJob);
}
Also used : Job(com.google.cloud.scheduler.v1beta1.Job) BeforeClass(org.junit.BeforeClass)

Example 19 with Job

use of com.google.cloud.scheduler.v1.Job in project java-scheduler by googleapis.

the class ITSystemTest method updateJobTest.

@Test
public void updateJobTest() {
    String timeZone = "PST";
    String schedule = "25 8 * * *";
    Job updateJob = Job.newBuilder().setName(JOB_NAME).setPubsubTarget(PUB_SUB_TARGET).setSchedule(schedule).setTimeZone(timeZone).build();
    UpdateJobRequest updateJobRequest = UpdateJobRequest.newBuilder().setJob(updateJob).build();
    Job job = client.updateJob(updateJobRequest);
    assertEquals(JOB_NAME, job.getName());
    assertEquals(PUB_SUB_TARGET, job.getPubsubTarget());
    assertEquals(Job.State.ENABLED, job.getState());
    assertEquals(timeZone, job.getTimeZone());
    assertEquals(schedule, job.getSchedule());
}
Also used : ByteString(com.google.protobuf.ByteString) UpdateJobRequest(com.google.cloud.scheduler.v1beta1.UpdateJobRequest) Job(com.google.cloud.scheduler.v1beta1.Job) Test(org.junit.Test)

Example 20 with Job

use of com.google.cloud.scheduler.v1.Job in project java-scheduler by googleapis.

the class ITSystemTest method getJobTest.

@Test
public void getJobTest() {
    Job job = client.getJob(JOB_NAME);
    assertJobDetails(job);
}
Also used : Job(com.google.cloud.scheduler.v1beta1.Job) Test(org.junit.Test)

Aggregations

Job (org.pentaho.platform.api.scheduler2.Job)94 Test (org.junit.Test)89 Job (io.fabric8.kubernetes.api.model.batch.v1.Job)38 Serializable (java.io.Serializable)25 ArrayList (java.util.ArrayList)24 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)21 Job (com.google.cloud.talent.v4beta1.Job)20 HashMap (java.util.HashMap)20 JobScheduleRequest (org.pentaho.platform.web.http.api.resources.JobScheduleRequest)19 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)18 SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)17 JobServiceClient (com.google.cloud.talent.v4beta1.JobServiceClient)16 Date (java.util.Date)14 IJobFilter (org.pentaho.platform.api.scheduler2.IJobFilter)14 Job (com.google.cloud.video.transcoder.v1.Job)13 TranscoderServiceClient (com.google.cloud.video.transcoder.v1.TranscoderServiceClient)13 JobBuilder (io.fabric8.kubernetes.api.model.batch.v1.JobBuilder)13 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)12 Map (java.util.Map)11 Test (org.junit.jupiter.api.Test)10