better exception for invalid interval

This commit is contained in:
Parag Jain 2016-02-24 21:01:07 -06:00
parent b82b487f20
commit 6b3c96c63a
2 changed files with 38 additions and 2 deletions

View File

@ -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();
}

View File

@ -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);
}
}