Skip to content

Commit

Permalink
RemoteTaskRunnerConfig: Fix Guice error on startup. (apache#3737)
Browse files Browse the repository at this point in the history
  • Loading branch information
gianm authored and nishantmonu51 committed Dec 5, 2016
1 parent ff42058 commit 4e67dd2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
13 changes: 7 additions & 6 deletions api/src/main/java/io/druid/guice/JsonConfigurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand All @@ -33,7 +34,6 @@
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;
Expand Down Expand Up @@ -69,7 +69,7 @@ public 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 + ".";
Expand Down Expand Up @@ -165,11 +165,12 @@ public Message apply(String input)
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))
.findProperties();
final List<BeanPropertyDefinition> beanDefs = mapper.getSerializationConfig()
.introspect(mapper.constructType(clazz))
.findProperties();
for (BeanPropertyDefinition beanDef : beanDefs) {
final AnnotatedField field = beanDef.getField();
if (field == null || !field.hasAnnotation(JsonProperty.class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public Period getTaskAssignmentTimeout()
return taskAssignmentTimeout;
}

@JsonProperty
public Period getTaskCleanupTimeout(){
return taskCleanupTimeout;
}
Expand Down Expand Up @@ -105,7 +104,7 @@ public Period getWorkerBlackListBackoffTime() {
return workerBlackListBackoffTime;
}

public void setTaskBlackListBackoffTimeMillis(Period taskBlackListBackoffTime) {
public void setWorkerBlackListBackoffTime(Period taskBlackListBackoffTime) {
this.workerBlackListBackoffTime = taskBlackListBackoffTime;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down

0 comments on commit 4e67dd2

Please sign in to comment.