minor, refine kylin config
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/82b22364 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/82b22364 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/82b22364 Branch: refs/heads/master-hbase0.98 Commit: 82b223641047a215a0b212f4c3d77e21d1a5203c Parents: 0301da0 Author: Hongbin Ma <mahong...@apache.org> Authored: Sat Mar 11 17:49:23 2017 +0800 Committer: Hongbin Ma <mahong...@apache.org> Committed: Sat Mar 11 17:49:23 2017 +0800 ---------------------------------------------------------------------- .../org/apache/kylin/common/KylinConfig.java | 20 +++++++++--- .../apache/kylin/rest/service/AdminService.java | 32 +------------------- 2 files changed, 17 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/82b22364/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java ---------------------------------------------------------------------- diff --git a/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java b/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java index 4fcc61f..c6b1511 100644 --- a/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java +++ b/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java @@ -228,7 +228,7 @@ public class KylinConfig extends KylinConfigBase { Properties conf = new Properties(); try { OrderedProperties orderedProperties = getKylinOrderedProperties(); - for (Map.Entry<String, String> each: orderedProperties.entrySet()) { + for (Map.Entry<String, String> each : orderedProperties.entrySet()) { conf.put(each.getKey(), each.getValue()); } } catch (FileNotFoundException e) { @@ -238,7 +238,7 @@ public class KylinConfig extends KylinConfigBase { return conf; } - public static OrderedProperties getKylinOrderedProperties() throws FileNotFoundException { + private static OrderedProperties getKylinOrderedProperties() throws FileNotFoundException { File propFile = getKylinPropertiesFile(); if (propFile == null || !propFile.exists()) { logger.error("fail to locate " + KYLIN_CONF_PROPERTIES_FILE); @@ -270,9 +270,21 @@ public class KylinConfig extends KylinConfigBase { } } - public static String getConfigAsString() throws IOException { - OrderedProperties orderedProperties = getKylinOrderedProperties(); + public String getConfigAsString() throws IOException { + Properties allProps = getAllProperties(); + OrderedProperties orderedProperties = KylinConfig.getKylinOrderedProperties(); + final StringBuilder sb = new StringBuilder(); + + for (Map.Entry<Object, Object> entry : allProps.entrySet()) { + String key = entry.getKey().toString(); + String value = entry.getValue().toString(); + if (!orderedProperties.containsProperty(key)) { + orderedProperties.setProperty(key, value); + } else if (!orderedProperties.getProperty(key).equalsIgnoreCase(value)) { + orderedProperties.setProperty(key, value); + } + } for (Map.Entry<String, String> entry : orderedProperties.entrySet()) { sb.append(entry.getKey() + "=" + entry.getValue()).append('\n'); } http://git-wip-us.apache.org/repos/asf/kylin/blob/82b22364/server-base/src/main/java/org/apache/kylin/rest/service/AdminService.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/service/AdminService.java b/server-base/src/main/java/org/apache/kylin/rest/service/AdminService.java index 4cacb6b..66725dc 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/service/AdminService.java +++ b/server-base/src/main/java/org/apache/kylin/rest/service/AdminService.java @@ -20,7 +20,6 @@ package org.apache.kylin.rest.service; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.lang.reflect.Method; import java.util.Map; import java.util.Properties; import java.util.TreeMap; @@ -28,7 +27,6 @@ import java.util.TreeMap; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.kylin.common.KylinConfig; -import org.apache.kylin.common.KylinConfigBase; import org.apache.kylin.common.util.OrderedProperties; import org.apache.kylin.rest.constant.Constant; import org.apache.kylin.rest.exception.InternalErrorException; @@ -96,7 +94,7 @@ public class AdminService extends BasicService { logger.debug("Get Kylin Runtime Config"); try { - return getAllConfigAsString(); + return KylinConfig.getInstanceFromEnv().getConfigAsString(); } catch (IOException e) { throw new InternalErrorException("Failed to get Kylin Runtime Config", e); } @@ -113,32 +111,4 @@ public class AdminService extends BasicService { } } - private String getAllConfigAsString() throws IOException { - Properties allProps; - try { - KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv(); - Method getAllMethod = KylinConfigBase.class.getDeclaredMethod("getAllProperties"); - getAllMethod.setAccessible(true); - allProps = (Properties) getAllMethod.invoke(kylinConfig); - } catch (Exception e) { - throw new RuntimeException(e); - } - - OrderedProperties orderedProperties = KylinConfig.getKylinOrderedProperties(); - - final StringBuilder sb = new StringBuilder(); - - for (Map.Entry<Object, Object> entry : allProps.entrySet()) { - String key = entry.getKey().toString(); - String value = entry.getValue().toString(); - if (!orderedProperties.containsProperty(key)) { - orderedProperties.setProperty(key, value); - } else if (!orderedProperties.getProperty(key).equalsIgnoreCase(value)) - orderedProperties.setProperty(key, value); - } - for (Map.Entry<String, String> entry : orderedProperties.entrySet()) { - sb.append(entry.getKey() + "=" + entry.getValue()).append('\n'); - } - return sb.toString(); - } }