Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

control-service: Allow for jobs with no schedule to be deployed #835

Merged
merged 12 commits into from
May 17, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ private void updateCronJob(DataJob dataJob,
JobDeployment jobDeployment,
String lastDeployedBy) throws ApiException {
log.debug("Deploy cron job for data job {}", dataJob);
String schedule = dataJob.getJobConfig().getSchedule();

// Schedule defaults to Feb 30 (i.e. never) if no schedule has been given.
String schedule = StringUtils.isEmpty(dataJob.getJobConfig().getSchedule()) ? "0 0 30 2 *" : dataJob.getJobConfig().getSchedule();

var jobName = dataJob.getName();
var volume = KubernetesService.volume(VOLUME_NAME);
Expand Down Expand Up @@ -291,6 +293,7 @@ private Map<String, String> getJobAnnotations(DataJob dataJob, String deployedBy
jobPodAnnotations.put(JobAnnotation.DEPLOYED_BY.getValue(), deployedBy);
jobPodAnnotations.put(JobAnnotation.DEPLOYED_DATE.getValue(), OffsetDateTime.now().toString());
jobPodAnnotations.put(JobAnnotation.STARTED_BY.getValue(), "scheduled/runtime"); //TODO are those valid?
jobPodAnnotations.put(JobAnnotation.UNSCHEDULED.getValue(), (StringUtils.isEmpty(dataJob.getJobConfig().getSchedule()) ? "true" : "false"));
return jobPodAnnotations;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public enum JobAnnotation {
DEPLOYED_DATE("deployed-date"),
DEPLOYED_BY("deployed-by"),
EXECUTION_TYPE("execution-type"),
OP_ID("op-id");
OP_ID("op-id"),
UNSCHEDULED("unscheduled");

@Getter
private String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void testScheduleLabelsAnnotations() {
var annotations = annotationCaptor.getValue();
//check everything was as expected
Assertions.assertEquals(3, labels.size(), "Expecting three labels");
Assertions.assertEquals(5, annotations.size(), "Expecting five annotations");
Assertions.assertEquals(6, annotations.size(), "Expecting five annotations");

var jobName = labels.get(JobLabel.NAME.getValue());
var jobVersion = labels.get(JobLabel.VERSION.getValue());
Expand All @@ -113,13 +113,15 @@ public void testScheduleLabelsAnnotations() {
var deployedDate = annotations.get(JobAnnotation.DEPLOYED_DATE.getValue());
var startedBy = annotations.get(JobAnnotation.STARTED_BY.getValue());
var executionType = annotations.get(JobAnnotation.EXECUTION_TYPE.getValue());
var unscheduled = annotations.get(JobAnnotation.UNSCHEDULED.getValue());

Assertions.assertEquals("schedule string", schedule);
Assertions.assertEquals("lastDeployedBy", deployedBy);
Assertions.assertEquals(OffsetDateTime.now().toString().substring(0, 10), deployedDate.toString().substring(0, 10),
"Testing if date is the same, we cannot be precise down to the millisecond.");
Assertions.assertEquals("scheduled/runtime", startedBy);
Assertions.assertEquals("scheduled", executionType);
Assertions.assertEquals("false", unscheduled);

} catch (ApiException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,28 @@ public void testJobContainerName() throws ApiException {
var jobContainer = containerCaptor.getValue();
Assertions.assertEquals(testDataJob.getName(), jobContainer.getName());
}

@Test
public void testJobNoSchedule() throws ApiException {
JobConfig jobConfig = new JobConfig();
jobConfig.setSchedule("");
testDataJob = new DataJob();
testDataJob.setName(TEST_JOB_NAME);
testDataJob.setJobConfig(jobConfig);

var jobDeployment = new JobDeployment();
jobDeployment.setDataJobName(TEST_JOB_NAME);
jobDeployment.setGitCommitSha("test-commit");
jobDeployment.setEnabled(true);
jobDeployment.setImageName("image");

jobImageDeployer.scheduleJob(testDataJob, jobDeployment, true, TEST_PRINCIPAL_NAME);

ArgumentCaptor<String> scheduleCaptor = ArgumentCaptor.forClass(String.class);
verify(kubernetesService).createCronJob(anyString(), anyString(), anyMap(), scheduleCaptor.capture(), anyBoolean(),
anyList(), any(KubernetesService.Resources.class), any(KubernetesService.Resources.class),
any(V1Container.class), any(V1Container.class), anyList(), anyMap(), anyMap(), anyMap(), anyMap(), anyList());
Assertions.assertEquals("0 0 30 2 *", scheduleCaptor.getValue());
Assertions.assertEquals("", testDataJob.getJobConfig().getSchedule());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ public void testAnnotations() {
var deployedBy = JobAnnotation.DEPLOYED_BY.getValue();
var executionType = JobAnnotation.EXECUTION_TYPE.getValue();
var opId = JobAnnotation.OP_ID.getValue();
var unscheduled = JobAnnotation.UNSCHEDULED.getValue();

Assertions.assertEquals("com.vmware.taurus/schedule", schedule, msg);
Assertions.assertEquals("com.vmware.taurus/started-by", startedBy, msg);
Assertions.assertEquals("com.vmware.taurus/deployed-date", deployedDate, msg);
Assertions.assertEquals("com.vmware.taurus/deployed-by", deployedBy, msg);
Assertions.assertEquals("com.vmware.taurus/execution-type", executionType, msg);
Assertions.assertEquals("com.vmware.taurus/op-id", opId, msg);
Assertions.assertEquals("com.vmware.taurus/unscheduled", unscheduled, msg);

Assertions.assertEquals(6, JobAnnotation.values().length, msg);
Assertions.assertEquals(7, JobAnnotation.values().length, msg);
}

@Test
Expand Down