diff --git a/server/src/main/java/io/druid/server/http/DatasourcesResource.java b/server/src/main/java/io/druid/server/http/DatasourcesResource.java index 069f5a6b8e8..8aa035f9669 100644 --- a/server/src/main/java/io/druid/server/http/DatasourcesResource.java +++ b/server/src/main/java/io/druid/server/http/DatasourcesResource.java @@ -166,6 +166,12 @@ public class DatasourcesResource return Response.ok().build(); } + /* When this method is removed, a new method needs to be introduced corresponding to + the end point "DELETE /druid/coordinator/v1/datasources/{dataSourceName}" (with no query parameters). + Ultimately we want to have no method with kill parameter - + DELETE `{dataSourceName}` will be used to disable datasource and + DELETE `{dataSourceName}/intervals/{interval}` will be used to nuke segments + */ @DELETE @Deprecated @Path("/{dataSourceName}") @@ -179,15 +185,30 @@ public class DatasourcesResource if (indexingServiceClient == null) { return Response.ok(ImmutableMap.of("error", "no indexing service found")).build(); } + if (kill != null && Boolean.valueOf(kill)) { try { indexingServiceClient.killSegments(dataSourceName, new Interval(interval)); } + catch (IllegalArgumentException e) { + return Response.status(Response.Status.BAD_REQUEST) + .entity( + ImmutableMap.of( + "error", + "Exception occurred. Probably the interval is invalid", + "message", + e.toString() + ) + ) + .build(); + } catch (Exception e) { return Response.serverError().entity( ImmutableMap.of( "error", - "Exception occurred. Are you sure you have an indexing service?" + "Exception occurred. Are you sure you have an indexing service?", + "message", + e.toString() ) ) .build(); @@ -220,7 +241,9 @@ public class DatasourcesResource return Response.serverError() .entity(ImmutableMap.of( "error", - "Exception occurred. Are you sure you have an indexing service?" + "Exception occurred. Are you sure you have an indexing service?", + "message", + e.toString() )) .build(); } diff --git a/server/src/test/java/io/druid/server/http/DatasourcesResourceTest.java b/server/src/test/java/io/druid/server/http/DatasourcesResourceTest.java index 2ede408ce72..51f5cbb8852 100644 --- a/server/src/test/java/io/druid/server/http/DatasourcesResourceTest.java +++ b/server/src/test/java/io/druid/server/http/DatasourcesResourceTest.java @@ -403,4 +403,17 @@ public class DatasourcesResourceTest EasyMock.verify(indexingServiceClient, server); } + @Test + public void testDeleteDataSource() { + IndexingServiceClient indexingServiceClient = EasyMock.createStrictMock(IndexingServiceClient.class); + EasyMock.replay(indexingServiceClient, server); + DatasourcesResource datasourcesResource = new DatasourcesResource(inventoryView, null, indexingServiceClient); + Response response = datasourcesResource.deleteDataSource("datasource", "true", "???"); + Assert.assertEquals(400, response.getStatus()); + Assert.assertNotNull(response.getEntity()); + Assert.assertTrue(response.getEntity().toString().contains("java.lang.IllegalArgumentException")); + + EasyMock.verify(indexingServiceClient, server); + } + }