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

Commit 5073813

Browse files
author
Corneil du Plessis
authored
Update JdbcSearchableJobExecutionDao to support Batch 4 and 5 schemas (#5613)
* Ensure that boot2 and boot3 job execution are queried. * Restore the default constructor for JdbcSearchableJobExecutionDao. * Remove final from local variables. * Update so the test cases from AbstractJdbcJobSearchableExecutionDaoTests can be moved to AbstractSimpleJobServiceTests. * Moved tests from AbstractJdbcJobSearchableExecutionDaoTests to AbstractSimpleJobServiceTests. Fix JobParameter loading on JdbcSearchableJobExecutionDao. * Added DirtiesContext for each method to prevent connection errors. * Fixed formatting. * Fix Datasource handling in SimpleJobServiceMariadbTests and SimpleJobServicePostgresTests. Fixes #5609
1 parent 6cb57b3 commit 5073813

File tree

13 files changed

+782
-588
lines changed

13 files changed

+782
-588
lines changed

spring-cloud-dataflow-rest-resource/src/main/java/org/springframework/cloud/dataflow/rest/support/jackson/JobParameterJacksonDeserializer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public JobParameter deserialize(JsonParser jsonParser, DeserializationContext de
5454

5555
if (!type.isEmpty() && !type.equalsIgnoreCase("STRING")) {
5656
if ("DATE".equalsIgnoreCase(type)) {
57-
// TODO: when upgraded to Java8 use java DateTime
5857
jobParameter = new JobParameter(DateTime.parse(value).toDate(), identifying);
5958
}
6059
else if ("DOUBLE".equalsIgnoreCase(type)) {

spring-cloud-dataflow-rest-resource/src/main/java/org/springframework/cloud/dataflow/rest/util/DeploymentPropertiesUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public static Map<String, String> extractAndQualifyDeployerProperties(Map<String
334334
.filter(kv -> kv.getKey().startsWith(wildcardPrefix) || kv.getKey().startsWith(appPrefix))
335335
.collect(Collectors.toMap(kv -> kv.getKey().startsWith(wildcardPrefix)
336336
? "spring.cloud.deployer." + kv.getKey().substring(wildcardLength)
337-
: "spring.cloud.deployer." + kv.getKey().substring(appLength), kv -> kv.getValue(),
337+
: "spring.cloud.deployer." + kv.getKey().substring(appLength), Entry::getValue,
338338
(fromWildcard, fromApp) -> fromApp));
339339
logger.debug("extractAndQualifyDeployerProperties:{}", result);
340340
return result;
@@ -361,12 +361,12 @@ public static Map<String, String> qualifyDeployerProperties(Map<String, String>
361361
.filter(kv -> kv.getKey().startsWith(wildcardPrefix) || kv.getKey().startsWith(appPrefix))
362362
.collect(Collectors.toMap(kv -> kv.getKey().startsWith(wildcardPrefix)
363363
? "spring.cloud.deployer." + kv.getKey().substring(wildcardLength)
364-
: "spring.cloud.deployer." + kv.getKey().substring(appLength), kv -> kv.getValue(),
364+
: "spring.cloud.deployer." + kv.getKey().substring(appLength), Entry::getValue,
365365
(fromWildcard, fromApp) -> fromApp));
366366

367367
Map<String, String> resultApp = new TreeMap<>(input).entrySet().stream()
368368
.filter(kv -> !kv.getKey().startsWith(wildcardPrefix) && !kv.getKey().startsWith(appPrefix))
369-
.collect(Collectors.toMap(kv -> kv.getKey(), kv -> kv.getValue(),
369+
.collect(Collectors.toMap(Entry::getKey, Entry::getValue,
370370
(fromWildcard, fromApp) -> fromApp));
371371

372372
resultDeployer.putAll(resultApp);
@@ -441,8 +441,8 @@ public static List<String> removeQuoting(List<String> params) {
441441
}
442442
start = regexMatcher.start();
443443
}
444-
if (param != null && param.length() > 0) {
445-
String p = removeQuoting(param.substring(start, param.length()).trim());
444+
if (param != null && !param.isEmpty()) {
445+
String p = removeQuoting(param.substring(start).trim());
446446
if (StringUtils.hasText(p)) {
447447
paramsToUse.add(p);
448448
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.cloud.dataflow.server.batch;
17+
18+
import org.springframework.cloud.dataflow.schema.AppBootSchemaVersion;
19+
import org.springframework.cloud.dataflow.schema.SchemaVersionTarget;
20+
import org.springframework.util.Assert;
21+
22+
/**
23+
* Provides enumeration of Batch Schema versions needed to be supported.
24+
* @author Corneil du Plessis
25+
*/
26+
public enum BatchVersion {
27+
BATCH_4,
28+
BATCH_5;
29+
public static BatchVersion from(AppBootSchemaVersion bootSchemaVersion) {
30+
Assert.notNull(bootSchemaVersion, "bootSchemaVersion required");
31+
return AppBootSchemaVersion.BOOT3.equals(bootSchemaVersion) ? BATCH_5 : BATCH_4;
32+
}
33+
public static BatchVersion from(SchemaVersionTarget versionTarget) {
34+
Assert.notNull(versionTarget, "versionTarget required");
35+
return from(versionTarget.getSchemaVersion());
36+
}
37+
}

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

Lines changed: 285 additions & 84 deletions
Large diffs are not rendered by default.

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2019 the original author or authors.
2+
* Copyright 2009-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
1616
package org.springframework.cloud.dataflow.server.batch;
1717

1818
import java.sql.Types;
19-
2019
import javax.sql.DataSource;
2120

2221
import org.slf4j.Logger;
@@ -60,6 +59,7 @@
6059
* ingredients as convenient as possible.
6160
*
6261
* @author Dave Syer
62+
* @author Corneil du Plessis
6363
*
6464
*/
6565
public class SimpleJobServiceFactoryBean implements FactoryBean<JobService>, InitializingBean, EnvironmentAware {
@@ -264,7 +264,8 @@ protected SearchableJobInstanceDao createJobInstanceDao() throws Exception {
264264
}
265265

266266
protected SearchableJobExecutionDao createJobExecutionDao() throws Exception {
267-
JdbcSearchableJobExecutionDao dao = new JdbcSearchableJobExecutionDao();
267+
BatchVersion batchVersion = BatchVersion.from(this.schemaVersionTarget);
268+
JdbcSearchableJobExecutionDao dao = new JdbcSearchableJobExecutionDao(batchVersion);
268269
dao.setDataSource(dataSource);
269270
dao.setJobExecutionIncrementer(incrementerFactory.getIncrementer(databaseType, tablePrefix
270271
+ "JOB_EXECUTION_SEQ"));

spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/repository/JobExecutionDaoContainer.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,16 @@
1616

1717
package org.springframework.cloud.dataflow.server.repository;
1818

19-
import javax.sql.DataSource;
2019
import java.util.HashMap;
2120
import java.util.Map;
21+
import javax.sql.DataSource;
2222

23-
import org.springframework.batch.core.repository.dao.JobExecutionDao;
24-
import org.springframework.cloud.dataflow.core.database.support.DatabaseType;
25-
import org.springframework.cloud.dataflow.core.database.support.MultiSchemaIncrementerFactory;
2623
import org.springframework.cloud.dataflow.schema.SchemaVersionTarget;
2724
import org.springframework.cloud.dataflow.schema.service.SchemaService;
25+
import org.springframework.cloud.dataflow.server.batch.BatchVersion;
2826
import org.springframework.cloud.dataflow.server.batch.JdbcSearchableJobExecutionDao;
2927
import org.springframework.cloud.dataflow.server.batch.SearchableJobExecutionDao;
3028
import org.springframework.cloud.dataflow.server.controller.NoSuchSchemaTargetException;
31-
import org.springframework.cloud.dataflow.server.repository.support.JdbcParameterUtils;
32-
import org.springframework.jdbc.support.JdbcUtils;
3329
import org.springframework.util.StringUtils;
3430

3531
/**
@@ -41,7 +37,8 @@ public class JobExecutionDaoContainer {
4137

4238
public JobExecutionDaoContainer(DataSource dataSource, SchemaService schemaService) {
4339
for (SchemaVersionTarget target : schemaService.getTargets().getSchemas()) {
44-
JdbcSearchableJobExecutionDao jdbcSearchableJobExecutionDao = new JdbcSearchableJobExecutionDao();
40+
BatchVersion batchVersion = BatchVersion.from(target);
41+
JdbcSearchableJobExecutionDao jdbcSearchableJobExecutionDao = new JdbcSearchableJobExecutionDao(batchVersion);
4542
jdbcSearchableJobExecutionDao.setDataSource(dataSource);
4643
jdbcSearchableJobExecutionDao.setTablePrefix(target.getBatchPrefix());
4744
try {

spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/batch/AbstractJdbcJobSearchableExecutionDaoTests.java

Lines changed: 0 additions & 195 deletions
This file was deleted.

0 commit comments

Comments
 (0)