From a6767972d6cc322a7beecd7b58e9abf12247bcfd Mon Sep 17 00:00:00 2001 From: Corneil du Plessis Date: Wed, 27 Mar 2024 14:54:02 +0200 Subject: [PATCH] Provide for explicit thin results in queryForPageableResults (#5749) Preserve existing findAll behaviour. --- .../aggregate/task/AggregateTaskExplorer.java | 9 +++++++++ .../task/DataflowTaskExecutionQueryDao.java | 9 +++++++++ .../AggregateDataFlowTaskExecutionQueryDao.java | 16 +++++++++++----- .../task/impl/DefaultAggregateTaskExplorer.java | 5 +++++ .../cloud/dataflow/rest/client/TaskTemplate.java | 1 + .../controller/TaskExecutionThinController.java | 2 +- .../repository/TaskExecutionExplorerTests.java | 4 ++-- .../server/db/migration/AbstractSmokeTest.java | 2 +- 8 files changed, 39 insertions(+), 9 deletions(-) diff --git a/spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/AggregateTaskExplorer.java b/spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/AggregateTaskExplorer.java index c2239e5b0e..a5390fc1a0 100644 --- a/spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/AggregateTaskExplorer.java +++ b/spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/AggregateTaskExplorer.java @@ -128,6 +128,15 @@ public interface AggregateTaskExplorer { */ Page findAll(Pageable pageable); + /** + * Retrieves all the task executions within the pageable constraints sorted by start + * date descending, taskExecution id descending. + * + * @param pageable the constraints for the search + * @param thinResults Indicated if arguments will be populated + * @return page containing the results from the search + */ + Page findAll(Pageable pageable, boolean thinResults); /** * Returns the id of the TaskExecution that the requested Spring Batch job execution * was executed within the context of. Returns null if none were found. diff --git a/spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/DataflowTaskExecutionQueryDao.java b/spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/DataflowTaskExecutionQueryDao.java index 9b5f80dda3..c33e14fb66 100644 --- a/spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/DataflowTaskExecutionQueryDao.java +++ b/spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/DataflowTaskExecutionQueryDao.java @@ -163,6 +163,15 @@ public interface DataflowTaskExecutionQueryDao { Page findAll(Pageable pageable); + /** + * Retrieves all the task executions within the pageable constraints. + * @param pageable the constraints for the search + * @param thinResults Indicated if arguments will be populated + * @return page containing the results from the search + */ + + Page findAll(Pageable pageable, boolean thinResults); + /** * Returns a {@link List} of the latest {@link TaskExecution} for 1 or more task * names. diff --git a/spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/impl/AggregateDataFlowTaskExecutionQueryDao.java b/spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/impl/AggregateDataFlowTaskExecutionQueryDao.java index bf19fd7b64..2b5724239e 100644 --- a/spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/impl/AggregateDataFlowTaskExecutionQueryDao.java +++ b/spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/impl/AggregateDataFlowTaskExecutionQueryDao.java @@ -471,14 +471,14 @@ public Page findRunningTaskExecutions(String taskName, P return queryForPageableResults(pageable, SELECT_CLAUSE, FROM_CLAUSE, RUNNING_TASK_WHERE_CLAUSE, new MapSqlParameterSource("taskName", taskName), - getRunningTaskExecutionCountByTaskName(taskName)); + getRunningTaskExecutionCountByTaskName(taskName), false); } @Override public Page findTaskExecutionsByName(String taskName, Pageable pageable) { return queryForPageableResults(pageable, SELECT_CLAUSE, FROM_CLAUSE, TASK_NAME_WHERE_CLAUSE, new MapSqlParameterSource("taskName", taskName), - getTaskExecutionCountByTaskName(taskName)); + getTaskExecutionCountByTaskName(taskName), false); } @Override @@ -490,9 +490,14 @@ public List getTaskNames() { @Override public Page findAll(Pageable pageable) { return queryForPageableResults(pageable, SELECT_CLAUSE, FROM_CLAUSE, null, - new MapSqlParameterSource(), getTaskExecutionCount()); + new MapSqlParameterSource(), getTaskExecutionCount(), false); } + @Override + public Page findAll(Pageable pageable, boolean thinResults) { + return queryForPageableResults(pageable, SELECT_CLAUSE, FROM_CLAUSE, null, + new MapSqlParameterSource(), getTaskExecutionCount(), thinResults); + } private Page queryForPageableResults( Pageable pageable, @@ -500,7 +505,8 @@ private Page queryForPageableResults( String fromClause, String whereClause, MapSqlParameterSource queryParameters, - long totalCount + long totalCount, + boolean thinResults ) { SqlPagingQueryProviderFactoryBean factoryBean = new SqlPagingQueryProviderFactoryBean(); factoryBean.setSelectClause(selectClause); @@ -539,7 +545,7 @@ private Page queryForPageableResults( } String query = pagingQueryProvider.getPageQuery(pageable); List resultList = this.jdbcTemplate.query(query, - queryParameters, new CompositeTaskExecutionRowMapper(false)); + queryParameters, new CompositeTaskExecutionRowMapper(!thinResults)); resultList.stream() .collect(Collectors.groupingBy(AggregateTaskExecution::getSchemaTarget)) .forEach(this::populateArguments); diff --git a/spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/impl/DefaultAggregateTaskExplorer.java b/spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/impl/DefaultAggregateTaskExplorer.java index 805b54f0d6..7a7046f72d 100644 --- a/spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/impl/DefaultAggregateTaskExplorer.java +++ b/spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/impl/DefaultAggregateTaskExplorer.java @@ -230,6 +230,11 @@ public Page findAll(Pageable pageable) { return taskExecutionQueryDao.findAll(pageable); } + @Override + public Page findAll(Pageable pageable, boolean thinResults) { + return taskExecutionQueryDao.findAll(pageable, thinResults); + } + @Override public Long getTaskExecutionIdByJobExecutionId(long jobExecutionId, String schemaTarget) { if (!StringUtils.hasText(schemaTarget)) { diff --git a/spring-cloud-dataflow-rest-client/src/main/java/org/springframework/cloud/dataflow/rest/client/TaskTemplate.java b/spring-cloud-dataflow-rest-client/src/main/java/org/springframework/cloud/dataflow/rest/client/TaskTemplate.java index 42b1104d03..586c2588c2 100644 --- a/spring-cloud-dataflow-rest-client/src/main/java/org/springframework/cloud/dataflow/rest/client/TaskTemplate.java +++ b/spring-cloud-dataflow-rest-client/src/main/java/org/springframework/cloud/dataflow/rest/client/TaskTemplate.java @@ -265,6 +265,7 @@ public TaskExecutionResource.Page executionList() { @Override public PagedModel thinExecutionList() { + Assert.notNull(thinExecutionsLink, "Expected link:" + THIN_EXECUTIONS_RELATION); return restTemplate.getForObject(thinExecutionsLink.getHref(), TaskExecutionThinResource.Page.class); } diff --git a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/TaskExecutionThinController.java b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/TaskExecutionThinController.java index f83aecde5a..64ad6d5925 100644 --- a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/TaskExecutionThinController.java +++ b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/TaskExecutionThinController.java @@ -52,7 +52,7 @@ public TaskExecutionThinController(AggregateTaskExplorer explorer) { @GetMapping(produces = "application/json") @ResponseStatus(HttpStatus.OK) public PagedModel listTasks(Pageable pageable, PagedResourcesAssembler pagedAssembler) { - return pagedAssembler.toModel(explorer.findAll(pageable), resourceAssembler); + return pagedAssembler.toModel(explorer.findAll(pageable, true), resourceAssembler); } static class TaskExecutionThinResourceAssembler extends RepresentationModelAssemblerSupport { diff --git a/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/repository/TaskExecutionExplorerTests.java b/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/repository/TaskExecutionExplorerTests.java index d6420bf946..269e778dfd 100644 --- a/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/repository/TaskExecutionExplorerTests.java +++ b/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/repository/TaskExecutionExplorerTests.java @@ -126,7 +126,7 @@ public void testExplorerFindAll() { insertTestExecutionDataIntoRepo(template, 1L, "foo"); insertTestExecutionDataIntoRepo(template, 0L, "foo"); - List resultList = explorer.findAll(PageRequest.of(0, 10)).getContent(); + List resultList = explorer.findAll(PageRequest.of(0, 10), true).getContent(); assertThat(resultList.size()).isEqualTo(ENTRY_COUNT); Map actual = new HashMap<>(); for (AggregateTaskExecution taskExecution : resultList) { @@ -164,7 +164,7 @@ public void testExplorerSort() throws Exception { insertTestExecutionDataIntoRepo(template, 1L, "baz"); insertTestExecutionDataIntoRepo(template, 0L, "fee"); - List resultList = explorer.findAll(PageRequest.of(0, 10, Sort.by("SCHEMA_TARGET"))).getContent(); + List resultList = explorer.findAll(PageRequest.of(0, 10, Sort.by("SCHEMA_TARGET")), true).getContent(); assertThat(resultList.size()).isEqualTo(4); List ids = resultList.stream().map(AggregateTaskExecution::getExecutionId).collect(Collectors.toList()); assertThat(ids).containsExactly(0L, 2L, 3L, 1L); diff --git a/spring-cloud-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/db/migration/AbstractSmokeTest.java b/spring-cloud-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/db/migration/AbstractSmokeTest.java index 2ea0ee53b5..469898a5ba 100644 --- a/spring-cloud-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/db/migration/AbstractSmokeTest.java +++ b/spring-cloud-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/db/migration/AbstractSmokeTest.java @@ -125,7 +125,7 @@ void taskCreation() { }); long expectedNewCount = originalCount + 2; assertThat(taskExplorer.getTaskExecutionCount()).isEqualTo(expectedNewCount); - List taskExecutions = taskExplorer.findAll(Pageable.ofSize(100)).getContent(); + List taskExecutions = taskExplorer.findAll(Pageable.ofSize(100), true).getContent(); assertThat(taskExecutions) .hasSize((int)expectedNewCount) .allSatisfy((taskExecution) -> assertThat(taskExecution.getExecutionId()).isNotEqualTo(0L));