Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit 7ff63bc

Browse files
sylankilayaperumalg
authored andcommitted
Add support for wildcard searching/listing of job executions by name
Checkstyle and testcases
1 parent 14b5afa commit 7ff63bc

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/batch/JdbcSearchableJobExecutionDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class JdbcSearchableJobExecutionDao extends JdbcJobExecutionDao implement
6464
+ " from %PREFIX%JOB_EXECUTION E, %PREFIX%JOB_INSTANCE I "
6565
+ "where E.JOB_INSTANCE_ID=I.JOB_INSTANCE_ID and E.END_TIME is NULL";
6666

67-
private static final String NAME_FILTER = "I.JOB_NAME=?";
67+
private static final String NAME_FILTER = "I.JOB_NAME LIKE ?";
6868

6969
private PagingQueryProvider allExecutionsPagingQueryProvider;
7070

spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/batch/JdbcSearchableJobInstanceDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
public class JdbcSearchableJobInstanceDao extends JdbcJobInstanceDao implements SearchableJobInstanceDao {
2727

2828
private static final String GET_COUNT_BY_JOB_NAME = "SELECT COUNT(1) from %PREFIX%JOB_INSTANCE "
29-
+ "where JOB_NAME=?";
29+
+ "where JOB_NAME LIKE ?";
3030

3131
/**
3232
* @see JdbcJobExecutionDao#afterPropertiesSet()

spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/batch/SimpleJobService.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,7 @@ public Collection<JobExecution> listJobExecutionsForJob(String jobName, int star
471471
public Collection<JobExecutionWithStepCount> listJobExecutionsForJobWithStepCount(String jobName, int start, int count)
472472
throws NoSuchJobException {
473473
checkJobExists(jobName);
474-
List<JobExecutionWithStepCount> jobExecutions = jobExecutionDao.getJobExecutionsWithStepCount(jobName, start, count);
475-
return jobExecutions;
474+
return jobExecutionDao.getJobExecutionsWithStepCount(jobName, start, count);
476475
}
477476

478477
@Override
@@ -530,14 +529,18 @@ public Collection<String> getStepNamesForJob(String jobName) throws NoSuchJobExc
530529
}
531530

532531
private void checkJobExists(String jobName) throws NoSuchJobException {
533-
if(getJsrJobNames().contains(jobName) ||
534-
jobLocator.getJobNames().contains(jobName) ||
535-
jobInstanceDao.countJobInstances(jobName) > 0) {
532+
if (collectionContainsJobName(jobName, getJsrJobNames()) ||
533+
collectionContainsJobName(jobName, jobLocator.getJobNames()) ||
534+
jobInstanceDao.countJobInstances(jobName) > 0) {
536535
return;
537536
}
538537
throw new NoSuchJobException("No Job with that name either current or historic: [" + jobName + "]");
539538
}
540539

540+
private boolean collectionContainsJobName(String jobName, Collection<String> collection) {
541+
return collection.stream().anyMatch(e -> e.contains(jobName));
542+
}
543+
541544
/**
542545
* Stop all the active jobs and wait for them (up to a time out) to finish
543546
* processing.

spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/JobExecutionController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public PagedModel<JobExecutionResource> list(Pageable pageable,
9696
/**
9797
* Retrieve all task job executions with the task name specified
9898
*
99-
* @param jobName name of the job
99+
* @param jobName name of the job. SQL server specific wildcards are enabled (eg.: myJob%, m_Job, ...)
100100
* @param pageable page-able collection of {@code TaskJobExecution}s.
101101
* @param assembler for the {@link TaskJobExecution}s
102102
* @return list task/job executions with the specified jobName.

spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/controller/JobExecutionControllerTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,25 @@ public void testGetExecutionsByNameNotFound() throws Exception {
210210
.andExpect(status().isNotFound());
211211
}
212212

213+
@Test
214+
public void testWildcardMatchMultipleResult() throws Exception {
215+
mockMvc.perform(get("/jobs/executions/")
216+
.param("name", JobExecutionUtils.BASE_JOB_NAME + "_FOO_ST%").accept(MediaType.APPLICATION_JSON))
217+
.andExpect(status().isOk())
218+
.andExpect(jsonPath("$.content[0].jobExecution.jobInstance.jobName", is(JobExecutionUtils.JOB_NAME_STOPPED)))
219+
.andExpect(jsonPath("$.content[1].jobExecution.jobInstance.jobName", is(JobExecutionUtils.JOB_NAME_STARTED)))
220+
.andExpect(jsonPath("$.content", hasSize(2)));
221+
}
222+
223+
@Test
224+
public void testWildcardMatchSingleResult() throws Exception {
225+
mockMvc.perform(get("/jobs/executions/")
226+
.param("name", "m_Job_ORIG").accept(MediaType.APPLICATION_JSON))
227+
.andExpect(status().isOk())
228+
.andExpect(jsonPath("$.content[0].jobExecution.jobInstance.jobName", is(JobExecutionUtils.JOB_NAME_ORIG)))
229+
.andExpect(jsonPath("$.content", hasSize(1)));
230+
}
231+
213232
private void createDirtyJob() {
214233
JobInstance instance = jobRepository.createJobInstance(JobExecutionUtils.BASE_JOB_NAME + "_NO_TASK", new JobParameters());
215234
JobExecution jobExecution = jobRepository.createJobExecution(

0 commit comments

Comments
 (0)