diff options
4 files changed, 43 insertions, 16 deletions
diff --git a/clustercontroller-core/pom.xml b/clustercontroller-core/pom.xml index 8d62acb0fb4..02f61517083 100644 --- a/clustercontroller-core/pom.xml +++ b/clustercontroller-core/pom.xml @@ -79,6 +79,12 @@ <scope>provided</scope> </dependency> <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>zookeeper-client-common</artifactId> + <version>${project.version}</version> + <scope>compile</scope> + </dependency> + <dependency> <!-- Not used by this module, but compilation fails without it because zookeeper uses these annotations. Provided scoped here to avoid dependents getting it transitively. --> <groupId>com.github.spotbugs</groupId> diff --git a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/ZooKeeperDatabase.java b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/ZooKeeperDatabase.java index 4cdbb49dedc..5e0d050cbcf 100644 --- a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/ZooKeeperDatabase.java +++ b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/database/ZooKeeperDatabase.java @@ -1,35 +1,35 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.clustercontroller.core.database; +import com.yahoo.vdslib.state.Node; +import com.yahoo.vdslib.state.NodeState; +import com.yahoo.vdslib.state.State; import com.yahoo.vespa.clustercontroller.core.AnnotatedClusterState; import com.yahoo.vespa.clustercontroller.core.ClusterStateBundle; import com.yahoo.vespa.clustercontroller.core.ContentCluster; import com.yahoo.vespa.clustercontroller.core.rpc.EnvelopedClusterStateBundleCodec; import com.yahoo.vespa.clustercontroller.core.rpc.SlimeClusterStateBundleCodec; +import com.yahoo.vespa.zookeeper.client.ZkClientConfigBuilder; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.Watcher; import org.apache.zookeeper.ZooDefs; import org.apache.zookeeper.ZooKeeper; -import org.apache.zookeeper.data.Stat; import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.data.Stat; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.logging.Level; -import com.yahoo.vdslib.state.NodeState; -import com.yahoo.vdslib.state.State; -import com.yahoo.vdslib.state.Node; - import java.util.logging.Logger; -import java.io.IOException; -import java.io.StringWriter; -import java.io.PrintWriter; -import java.nio.charset.Charset; public class ZooKeeperDatabase extends Database { @@ -108,7 +108,7 @@ public class ZooKeeperDatabase extends Database { public ZooKeeperDatabase(ContentCluster cluster, int nodeIndex, String address, int timeout, Database.DatabaseListener zksl) throws IOException, KeeperException, InterruptedException { this.nodeIndex = nodeIndex; zooKeeperRoot = "/vespa/fleetcontroller/" + cluster.getName() + "/"; - session = new ZooKeeper(address, timeout, watcher); + session = new ZooKeeper(address, timeout, watcher, new ZkClientConfigBuilder().toConfig()); boolean completedOk = false; try{ this.listener = zksl; diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/Curator.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/Curator.java index b825e33cbd8..9a6ef3f74f1 100644 --- a/zkfacade/src/main/java/com/yahoo/vespa/curator/Curator.java +++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/Curator.java @@ -4,9 +4,7 @@ package com.yahoo.vespa.curator; import com.google.inject.Inject; import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.cloud.config.CuratorConfig; -import com.yahoo.io.IOUtils; import com.yahoo.path.Path; -import com.yahoo.text.Utf8; import com.yahoo.vespa.curator.api.VespaCurator; import com.yahoo.vespa.curator.recipes.CuratorCounter; import com.yahoo.vespa.defaults.Defaults; @@ -30,6 +28,8 @@ import org.apache.zookeeper.data.Stat; import org.apache.zookeeper.server.quorum.QuorumPeerConfig; import java.io.File; +import java.io.IOException; +import java.io.UncheckedIOException; import java.time.Duration; import java.util.Arrays; import java.util.List; @@ -124,13 +124,12 @@ public class Curator implements VespaCurator, AutoCloseable { private static ZKClientConfig createClientConfig(Optional<File> clientConfigFile) { if (clientConfigFile.isPresent()) { - String config = new ZkClientConfigBuilder().toConfigString(); - clientConfigFile.get().getParentFile().mkdirs(); - IOUtils.writeFile(clientConfigFile.get(), Utf8.toBytes(config)); try { - return new ZKClientConfig(clientConfigFile.get()); + return new ZkClientConfigBuilder().toConfig(clientConfigFile.get().toPath()); } catch (QuorumPeerConfig.ConfigException e) { throw new RuntimeException("Unable to create ZooKeeper client config file " + clientConfigFile.get()); + } catch (IOException e) { + throw new UncheckedIOException(e); } } else { return new ZKClientConfig(); diff --git a/zookeeper-client-common/src/main/java/com/yahoo/vespa/zookeeper/client/ZkClientConfigBuilder.java b/zookeeper-client-common/src/main/java/com/yahoo/vespa/zookeeper/client/ZkClientConfigBuilder.java index 62191880b8f..af75bd7aa5c 100644 --- a/zookeeper-client-common/src/main/java/com/yahoo/vespa/zookeeper/client/ZkClientConfigBuilder.java +++ b/zookeeper-client-common/src/main/java/com/yahoo/vespa/zookeeper/client/ZkClientConfigBuilder.java @@ -4,7 +4,13 @@ package com.yahoo.vespa.zookeeper.client; import com.yahoo.security.tls.MixedMode; import com.yahoo.security.tls.TlsContext; import com.yahoo.security.tls.TransportSecurityUtils; +import org.apache.zookeeper.client.ZKClientConfig; +import org.apache.zookeeper.server.quorum.QuorumPeerConfig; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -28,6 +34,22 @@ public class ZkClientConfigBuilder { public ZkClientConfigBuilder() {} + public ZKClientConfig toConfig(Path configFile) throws IOException, QuorumPeerConfig.ConfigException { + String configString = toConfigString(); + Files.createDirectories(configFile.getParent()); + Path tempFile = configFile.resolveSibling("." + configFile.getFileName() + ".tmp"); + Files.writeString(tempFile, configString); + Files.move(tempFile, configFile, StandardCopyOption.ATOMIC_MOVE); + return new ZKClientConfig(configFile.toString()); + } + + public ZKClientConfig toConfig() { + ZKClientConfig config = new ZKClientConfig(); + Map<String, String> configProperties = toConfigProperties(); + configProperties.forEach(config::setProperty); + return config; + } + public String toConfigString() { StringBuilder builder = new StringBuilder(); Map<String, String> properties = toConfigProperties(); |