You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2016/12/29 01:45:29 UTC
[3/7] kylin git commit: minor, get config by prefix in KylinConfigCLI
minor, get config by prefix in KylinConfigCLI
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/6762fae0
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/6762fae0
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/6762fae0
Branch: refs/heads/yang22-hbase1.x
Commit: 6762fae07f157d762bcafab6996b23dc35c91171
Parents: fd1ed2e
Author: lidongsjtu <li...@apache.org>
Authored: Wed Dec 28 22:17:35 2016 +0800
Committer: lidongsjtu <li...@apache.org>
Committed: Wed Dec 28 22:22:26 2016 +0800
----------------------------------------------------------------------
.../test_case_data/localmeta/kylin.properties | 3 +
.../org/apache/kylin/tool/KylinConfigCLI.java | 30 +++++++-
.../apache/kylin/tool/KylinConfigCLITest.java | 79 ++++++++++++++++++++
3 files changed, 108 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/6762fae0/examples/test_case_data/localmeta/kylin.properties
----------------------------------------------------------------------
diff --git a/examples/test_case_data/localmeta/kylin.properties b/examples/test_case_data/localmeta/kylin.properties
index 1dfac32..f4c6772 100644
--- a/examples/test_case_data/localmeta/kylin.properties
+++ b/examples/test_case_data/localmeta/kylin.properties
@@ -131,3 +131,6 @@ kylin.test.bcc.new.key=some-value
kylin.engine.mr.config-override.test1=test1
kylin.engine.mr.config-override.test2=test2
kylin.job.lock=org.apache.kylin.job.lock.MockJobLock
+
+kylin.engine.provider.0=org.apache.kylin.engine.mr.MRBatchCubingEngine
+kylin.cube.engine.2=org.apache.kylin.engine.mr.MRBatchCubingEngine2
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/kylin/blob/6762fae0/tool/src/main/java/org/apache/kylin/tool/KylinConfigCLI.java
----------------------------------------------------------------------
diff --git a/tool/src/main/java/org/apache/kylin/tool/KylinConfigCLI.java b/tool/src/main/java/org/apache/kylin/tool/KylinConfigCLI.java
index e1a5b99..b740beb 100644
--- a/tool/src/main/java/org/apache/kylin/tool/KylinConfigCLI.java
+++ b/tool/src/main/java/org/apache/kylin/tool/KylinConfigCLI.java
@@ -18,11 +18,14 @@
package org.apache.kylin.tool;
+import java.util.Map;
import java.util.Properties;
import org.apache.kylin.common.BackwardCompatibilityConfig;
import org.apache.kylin.common.KylinConfig;
+import com.google.common.collect.Maps;
+
public class KylinConfigCLI {
public static void main(String[] args) {
if (args.length != 1) {
@@ -33,10 +36,29 @@ public class KylinConfigCLI {
Properties config = KylinConfig.getKylinProperties();
BackwardCompatibilityConfig bcc = new BackwardCompatibilityConfig();
- String value = config.getProperty(bcc.check(args[0]));
- if (value == null) {
- value = "";
+ String key = bcc.check(args[0].trim());
+ if (!key.endsWith(".")) {
+ String value = config.getProperty(key);
+ if (value == null) {
+ value = "";
+ }
+ System.out.println(value);
+ } else {
+ Map<String, String> props = getPropertiesByPrefix(config, key);
+ for (Map.Entry<String, String> prop : props.entrySet()) {
+ System.out.println(prop.getKey() + "=" + prop.getValue());
+ }
+ }
+ }
+
+ static private Map<String, String> getPropertiesByPrefix(Properties props, String prefix) {
+ Map<String, String> result = Maps.newLinkedHashMap();
+ for (Map.Entry<Object, Object> entry : props.entrySet()) {
+ String entryKey = (String) entry.getKey();
+ if (entryKey.startsWith(prefix)) {
+ result.put(entryKey.substring(prefix.length()), (String) entry.getValue());
+ }
}
- System.out.println(value);
+ return result;
}
}
http://git-wip-us.apache.org/repos/asf/kylin/blob/6762fae0/tool/src/test/java/org/apache/kylin/tool/KylinConfigCLITest.java
----------------------------------------------------------------------
diff --git a/tool/src/test/java/org/apache/kylin/tool/KylinConfigCLITest.java b/tool/src/test/java/org/apache/kylin/tool/KylinConfigCLITest.java
new file mode 100644
index 0000000..5c56b5f
--- /dev/null
+++ b/tool/src/test/java/org/apache/kylin/tool/KylinConfigCLITest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2016 Kyligence Inc. All rights reserved.
+ *
+ * http://kyligence.io
+ *
+ * This software is the confidential and proprietary information of
+ * Kyligence Inc. ("Confidential Information"). You shall not disclose
+ * such Confidential Information and shall use it only in accordance
+ * with the terms of the license agreement you entered into with
+ * Kyligence Inc.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.apache.kylin.tool;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.nio.charset.Charset;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.kylin.common.util.LocalFileMetadataTestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class KylinConfigCLITest extends LocalFileMetadataTestCase {
+ @Test
+ public void testGetProperty() throws IOException {
+ PrintStream o = System.out;
+ File f = File.createTempFile("cfg", ".tmp");
+ System.setOut(new PrintStream(new FileOutputStream(f)));
+ KylinConfigCLI.main(new String[] { "kylin.storage.url" });
+
+ String val = FileUtils.readFileToString(f, Charset.defaultCharset()).trim();
+ assertEquals("hbase", val);
+
+ FileUtils.forceDelete(f);
+ System.setOut(o);
+ }
+
+ @Test
+ public void testGetPrefix() throws IOException {
+ PrintStream o = System.out;
+ File f = File.createTempFile("cfg", ".tmp");
+ System.setOut(new PrintStream(new FileOutputStream(f)));
+ KylinConfigCLI.main(new String[] { "kylin.cube.engine." });
+
+ String val = FileUtils.readFileToString(f, Charset.defaultCharset()).trim();
+ assertEquals("2=org.apache.kylin.engine.mr.MRBatchCubingEngine2\n0=org.apache.kylin.engine.mr.MRBatchCubingEngine", val);
+
+ FileUtils.forceDelete(f);
+ System.setOut(o);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ this.createTestMetadata();
+ }
+
+ @After
+ public void after() throws Exception {
+ this.cleanupTestMetadata();
+ }
+}