Skip to content

Commit 3f80045

Browse files
author
Corneil du Plessis
committed
Update Task Thin Executions list function for parity with 2.11.x
Updated task thin executions link handing and added extra test for parity with 2.11.x. Update minimum supported version of client. See spring-attic#6062
1 parent 364414b commit 3f80045

File tree

2 files changed

+10
-51
lines changed

2 files changed

+10
-51
lines changed

spring-cloud-dataflow-rest-client/src/main/java/org/springframework/cloud/dataflow/rest/client/TaskTemplate.java

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,8 @@ public class TaskTemplate implements TaskOperations {
6363

6464
private static final String DEFINITION_RELATION = "tasks/definitions/definition";
6565

66-
private static final String EXECUTIONS_CURRENT_RELATION_VERSION = "1.7.0";
66+
private static final String VALIDATION_MIN_VERSION = "3.0.0";
6767

68-
private static final String VALIDATION_RELATION_VERSION = "1.7.0";
69-
private static final String VALIDATION_THIN_TASK_VERSION = "2.11.3";
7068
private static final String EXECUTIONS_RELATION = "tasks/executions";
7169

7270
private static final String THIN_EXECUTIONS_RELATION = "tasks/thinexecutions";
@@ -135,17 +133,16 @@ public class TaskTemplate implements TaskOperations {
135133
EXECUTIONS_INFO_RELATION,
136134
PLATFORM_LIST_RELATION,
137135
RETRIEVE_LOG,
138-
VALIDATION_REL
136+
VALIDATION_REL,
137+
EXECUTIONS_CURRENT_RELATION
139138
).forEach(relation -> {
140139
Assert.isTrue(resources.getLink(relation).isPresent(), () -> relation + " relation is required");
141140
});
142141
this.dataFlowServerVersion = dataFlowServerVersion;
143142
this.restTemplate = restTemplate;
144143

145144
String version = VersionUtils.getThreePartVersion(dataFlowServerVersion);
146-
if (VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion(version, VALIDATION_RELATION_VERSION)) {
147-
Assert.notNull(resources.getLink(VALIDATION_REL), ()-> VALIDATION_REL + " relation is required");
148-
}
145+
Assert.isTrue(VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion(version, VALIDATION_MIN_VERSION), () -> "Minimum Data Flow version required is " + VALIDATION_MIN_VERSION + " but got " + version);
149146

150147
this.aboutLink = resources.getLink("about").get();
151148

@@ -158,9 +155,7 @@ public class TaskTemplate implements TaskOperations {
158155
this.thinExecutionsByNameLink = resources.getLink(THIN_EXECUTIONS_BY_NAME_RELATION).orElse(null);
159156
this.executionLaunchLink = resources.getLink(EXECUTION_LAUNCH_RELATION).orElse(null);
160157
this.executionByNameLink = resources.getLink(EXECUTION_RELATION_BY_NAME).get();
161-
if (resources.getLink(EXECUTIONS_INFO_RELATION).isPresent()) {
162-
this.executionsInfoLink = resources.getLink(EXECUTIONS_INFO_RELATION).get();
163-
}
158+
this.executionsInfoLink = resources.getLink(EXECUTIONS_INFO_RELATION).orElse(null);
164159
this.validationLink = resources.getLink(VALIDATION_REL).get();
165160
this.platformListLink = resources.getLink(PLATFORM_LIST_RELATION).get();
166161
this.retrieveLogLink = resources.getLink(RETRIEVE_LOG).get();
@@ -189,39 +184,16 @@ public TaskDefinitionResource create(String name, String definition, String desc
189184
return restTemplate.postForObject(definitionsLink.expand().getHref(), values,
190185
TaskDefinitionResource.class);
191186
}
192-
private boolean isNewServer() {
193-
if(this.actualDataFlowServerCoreVersion == null) {
194-
AboutResource aboutResource = restTemplate.getForObject(aboutLink.expand().getHref(), AboutResource.class);
195-
Assert.notNull(aboutResource, "Expected about");
196-
this.actualDataFlowServerCoreVersion = aboutResource.getVersionInfo().getCore().getVersion();
197-
}
198-
String v2_11_0 = VersionUtils.getThreePartVersion("2.11.0-SNAPSHOT");
199-
String serverVersion = VersionUtils.getThreePartVersion(this.actualDataFlowServerCoreVersion);
200-
return VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion(serverVersion, v2_11_0);
201-
}
187+
202188
@Override
203189
public LaunchResponseResource launch(String name, Map<String, String> properties, List<String> arguments) {
204190
MultiValueMap<String, Object> values = new LinkedMultiValueMap<>();
205191
String formattedProperties = DeploymentPropertiesUtils.format(properties);
206192
String commandLineArguments = StringUtils.collectionToDelimitedString(arguments, " ");
207193
values.add("properties", formattedProperties);
208194
values.add("arguments", commandLineArguments);
209-
if(isNewServer()) {
210-
Assert.notNull(executionLaunchLink, "This version of SCDF doesn't support tasks/executions/launch");
211-
values.add("name", name);
212-
String url = executionLaunchLink.expand(name).getHref();
213-
values.remove("name");
214-
return restTemplate.postForObject(url, values, LaunchResponseResource.class);
215-
} else {
216-
Long id = restTemplate.postForObject(executionByNameLink.expand(name).getHref(), values, Long.class, name);
217-
if(id != null) {
218-
LaunchResponseResource response = new LaunchResponseResource();
219-
response.setExecutionId(id);
220-
return response;
221-
} else {
222-
throw new RuntimeException("Expected id");
223-
}
224-
}
195+
String url = executionLaunchLink.expand(name).getHref();
196+
return restTemplate.postForObject(url, values, LaunchResponseResource.class);
225197
}
226198

227199
@Override

spring-cloud-dataflow-rest-client/src/test/java/org/springframework/cloud/dataflow/rest/client/TaskTemplateTests.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,14 @@ void setup() {
4747
restTemplate = mock(RestTemplate.class);
4848
}
4949

50-
@Test
51-
void oldDataFlow() {
52-
validateExecutionLinkNotPresent("1.6.0");
53-
}
54-
5550
@Test
5651
void minDataFlow() {
57-
validateExecutionLinkPresent("1.7.0");
52+
validateExecutionLinkPresent("3.0.0");
5853
}
5954

6055
@Test
6156
void futureDataFlow() {
62-
validateExecutionLinkPresent("1.8.0");
63-
validateExecutionLinkPresent("1.9.0");
64-
validateExecutionLinkPresent("2.0.0");
57+
validateExecutionLinkPresent("3.0.0");
6558
}
6659

6760

@@ -71,12 +64,6 @@ private void validateExecutionLinkPresent(String dataFlowVersion) {
7164
assertThat(testResource.isLinkRequested(CURRENT_TASK_EXECUTION_LINK)).isTrue();
7265
}
7366

74-
private void validateExecutionLinkNotPresent(String version) {
75-
TestResource testResource = new TestResource();
76-
new TaskTemplate(this.restTemplate, testResource, version);
77-
assertThat(testResource.isLinkRequested(CURRENT_TASK_EXECUTION_LINK)).isFalse();
78-
}
79-
8067
public static class TestResource extends RepresentationModel<TestResource> {
8168

8269
private final Map<String, Long> linksRequested = new HashMap<>();

0 commit comments

Comments
 (0)