Skip to content

Commit bfa3c51

Browse files
Corneil du Plessiscppwfs
Corneil du Plessis
authored andcommitted
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 See spring-attic#6062 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 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 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 Revised TaskTemplate to retain order of link init in the constructor. 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. Added test for invalid old version. See spring-attic#6062
1 parent 6c40236 commit bfa3c51

File tree

4 files changed

+32
-72
lines changed

4 files changed

+32
-72
lines changed

spring-cloud-dataflow-classic-docs/src/test/java/org/springframework/cloud/dataflow/server/rest/documentation/ApiDocumentation.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ void index() throws Exception {
222222
fieldWithPath("_links.tasks/thinexecutions.href").description("Link to the tasks/thinexecutions"),
223223

224224
fieldWithPath("_links.tasks/thinexecutions/name.href").description("Link to the tasks/thinexecutions/name"),
225-
fieldWithPath("_links.tasks/thinexecutions/name.templated").description("Link to the tasks/thinexecutions/name is templated"),
225+
fieldWithPath("_links.tasks/thinexecutions/name.templated").type(JsonFieldType.BOOLEAN).optional().description("Link to the tasks/thinexecutions/name is templated"),
226226

227227
fieldWithPath("_links.tasks/info/executions.href").description("Link to the tasks/info/executions"),
228228
fieldWithPath("_links.tasks/info/executions.templated").type(JsonFieldType.BOOLEAN).optional().description("Link tasks/info is templated"),

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

+19-57
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-SNAPSHOT";
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,50 +133,37 @@ 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,
138+
THIN_EXECUTIONS_RELATION,
139+
THIN_EXECUTIONS_BY_NAME_RELATION,
140+
EXECUTION_LAUNCH_RELATION
139141
).forEach(relation -> {
140142
Assert.isTrue(resources.getLink(relation).isPresent(), () -> relation + " relation is required");
141143
});
142144
this.dataFlowServerVersion = dataFlowServerVersion;
143145
this.restTemplate = restTemplate;
144146

145147
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+
if (StringUtils.hasText(version)) {
149+
Assert.isTrue(
150+
VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion(version,
151+
VALIDATION_MIN_VERSION),
152+
() -> "Minimum Data Flow version required is " + VALIDATION_MIN_VERSION + " but got " + version);
148153
}
149-
if (VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion(version, EXECUTIONS_CURRENT_RELATION_VERSION)) {
150-
Assert.isTrue(resources.getLink(EXECUTIONS_CURRENT_RELATION).isPresent(), ()-> EXECUTIONS_CURRENT_RELATION + " relation is required");
151-
this.executionsCurrentLink = resources.getLink(EXECUTIONS_CURRENT_RELATION).get();
152-
} else {
153-
this.executionsCurrentLink = null;
154-
}
155-
154+
this.executionsCurrentLink = resources.getLink(EXECUTIONS_CURRENT_RELATION).get();
156155
this.aboutLink = resources.getLink("about").get();
157156

158157
this.definitionsLink = resources.getLink(DEFINITIONS_RELATION).get();
159158
this.definitionLink = resources.getLink(DEFINITION_RELATION).get();
160159
this.executionsLink = resources.getLink(EXECUTIONS_RELATION).get();
161160
this.executionLink = resources.getLink(EXECUTION_RELATION).get();
162-
if(resources.getLink(THIN_EXECUTIONS_RELATION).isPresent()) {
163-
this.thinExecutionsLink = resources.getLink(THIN_EXECUTIONS_RELATION).get();
164-
} else {
165-
this.thinExecutionsLink = null;
166-
}
167-
if(resources.getLink(THIN_EXECUTIONS_BY_NAME_RELATION).isPresent()) {
168-
this.thinExecutionsByNameLink = resources.getLink(THIN_EXECUTIONS_BY_NAME_RELATION).get();
169-
} else {
170-
this.thinExecutionsByNameLink = null;
171-
}
172161

173-
if(resources.getLink(EXECUTION_LAUNCH_RELATION).isPresent()) {
174-
this.executionLaunchLink = resources.getLink(EXECUTION_LAUNCH_RELATION).get();
175-
} else {
176-
this.executionLaunchLink = null;
177-
}
162+
this.thinExecutionsLink = resources.getLink(THIN_EXECUTIONS_RELATION).get();
163+
this.thinExecutionsByNameLink = resources.getLink(THIN_EXECUTIONS_BY_NAME_RELATION).get();
164+
this.executionLaunchLink = resources.getLink(EXECUTION_LAUNCH_RELATION).get();
178165
this.executionByNameLink = resources.getLink(EXECUTION_RELATION_BY_NAME).get();
179-
if (resources.getLink(EXECUTIONS_INFO_RELATION).isPresent()) {
180-
this.executionsInfoLink = resources.getLink(EXECUTIONS_INFO_RELATION).get();
181-
}
166+
this.executionsInfoLink = resources.getLink(EXECUTIONS_INFO_RELATION).get();
182167
this.validationLink = resources.getLink(VALIDATION_REL).get();
183168
this.platformListLink = resources.getLink(PLATFORM_LIST_RELATION).get();
184169
this.retrieveLogLink = resources.getLink(RETRIEVE_LOG).get();
@@ -207,39 +192,16 @@ public TaskDefinitionResource create(String name, String definition, String desc
207192
return restTemplate.postForObject(definitionsLink.expand().getHref(), values,
208193
TaskDefinitionResource.class);
209194
}
210-
private boolean isNewServer() {
211-
if(this.actualDataFlowServerCoreVersion == null) {
212-
AboutResource aboutResource = restTemplate.getForObject(aboutLink.expand().getHref(), AboutResource.class);
213-
Assert.notNull(aboutResource, "Expected about");
214-
this.actualDataFlowServerCoreVersion = aboutResource.getVersionInfo().getCore().getVersion();
215-
}
216-
String v2_11_0 = VersionUtils.getThreePartVersion("2.11.0-SNAPSHOT");
217-
String serverVersion = VersionUtils.getThreePartVersion(this.actualDataFlowServerCoreVersion);
218-
return VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion(serverVersion, v2_11_0);
219-
}
195+
220196
@Override
221197
public LaunchResponseResource launch(String name, Map<String, String> properties, List<String> arguments) {
222198
MultiValueMap<String, Object> values = new LinkedMultiValueMap<>();
223199
String formattedProperties = DeploymentPropertiesUtils.format(properties);
224200
String commandLineArguments = StringUtils.collectionToDelimitedString(arguments, " ");
225201
values.add("properties", formattedProperties);
226202
values.add("arguments", commandLineArguments);
227-
if(isNewServer()) {
228-
Assert.notNull(executionLaunchLink, "This version of SCDF doesn't support tasks/executions/launch");
229-
values.add("name", name);
230-
String url = executionLaunchLink.expand(name).getHref();
231-
values.remove("name");
232-
return restTemplate.postForObject(url, values, LaunchResponseResource.class);
233-
} else {
234-
Long id = restTemplate.postForObject(executionByNameLink.expand(name).getHref(), values, Long.class, name);
235-
if(id != null) {
236-
LaunchResponseResource response = new LaunchResponseResource();
237-
response.setExecutionId(id);
238-
return response;
239-
} else {
240-
throw new RuntimeException("Expected id");
241-
}
242-
}
203+
String url = executionLaunchLink.expand(name).getHref();
204+
return restTemplate.postForObject(url, values, LaunchResponseResource.class);
243205
}
244206

245207
@Override

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

+6-14
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.web.client.RestTemplate;
2929

3030
import static org.assertj.core.api.Assertions.assertThat;
31+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3132
import static org.mockito.Mockito.mock;
3233

3334
/**
@@ -46,22 +47,19 @@ class TaskTemplateTests {
4647
void setup() {
4748
restTemplate = mock(RestTemplate.class);
4849
}
49-
5050
@Test
51-
void oldDataFlow() {
52-
validateExecutionLinkNotPresent("1.6.0");
51+
void invalidVersion() {
52+
assertThatExceptionOfType(IllegalArgumentException.class)
53+
.isThrownBy(() -> validateExecutionLinkPresent("2.11.5"));
5354
}
54-
5555
@Test
5656
void minDataFlow() {
57-
validateExecutionLinkPresent("1.7.0");
57+
validateExecutionLinkPresent("3.0.0");
5858
}
5959

6060
@Test
6161
void futureDataFlow() {
62-
validateExecutionLinkPresent("1.8.0");
63-
validateExecutionLinkPresent("1.9.0");
64-
validateExecutionLinkPresent("2.0.0");
62+
validateExecutionLinkPresent("3.0.0");
6563
}
6664

6765

@@ -71,12 +69,6 @@ private void validateExecutionLinkPresent(String dataFlowVersion) {
7169
assertThat(testResource.isLinkRequested(CURRENT_TASK_EXECUTION_LINK)).isTrue();
7270
}
7371

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-
8072
public static class TestResource extends RepresentationModel<TestResource> {
8173

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

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

+6
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@ void getAllThinExecutions() throws Exception {
343343
}
344344
@Test
345345
void getThinExecutionsByName() throws Exception {
346+
mockMvc.perform(get("/tasks/thinexecutions").queryParam("name", TASK_NAME_ORIG).accept(MediaType.APPLICATION_JSON))
347+
.andExpect(status().isOk())
348+
.andExpect(jsonPath("$._embedded.taskExecutionThinResourceList[*].executionId", containsInAnyOrder(2, 1)))
349+
.andExpect(jsonPath("$._embedded.taskExecutionThinResourceList[*].parentExecutionId", containsInAnyOrder(null, 1)))
350+
.andExpect(jsonPath("$._embedded.taskExecutionThinResourceList[*].taskExecutionStatus", containsInAnyOrder("RUNNING", "RUNNING")))
351+
.andExpect(jsonPath("$._embedded.taskExecutionThinResourceList", hasSize(2)));
346352
mockMvc.perform(get("/tasks/thinexecutions").queryParam("name", "nope").accept(MediaType.APPLICATION_JSON))
347353
.andExpect(jsonPath("$.page.totalElements", is(0)));
348354
mockMvc.perform(get("/tasks/thinexecutions").queryParam("name", "none").accept(MediaType.APPLICATION_JSON))

0 commit comments

Comments
 (0)