fjy closed pull request #6706: Fix shutdownAllTasks API for non-existing 
dataSource
URL: https://github.com/apache/incubator-druid/pull/6706
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/indexing-service/src/main/java/org/apache/druid/indexing/overlord/http/OverlordResource.java
 
b/indexing-service/src/main/java/org/apache/druid/indexing/overlord/http/OverlordResource.java
index 84f4ac91c5a..fd7fae4b93e 100644
--- 
a/indexing-service/src/main/java/org/apache/druid/indexing/overlord/http/OverlordResource.java
+++ 
b/indexing-service/src/main/java/org/apache/druid/indexing/overlord/http/OverlordResource.java
@@ -352,10 +352,14 @@ public Response 
shutdownTasksForDataSource(@PathParam("dataSource") final String
           public Response apply(TaskQueue taskQueue)
           {
             final List<TaskInfo<Task, TaskStatus>> tasks = 
taskStorageQueryAdapter.getActiveTaskInfo(dataSource);
-            for (final TaskInfo<Task, TaskStatus> task : tasks) {
-              taskQueue.shutdown(task.getId(), "Shutdown request from user");
+            if (tasks.isEmpty()) {
+              return Response.status(Status.NOT_FOUND).build();
+            } else {
+              for (final TaskInfo<Task, TaskStatus> task : tasks) {
+                taskQueue.shutdown(task.getId(), "Shutdown request from user");
+              }
+              return Response.ok(ImmutableMap.of("dataSource", 
dataSource)).build();
             }
-            return Response.ok(ImmutableMap.of("dataSource", 
dataSource)).build();
           }
         }
     );
diff --git 
a/indexing-service/src/test/java/org/apache/druid/indexing/overlord/http/OverlordResourceTest.java
 
b/indexing-service/src/test/java/org/apache/druid/indexing/overlord/http/OverlordResourceTest.java
index 4558de2863e..89824b046f3 100644
--- 
a/indexing-service/src/test/java/org/apache/druid/indexing/overlord/http/OverlordResourceTest.java
+++ 
b/indexing-service/src/test/java/org/apache/druid/indexing/overlord/http/OverlordResourceTest.java
@@ -65,7 +65,9 @@
 
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
@@ -975,6 +977,19 @@ public void testShutdownAllTasks()
     Assert.assertEquals("datasource", response.get("dataSource"));
   }
 
+  @Test
+  public void testShutdownAllTasksForNonExistingDataSource()
+  {
+    final TaskQueue taskQueue = EasyMock.createMock(TaskQueue.class);
+    EasyMock.expect(taskMaster.isLeader()).andReturn(true).anyTimes();
+    
EasyMock.expect(taskMaster.getTaskQueue()).andReturn(Optional.of(taskQueue)).anyTimes();
+    
EasyMock.expect(taskStorageQueryAdapter.getActiveTaskInfo(EasyMock.anyString())).andReturn(Collections.emptyList());
+    EasyMock.replay(taskRunner, taskMaster, taskStorageQueryAdapter, 
indexerMetadataStorageAdapter, req);
+
+    final Response response = 
overlordResource.shutdownTasksForDataSource("notExisting");
+    Assert.assertEquals(Status.NOT_FOUND.getStatusCode(), 
response.getStatus());
+  }
+
   private void expectAuthorizationTokenCheck()
   {
     AuthenticationResult authenticationResult = new 
AuthenticationResult("druid", "druid", null, null);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to