Fix for issue 2021.

This commit is contained in:
Harsh Jain 2016-01-16 00:58:33 +05:30
parent 34cd8f8c72
commit 6ec6835b5d
2 changed files with 44 additions and 1 deletions

View File

@ -167,6 +167,7 @@ public class DatasourcesResource
} }
@DELETE @DELETE
@Deprecated
@Path("/{dataSourceName}") @Path("/{dataSourceName}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response deleteDataSource( public Response deleteDataSource(
@ -200,7 +201,30 @@ public class DatasourcesResource
return Response.ok().build(); return Response.ok().build();
} }
@GET @DELETE
@Path("/{dataSourceName}/intervals/{interval}")
@Produces(MediaType.APPLICATION_JSON)
public Response deleteDataSourceSpecificInterval(@PathParam("dataSourceName") final String dataSourceName, @PathParam("interval") final String interval, @QueryParam("kill") final String kill)
{
if (indexingServiceClient == null) {
return Response.ok(ImmutableMap.of("error", "no indexing service found")).build();
}
final Interval theInterval = new Interval(interval.replace("_", "/"));
if (kill != null && Boolean.valueOf(kill)) {
try {
indexingServiceClient.killSegments(dataSourceName, new Interval(theInterval));
} catch (Exception e) {
return Response.serverError().entity(ImmutableMap.of("error", "Exception occurred. Are you sure you have an indexing service?")).build();
}
} else {
if (!databaseSegmentManager.removeDatasource(dataSourceName)) {
return Response.noContent().build();
}
}
return Response.ok().build();
}
@GET
@Path("/{dataSourceName}/intervals") @Path("/{dataSourceName}/intervals")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response getSegmentDataSourceIntervals( public Response getSegmentDataSourceIntervals(

View File

@ -25,6 +25,7 @@ import io.druid.client.CoordinatorServerView;
import io.druid.client.DruidDataSource; import io.druid.client.DruidDataSource;
import io.druid.client.DruidServer; import io.druid.client.DruidServer;
import io.druid.client.InventoryView; import io.druid.client.InventoryView;
import io.druid.client.indexing.IndexingServiceClient;
import io.druid.timeline.DataSegment; import io.druid.timeline.DataSegment;
import org.easymock.EasyMock; import org.easymock.EasyMock;
import org.joda.time.Interval; import org.joda.time.Interval;
@ -383,4 +384,22 @@ public class DatasourcesResourceTest
} }
EasyMock.verify(inventoryView); EasyMock.verify(inventoryView);
} }
@Test
public void testDeleteDataSourceSpecificInterval() throws Exception
{
String interval = "2010-01-01_P1D";
Interval theInterval = new Interval(interval.replace("_", "/"));
IndexingServiceClient indexingServiceClient = EasyMock.createStrictMock(IndexingServiceClient.class);
indexingServiceClient.killSegments("datasource1", theInterval);
EasyMock.expectLastCall().once();
EasyMock.replay(indexingServiceClient, server);
DatasourcesResource datasourcesResource = new DatasourcesResource(inventoryView, null, indexingServiceClient);
Response response = datasourcesResource.deleteDataSourceSpecificInterval("datasource1", interval, "true");
Assert.assertEquals(200, response.getStatus());
EasyMock.verify(indexingServiceClient, server);
}
} }