Search in sources :

Example 1 with DruidDataSource

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);
}
Also used : ImmutableDruidDataSource(org.apache.druid.client.ImmutableDruidDataSource) SegmentId(org.apache.druid.timeline.SegmentId) TreeMap(java.util.TreeMap) DruidDataSource(org.apache.druid.client.DruidDataSource) ImmutableDruidDataSource(org.apache.druid.client.ImmutableDruidDataSource) DataSegment(org.apache.druid.timeline.DataSegment) Nullable(javax.annotation.Nullable)

Example 2 with DruidDataSource

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);
}
Also used : Response(javax.ws.rs.core.Response) DruidDataSource(org.apache.druid.client.DruidDataSource) ImmutableDruidDataSource(org.apache.druid.client.ImmutableDruidDataSource) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 3 with DruidDataSource

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);
}
Also used : Response(javax.ws.rs.core.Response) DruidDataSource(org.apache.druid.client.DruidDataSource) ImmutableDruidDataSource(org.apache.druid.client.ImmutableDruidDataSource) DataSegment(org.apache.druid.timeline.DataSegment) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Object2LongMap(it.unimi.dsi.fastutil.objects.Object2LongMap) TreeMap(java.util.TreeMap) Object2LongOpenHashMap(it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap) Test(org.junit.Test)

Example 4 with DruidDataSource

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);
}
Also used : Response(javax.ws.rs.core.Response) DruidDataSource(org.apache.druid.client.DruidDataSource) ImmutableDruidDataSource(org.apache.druid.client.ImmutableDruidDataSource) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 5 with DruidDataSource

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);
}
Also used : Response(javax.ws.rs.core.Response) DruidDataSource(org.apache.druid.client.DruidDataSource) ImmutableDruidDataSource(org.apache.druid.client.ImmutableDruidDataSource) Interval(org.joda.time.Interval) Test(org.junit.Test)

Aggregations

DruidDataSource (org.apache.druid.client.DruidDataSource)22 ImmutableDruidDataSource (org.apache.druid.client.ImmutableDruidDataSource)21 Test (org.junit.Test)17 Response (javax.ws.rs.core.Response)14 DataSegment (org.apache.druid.timeline.DataSegment)10 DruidServer (org.apache.druid.client.DruidServer)7 Interval (org.joda.time.Interval)7 Object2LongMap (it.unimi.dsi.fastutil.objects.Object2LongMap)5 SegmentId (org.apache.druid.timeline.SegmentId)5 HashMap (java.util.HashMap)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 ImmutableDruidServer (org.apache.druid.client.ImmutableDruidServer)4 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 ForeverBroadcastDistributionRule (org.apache.druid.server.coordinator.rules.ForeverBroadcastDistributionRule)3 ForeverLoadRule (org.apache.druid.server.coordinator.rules.ForeverLoadRule)3 IntervalLoadRule (org.apache.druid.server.coordinator.rules.IntervalLoadRule)3 Rule (org.apache.druid.server.coordinator.rules.Rule)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 EnumMap (java.util.EnumMap)2