Skip to content

Commit 4baeb36

Browse files
ac9817FrankChen021
authored andcommitted
kubernetes-overlord-extension: Fix tasks not being shutdown (#16711)
1 parent ed78bf5 commit 4baeb36

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/KubernetesTaskRunner.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,17 @@ public Collection<TaskRunnerWorkItem> getPendingTasks()
443443
@Override
444444
public TaskLocation getTaskLocation(String taskId)
445445
{
446-
final KubernetesWorkItem workItem = tasks.get(taskId);
447-
if (workItem == null) {
446+
try {
447+
final KubernetesWorkItem workItem = tasks.get(taskId);
448+
if (workItem == null) {
449+
return TaskLocation.unknown();
450+
} else {
451+
return workItem.getLocation();
452+
}
453+
}
454+
catch (Exception e) {
455+
log.warn("Unable to find location for task [%s]", taskId);
448456
return TaskLocation.unknown();
449-
} else {
450-
return workItem.getLocation();
451457
}
452458
}
453459

extensions-contrib/kubernetes-overlord-extensions/src/test/java/org/apache/druid/k8s/overlord/KubernetesTaskRunnerTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,24 @@ public TaskLocation getLocation()
653653
Assert.assertEquals(TaskLocation.create("host", 0, 1, false), taskLocation);
654654
}
655655

656+
@Test
657+
public void test_getTaskLocation_throws()
658+
{
659+
KubernetesWorkItem workItem = new KubernetesWorkItem(task, null)
660+
{
661+
@Override
662+
public TaskLocation getLocation()
663+
{
664+
throw new RuntimeException();
665+
}
666+
};
667+
668+
runner.tasks.put(task.getId(), workItem);
669+
670+
TaskLocation taskLocation = runner.getTaskLocation(task.getId());
671+
Assert.assertEquals(TaskLocation.unknown(), taskLocation);
672+
}
673+
656674
@Test
657675
public void test_getTaskLocation_noTaskFound()
658676
{

0 commit comments

Comments
 (0)