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

Commit 02ba9ce

Browse files
ilayaperumalgcppwfs
authored andcommitted
Add validation on TaskDeployment
- Add exception handling mechanism when finding the TaskDeployment by the given taskID - Add test
1 parent ef94b55 commit 02ba9ce

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/DefaultTaskExecutionService.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,16 @@ public String getLog(String platformName, String taskId) {
212212
// In case of Cloud Foundry, fetching logs by external execution Id isn't valid as the execution instance is destroyed.
213213
// We need to use the task name instead.
214214
if (launcher != null && launcher.getType().equals(TaskPlatformFactory.CLOUDFOUNDRY_PLATFORM_TYPE)) {
215-
TaskDeployment taskDeployment = this.taskDeploymentRepository.findByTaskDeploymentId(taskId);
216-
taskId = taskDeployment.getTaskDefinitionName();
215+
try {
216+
TaskDeployment taskDeployment = this.taskDeploymentRepository.findByTaskDeploymentId(taskId);
217+
if (taskDeployment == null) {
218+
throw new IllegalArgumentException();
219+
}
220+
taskId = taskDeployment.getTaskDefinitionName();
221+
}
222+
catch (Exception e) {
223+
return "Log could not be retrieved as the task instance is not running by the ID: "+ taskId;
224+
}
217225
}
218226
return findTaskLauncher(platformName).getLog(taskId);
219227
}

spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/service/impl/DefaultTaskExecutionServiceTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,17 @@ public void getCFTaskLog() {
262262
assertEquals("Logs", this.taskExecutionService.getLog(taskDeployment.getPlatformName(), taskDeploymentId));
263263
}
264264

265+
@Test
266+
@DirtiesContext
267+
public void getCFTaskLogByInvalidTaskId() {
268+
String platformName = "cf-test-platform";
269+
String taskDeploymentId = "12345";
270+
this.launcherRepository.save(new Launcher(platformName,
271+
TaskPlatformFactory.CLOUDFOUNDRY_PLATFORM_TYPE, taskLauncher));
272+
assertEquals("Log could not be retrieved as the task instance is not running by the ID: 12345",
273+
this.taskExecutionService.getLog(platformName, taskDeploymentId));
274+
}
275+
265276

266277
@Test
267278
@DirtiesContext

0 commit comments

Comments
 (0)