Search in sources :

Example 1 with ServerDiscoverySelector

use of io.druid.curator.discovery.ServerDiscoverySelector in project druid by druid-io.

the class TieredBrokerHostSelector method getDefaultLookup.

public Pair<String, ServerDiscoverySelector> getDefaultLookup() {
    final String brokerServiceName = tierConfig.getDefaultBrokerServiceName();
    final ServerDiscoverySelector retVal = selectorMap.get(brokerServiceName);
    return new Pair<>(brokerServiceName, retVal);
}
Also used : ServerDiscoverySelector(io.druid.curator.discovery.ServerDiscoverySelector) Pair(io.druid.java.util.common.Pair)

Example 2 with ServerDiscoverySelector

use of io.druid.curator.discovery.ServerDiscoverySelector in project druid by druid-io.

the class ITUnionQueryTest method postEvents.

public void postEvents(int id) throws Exception {
    final ServerDiscoverySelector eventReceiverSelector = factory.createSelector(EVENT_RECEIVER_SERVICE_PREFIX + id);
    eventReceiverSelector.start();
    try {
        ServerDiscoveryUtil.waitUntilInstanceReady(eventReceiverSelector, "Event Receiver");
        // Access the docker VM mapped host and port instead of service announced in zookeeper
        String host = config.getMiddleManagerHost() + ":" + eventReceiverSelector.pick().getPort();
        LOG.info("Event Receiver Found at host [%s]", host);
        EventReceiverFirehoseTestClient client = new EventReceiverFirehoseTestClient(host, EVENT_RECEIVER_SERVICE_PREFIX + id, jsonMapper, httpClient, smileMapper);
        client.postEventsFromFile(UNION_DATA_FILE);
    } finally {
        eventReceiverSelector.stop();
    }
}
Also used : ServerDiscoverySelector(io.druid.curator.discovery.ServerDiscoverySelector) EventReceiverFirehoseTestClient(io.druid.testing.clients.EventReceiverFirehoseTestClient)

Example 3 with ServerDiscoverySelector

use of io.druid.curator.discovery.ServerDiscoverySelector in project druid by druid-io.

the class ITRealtimeIndexTaskTest method postEvents.

public void postEvents() throws Exception {
    DateTimeZone zone = DateTimeZone.forID("UTC");
    final ServerDiscoverySelector eventReceiverSelector = factory.createSelector(EVENT_RECEIVER_SERVICE_NAME);
    eventReceiverSelector.start();
    BufferedReader reader = null;
    InputStreamReader isr = null;
    try {
        isr = new InputStreamReader(ITRealtimeIndexTaskTest.class.getResourceAsStream(EVENT_DATA_FILE));
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    try {
        reader = new BufferedReader(isr);
        ServerDiscoveryUtil.waitUntilInstanceReady(eventReceiverSelector, "Event Receiver");
        // Use the host from the config file and the port announced in zookeeper
        String host = config.getMiddleManagerHost() + ":" + eventReceiverSelector.pick().getPort();
        LOG.info("Event Receiver Found at host [%s]", host);
        EventReceiverFirehoseTestClient client = new EventReceiverFirehoseTestClient(host, EVENT_RECEIVER_SERVICE_NAME, jsonMapper, httpClient, smileMapper);
        // there are 22 lines in the file
        int i = 1;
        // timestamp used for sending each event
        DateTime dt = new DateTime(zone);
        // timestamp of 1st event
        dtFirst = dt;
        // timestamp of last event
        dtLast = dt;
        String line;
        while ((line = reader.readLine()) != null) {
            if (i == 15) {
                // for the 15th line, use a time before the window
                dt = dt.minusMinutes(10);
            } else if (i == 16) {
                // remember this time to use in the expected response from the groupBy query
                dtGroupBy = dt;
            } else if (i == 18) {
                // use a time 6 seconds ago so it will be out of order
                dt = dt.minusSeconds(6);
            }
            String event = line.replace(TIME_PLACEHOLDER, EVENT_FMT.print(dt));
            LOG.info("sending event: [%s]\n", event);
            Collection<Map<String, Object>> events = new ArrayList<Map<String, Object>>();
            events.add((Map<String, Object>) this.jsonMapper.readValue(event, new TypeReference<Map<String, Object>>() {
            }));
            int eventsPosted = client.postEvents(events, this.jsonMapper, MediaType.APPLICATION_JSON);
            if (eventsPosted != events.size()) {
                throw new ISE("Event not posted");
            }
            try {
                Thread.sleep(DELAY_BETWEEN_EVENTS_SECS * 1000);
            } catch (InterruptedException ex) {
            /* nothing */
            }
            dtLast = dt;
            dt = new DateTime(zone);
            i++;
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    } finally {
        reader.close();
        eventReceiverSelector.stop();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) ServerDiscoverySelector(io.druid.curator.discovery.ServerDiscoverySelector) EventReceiverFirehoseTestClient(io.druid.testing.clients.EventReceiverFirehoseTestClient) BufferedReader(java.io.BufferedReader) ISE(io.druid.java.util.common.ISE) Map(java.util.Map)

Example 4 with ServerDiscoverySelector

use of io.druid.curator.discovery.ServerDiscoverySelector in project druid by druid-io.

the class QueryHostFinder method findServerInner.

private Server findServerInner(final Pair<String, ServerDiscoverySelector> selected) {
    if (selected == null) {
        log.error("Danger, Will Robinson! Unable to find any brokers!");
    }
    final String serviceName = selected == null ? hostSelector.getDefaultServiceName() : selected.lhs;
    final ServerDiscoverySelector selector = selected == null ? null : selected.rhs;
    Server server = selector == null ? null : selector.pick();
    if (server == null) {
        log.error("WTF?! No server found for serviceName[%s]. Using backup", serviceName);
        server = serverBackup.get(serviceName);
        if (server == null) {
            log.error("WTF?! No backup found for serviceName[%s]. Using default[%s]", serviceName, hostSelector.getDefaultServiceName());
            server = serverBackup.get(hostSelector.getDefaultServiceName());
        }
    }
    if (server != null) {
        serverBackup.put(serviceName, server);
    }
    return server;
}
Also used : ServerDiscoverySelector(io.druid.curator.discovery.ServerDiscoverySelector) Server(io.druid.client.selector.Server)

Example 5 with ServerDiscoverySelector

use of io.druid.curator.discovery.ServerDiscoverySelector in project druid by druid-io.

the class TieredBrokerHostSelector method start.

@LifecycleStart
public void start() {
    synchronized (lock) {
        if (started) {
            return;
        }
        try {
            for (Map.Entry<String, String> entry : tierConfig.getTierToBrokerMap().entrySet()) {
                ServerDiscoverySelector selector = serverDiscoveryFactory.createSelector(entry.getValue());
                selector.start();
                selectorMap.put(entry.getValue(), selector);
            }
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
        started = true;
    }
}
Also used : ServerDiscoverySelector(io.druid.curator.discovery.ServerDiscoverySelector) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) LifecycleStart(io.druid.java.util.common.lifecycle.LifecycleStart)

Aggregations

ServerDiscoverySelector (io.druid.curator.discovery.ServerDiscoverySelector)7 Map (java.util.Map)3 Server (io.druid.client.selector.Server)2 Pair (io.druid.java.util.common.Pair)2 EventReceiverFirehoseTestClient (io.druid.testing.clients.EventReceiverFirehoseTestClient)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 DateTime (org.joda.time.DateTime)2 ISE (io.druid.java.util.common.ISE)1 LifecycleStart (io.druid.java.util.common.lifecycle.LifecycleStart)1 LoadRule (io.druid.server.coordinator.rules.LoadRule)1 Rule (io.druid.server.coordinator.rules.Rule)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 DateTimeZone (org.joda.time.DateTimeZone)1 Interval (org.joda.time.Interval)1 Test (org.junit.Test)1