sijie closed pull request #1160: Dump config
URL: https://github.com/apache/bookkeeper/pull/1160
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/AbstractConfiguration.java
 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/AbstractConfiguration.java
index e772c7917..7d537a8fe 100644
--- 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/AbstractConfiguration.java
+++ 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/AbstractConfiguration.java
@@ -20,13 +20,18 @@
 import static 
org.apache.bookkeeper.conf.ClientConfiguration.CLIENT_AUTH_PROVIDER_FACTORY_CLASS;
 
 import java.net.URL;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+
 import javax.net.ssl.SSLEngine;
 
 import org.apache.bookkeeper.feature.Feature;
 import org.apache.bookkeeper.meta.LedgerManagerFactory;
 import org.apache.bookkeeper.util.EntryFormatter;
+import org.apache.bookkeeper.util.JsonUtil;
+import org.apache.bookkeeper.util.JsonUtil.ParseJsonException;
 import org.apache.bookkeeper.util.LedgerIdFormatter;
 import org.apache.bookkeeper.util.ReflectionUtils;
 import org.apache.bookkeeper.util.StringEntryFormatter;
@@ -618,4 +623,27 @@ public String getTLSEnabledProtocols() {
      * Trickery to allow inheritance with fluent style.
      */
     protected abstract T getThis();
+
+    /**
+     * returns the string representation of json format of this config.
+     *
+     * @return
+     * @throws ParseJsonException
+     */
+    public String asJson() throws ParseJsonException {
+        return JsonUtil.toJson(toMap());
+    }
+
+    private Map<String, Object> toMap() {
+        Map<String, Object> configMap = new HashMap<>();
+        Iterator<String> iterator = this.getKeys();
+        while (iterator.hasNext()) {
+            String key = iterator.next().toString();
+            Object property = this.getProperty(key);
+            if (property != null) {
+                configMap.put(key, property.toString());
+            }
+        }
+        return configMap;
+    }
 }
diff --git 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieServer.java 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieServer.java
index 602134a98..4765c4496 100644
--- 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieServer.java
+++ 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieServer.java
@@ -46,6 +46,7 @@
 import org.apache.bookkeeper.tls.SecurityException;
 import org.apache.bookkeeper.tls.SecurityHandlerFactory;
 import org.apache.bookkeeper.tls.SecurityProviderFactoryFactory;
+import org.apache.bookkeeper.util.JsonUtil.ParseJsonException;
 import org.apache.zookeeper.KeeperException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -81,6 +82,14 @@ public BookieServer(ServerConfiguration conf, StatsLogger 
statsLogger)
             BookieException, UnavailableException, CompatibilityException, 
SecurityException {
         this.conf = conf;
         validateUser(conf);
+        String configAsString;
+        try {
+            configAsString = conf.asJson();
+            LOG.info(configAsString);
+        } catch (ParseJsonException pe) {
+            LOG.error("Got ParseJsonException while converting Config to 
JSONString", pe);
+        }
+
         this.statsLogger = statsLogger;
         this.nettyServer = new BookieNettyServer(this.conf, null);
         try {
diff --git 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/server/http/service/ConfigurationService.java
 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/server/http/service/ConfigurationService.java
index 983da4aca..2ac9e8e6a 100644
--- 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/server/http/service/ConfigurationService.java
+++ 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/server/http/service/ConfigurationService.java
@@ -21,7 +21,6 @@
 import static com.google.common.base.Preconditions.checkNotNull;
 
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.bookkeeper.conf.ServerConfiguration;
@@ -48,8 +47,7 @@ public HttpServiceResponse handle(HttpServiceRequest request) 
throws Exception {
         HttpServiceResponse response = new HttpServiceResponse();
         // GET
         if (HttpServer.Method.GET == request.getMethod()) {
-            Map<String, Object> configMap = toMap(conf);
-            String jsonResponse = JsonUtil.toJson(configMap);
+            String jsonResponse = conf.asJson();
             response.setBody(jsonResponse);
             return response;
         } else if (HttpServer.Method.PUT == request.getMethod()) {
@@ -75,17 +73,4 @@ public HttpServiceResponse handle(HttpServiceRequest 
request) throws Exception {
         }
 
     }
-
-    private Map<String, Object> toMap(ServerConfiguration conf) {
-        Map<String, Object> configMap = new HashMap<>();
-        Iterator iterator = conf.getKeys();
-        while (iterator.hasNext()) {
-            String key = iterator.next().toString();
-            Object property = conf.getProperty(key);
-            if (property != null) {
-                configMap.put(key, property.toString());
-            }
-        }
-        return configMap;
-    }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to