Fix shutdownAllTasks API for non-existing dataSource (#6706)

This commit is contained in:
Jihoon Son 2018-12-08 09:54:01 -08:00 committed by Fangjin Yang
parent b7709e1245
commit f727333b70
2 changed files with 22 additions and 3 deletions

View File

@ -352,10 +352,14 @@ public class OverlordResource
public Response apply(TaskQueue taskQueue) public Response apply(TaskQueue taskQueue)
{ {
final List<TaskInfo<Task, TaskStatus>> tasks = taskStorageQueryAdapter.getActiveTaskInfo(dataSource); final List<TaskInfo<Task, TaskStatus>> tasks = taskStorageQueryAdapter.getActiveTaskInfo(dataSource);
for (final TaskInfo<Task, TaskStatus> task : tasks) { if (tasks.isEmpty()) {
taskQueue.shutdown(task.getId(), "Shutdown request from user"); 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();
} }
} }
); );

View File

@ -65,7 +65,9 @@ import org.junit.rules.ExpectedException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -975,6 +977,19 @@ public class OverlordResourceTest
Assert.assertEquals("datasource", response.get("dataSource")); 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() private void expectAuthorizationTokenCheck()
{ {
AuthenticationResult authenticationResult = new AuthenticationResult("druid", "druid", null, null); AuthenticationResult authenticationResult = new AuthenticationResult("druid", "druid", null, null);