This is an automated email from the ASF dual-hosted git repository.
zixuan pushed a commit to branch branch-2.10
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.10 by this push:
new 7b9a78e7726 [fix][cli][branch-2.10] Fix mbeans to json (#19294)
7b9a78e7726 is described below
commit 7b9a78e7726c0986b44225eeefcc54350753fc06
Author: Zixuan Liu <[email protected]>
AuthorDate: Sun Jan 29 18:03:52 2023 +0800
[fix][cli][branch-2.10] Fix mbeans to json (#19294)
Signed-off-by: Zixuan Liu <[email protected]>
---
bin/pulsar | 11 +++++
pom.xml | 2 +
.../apache/pulsar/broker/admin/BrokerStatTest.java | 50 ++++++++++++++++++++++
3 files changed, 63 insertions(+)
diff --git a/bin/pulsar b/bin/pulsar
index f1067c07a3f..8f8d77ed1f7 100755
--- a/bin/pulsar
+++ b/bin/pulsar
@@ -313,6 +313,17 @@ OPTS="$OPTS
-Dpulsar.functions.extra.dependencies.dir=${FUNCTIONS_EXTRA_DEPS_DIR
OPTS="$OPTS -Dpulsar.functions.instance.classpath=${PULSAR_CLASSPATH}"
OPTS="$OPTS -Dpulsar.functions.log.conf=${FUNCTIONS_LOG_CONF}"
+
+IS_JAVA_8=`$JAVA -version 2>&1 |grep version|grep '"1\.8'`
+# Start --add-opens options
+# '--add-opens' option is not supported in jdk8
+if [[ -z "$IS_JAVA_8" ]]; then
+ # JvmDefaultGCMetricsLogger & MBeanStatsGenerator
+ OPTS="$OPTS --add-opens java.management/sun.management=ALL-UNNAMED"
+ # MBeanStatsGenerator
+ OPTS="$OPTS --add-opens
jdk.management/com.sun.management.internal=ALL-UNNAMED"
+fi
+
ZK_OPTS=" -Dzookeeper.4lw.commands.whitelist=*
-Dzookeeper.snapshot.trust.empty=true -Dzookeeper.tcpKeepAlive=true"
LOG4J2_SHUTDOWN_HOOK_DISABLED="-Dlog4j.shutdownHookEnabled=false"
diff --git a/pom.xml b/pom.xml
index a82f140f768..ecbeccde621 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1915,6 +1915,8 @@ flexible messaging model and an intuitive client
API.</description>
--add-opens java.base/jdk.internal.loader=ALL-UNNAMED
--add-opens java.base/java.lang=ALL-UNNAMED <!--Mockito-->
--add-opens java.base/java.io=ALL-UNNAMED <!--Bookkeeper NativeIO -->
+ --add-opens java.management/sun.management=ALL-UNNAMED
<!--JvmDefaultGCMetricsLogger & MBeanStatsGenerator-->
+ --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED
<!--MBeanStatsGenerator-->
</test.additional.args>
</properties>
<build>
diff --git
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/BrokerStatTest.java
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/BrokerStatTest.java
new file mode 100644
index 00000000000..58c934c544d
--- /dev/null
+++
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/BrokerStatTest.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.admin;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest;
+import org.apache.pulsar.client.admin.PulsarAdminException;
+import org.apache.pulsar.common.util.ObjectMapperFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+@Slf4j
+@Test(groups = "broker-admin")
+public class BrokerStatTest extends MockedPulsarServiceBaseTest {
+ @BeforeMethod
+ @Override
+ public void setup() throws Exception {
+ super.internalSetup();
+ }
+
+ @AfterMethod(alwaysRun = true)
+ @Override
+ public void cleanup() throws Exception {
+ super.internalCleanup();
+ }
+
+ @Test
+ public void testGetMBeans() throws PulsarAdminException,
JsonProcessingException {
+ String data = admin.brokerStats().getMBeans();
+ ObjectMapperFactory.create().readTree(data);
+ }
+}