diff options
author | Harald Musum <musum@verizonmedia.com> | 2020-11-17 14:12:02 +0100 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2020-11-17 14:12:02 +0100 |
commit | a749740a9ae84e78c597acf9361be945a28a68a7 (patch) | |
tree | 3a037e028b0926844b631404be8894dc9a4f52be | |
parent | e4c14623ad4ecbe6337a49d2176621c528bf7c22 (diff) |
Add curator config and populate it for config servers and cluster controllers
5 files changed, 69 insertions, 9 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/admin/clustercontroller/ClusterControllerCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/admin/clustercontroller/ClusterControllerCluster.java index 675ec22dc2b..a44f14e858c 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/admin/clustercontroller/ClusterControllerCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/admin/clustercontroller/ClusterControllerCluster.java @@ -1,7 +1,8 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.model.admin.clustercontroller; import com.google.common.base.Joiner; +import com.yahoo.cloud.config.CuratorConfig; import com.yahoo.cloud.config.ZookeeperServerConfig; import com.yahoo.cloud.config.ZookeepersConfig; import com.yahoo.config.model.producer.AbstractConfigProducer; @@ -19,13 +20,14 @@ import java.util.Collection; * @author Ulf Lilleengen */ public class ClusterControllerCluster extends AbstractConfigProducer<ClusterControllerContainerCluster> implements + CuratorConfig.Producer, ZookeeperServerConfig.Producer, ZookeepersConfig.Producer { private static final int ZK_CLIENT_PORT = 2181; private ClusterControllerContainerCluster containerCluster = null; - public ClusterControllerCluster(AbstractConfigProducer parent, String subId) { + public ClusterControllerCluster(AbstractConfigProducer<?> parent, String subId) { super(parent, subId); } @@ -73,5 +75,15 @@ public class ClusterControllerCluster extends AbstractConfigProducer<ClusterCont } } + @Override + public void getConfig(CuratorConfig.Builder builder) { + for (ClusterControllerContainer container : containerCluster.getContainers()) { + CuratorConfig.Server.Builder serverBuilder = new CuratorConfig.Server.Builder(); + serverBuilder.hostname(container.getHostName()).port(ZK_CLIENT_PORT); + builder.server(serverBuilder); + builder.zookeeperLocalhostAffinity(false); + } + } + } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/configserver/ConfigserverCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/container/configserver/ConfigserverCluster.java index 470b82496a3..76276aa3838 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/configserver/ConfigserverCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/configserver/ConfigserverCluster.java @@ -1,7 +1,8 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.model.container.configserver; import com.yahoo.cloud.config.ConfigserverConfig; +import com.yahoo.cloud.config.CuratorConfig; import com.yahoo.cloud.config.ZookeeperServerConfig; import com.yahoo.config.model.producer.AbstractConfigProducer; import com.yahoo.config.provision.Environment; @@ -27,20 +28,22 @@ import java.util.stream.IntStream; */ public class ConfigserverCluster extends AbstractConfigProducer implements - ZookeeperServerConfig.Producer, ConfigserverConfig.Producer, - StatisticsConfig.Producer, + CuratorConfig.Producer, HealthMonitorConfig.Producer, - VipStatusConfig.Producer { + StatisticsConfig.Producer, + VipStatusConfig.Producer, + ZookeeperServerConfig.Producer { + private final CloudConfigOptions options; - private ContainerCluster containerCluster; + private ContainerCluster<?> containerCluster; - public ConfigserverCluster(AbstractConfigProducer parent, String subId, CloudConfigOptions options) { + public ConfigserverCluster(AbstractConfigProducer<?> parent, String subId, CloudConfigOptions options) { super(parent, subId); this.options = options; } - public void setContainerCluster(ContainerCluster containerCluster) { + public void setContainerCluster(ContainerCluster<?> containerCluster) { this.containerCluster = containerCluster; // If we are in a config server cluster the correct zone is propagated through cloud config options, @@ -184,4 +187,18 @@ public class ConfigserverCluster extends AbstractConfigProducer public void getConfig(VipStatusConfig.Builder builder) { builder.initiallyInRotation(false); } + + @Override + public void getConfig(CuratorConfig.Builder builder) { + for (ConfigServer server : getConfigServers()) { + CuratorConfig.Server.Builder curatorBuilder = new CuratorConfig.Server.Builder(); + curatorBuilder.hostname(server.hostName); + if (options.zookeeperClientPort().isPresent()) { + curatorBuilder.port(options.zookeeperClientPort().get()); + } + builder.server(curatorBuilder); + } + builder.zookeeperLocalhostAffinity(true); + } + } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/admin/ClusterControllerTestCase.java b/config-model/src/test/java/com/yahoo/vespa/model/admin/ClusterControllerTestCase.java index 4b23a7e2e71..ca7e4b43bdf 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/admin/ClusterControllerTestCase.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/admin/ClusterControllerTestCase.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.model.admin; import com.google.common.collect.Collections2; +import com.yahoo.cloud.config.CuratorConfig; import com.yahoo.cloud.config.ZookeeperServerConfig; import com.yahoo.cloud.config.ZookeepersConfig; import com.yahoo.component.Version; @@ -207,6 +208,8 @@ public class ClusterControllerTestCase extends DomBuilderTest { assertZookeeperServerConfig(root, 0); assertZookeeperServerConfig(root, 1); assertZookeeperServerConfig(root, 2); + + assertCuratorConfig(root); } private void assertZookeepersConfig(TestRoot root) { @@ -226,6 +229,17 @@ public class ClusterControllerTestCase extends DomBuilderTest { assertTrue(serverIds.contains(id)); } + public void assertCuratorConfig(TestRoot root) { + CuratorConfig.Builder builder = new CuratorConfig.Builder(); + root.getConfig(builder, "admin/standalone/cluster-controllers"); + CuratorConfig config = builder.build(); + + assertEquals(3, config.server().size()); + assertEquals("my.host1.com", config.server().get(0).hostname()); + assertEquals(2181, config.server().get(0).port()); + assertFalse(config.zookeeperLocalhostAffinity()); + } + @Test public void testUnconfigured() throws Exception { String xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" + diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/configserver/ConfigserverClusterTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/configserver/ConfigserverClusterTest.java index 33dc3f59a80..d56acb3cff0 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/configserver/ConfigserverClusterTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/configserver/ConfigserverClusterTest.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.model.container.configserver; import com.yahoo.cloud.config.ConfigserverConfig; +import com.yahoo.cloud.config.CuratorConfig; import com.yahoo.cloud.config.ZookeeperServerConfig; import com.yahoo.config.ConfigInstance; import com.yahoo.config.model.deploy.DeployState; @@ -111,6 +112,15 @@ public class ConfigserverClusterTest { assertThat(config.region(), is("bar")); } + @Test + public void testCuratorConfig() { + CuratorConfig config = getConfig(CuratorConfig.class); + assertEquals(1, config.server().size()); + assertEquals("localhost", config.server().get(0).hostname()); + assertEquals(2181, config.server().get(0).port()); + assertTrue(config.zookeeperLocalhostAffinity()); + } + @SuppressWarnings("varargs") private static <T> void assertZookeeperServerProperty( List<ZookeeperServerConfig.Server> zkServers, Function<ZookeeperServerConfig.Server, T> propertyMapper, T... expectedProperties) { diff --git a/configdefinitions/src/vespa/curator.def b/configdefinitions/src/vespa/curator.def new file mode 100644 index 00000000000..ac03d994bb3 --- /dev/null +++ b/configdefinitions/src/vespa/curator.def @@ -0,0 +1,7 @@ +# Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +namespace=cloud.config + +server[].hostname string +server[].port int default=2181 + +zookeeperLocalhostAffinity bool default=false |