Skip to content

Commit

Permalink
Back port of Task Thin Execution List and List By Name
Browse files Browse the repository at this point in the history
Updates api docs for tasks/thinexecutions/name and all HATEOAS links. Updates related tests for links.
Update find by name to return 404 when task definition doesn't exist.

Fixes #5995
  • Loading branch information
Corneil du Plessis committed Nov 11, 2024
1 parent d7e378e commit 02068a7
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ public TaskExecutionController taskExecutionController(
}

@Bean
public TaskExecutionThinController taskExecutionThinController(AggregateTaskExplorer aggregateTaskExplorer, TaskJobService taskJobService) {
return new TaskExecutionThinController(aggregateTaskExplorer, taskJobService);
public TaskExecutionThinController taskExecutionThinController(AggregateTaskExplorer aggregateTaskExplorer, TaskDefinitionRepository taskDefinitionRepository, TaskJobService taskJobService) {
return new TaskExecutionThinController(aggregateTaskExplorer, taskDefinitionRepository, taskJobService);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.springframework.cloud.dataflow.aggregate.task.AggregateTaskExplorer;
import org.springframework.cloud.dataflow.rest.resource.TaskExecutionThinResource;
import org.springframework.cloud.dataflow.schema.AggregateTaskExecution;
import org.springframework.cloud.dataflow.server.repository.NoSuchTaskDefinitionException;
import org.springframework.cloud.dataflow.server.repository.TaskDefinitionRepository;
import org.springframework.cloud.dataflow.server.service.TaskJobService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -46,13 +48,15 @@
public class TaskExecutionThinController {

private final AggregateTaskExplorer explorer;
private final TaskDefinitionRepository taskDefinitionRepository;
private final TaskExecutionThinResourceAssembler resourceAssembler;

private final TaskJobService taskJobService;

public TaskExecutionThinController(AggregateTaskExplorer explorer, TaskJobService taskJobService) {
public TaskExecutionThinController(AggregateTaskExplorer explorer, TaskDefinitionRepository taskDefinitionRepository, TaskJobService taskJobService) {
this.explorer = explorer;
this.taskJobService = taskJobService;
this.taskDefinitionRepository = taskDefinitionRepository;
this.taskJobService = taskJobService;
this.resourceAssembler = new TaskExecutionThinResourceAssembler();
}

Expand All @@ -68,6 +72,10 @@ public PagedModel<TaskExecutionThinResource> listTasks(Pageable pageable, PagedR
@ResponseStatus(HttpStatus.OK)
public PagedModel<TaskExecutionThinResource> retrieveTasksByName(@RequestParam("name") String taskName,
Pageable pageable, PagedResourcesAssembler<AggregateTaskExecution> pagedAssembler) {
long tasks = this.taskDefinitionRepository.countByTaskName(taskName);
if(tasks == 0) {
throw new NoSuchTaskDefinitionException(taskName);
}
Page<AggregateTaskExecution> page = this.explorer.findTaskExecutionsByName(taskName, pageable);
taskJobService.populateComposeTaskRunnerStatus(page.getContent());
return pagedAssembler.toModel(page, resourceAssembler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ public interface TaskDefinitionRepository extends KeyValueRepository<TaskDefinit
*/
TaskDefinition findByTaskName(String name);

long countByTaskName(String taskName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ public TaskExecutionController taskExecutionController(
}

@Bean
public TaskExecutionThinController taskExecutionThinController(AggregateTaskExplorer aggregateTaskExplorer, TaskJobService taskJobService) {
return new TaskExecutionThinController(aggregateTaskExplorer, taskJobService);
public TaskExecutionThinController taskExecutionThinController(AggregateTaskExplorer aggregateTaskExplorer, TaskDefinitionRepository taskDefinitionRepository, TaskJobService taskJobService) {
return new TaskExecutionThinController(aggregateTaskExplorer, taskDefinitionRepository, taskJobService);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,8 @@ public TaskExecutionController taskExecutionController(
);
}
@Bean
public TaskExecutionThinController taskExecutionThinController(AggregateTaskExplorer explorer, TaskJobService taskJobService) {
return new TaskExecutionThinController(explorer, taskJobService);
public TaskExecutionThinController taskExecutionThinController(AggregateTaskExplorer explorer, TaskDefinitionRepository taskDefinitionRepository, TaskJobService taskJobService) {
return new TaskExecutionThinController(explorer, taskDefinitionRepository, taskJobService);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public void setupMockMVC() {
SAMPLE_CLEANSED_ARGUMENT_LIST.add("spring.datasource.password=******");

taskDefinitionRepository.save(new TaskDefinition(TASK_NAME_ORIG, "demo"));
taskDefinitionRepository.save(new TaskDefinition("nope", "demo"));
SchemaVersionTarget schemaVersionTarget = aggregateExecutionSupport.findSchemaVersionTarget(TASK_NAME_ORIG, taskDefinitionReader);
TaskExecutionDao dao = daoContainer.get(schemaVersionTarget.getName());
TaskExecution taskExecution1 =
Expand Down Expand Up @@ -383,6 +384,10 @@ void getThinExecutionsByTaskName() throws Exception {
.andExpect(jsonPath("$._embedded.taskExecutionThinResourceList[*].parentExecutionId", containsInAnyOrder(null, 1)))
.andExpect(jsonPath("$._embedded.taskExecutionThinResourceList[*].taskExecutionStatus", containsInAnyOrder("RUNNING", "RUNNING")))
.andExpect(jsonPath("$._embedded.taskExecutionThinResourceList", hasSize(2)));
mockMvc.perform(get("/tasks/thinexecutions").queryParam("name", "nope").accept(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.page.totalElements", is(0)));
mockMvc.perform(get("/tasks/thinexecutions").queryParam("name", "none").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isNotFound());
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/build-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if [ -z "$BASH_VERSION" ]; then
exit 1
fi
SCDIR=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
SCDIR=$(realpath $SCDIR)
pushd "$SCDIR/../.." > /dev/null || exit
SCDIR=$(realpath "$SCDIR/../..")
pushd "$SCDIR" || exit
./mvnw install -DskipTests -am -pl :spring-cloud-dataflow-classic-docs,:spring-cloud-dataflow-docs,:spring-cloud-skipper-server-core,:spring-cloud-skipper-docs -Pfull,docs
popd > /dev/null || exit

0 comments on commit 02068a7

Please sign in to comment.