use of io.druid.curator.discovery.ServerDiscoverySelector in project druid by druid-io.
the class TieredBrokerHostSelector method select.
public Pair<String, ServerDiscoverySelector> select(final Query<T> query) {
synchronized (lock) {
if (!ruleManager.isStarted() || !started) {
return getDefaultLookup();
}
}
String brokerServiceName = null;
for (TieredBrokerSelectorStrategy strategy : strategies) {
final Optional<String> optionalName = strategy.getBrokerServiceName(tierConfig, query);
if (optionalName.isPresent()) {
brokerServiceName = optionalName.get();
break;
}
}
if (brokerServiceName == null) {
// For Union Queries tier will be selected on the rules for first dataSource.
List<Rule> rules = ruleManager.getRulesWithDefault(Iterables.getFirst(query.getDataSource().getNames(), null));
// find the rule that can apply to the entire set of intervals
DateTime now = new DateTime();
int lastRulePosition = -1;
LoadRule baseRule = null;
for (Interval interval : query.getIntervals()) {
int currRulePosition = 0;
for (Rule rule : rules) {
if (rule instanceof LoadRule && currRulePosition > lastRulePosition && rule.appliesTo(interval, now)) {
lastRulePosition = currRulePosition;
baseRule = (LoadRule) rule;
break;
}
currRulePosition++;
}
}
if (baseRule == null) {
return getDefaultLookup();
}
// in the baseRule, find the broker of highest priority
for (Map.Entry<String, String> entry : tierConfig.getTierToBrokerMap().entrySet()) {
if (baseRule.getTieredReplicants().containsKey(entry.getKey())) {
brokerServiceName = entry.getValue();
break;
}
}
}
if (brokerServiceName == null) {
log.error("WTF?! No brokerServiceName found for datasource[%s], intervals[%s]. Using default[%s].", query.getDataSource(), query.getIntervals(), tierConfig.getDefaultBrokerServiceName());
brokerServiceName = tierConfig.getDefaultBrokerServiceName();
}
ServerDiscoverySelector retVal = selectorMap.get(brokerServiceName);
if (retVal == null) {
log.error("WTF?! No selector found for brokerServiceName[%s]. Using default selector for[%s]", brokerServiceName, tierConfig.getDefaultBrokerServiceName());
retVal = selectorMap.get(tierConfig.getDefaultBrokerServiceName());
}
return new Pair<>(brokerServiceName, retVal);
}
use of io.druid.curator.discovery.ServerDiscoverySelector in project druid by druid-io.
the class OverlordProxyServletTest method testRewriteURI.
@Test
public void testRewriteURI() {
ServerDiscoverySelector selector = EasyMock.createMock(ServerDiscoverySelector.class);
Server server = EasyMock.createMock(Server.class);
EasyMock.expect(server.getHost()).andReturn("overlord:port");
EasyMock.expect(selector.pick()).andReturn(server).anyTimes();
HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
EasyMock.expect(request.getScheme()).andReturn("https").anyTimes();
EasyMock.expect(request.getQueryString()).andReturn("param1=test¶m2=test2").anyTimes();
EasyMock.expect(request.getRequestURI()).andReturn("/druid/overlord/worker").anyTimes();
EasyMock.replay(server, selector, request);
URI uri = URI.create(new OverlordProxyServlet(selector).rewriteTarget(request));
Assert.assertEquals("https://overlord:port/druid/overlord/worker?param1=test¶m2=test2", uri.toString());
}
Aggregations