diff --git a/indexing-service/src/main/java/io/druid/server/initialization/IndexerZkConfig.java b/indexing-service/src/main/java/io/druid/server/initialization/IndexerZkConfig.java index 6333ea3f0e9..aefa80313e2 100644 --- a/indexing-service/src/main/java/io/druid/server/initialization/IndexerZkConfig.java +++ b/indexing-service/src/main/java/io/druid/server/initialization/IndexerZkConfig.java @@ -19,9 +19,9 @@ package io.druid.server.initialization; -import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JacksonInject; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.inject.Inject; import org.apache.curator.utils.ZKPaths; /** @@ -29,19 +29,41 @@ import org.apache.curator.utils.ZKPaths; */ public class IndexerZkConfig { - @Inject - @JsonIgnore - private ZkPathsConfig zkPathsConfig = new ZkPathsConfig(); + @JsonCreator + public IndexerZkConfig( + @JacksonInject ZkPathsConfig zkPathsConfig, + @JsonProperty("base") String base, + @JsonProperty("announcementsPath") String announcementsPath, + @JsonProperty("tasksPath") String tasksPath, + @JsonProperty("status") String status, + @JsonProperty("leaderLatchPath") String leaderLatchPath + ) + { + this.zkPathsConfig = zkPathsConfig; + this.base = base; + this.announcementsPath = announcementsPath; + this.tasksPath = tasksPath; + this.status = status; + this.leaderLatchPath = leaderLatchPath; + } + + @JacksonInject + private final ZkPathsConfig zkPathsConfig; + @JsonProperty - private String base; + private final String base; + @JsonProperty - private String announcementsPath; + private final String announcementsPath; + @JsonProperty - private String tasksPath; + private final String tasksPath; + @JsonProperty - private String status; + private final String status; + @JsonProperty - private String leaderLatchPath; + private final String leaderLatchPath; private String defaultIndexerPath(final String subPath) { @@ -77,11 +99,4 @@ public class IndexerZkConfig { return zkPathsConfig; } - - // Setter required for easy debugging - public IndexerZkConfig setZkPathsConfig(ZkPathsConfig zkPathsConfig) - { - this.zkPathsConfig = zkPathsConfig; - return this; - } } diff --git a/indexing-service/src/test/java/io/druid/indexing/overlord/RemoteTaskRunnerTest.java b/indexing-service/src/test/java/io/druid/indexing/overlord/RemoteTaskRunnerTest.java index 01bfbca8480..63174d9640f 100644 --- a/indexing-service/src/test/java/io/druid/indexing/overlord/RemoteTaskRunnerTest.java +++ b/indexing-service/src/test/java/io/druid/indexing/overlord/RemoteTaskRunnerTest.java @@ -396,14 +396,14 @@ public class RemoteTaskRunnerTest remoteTaskRunner = new RemoteTaskRunner( jsonMapper, config, - new IndexerZkConfig().setZkPathsConfig(new ZkPathsConfig() + new IndexerZkConfig(new ZkPathsConfig() { @Override public String getBase() { return basePath; } - }), + },null,null,null,null,null), cf, new SimplePathChildrenCacheFactory.Builder().build(), null, diff --git a/indexing-service/src/test/java/io/druid/indexing/worker/WorkerTaskMonitorTest.java b/indexing-service/src/test/java/io/druid/indexing/worker/WorkerTaskMonitorTest.java index 76b269b855e..a8b55c8ffd3 100644 --- a/indexing-service/src/test/java/io/druid/indexing/worker/WorkerTaskMonitorTest.java +++ b/indexing-service/src/test/java/io/druid/indexing/worker/WorkerTaskMonitorTest.java @@ -140,7 +140,7 @@ public class WorkerTaskMonitorTest workerCuratorCoordinator = new WorkerCuratorCoordinator( jsonMapper, - new IndexerZkConfig().setZkPathsConfig( + new IndexerZkConfig( new ZkPathsConfig() { @Override @@ -148,7 +148,7 @@ public class WorkerTaskMonitorTest { return basePath; } - }), + },null,null,null,null,null), new TestRemoteTaskRunnerConfig(), cf, worker diff --git a/indexing-service/src/test/java/io/druid/indexing/worker/http/WorkerResourceTest.java b/indexing-service/src/test/java/io/druid/indexing/worker/http/WorkerResourceTest.java index 2b786532e79..91577521be9 100644 --- a/indexing-service/src/test/java/io/druid/indexing/worker/http/WorkerResourceTest.java +++ b/indexing-service/src/test/java/io/druid/indexing/worker/http/WorkerResourceTest.java @@ -77,14 +77,14 @@ public class WorkerResourceTest curatorCoordinator = new WorkerCuratorCoordinator( jsonMapper, - new IndexerZkConfig().setZkPathsConfig(new ZkPathsConfig() + new IndexerZkConfig(new ZkPathsConfig() { @Override public String getBase() { return basePath; } - }), + },null,null,null,null,null), new RemoteTaskRunnerConfig(), cf, worker diff --git a/indexing-service/src/test/java/io/druid/server/initialization/IndexerZkConfigTest.java b/indexing-service/src/test/java/io/druid/server/initialization/IndexerZkConfigTest.java index d19d7b6490d..26331fabcf3 100644 --- a/indexing-service/src/test/java/io/druid/server/initialization/IndexerZkConfigTest.java +++ b/indexing-service/src/test/java/io/druid/server/initialization/IndexerZkConfigTest.java @@ -34,6 +34,7 @@ import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import java.lang.reflect.Field; @@ -42,7 +43,9 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Properties; import java.util.UUID; /** @@ -52,7 +55,7 @@ public class IndexerZkConfigTest { private static final String indexerPropertyString = "test.druid.zk.paths.indexer"; private static final String zkServiceConfigString = "test.druid.zk.paths"; - private static final Collection clobberableProperties = new ArrayList<>(); + private static final Collection clobberableProperties = new HashSet<>(); private static final Module simpleZkConfigModule = new Module() { @@ -65,13 +68,11 @@ public class IndexerZkConfigTest JsonConfigProvider.bind(binder, indexerPropertyString, IndexerZkConfig.class); JsonConfigProvider.bind( binder, zkServiceConfigString, - CuratorConfig.class + ZkPathsConfig.class ); } }; - private static final Map priorValues = new HashMap<>(); - @BeforeClass public static void setup() { @@ -85,22 +86,9 @@ public class IndexerZkConfigTest clobberableProperties.add(String.format("%s.%s", zkServiceConfigString, field.getName())); } } - for (String clobberableProperty : clobberableProperties) { - priorValues.put(clobberableProperty, System.getProperty(clobberableProperty)); - } } - @AfterClass - public static void cleanup() - { - for (Map.Entry entry : priorValues.entrySet()) { - if (null != entry.getKey() && null != entry.getValue()) { - System.setProperty(entry.getKey(), entry.getValue()); - } - } - } - - private Map propertyValues = new HashMap<>(); + private Properties propertyValues = new Properties(); private int assertions = 0; @Before @@ -109,7 +97,6 @@ public class IndexerZkConfigTest for (String property : clobberableProperties) { propertyValues.put(property, UUID.randomUUID().toString()); } - System.getProperties().putAll(propertyValues); assertions = 0; } @@ -150,6 +137,28 @@ public class IndexerZkConfigTest } } + @Test + public void testNullConfig(){ + propertyValues.clear(); + + final Injector injector = Initialization.makeInjectorWithModules( + GuiceInjectors.makeStartupInjector(), + ImmutableList.of(simpleZkConfigModule) + ); + JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get(); + + JsonConfigProvider zkPathsConfig = JsonConfigProvider.of(zkServiceConfigString, ZkPathsConfig.class); + zkPathsConfig.inject(propertyValues, configurator); + + JsonConfigProvider indexerZkConfig = JsonConfigProvider.of( + indexerPropertyString, + IndexerZkConfig.class + ); + indexerZkConfig.inject(propertyValues, configurator); + + Assert.assertEquals("/druid/indexer/leaderLatchPath", indexerZkConfig.get().get().getLeaderLatchPath()); + } + @Test public void testSimpleConfig() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { @@ -160,16 +169,46 @@ public class IndexerZkConfigTest JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get(); JsonConfigProvider zkPathsConfig = JsonConfigProvider.of(zkServiceConfigString, ZkPathsConfig.class); - zkPathsConfig.inject(System.getProperties(), configurator); + zkPathsConfig.inject(propertyValues, configurator); JsonConfigProvider indexerZkConfig = JsonConfigProvider.of( indexerPropertyString, IndexerZkConfig.class ); - indexerZkConfig.inject(System.getProperties(), configurator); + indexerZkConfig.inject(propertyValues, configurator); - validateEntries(indexerZkConfig.get().get()); - validateEntries(zkPathsConfig.get().get()); + + IndexerZkConfig zkConfig = indexerZkConfig.get().get(); + ZkPathsConfig zkPathsConfig1 = zkPathsConfig.get().get(); + + validateEntries(zkConfig); + validateEntries(zkPathsConfig1); Assert.assertEquals(clobberableProperties.size(), assertions); } + + @Test + public void testExactConfig(){ + final Injector injector = Initialization.makeInjectorWithModules( + GuiceInjectors.makeStartupInjector(), + ImmutableList.of(simpleZkConfigModule) + ); + propertyValues.setProperty(zkServiceConfigString + ".base", "/druid/metrics"); + + + JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get(); + + JsonConfigProvider zkPathsConfig = JsonConfigProvider.of( + zkServiceConfigString, + ZkPathsConfig.class + ); + + zkPathsConfig.inject(propertyValues, configurator); + + ZkPathsConfig zkPathsConfig1 = zkPathsConfig.get().get(); + + IndexerZkConfig indexerZkConfig = new IndexerZkConfig(zkPathsConfig1,null,null,null,null,null); + + Assert.assertEquals("indexer", indexerZkConfig.getBase()); + Assert.assertEquals("/druid/metrics/indexer/announcements", indexerZkConfig.getAnnouncementsPath()); + } }