From d0678755559f77d33020172863a0e7385805d94b Mon Sep 17 00:00:00 2001 From: Matteo Merli Date: Fri, 10 Feb 2017 17:16:16 -0800 Subject: [PATCH] Ignore already existing required z-nodes in global zk --- .../pulsar/PulsarClusterMetadataSetup.java | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/pulsar-broker/src/main/java/com/yahoo/pulsar/PulsarClusterMetadataSetup.java b/pulsar-broker/src/main/java/com/yahoo/pulsar/PulsarClusterMetadataSetup.java index 2dc7654299721..402319293ded9 100644 --- a/pulsar-broker/src/main/java/com/yahoo/pulsar/PulsarClusterMetadataSetup.java +++ b/pulsar-broker/src/main/java/com/yahoo/pulsar/PulsarClusterMetadataSetup.java @@ -22,6 +22,7 @@ import org.apache.bookkeeper.meta.HierarchicalLedgerManagerFactory; import org.apache.bookkeeper.util.ZkUtils; import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException.NodeExistsException; import org.apache.zookeeper.ZooDefs; import org.apache.zookeeper.ZooKeeper; import org.slf4j.Logger; @@ -44,14 +45,16 @@ private static class Arguments { @Parameter(names = { "-c", "--cluster" }, description = "Cluster name", required = true) private String cluster; - @Parameter(names = { "-uw", "--web-service-url" }, description = "Web-service URL for new cluster", required = true) + @Parameter(names = { "-uw", + "--web-service-url" }, description = "Web-service URL for new cluster", required = true) private String clusterWebServiceUrl; @Parameter(names = { "-tw", "--web-service-url-tls" }, description = "Web-service URL for new cluster with TLS encryption", required = false) private String clusterWebServiceUrlTls; - - @Parameter(names = { "-ub", "--broker-service-url" }, description = "Broker-service URL for new cluster", required = false) + + @Parameter(names = { "-ub", + "--broker-service-url" }, description = "Broker-service URL for new cluster", required = false) private String clusterBrokerServiceUrl; @Parameter(names = { "-tb", @@ -103,10 +106,19 @@ public static void main(String[] args) throws Exception { localZk.create("/managed-ledgers", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); localZk.create("/namespace", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); - ZkUtils.createFullPathOptimistic(globalZk, "/admin/policies", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, - CreateMode.PERSISTENT); - ZkUtils.createFullPathOptimistic(globalZk, "/admin/clusters", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, - CreateMode.PERSISTENT); + try { + ZkUtils.createFullPathOptimistic(globalZk, "/admin/policies", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } catch (NodeExistsException e) { + // Ignore + } + + try { + ZkUtils.createFullPathOptimistic(globalZk, "/admin/clusters", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } catch (NodeExistsException e) { + // Ignore + } ClusterData clusterData = new ClusterData(arguments.clusterWebServiceUrl, arguments.clusterWebServiceUrlTls, arguments.clusterBrokerServiceUrl, arguments.clusterBrokerServiceUrlTls); @@ -119,8 +131,12 @@ public static void main(String[] args) throws Exception { ClusterData globalClusterData = new ClusterData(null, null); byte[] globalClusterDataJson = ObjectMapperFactory.getThreadLocal().writeValueAsBytes(globalClusterData); - globalZk.create("/admin/clusters/global", globalClusterDataJson, ZooDefs.Ids.OPEN_ACL_UNSAFE, - CreateMode.PERSISTENT); + try { + globalZk.create("/admin/clusters/global", globalClusterDataJson, ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } catch (NodeExistsException e) { + // Ignore + } log.info("Cluster metadata for '{}' setup correctly", arguments.cluster); }