Repository: kylin
Updated Branches:
  refs/heads/2.x-staging e0cfca5f2 -> 81ca14e99


minor, add cat in ResourceTool

Signed-off-by: Li, Yang <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/f6212906
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/f6212906
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/f6212906

Branch: refs/heads/2.x-staging
Commit: f6212906177ebaff1c365b222af116038cd5ca00
Parents: e0cfca5
Author: Chen Luwei <[email protected]>
Authored: Wed Jan 13 14:10:05 2016 +0800
Committer: Li, Yang <[email protected]>
Committed: Sun Feb 14 15:28:38 2016 +0800

----------------------------------------------------------------------
 .../kylin/common/persistence/ResourceTool.java  | 29 +++++++++
 .../storage/hbase/steps/ResourceStoreTest.java  | 63 ++++++++++++++++++++
 2 files changed, 92 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/f6212906/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceTool.java
----------------------------------------------------------------------
diff --git 
a/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceTool.java
 
b/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceTool.java
index 8faeadf..d1661ac 100644
--- 
a/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceTool.java
+++ 
b/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceTool.java
@@ -19,6 +19,9 @@
 package org.apache.kylin.common.persistence;
 
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Callable;
@@ -68,11 +71,37 @@ public class ResourceTool {
         case "remove":
             remove(KylinConfig.getInstanceFromEnv(), args[1]);
             break;
+        case "cat":
+            cat(KylinConfig.getInstanceFromEnv(), args[1]);
+            break;
         default:
             System.out.println("Unknown cmd: " + cmd);
         }
     }
 
+    public static void cat(KylinConfig config, String path) throws IOException 
{
+        ResourceStore store = ResourceStore.getStore(config);
+        InputStream is = store.getResource(path).inputStream;
+        BufferedReader br = null;
+        String line;
+        try {
+            br = new BufferedReader(new InputStreamReader(is));
+            while ((line = br.readLine()) != null) {
+                System.out.println(line);
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            if (br != null) {
+                try {
+                    br.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
     public static void list(KylinConfig config, String path) throws 
IOException {
         ResourceStore store = ResourceStore.getStore(config);
         ArrayList<String> result = store.listResources(path);

http://git-wip-us.apache.org/repos/asf/kylin/blob/f6212906/storage-hbase/src/test/java/org/apache/kylin/storage/hbase/steps/ResourceStoreTest.java
----------------------------------------------------------------------
diff --git 
a/storage-hbase/src/test/java/org/apache/kylin/storage/hbase/steps/ResourceStoreTest.java
 
b/storage-hbase/src/test/java/org/apache/kylin/storage/hbase/steps/ResourceStoreTest.java
new file mode 100644
index 0000000..020394b
--- /dev/null
+++ 
b/storage-hbase/src/test/java/org/apache/kylin/storage/hbase/steps/ResourceStoreTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.storage.hbase.steps;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.kylin.common.KylinConfig;
+import org.apache.kylin.common.persistence.ResourceTool;
+import org.apache.kylin.common.util.ClassUtil;
+
+import java.io.File;
+
+/**
+ * This is a helper class for developer to directly manipulate the metadata 
store in sandbox
+ * This is designed to run in IDE(i.e. not on sandbox hadoop CLI)
+ *
+ * For production metadata store manipulation refer to bin/metastore.sh in 
binary package
+ * It is desinged to run in hadoop CLI, both in sandbox or in real hadoop 
environment
+ */
+public class ResourceStoreTest {
+    
+    private static final Log logger = 
LogFactory.getLog(ResourceStoreTest.class);
+
+    public static void main(String[] args) throws Exception {
+        logger.info("Adding to classpath: " + new 
File(HBaseMetadataTestCase.SANDBOX_TEST_DATA).getAbsolutePath());
+        ClassUtil.addClasspath(new 
File(HBaseMetadataTestCase.SANDBOX_TEST_DATA).getAbsolutePath());
+        System.setProperty(KylinConfig.KYLIN_CONF, 
"../examples/test_case_data/sandbox");
+        if (System.getProperty("hdp.version") == null) {
+            throw new RuntimeException("No hdp.version set; Please set 
hdp.version in your jvm option, for example: -Dhdp.version=2.2.4.2-2");
+        }
+
+        if (args.length < 2) {
+            printUsage();
+            return;
+        }
+
+        if ("cat".equalsIgnoreCase(args[0])) {
+            ResourceTool.main(new String[] { "cat", args[1] });
+        } else {
+            printUsage();
+        }
+    }
+
+    private static void printUsage() {
+        logger.info("Usage: ResourceStoreTest cat file");
+    }
+}

Reply via email to