Search in sources :

Example 11 with ServerSelector

use of io.druid.client.selector.ServerSelector in project druid by druid-io.

the class BrokerServerView method clear.

public void clear() {
    synchronized (lock) {
        final Iterator<String> clientsIter = clients.keySet().iterator();
        while (clientsIter.hasNext()) {
            clientsIter.remove();
        }
        timelines.clear();
        final Iterator<ServerSelector> selectorsIter = selectors.values().iterator();
        while (selectorsIter.hasNext()) {
            final ServerSelector selector = selectorsIter.next();
            selectorsIter.remove();
            while (!selector.isEmpty()) {
                final QueryableDruidServer pick = selector.pick();
                selector.removeServer(pick);
            }
        }
    }
}
Also used : ServerSelector(io.druid.client.selector.ServerSelector) QueryableDruidServer(io.druid.client.selector.QueryableDruidServer)

Example 12 with ServerSelector

use of io.druid.client.selector.ServerSelector in project druid by druid-io.

the class ClientInfoResource method getDatasource.

@GET
@Path("/{dataSourceName}")
@Produces(MediaType.APPLICATION_JSON)
@ResourceFilters(DatasourceResourceFilter.class)
public Map<String, Object> getDatasource(@PathParam("dataSourceName") String dataSourceName, @QueryParam("interval") String interval, @QueryParam("full") String full) {
    if (full == null) {
        return ImmutableMap.<String, Object>of(KEY_DIMENSIONS, getDatasourceDimensions(dataSourceName, interval), KEY_METRICS, getDatasourceMetrics(dataSourceName, interval));
    }
    Interval theInterval;
    if (interval == null || interval.isEmpty()) {
        DateTime now = getCurrentTime();
        theInterval = new Interval(segmentMetadataQueryConfig.getDefaultHistory(), now);
    } else {
        theInterval = new Interval(interval);
    }
    TimelineLookup<String, ServerSelector> timeline = timelineServerView.getTimeline(new TableDataSource(dataSourceName));
    Iterable<TimelineObjectHolder<String, ServerSelector>> serversLookup = timeline != null ? timeline.lookup(theInterval) : null;
    if (serversLookup == null || Iterables.isEmpty(serversLookup)) {
        return Collections.EMPTY_MAP;
    }
    Map<Interval, Object> servedIntervals = new TreeMap<>(new Comparator<Interval>() {

        @Override
        public int compare(Interval o1, Interval o2) {
            if (o1.equals(o2) || o1.overlaps(o2)) {
                return 0;
            } else {
                return o1.isBefore(o2) ? -1 : 1;
            }
        }
    });
    for (TimelineObjectHolder<String, ServerSelector> holder : serversLookup) {
        final Set<Object> dimensions = Sets.newHashSet();
        final Set<Object> metrics = Sets.newHashSet();
        final PartitionHolder<ServerSelector> partitionHolder = holder.getObject();
        if (partitionHolder.isComplete()) {
            for (ServerSelector server : partitionHolder.payloads()) {
                final DataSegment segment = server.getSegment();
                dimensions.addAll(segment.getDimensions());
                metrics.addAll(segment.getMetrics());
            }
        }
        servedIntervals.put(holder.getInterval(), ImmutableMap.of(KEY_DIMENSIONS, dimensions, KEY_METRICS, metrics));
    }
    //collapse intervals if they abut and have same set of columns
    Map<String, Object> result = Maps.newLinkedHashMap();
    Interval curr = null;
    Map<String, Set<String>> cols = null;
    for (Map.Entry<Interval, Object> e : servedIntervals.entrySet()) {
        Interval ival = e.getKey();
        if (curr != null && curr.abuts(ival) && cols.equals(e.getValue())) {
            curr = curr.withEnd(ival.getEnd());
        } else {
            if (curr != null) {
                result.put(curr.toString(), cols);
            }
            curr = ival;
            cols = (Map<String, Set<String>>) e.getValue();
        }
    }
    //add the last one in
    if (curr != null) {
        result.put(curr.toString(), cols);
    }
    return result;
}
Also used : Set(java.util.Set) TreeMap(java.util.TreeMap) DataSegment(io.druid.timeline.DataSegment) DateTime(org.joda.time.DateTime) ServerSelector(io.druid.client.selector.ServerSelector) TimelineObjectHolder(io.druid.timeline.TimelineObjectHolder) TableDataSource(io.druid.query.TableDataSource) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Interval(org.joda.time.Interval) Path(javax.ws.rs.Path) ResourceFilters(com.sun.jersey.spi.container.ResourceFilters) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 13 with ServerSelector

use of io.druid.client.selector.ServerSelector in project druid by druid-io.

the class BrokerServerViewTest method assertValues.

private void assertValues(List<Pair<Interval, Pair<String, Pair<DruidServer, DataSegment>>>> expected, List<TimelineObjectHolder> actual) {
    Assert.assertEquals(expected.size(), actual.size());
    for (int i = 0; i < expected.size(); ++i) {
        Pair<Interval, Pair<String, Pair<DruidServer, DataSegment>>> expectedPair = expected.get(i);
        TimelineObjectHolder<String, ServerSelector> actualTimelineObjectHolder = actual.get(i);
        Assert.assertEquals(expectedPair.lhs, actualTimelineObjectHolder.getInterval());
        Assert.assertEquals(expectedPair.rhs.lhs, actualTimelineObjectHolder.getVersion());
        PartitionHolder<ServerSelector> actualPartitionHolder = actualTimelineObjectHolder.getObject();
        Assert.assertTrue(actualPartitionHolder.isComplete());
        Assert.assertEquals(1, Iterables.size(actualPartitionHolder));
        ServerSelector selector = ((SingleElementPartitionChunk<ServerSelector>) actualPartitionHolder.iterator().next()).getObject();
        Assert.assertFalse(selector.isEmpty());
        Assert.assertEquals(expectedPair.rhs.rhs.lhs, selector.pick().getServer());
        Assert.assertEquals(expectedPair.rhs.rhs.rhs, selector.getSegment());
    }
}
Also used : ServerSelector(io.druid.client.selector.ServerSelector) DataSegment(io.druid.timeline.DataSegment) SingleElementPartitionChunk(io.druid.timeline.partition.SingleElementPartitionChunk) Interval(org.joda.time.Interval) Pair(io.druid.java.util.common.Pair)

Example 14 with ServerSelector

use of io.druid.client.selector.ServerSelector in project druid by druid-io.

the class ClientInfoResourceTest method setup.

@Before
public void setup() {
    VersionedIntervalTimeline<String, ServerSelector> timeline = new VersionedIntervalTimeline<>(Ordering.<String>natural());
    DruidServer server = new DruidServer("name", "host", 1234, "type", "tier", 0);
    addSegment(timeline, server, "1960-02-13/1961-02-14", ImmutableList.of("d5"), ImmutableList.of("m5"), "v0");
    // segments within [2014-02-13, 2014-02-18]
    addSegment(timeline, server, "2014-02-13/2014-02-14", ImmutableList.of("d1"), ImmutableList.of("m1"), "v0");
    addSegment(timeline, server, "2014-02-14/2014-02-15", ImmutableList.of("d1"), ImmutableList.of("m1"), "v0");
    addSegment(timeline, server, "2014-02-16/2014-02-17", ImmutableList.of("d1"), ImmutableList.of("m1"), "v0");
    addSegment(timeline, server, "2014-02-17/2014-02-18", ImmutableList.of("d2"), ImmutableList.of("m2"), "v0");
    // segments within [2015-02-01, 2015-02-13]
    addSegment(timeline, server, "2015-02-01/2015-02-07", ImmutableList.of("d1"), ImmutableList.of("m1"), "v1");
    addSegment(timeline, server, "2015-02-07/2015-02-13", ImmutableList.of("d1"), ImmutableList.of("m1"), "v1");
    addSegmentWithShardSpec(timeline, server, "2015-02-03/2015-02-05", ImmutableList.of("d1", "d2"), ImmutableList.of("m1", "m2"), "v2", new NumberedShardSpec(0, 2));
    addSegmentWithShardSpec(timeline, server, "2015-02-03/2015-02-05", ImmutableList.of("d1", "d2", "d3"), ImmutableList.of("m1", "m2", "m3"), "v2", new NumberedShardSpec(1, 2));
    addSegment(timeline, server, "2015-02-09/2015-02-10", ImmutableList.of("d1", "d3"), ImmutableList.of("m1", "m3"), "v2");
    addSegment(timeline, server, "2015-02-11/2015-02-12", ImmutableList.of("d3"), ImmutableList.of("m3"), "v2");
    // segments within [2015-03-13, 2015-03-19]
    addSegment(timeline, server, "2015-03-13/2015-03-19", ImmutableList.of("d1"), ImmutableList.of("m1"), "v3");
    addSegment(timeline, server, "2015-03-13/2015-03-14", ImmutableList.of("d1"), ImmutableList.of("m1"), "v4");
    addSegment(timeline, server, "2015-03-14/2015-03-15", ImmutableList.of("d1"), ImmutableList.of("m1"), "v5");
    addSegment(timeline, server, "2015-03-15/2015-03-16", ImmutableList.of("d1"), ImmutableList.of("m1"), "v6");
    // imcomplete segment
    addSegmentWithShardSpec(timeline, server, "2015-04-03/2015-04-05", ImmutableList.of("d4"), ImmutableList.of("m4"), "v7", new NumberedShardSpec(0, 2));
    serverInventoryView = EasyMock.createMock(FilteredServerInventoryView.class);
    EasyMock.expect(serverInventoryView.getInventory()).andReturn(ImmutableList.of(server)).anyTimes();
    timelineServerView = EasyMock.createMock(TimelineServerView.class);
    EasyMock.expect(timelineServerView.getTimeline(EasyMock.anyObject(TableDataSource.class))).andReturn(timeline);
    EasyMock.replay(serverInventoryView, timelineServerView);
    resource = getResourceTestHelper(serverInventoryView, timelineServerView, new SegmentMetadataQueryConfig());
}
Also used : FilteredServerInventoryView(io.druid.client.FilteredServerInventoryView) ServerSelector(io.druid.client.selector.ServerSelector) TableDataSource(io.druid.query.TableDataSource) VersionedIntervalTimeline(io.druid.timeline.VersionedIntervalTimeline) DruidServer(io.druid.client.DruidServer) TimelineServerView(io.druid.client.TimelineServerView) NumberedShardSpec(io.druid.timeline.partition.NumberedShardSpec) SegmentMetadataQueryConfig(io.druid.query.metadata.SegmentMetadataQueryConfig) Before(org.junit.Before)

Example 15 with ServerSelector

use of io.druid.client.selector.ServerSelector in project druid by druid-io.

the class ClientInfoResourceTest method addSegmentWithShardSpec.

private void addSegmentWithShardSpec(VersionedIntervalTimeline<String, ServerSelector> timeline, DruidServer server, String interval, List<String> dims, List<String> metrics, String version, ShardSpec shardSpec) {
    DataSegment segment = DataSegment.builder().dataSource(dataSource).interval(new Interval(interval)).version(version).dimensions(dims).metrics(metrics).shardSpec(shardSpec).size(1).build();
    server.addDataSegment(segment.getIdentifier(), segment);
    ServerSelector ss = new ServerSelector(segment, null);
    timeline.add(new Interval(interval), version, shardSpec.createChunk(ss));
}
Also used : ServerSelector(io.druid.client.selector.ServerSelector) DataSegment(io.druid.timeline.DataSegment) Interval(org.joda.time.Interval)

Aggregations

ServerSelector (io.druid.client.selector.ServerSelector)19 Interval (org.joda.time.Interval)13 QueryableDruidServer (io.druid.client.selector.QueryableDruidServer)12 DataSegment (io.druid.timeline.DataSegment)12 HighestPriorityTierSelectorStrategy (io.druid.client.selector.HighestPriorityTierSelectorStrategy)7 Test (org.junit.Test)7 List (java.util.List)6 HashMap (java.util.HashMap)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 RandomServerSelectorStrategy (io.druid.client.selector.RandomServerSelectorStrategy)4 Sequence (io.druid.java.util.common.guava.Sequence)4 TimeBoundaryQuery (io.druid.query.timeboundary.TimeBoundaryQuery)4 Map (java.util.Map)4 HttpClient (com.metamx.http.client.HttpClient)3 Request (com.metamx.http.client.Request)3 HttpResponseHandler (com.metamx.http.client.response.HttpResponseHandler)3 ConnectionCountServerSelectorStrategy (io.druid.client.selector.ConnectionCountServerSelectorStrategy)3 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)3 ReflectionQueryToolChestWarehouse (io.druid.query.ReflectionQueryToolChestWarehouse)3 DateTime (org.joda.time.DateTime)3