misc fixes for router

This commit is contained in:
fjy 2014-04-15 14:23:54 -07:00
parent 291dac8de8
commit 9b06b6aa58
5 changed files with 22 additions and 11 deletions

View File

@ -61,8 +61,8 @@ public abstract class AbstractTask implements Task
protected AbstractTask(String id, String groupId, TaskResource taskResource, String dataSource) protected AbstractTask(String id, String groupId, TaskResource taskResource, String dataSource)
{ {
this.id = Preconditions.checkNotNull(id.toLowerCase(), "id"); this.id = Preconditions.checkNotNull(id, "id");
this.groupId = Preconditions.checkNotNull(groupId.toLowerCase(), "groupId"); this.groupId = Preconditions.checkNotNull(groupId, "groupId");
this.taskResource = Preconditions.checkNotNull(taskResource, "resource"); this.taskResource = Preconditions.checkNotNull(taskResource, "resource");
this.dataSource = Preconditions.checkNotNull(dataSource.toLowerCase(), "dataSource"); this.dataSource = Preconditions.checkNotNull(dataSource.toLowerCase(), "dataSource");
} }

View File

@ -50,10 +50,14 @@ public class QueryHostFinder<T>
{ {
final Pair<String, ServerDiscoverySelector> selected = hostSelector.select(query); final Pair<String, ServerDiscoverySelector> selected = hostSelector.select(query);
final String serviceName = selected.lhs; if (selected == null) {
final ServerDiscoverySelector selector = selected.rhs; log.error("Danger, Will Robinson! Unable to find any brokers!");
}
Server server = selector.pick(); 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) { if (server == null) {
log.error( log.error(
"WTF?! No server found for serviceName[%s]. Using backup", "WTF?! No server found for serviceName[%s]. Using backup",

View File

@ -122,7 +122,7 @@ public class TieredBrokerHostSelector<T> implements HostSelector<T>
{ {
synchronized (lock) { synchronized (lock) {
if (!ruleManager.isStarted() || !started) { if (!ruleManager.isStarted() || !started) {
return null; return getDefaultLookup();
} }
} }
@ -157,7 +157,7 @@ public class TieredBrokerHostSelector<T> implements HostSelector<T>
} }
if (baseRule == null) { if (baseRule == null) {
return null; return getDefaultLookup();
} }
// in the baseRule, find the broker of highest priority // in the baseRule, find the broker of highest priority
@ -192,4 +192,11 @@ public class TieredBrokerHostSelector<T> implements HostSelector<T>
return new Pair<>(brokerServiceName, retVal); return new Pair<>(brokerServiceName, retVal);
} }
private Pair<String, ServerDiscoverySelector> getDefaultLookup()
{
final String brokerServiceName = tierConfig.getDefaultBrokerServiceName();
final ServerDiscoverySelector retVal = selectorMap.get(brokerServiceName);
return new Pair<>(brokerServiceName, retVal);
}
} }

View File

@ -142,19 +142,18 @@ public class TieredBrokerHostSelectorTest
@Test @Test
public void testSelectMatchesNothing() throws Exception public void testSelectMatchesNothing() throws Exception
{ {
Pair retVal = brokerSelector.select( String brokerName = (String) brokerSelector.select(
Druids.newTimeseriesQueryBuilder() Druids.newTimeseriesQueryBuilder()
.dataSource("test") .dataSource("test")
.granularity("all") .granularity("all")
.aggregators(Arrays.<AggregatorFactory>asList(new CountAggregatorFactory("rows"))) .aggregators(Arrays.<AggregatorFactory>asList(new CountAggregatorFactory("rows")))
.intervals(Arrays.<Interval>asList(new Interval("2010-08-31/2010-09-01"))) .intervals(Arrays.<Interval>asList(new Interval("2010-08-31/2010-09-01")))
.build() .build()
); ).lhs;
Assert.assertEquals(null, retVal); Assert.assertEquals("hotBroker", brokerName);
} }
@Test @Test
public void testSelectMultiInterval() throws Exception public void testSelectMultiInterval() throws Exception
{ {

View File

@ -86,6 +86,7 @@ public class RouterJettyServerInitializer implements JettyServerInitializer
), "/druid/v2/*" ), "/druid/v2/*"
); );
queries.addFilter(GzipFilter.class, "/druid/v2/*", null); queries.addFilter(GzipFilter.class, "/druid/v2/*", null);
queries.addFilter(GuiceFilter.class, "/status/*", null);
final ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS); final ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
root.addServlet(new ServletHolder(new DefaultServlet()), "/*"); root.addServlet(new ServletHolder(new DefaultServlet()), "/*");