Skip to content

Commit 271fee2

Browse files
Demogorgon314lhotari
authored andcommitted
[improve][broker] Make cluster metadata teardown command support metadata config path (apache#23520)
(cherry picked from commit 69ca0cb)
1 parent b5dfd4b commit 271fee2

File tree

3 files changed

+118
-3
lines changed

3 files changed

+118
-3
lines changed

pulsar-broker/src/main/java/org/apache/pulsar/PulsarClusterMetadataTeardown.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.apache.pulsar.metadata.api.MetadataStoreConfig;
4040
import org.apache.pulsar.metadata.api.MetadataStoreFactory;
4141
import org.apache.pulsar.metadata.api.extended.MetadataStoreExtended;
42+
import org.apache.pulsar.metadata.impl.ZKMetadataStore;
4243
import org.slf4j.Logger;
4344
import org.slf4j.LoggerFactory;
4445

@@ -49,9 +50,17 @@ public class PulsarClusterMetadataTeardown {
4950

5051
private static class Arguments {
5152
@Parameter(names = { "-zk",
52-
"--zookeeper"}, description = "Local ZooKeeper quorum connection string", required = true)
53+
"--zookeeper"}, description = "Local ZooKeeper quorum connection string")
5354
private String zookeeper;
5455

56+
@Parameter(names = {
57+
"--metadata-store"}, description = "Metadata Store service url. eg: zk:my-zk:2181")
58+
private String metadataStoreUrl;
59+
60+
@Parameter(names = {"-mscp",
61+
"--metadata-store-config-path"}, description = "Metadata Store config path")
62+
private String metadataStoreConfigPath;
63+
5564
@Parameter(names = {
5665
"--zookeeper-session-timeout-ms"
5766
}, description = "Local zookeeper session timeout ms")
@@ -63,6 +72,11 @@ private static class Arguments {
6372
@Parameter(names = { "-cs", "--configuration-store" }, description = "Configuration Store connection string")
6473
private String configurationStore;
6574

75+
@Parameter(names = {"-cmscp",
76+
"--configuration-metadata-store-config-path"}, description = "Configuration Metadata Store config path",
77+
hidden = false)
78+
private String configurationStoreConfigPath;
79+
6680
@Parameter(names = { "--bookkeeper-metadata-service-uri" }, description = "Metadata service uri of BookKeeper")
6781
private String bkMetadataServiceUri;
6882

@@ -97,11 +111,21 @@ public static void main(String[] args) throws Exception {
97111
throw e;
98112
}
99113

114+
if (arguments.metadataStoreUrl == null && arguments.zookeeper == null) {
115+
jcommander.usage();
116+
throw new IllegalArgumentException("Metadata store address argument is required (--metadata-store)");
117+
}
118+
119+
if (arguments.metadataStoreUrl == null) {
120+
arguments.metadataStoreUrl = ZKMetadataStore.ZK_SCHEME_IDENTIFIER + arguments.zookeeper;
121+
}
122+
100123
@Cleanup
101-
MetadataStoreExtended metadataStore = MetadataStoreExtended.create(arguments.zookeeper,
124+
MetadataStoreExtended metadataStore = MetadataStoreExtended.create(arguments.metadataStoreUrl,
102125
MetadataStoreConfig.builder()
103126
.sessionTimeoutMillis(arguments.zkSessionTimeoutMillis)
104127
.metadataStoreName(MetadataStoreConfig.METADATA_STORE)
128+
.configFilePath(arguments.metadataStoreConfigPath)
105129
.build());
106130

107131
if (arguments.bkMetadataServiceUri != null) {
@@ -125,6 +149,7 @@ public static void main(String[] args) throws Exception {
125149
@Cleanup
126150
MetadataStore configMetadataStore = MetadataStoreFactory.create(arguments.configurationStore,
127151
MetadataStoreConfig.builder().sessionTimeoutMillis(arguments.zkSessionTimeoutMillis)
152+
.configFilePath(arguments.configurationStoreConfigPath)
128153
.metadataStoreName(MetadataStoreConfig.CONFIGURATION_METADATA_STORE).build());
129154
deleteRecursively(configMetadataStore, "/admin/clusters/" + arguments.cluster).join();
130155
}

pulsar-broker/src/test/java/org/apache/pulsar/broker/zookeeper/ClusterMetadataSetupTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ public void start() throws IOException {
533533
log.info("ZooKeeper started at {}", hostPort);
534534
}
535535

536-
private void clear() {
536+
void clear() {
537537
zks.getZKDatabase().clear();
538538
}
539539

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.pulsar.broker.zookeeper;
20+
21+
import static org.testng.Assert.assertEquals;
22+
import static org.testng.Assert.assertFalse;
23+
import static org.testng.Assert.assertNotNull;
24+
import java.util.SortedMap;
25+
import org.apache.pulsar.PulsarClusterMetadataSetup;
26+
import org.apache.pulsar.PulsarClusterMetadataTeardown;
27+
import org.apache.pulsar.common.policies.data.ClusterData;
28+
import org.apache.pulsar.common.util.ObjectMapperFactory;
29+
import org.testng.annotations.AfterClass;
30+
import org.testng.annotations.AfterMethod;
31+
import org.testng.annotations.BeforeClass;
32+
import org.testng.annotations.Test;
33+
34+
public class ClusterMetadataTeardownTest {
35+
36+
private ClusterMetadataSetupTest.ZookeeperServerTest localZkS;
37+
38+
@BeforeClass
39+
void setup() throws Exception {
40+
localZkS = new ClusterMetadataSetupTest.ZookeeperServerTest(0);
41+
localZkS.start();
42+
}
43+
44+
@AfterClass
45+
void teardown() throws Exception {
46+
localZkS.close();
47+
}
48+
49+
@AfterMethod(alwaysRun = true)
50+
void cleanup() {
51+
localZkS.clear();
52+
}
53+
54+
@Test
55+
public void testSetupClusterMetadataAndTeardown() throws Exception {
56+
String[] args1 = {
57+
"--cluster", "testReSetupClusterMetadata-cluster",
58+
"--zookeeper", "127.0.0.1:" + localZkS.getZookeeperPort(),
59+
"--configuration-store", "127.0.0.1:" + localZkS.getZookeeperPort(),
60+
"--configuration-metadata-store-config-path", "src/test/resources/conf/zk_client_enable_sasl.conf",
61+
"--web-service-url", "http://127.0.0.1:8080",
62+
"--web-service-url-tls", "https://127.0.0.1:8443",
63+
"--broker-service-url", "pulsar://127.0.0.1:6650",
64+
"--broker-service-url-tls", "pulsar+ssl://127.0.0.1:6651"
65+
};
66+
PulsarClusterMetadataSetup.main(args1);
67+
SortedMap<String, String> data1 = localZkS.dumpData();
68+
String clusterDataJson = data1.get("/admin/clusters/testReSetupClusterMetadata-cluster");
69+
assertNotNull(clusterDataJson);
70+
ClusterData clusterData = ObjectMapperFactory
71+
.getMapper()
72+
.reader()
73+
.readValue(clusterDataJson, ClusterData.class);
74+
assertEquals(clusterData.getServiceUrl(), "http://127.0.0.1:8080");
75+
assertEquals(clusterData.getServiceUrlTls(), "https://127.0.0.1:8443");
76+
assertEquals(clusterData.getBrokerServiceUrl(), "pulsar://127.0.0.1:6650");
77+
assertEquals(clusterData.getBrokerServiceUrlTls(), "pulsar+ssl://127.0.0.1:6651");
78+
assertFalse(clusterData.isBrokerClientTlsEnabled());
79+
80+
String[] args2 = {
81+
"--cluster", "testReSetupClusterMetadata-cluster",
82+
"--zookeeper", "127.0.0.1:" + localZkS.getZookeeperPort(),
83+
"--configuration-store", "127.0.0.1:" + localZkS.getZookeeperPort(),
84+
"--configuration-metadata-store-config-path", "src/test/resources/conf/zk_client_enable_sasl.conf",
85+
};
86+
PulsarClusterMetadataTeardown.main(args2);
87+
SortedMap<String, String> data2 = localZkS.dumpData();
88+
assertFalse(data2.containsKey("/admin/clusters/testReSetupClusterMetadata-cluster"));
89+
}
90+
}

0 commit comments

Comments
 (0)