RemoteTaskRunnerConfig: Fix Guice error on startup. (#3737)

This commit is contained in:
Gian Merlino 2016-12-05 10:49:53 -08:00 committed by Nishant
parent ff42058453
commit 4e67dd28c0
3 changed files with 15 additions and 8 deletions

View File

@ -24,6 +24,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.introspect.AnnotatedField;
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Strings;
import com.google.common.base.Throwables;
@ -33,7 +34,6 @@ import com.google.common.collect.Maps;
import com.google.inject.Inject;
import com.google.inject.ProvisionException;
import com.google.inject.spi.Message;
import io.druid.java.util.common.logger.Logger;
import javax.validation.ConstraintViolation;
@ -69,7 +69,7 @@ public class JsonConfigurator
public <T> T configurate(Properties props, String propertyPrefix, Class<T> clazz) throws ProvisionException
{
verifyClazzIsConfigurable(clazz);
verifyClazzIsConfigurable(jsonMapper, clazz);
// Make it end with a period so we only include properties with sub-object thingies.
final String propertyBase = propertyPrefix.endsWith(".") ? propertyPrefix : propertyPrefix + ".";
@ -165,10 +165,11 @@ public class JsonConfigurator
return config;
}
private <T> void verifyClazzIsConfigurable(Class<T> clazz)
@VisibleForTesting
public static <T> void verifyClazzIsConfigurable(ObjectMapper mapper, Class<T> clazz)
{
final List<BeanPropertyDefinition> beanDefs = jsonMapper.getSerializationConfig()
.introspect(jsonMapper.constructType(clazz))
final List<BeanPropertyDefinition> beanDefs = mapper.getSerializationConfig()
.introspect(mapper.constructType(clazz))
.findProperties();
for (BeanPropertyDefinition beanDef : beanDefs) {
final AnnotatedField field = beanDef.getField();

View File

@ -72,7 +72,6 @@ public class RemoteTaskRunnerConfig extends WorkerTaskRunnerConfig
return taskAssignmentTimeout;
}
@JsonProperty
public Period getTaskCleanupTimeout(){
return taskCleanupTimeout;
}
@ -105,7 +104,7 @@ public class RemoteTaskRunnerConfig extends WorkerTaskRunnerConfig
return workerBlackListBackoffTime;
}
public void setTaskBlackListBackoffTimeMillis(Period taskBlackListBackoffTime) {
public void setWorkerBlackListBackoffTime(Period taskBlackListBackoffTime) {
this.workerBlackListBackoffTime = taskBlackListBackoffTime;
}

View File

@ -20,6 +20,7 @@
package io.druid.indexing.overlord.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.druid.guice.JsonConfigurator;
import io.druid.jackson.DefaultObjectMapper;
import org.joda.time.Period;
import org.junit.Assert;
@ -40,6 +41,12 @@ public class RemoteTaskRunnerConfigTest
private static final Period DEFAULT_TASK_BACKOFF = new Period("PT10M");
private static final Period DEFAULT_BLACKLIST_CLEANUP_PERIOD = new Period("PT5M");
@Test
public void testIsJsonConfiguratable()
{
JsonConfigurator.verifyClazzIsConfigurable(mapper, RemoteTaskRunnerConfig.class);
}
@Test
public void testGetTaskAssignmentTimeout() throws Exception
{