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/fdecf093 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/fdecf093 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/fdecf093 Branch: refs/heads/master-hbase1.x Commit: fdecf0937802a2d17418595e6c0543c9668ac8a4 Parents: 08eda7b Author: lidongsjtu <lid...@apache.org> Authored: Wed Dec 28 22:17:35 2016 +0800 Committer: lidongsjtu <lid...@apache.org> Committed: Wed Dec 28 22:45:57 2016 +0800 ---------------------------------------------------------------------- .../test_case_data/localmeta/kylin.properties | 3 + .../org/apache/kylin/tool/KylinConfigCLI.java | 30 ++++++-- .../apache/kylin/tool/KylinConfigCLITest.java | 73 ++++++++++++++++++++ 3 files changed, 102 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/fdecf093/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/fdecf093/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/fdecf093/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..7d1e248 --- /dev/null +++ b/tool/src/test/java/org/apache/kylin/tool/KylinConfigCLITest.java @@ -0,0 +1,73 @@ +/* + * 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.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(); + } +}