Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()) {
Expand All @@ -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;
}
}