Skip to content

Commit

Permalink
CF task execs are allowed if previous exec did not record external ex…
Browse files Browse the repository at this point in the history
…ec id

resolves spring-cloud#4587
  • Loading branch information
cppwfs authored and jvalkeal committed Jun 22, 2021
1 parent 123093f commit c3e52a2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,14 @@ private void verifyTaskIsNotRunning(String taskName, TaskExecution taskExecution
* Use the TaskLauncher to verify the actual state.
*/
if (runningTaskExecutions.getTotalElements() > 0) {
TaskExecution latestRunningExecution = runningTaskExecutions.toList().get(0);
if(latestRunningExecution.getExternalExecutionId() == null) {
logger.warn("Task repository shows a running task execution for task {} with no externalExecutionId.",
taskName);
return;
}
LaunchState launchState = taskLauncher.status(latestRunningExecution.getExternalExecutionId()).getState();

LaunchState launchState = taskLauncher.status(runningTaskExecutions.toList().get(0).getExternalExecutionId()).getState();
if (launchState.equals(LaunchState.running) || launchState.equals(LaunchState.launching)) {
throw new IllegalStateException("Unable to update application due to currently running applications");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public void executeSingleTaskDefaultsToExistingSinglePlatformTest() {
initializeSuccessfulRegistry(appRegistry);
ArgumentCaptor<AppDeploymentRequest> argument = ArgumentCaptor.forClass(AppDeploymentRequest.class);
when(taskLauncher.launch(argument.capture())).thenReturn("0");
validateBasicProperties(Collections.emptyMap(), argument, FAKE_PLATFORM);
validateBasicProperties(Collections.emptyMap(), argument, FAKE_PLATFORM, 1L);
}

@Test
Expand All @@ -227,13 +227,34 @@ public void executeSingleTaskDefaultsToExistingSinglePlatformTestForKubernetes()
when(taskLauncher.launch(argument.capture())).thenReturn("0");
Map<String, String> taskDeploymentProperties = new HashMap<>();
taskDeploymentProperties.put("spring.cloud.dataflow.task.platformName", K8_PLATFORM);
validateBasicProperties(taskDeploymentProperties, argument, K8_PLATFORM);
validateBasicProperties(taskDeploymentProperties, argument, K8_PLATFORM, 1L);
}

@Test
@DirtiesContext
public void testFailedFirstLaunch() throws Exception{
this.launcherRepository.save(new Launcher(TaskPlatformFactory.CLOUDFOUNDRY_PLATFORM_TYPE, "Cloud Foundry", taskLauncher));
initializeSuccessfulRegistry(appRegistry);
TaskExecution taskExecution = new TaskExecution(1, 0, TASK_NAME_ORIG, new Date(), new Date(), "", Collections.emptyList(), "", null, null);
this.taskRepository.createTaskExecution(taskExecution);
TaskManifest taskManifest = new TaskManifest();
taskManifest.setPlatformName("Cloud Foundry");
AppDefinition taskDefinition = new AppDefinition(TASK_NAME_ORIG, null);
AppDeploymentRequest taskDeploymentRequest = new AppDeploymentRequest(taskDefinition, new FileUrlResource("src/test/resources/apps"));
taskManifest.setTaskDeploymentRequest(taskDeploymentRequest);
dataflowTaskExecutionMetadataDao.save(taskExecution, taskManifest);
ArgumentCaptor<AppDeploymentRequest> argument = ArgumentCaptor.forClass(AppDeploymentRequest.class);
when(taskLauncher.launch(argument.capture())).thenReturn("0");
Map<String, String> taskDeploymentProperties = new HashMap<>();
taskDeploymentProperties.put("spring.cloud.dataflow.task.platformName", TaskPlatformFactory.CLOUDFOUNDRY_PLATFORM_TYPE);
validateBasicProperties(taskDeploymentProperties, argument, TaskPlatformFactory.CLOUDFOUNDRY_PLATFORM_TYPE, 2L);

}

private void validateBasicProperties(Map<String, String> taskDeploymentProperties,
ArgumentCaptor<AppDeploymentRequest> argument,
String platform) {
assertEquals(1L, this.taskExecutionService.executeTask(TASK_NAME_ORIG,
String platform, long numberOfRunningTasks) {
assertEquals(numberOfRunningTasks, this.taskExecutionService.executeTask(TASK_NAME_ORIG,
taskDeploymentProperties, new LinkedList<>()));
AppDeploymentRequest appDeploymentRequest = argument.getValue();
assertTrue(appDeploymentRequest.getDefinition().getProperties().containsKey("spring.datasource.username"));
Expand Down

0 comments on commit c3e52a2

Please sign in to comment.