Search in sources :

Example 6 with ServerSelector

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

the class DirectDruidClientTest method testCancel.

@Test
public void testCancel() throws Exception {
    HttpClient httpClient = EasyMock.createStrictMock(HttpClient.class);
    Capture<Request> capturedRequest = EasyMock.newCapture();
    ListenableFuture<Object> cancelledFuture = Futures.immediateCancelledFuture();
    SettableFuture<Object> cancellationFuture = SettableFuture.create();
    EasyMock.expect(httpClient.go(EasyMock.capture(capturedRequest), EasyMock.<HttpResponseHandler>anyObject())).andReturn(cancelledFuture).once();
    EasyMock.expect(httpClient.go(EasyMock.capture(capturedRequest), EasyMock.<HttpResponseHandler>anyObject())).andReturn(cancellationFuture).once();
    EasyMock.replay(httpClient);
    final ServerSelector serverSelector = new ServerSelector(new DataSegment("test", new Interval("2013-01-01/2013-01-02"), new DateTime("2013-01-01").toString(), Maps.<String, Object>newHashMap(), Lists.<String>newArrayList(), Lists.<String>newArrayList(), NoneShardSpec.instance(), 0, 0L), new HighestPriorityTierSelectorStrategy(new ConnectionCountServerSelectorStrategy()));
    DirectDruidClient client1 = new DirectDruidClient(new ReflectionQueryToolChestWarehouse(), QueryRunnerTestHelper.NOOP_QUERYWATCHER, new DefaultObjectMapper(), httpClient, "foo", new NoopServiceEmitter());
    QueryableDruidServer queryableDruidServer1 = new QueryableDruidServer(new DruidServer("test1", "localhost", 0, "historical", DruidServer.DEFAULT_TIER, 0), client1);
    serverSelector.addServerAndUpdateSegment(queryableDruidServer1, serverSelector.getSegment());
    TimeBoundaryQuery query = Druids.newTimeBoundaryQueryBuilder().dataSource("test").build();
    HashMap<String, List> context = Maps.newHashMap();
    cancellationFuture.set(new StatusResponseHolder(HttpResponseStatus.OK, new StringBuilder("cancelled")));
    Sequence results = client1.run(query, context);
    Assert.assertEquals(HttpMethod.DELETE, capturedRequest.getValue().getMethod());
    Assert.assertEquals(0, client1.getNumOpenConnections());
    QueryInterruptedException exception = null;
    try {
        Sequences.toList(results, Lists.newArrayList());
    } catch (QueryInterruptedException e) {
        exception = e;
    }
    Assert.assertNotNull(exception);
    EasyMock.verify(httpClient);
}
Also used : TimeBoundaryQuery(io.druid.query.timeboundary.TimeBoundaryQuery) DataSegment(io.druid.timeline.DataSegment) DateTime(org.joda.time.DateTime) QueryableDruidServer(io.druid.client.selector.QueryableDruidServer) ServerSelector(io.druid.client.selector.ServerSelector) HighestPriorityTierSelectorStrategy(io.druid.client.selector.HighestPriorityTierSelectorStrategy) StatusResponseHolder(com.metamx.http.client.response.StatusResponseHolder) List(java.util.List) QueryInterruptedException(io.druid.query.QueryInterruptedException) ConnectionCountServerSelectorStrategy(io.druid.client.selector.ConnectionCountServerSelectorStrategy) Request(com.metamx.http.client.Request) QueryableDruidServer(io.druid.client.selector.QueryableDruidServer) NoopServiceEmitter(io.druid.server.metrics.NoopServiceEmitter) Sequence(io.druid.java.util.common.guava.Sequence) HttpClient(com.metamx.http.client.HttpClient) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) HttpResponseHandler(com.metamx.http.client.response.HttpResponseHandler) ReflectionQueryToolChestWarehouse(io.druid.query.ReflectionQueryToolChestWarehouse) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 7 with ServerSelector

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

the class ClientInfoResourceTest method addSegment.

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

Example 8 with ServerSelector

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

the class ServerViewUtil method getTargetLocations.

public static List<LocatedSegmentDescriptor> getTargetLocations(TimelineServerView serverView, DataSource datasource, List<Interval> intervals, int numCandidates) {
    TimelineLookup<String, ServerSelector> timeline = serverView.getTimeline(datasource);
    if (timeline == null) {
        return Collections.emptyList();
    }
    List<LocatedSegmentDescriptor> located = Lists.newArrayList();
    for (Interval interval : intervals) {
        for (TimelineObjectHolder<String, ServerSelector> holder : timeline.lookup(interval)) {
            for (PartitionChunk<ServerSelector> chunk : holder.getObject()) {
                ServerSelector selector = chunk.getObject();
                final SegmentDescriptor descriptor = new SegmentDescriptor(holder.getInterval(), holder.getVersion(), chunk.getChunkNumber());
                long size = selector.getSegment().getSize();
                List<DruidServerMetadata> candidates = selector.getCandidates(numCandidates);
                located.add(new LocatedSegmentDescriptor(descriptor, size, candidates));
            }
        }
    }
    return located;
}
Also used : ServerSelector(io.druid.client.selector.ServerSelector) LocatedSegmentDescriptor(io.druid.query.LocatedSegmentDescriptor) SegmentDescriptor(io.druid.query.SegmentDescriptor) LocatedSegmentDescriptor(io.druid.query.LocatedSegmentDescriptor) DruidServerMetadata(io.druid.server.coordination.DruidServerMetadata) Interval(org.joda.time.Interval)

Example 9 with ServerSelector

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

the class BrokerServerView method serverRemovedSegment.

private void serverRemovedSegment(DruidServerMetadata server, DataSegment segment) {
    String segmentId = segment.getIdentifier();
    final ServerSelector selector;
    synchronized (lock) {
        log.debug("Removing segment[%s] from server[%s].", segmentId, server);
        selector = selectors.get(segmentId);
        if (selector == null) {
            log.warn("Told to remove non-existant segment[%s]", segmentId);
            return;
        }
        QueryableDruidServer queryableDruidServer = clients.get(server.getName());
        if (!selector.removeServer(queryableDruidServer)) {
            log.warn("Asked to disassociate non-existant association between server[%s] and segment[%s]", server, segmentId);
        }
        if (selector.isEmpty()) {
            VersionedIntervalTimeline<String, ServerSelector> timeline = timelines.get(segment.getDataSource());
            selectors.remove(segmentId);
            final PartitionChunk<ServerSelector> removedPartition = timeline.remove(segment.getInterval(), segment.getVersion(), segment.getShardSpec().createChunk(selector));
            if (removedPartition == null) {
                log.warn("Asked to remove timeline entry[interval: %s, version: %s] that doesn't exist", segment.getInterval(), segment.getVersion());
            }
        }
    }
}
Also used : ServerSelector(io.druid.client.selector.ServerSelector) QueryableDruidServer(io.druid.client.selector.QueryableDruidServer)

Example 10 with ServerSelector

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

the class BrokerServerView method serverAddedSegment.

private void serverAddedSegment(final DruidServerMetadata server, final DataSegment segment) {
    String segmentId = segment.getIdentifier();
    synchronized (lock) {
        log.debug("Adding segment[%s] for server[%s]", segment, server);
        ServerSelector selector = selectors.get(segmentId);
        if (selector == null) {
            selector = new ServerSelector(segment, tierSelectorStrategy);
            VersionedIntervalTimeline<String, ServerSelector> timeline = timelines.get(segment.getDataSource());
            if (timeline == null) {
                timeline = new VersionedIntervalTimeline<>(Ordering.natural());
                timelines.put(segment.getDataSource(), timeline);
            }
            timeline.add(segment.getInterval(), segment.getVersion(), segment.getShardSpec().createChunk(selector));
            selectors.put(segmentId, selector);
        }
        QueryableDruidServer queryableDruidServer = clients.get(server.getName());
        if (queryableDruidServer == null) {
            queryableDruidServer = addServer(baseView.getInventoryValue(server.getName()));
        }
        selector.addServerAndUpdateSegment(queryableDruidServer, segment);
    }
}
Also used : ServerSelector(io.druid.client.selector.ServerSelector) QueryableDruidServer(io.druid.client.selector.QueryableDruidServer)

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