use of org.apache.druid.client.DruidDataSource in project druid by druid-io.
the class DataSourcesResource method getDataSource.
@Nullable
private ImmutableDruidDataSource getDataSource(final String dataSourceName) {
List<DruidDataSource> dataSources = serverInventoryView.getInventory().stream().map(server -> server.getDataSource(dataSourceName)).filter(Objects::nonNull).collect(Collectors.toList());
if (dataSources.isEmpty()) {
return null;
}
// Note: this logic doesn't guarantee that the result is a snapshot that ever existed in the cluster because all
// DruidDataSource objects (belonging to different servers) are independently, concurrently mutable objects.
// But this is OK because a "snapshot" hardly even makes sense in a distributed system anyway.
final SortedMap<SegmentId, DataSegment> segmentMap = new TreeMap<>();
for (DruidDataSource dataSource : dataSources) {
Iterable<DataSegment> segments = dataSource.getSegments();
for (DataSegment segment : segments) {
segmentMap.put(segment.getId(), segment);
}
}
return new ImmutableDruidDataSource(dataSourceName, Collections.emptyMap(), segmentMap);
}
use of org.apache.druid.client.DruidDataSource in project druid by druid-io.
the class DataSourcesResourceTest method testMarkAsUnusedSegmentsInIntervalException.
@Test
public void testMarkAsUnusedSegmentsInIntervalException() {
final Interval theInterval = Intervals.of("2010-01-01/P1D");
final DruidDataSource dataSource1 = new DruidDataSource("datasource1", new HashMap<>());
EasyMock.expect(inventoryView.getInventory()).andReturn(ImmutableList.of(server)).once();
EasyMock.expect(server.getDataSource("datasource1")).andReturn(dataSource1).once();
EasyMock.expect(segmentsMetadataManager.markAsUnusedSegmentsInInterval("datasource1", theInterval)).andThrow(new RuntimeException("Exception occurred")).once();
EasyMock.replay(segmentsMetadataManager, inventoryView, server);
final DataSourcesResource.MarkDataSourceSegmentsPayload payload = new DataSourcesResource.MarkDataSourceSegmentsPayload(theInterval, null);
DataSourcesResource dataSourcesResource = new DataSourcesResource(inventoryView, segmentsMetadataManager, null, null, null, null);
Response response = dataSourcesResource.markSegmentsAsUnused("datasource1", payload);
Assert.assertEquals(500, response.getStatus());
Assert.assertNotNull(response.getEntity());
EasyMock.verify(segmentsMetadataManager, inventoryView, server);
}
use of org.apache.druid.client.DruidDataSource in project druid by druid-io.
the class DataSourcesResourceTest method testSimpleGetTheDataSource.
@Test
public void testSimpleGetTheDataSource() {
DruidDataSource dataSource1 = new DruidDataSource("datasource1", new HashMap<>());
dataSource1.addSegment(new DataSegment("datasegment1", Intervals.of("2010-01-01/P1D"), "", null, null, null, null, 0x9, 10));
EasyMock.expect(server.getDataSource("datasource1")).andReturn(dataSource1).atLeastOnce();
EasyMock.expect(server.getTier()).andReturn(null).atLeastOnce();
EasyMock.expect(inventoryView.getInventory()).andReturn(ImmutableList.of(server)).atLeastOnce();
EasyMock.replay(inventoryView, server);
DataSourcesResource dataSourcesResource = new DataSourcesResource(inventoryView, null, null, null, null, null);
Response response = dataSourcesResource.getDataSource("datasource1", null);
Assert.assertEquals(200, response.getStatus());
Map<String, Map<String, Object>> result = (Map<String, Map<String, Object>>) response.getEntity();
Assert.assertEquals(1, ((Map) (result.get("tiers").get(null))).get("segmentCount"));
Assert.assertEquals(10L, ((Map) (result.get("tiers").get(null))).get("size"));
Assert.assertEquals(10L, ((Map) (result.get("tiers").get(null))).get("replicatedSize"));
Assert.assertNotNull(result.get("segments"));
Assert.assertEquals("2010-01-01T00:00:00.000Z", result.get("segments").get("minTime").toString());
Assert.assertEquals("2010-01-02T00:00:00.000Z", result.get("segments").get("maxTime").toString());
Assert.assertEquals(1, result.get("segments").get("count"));
Assert.assertEquals(10L, result.get("segments").get("size"));
Assert.assertEquals(10L, result.get("segments").get("replicatedSize"));
EasyMock.verify(inventoryView, server);
}
use of org.apache.druid.client.DruidDataSource in project druid by druid-io.
the class DataSourcesResourceTest method testMarkAsUnusedSegmentsInIntervalNoChanges.
@Test
public void testMarkAsUnusedSegmentsInIntervalNoChanges() {
final Interval theInterval = Intervals.of("2010-01-01/P1D");
final DruidDataSource dataSource1 = new DruidDataSource("datasource1", new HashMap<>());
EasyMock.expect(inventoryView.getInventory()).andReturn(ImmutableList.of(server)).once();
EasyMock.expect(server.getDataSource("datasource1")).andReturn(dataSource1).once();
EasyMock.expect(segmentsMetadataManager.markAsUnusedSegmentsInInterval("datasource1", theInterval)).andReturn(0).once();
EasyMock.replay(segmentsMetadataManager, inventoryView, server);
final DataSourcesResource.MarkDataSourceSegmentsPayload payload = new DataSourcesResource.MarkDataSourceSegmentsPayload(theInterval, null);
DataSourcesResource dataSourcesResource = new DataSourcesResource(inventoryView, segmentsMetadataManager, null, null, null, null);
Response response = dataSourcesResource.markSegmentsAsUnused("datasource1", payload);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(ImmutableMap.of("numChangedSegments", 0), response.getEntity());
EasyMock.verify(segmentsMetadataManager, inventoryView, server);
}
use of org.apache.druid.client.DruidDataSource in project druid by druid-io.
the class DataSourcesResourceTest method testMarkAsUsedNonOvershadowedSegmentsIntervalNoneUpdated.
@Test
public void testMarkAsUsedNonOvershadowedSegmentsIntervalNoneUpdated() {
DruidDataSource dataSource = new DruidDataSource("datasource1", new HashMap<>());
Interval interval = Intervals.of("2010-01-22/P1D");
int numUpdatedSegments = segmentsMetadataManager.markAsUsedNonOvershadowedSegmentsInInterval(EasyMock.eq("datasource1"), EasyMock.eq(interval));
EasyMock.expect(numUpdatedSegments).andReturn(0).once();
EasyMock.expect(inventoryView.getInventory()).andReturn(ImmutableList.of(server)).once();
EasyMock.expect(server.getDataSource("datasource1")).andReturn(dataSource).once();
EasyMock.replay(segmentsMetadataManager, inventoryView, server);
DataSourcesResource dataSourcesResource = new DataSourcesResource(inventoryView, segmentsMetadataManager, null, null, null, null);
Response response = dataSourcesResource.markAsUsedNonOvershadowedSegments("datasource1", new DataSourcesResource.MarkDataSourceSegmentsPayload(interval, null));
Assert.assertEquals(ImmutableMap.of("numChangedSegments", 0), response.getEntity());
EasyMock.verify(segmentsMetadataManager, inventoryView, server);
}
Aggregations