use of com.google.cloud.scheduler.v1beta1.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);
}
}
use of com.google.cloud.scheduler.v1beta1.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());
}
use of com.google.cloud.scheduler.v1beta1.Job in project java-scheduler by googleapis.
the class CloudSchedulerClientTest method listJobsTest.
@Test
public void listJobsTest() throws Exception {
Job responsesElement = Job.newBuilder().build();
ListJobsResponse expectedResponse = ListJobsResponse.newBuilder().setNextPageToken("").addAllJobs(Arrays.asList(responsesElement)).build();
mockCloudScheduler.addResponse(expectedResponse);
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
ListJobsPagedResponse pagedListResponse = client.listJobs(parent);
List<Job> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getJobsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockCloudScheduler.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListJobsRequest actualRequest = ((ListJobsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.scheduler.v1beta1.Job in project java-scheduler by googleapis.
the class CloudSchedulerClientTest method listJobsTest2.
@Test
public void listJobsTest2() throws Exception {
Job responsesElement = Job.newBuilder().build();
ListJobsResponse expectedResponse = ListJobsResponse.newBuilder().setNextPageToken("").addAllJobs(Arrays.asList(responsesElement)).build();
mockCloudScheduler.addResponse(expectedResponse);
String parent = "parent-995424086";
ListJobsPagedResponse pagedListResponse = client.listJobs(parent);
List<Job> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getJobsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockCloudScheduler.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListJobsRequest actualRequest = ((ListJobsRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.scheduler.v1beta1.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);
}
Aggregations