You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by bi...@apache.org on 2017/09/18 05:44:00 UTC

[07/29] kylin git commit: KYLIN-2868 fix issue that filters not work in ResourceTool

KYLIN-2868 fix issue that filters not work in ResourceTool


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

Branch: refs/heads/security_update
Commit: 2dbbd51f69579a7105d5541a08d103ef0976e0ef
Parents: 08d64cc
Author: lidongsjtu <li...@apache.org>
Authored: Wed Sep 13 23:02:36 2017 +0800
Committer: Hongbin Ma <ma...@kyligence.io>
Committed: Thu Sep 14 10:58:16 2017 +0800

----------------------------------------------------------------------
 .../kylin/common/persistence/ResourceTool.java  | 54 ++++++++++++--------
 1 file changed, 32 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/2dbbd51f/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 2571c91..6c6189d 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
@@ -24,6 +24,7 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.util.List;
 import java.util.NavigableSet;
+import java.util.Set;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.kylin.common.KylinConfig;
@@ -31,13 +32,15 @@ import org.apache.kylin.common.util.StringUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.Sets;
+
 public class ResourceTool {
 
     private static String[] includes = null;
     private static String[] excludes = null;
     private static final Logger logger = LoggerFactory.getLogger(ResourceTool.class);
 
-    private static final String[] IMMUTABLE_PREFIX = { "/UUID" };
+    private static final Set<String> IMMUTABLE_PREFIX = Sets.newHashSet("/UUID");
 
     public static void main(String[] args) throws IOException {
         args = StringUtil.filterSystemArgs(args);
@@ -61,7 +64,7 @@ public class ResourceTool {
             addExcludes(exclude.split("\\s*,\\s*"));
         }
 
-        addExcludes(IMMUTABLE_PREFIX);
+        addExcludes(IMMUTABLE_PREFIX.toArray(new String[IMMUTABLE_PREFIX.size()]));
 
         String cmd = args[0];
         switch (cmd) {
@@ -150,13 +153,14 @@ public class ResourceTool {
         System.out.println("" + result);
         return result;
     }
-    
-    public static void copy(KylinConfig srcConfig, KylinConfig dstConfig, String path) throws IOException {        
-        copy(srcConfig, dstConfig, path, false);        
+
+    public static void copy(KylinConfig srcConfig, KylinConfig dstConfig, String path) throws IOException {
+        copy(srcConfig, dstConfig, path, false);
     }
 
-    //Do NOT invoke this method directly, unless you want to copy and possibly overwrite immutable resources such as UUID. 
-    public static void copy(KylinConfig srcConfig, KylinConfig dstConfig, String path, boolean copyImmutableResource) throws IOException {
+    //Do NOT invoke this method directly, unless you want to copy and possibly overwrite immutable resources such as UUID.
+    public static void copy(KylinConfig srcConfig, KylinConfig dstConfig, String path, boolean copyImmutableResource)
+            throws IOException {
         ResourceStore src = ResourceStore.getStore(srcConfig);
         ResourceStore dst = ResourceStore.getStore(dstConfig);
 
@@ -165,12 +169,13 @@ public class ResourceTool {
         copyR(src, dst, path, copyImmutableResource);
     }
 
-    public static void copy(KylinConfig srcConfig, KylinConfig dstConfig, List<String> paths) throws IOException {        
-        copy(srcConfig, dstConfig, paths, false);        
+    public static void copy(KylinConfig srcConfig, KylinConfig dstConfig, List<String> paths) throws IOException {
+        copy(srcConfig, dstConfig, paths, false);
     }
-    
-    //Do NOT invoke this method directly, unless you want to copy and possibly overwrite immutable resources such as UUID. 
-    public static void copy(KylinConfig srcConfig, KylinConfig dstConfig, List<String> paths, boolean copyImmutableResource) throws IOException {
+
+    //Do NOT invoke this method directly, unless you want to copy and possibly overwrite immutable resources such as UUID.
+    public static void copy(KylinConfig srcConfig, KylinConfig dstConfig, List<String> paths,
+            boolean copyImmutableResource) throws IOException {
         ResourceStore src = ResourceStore.getStore(srcConfig);
         ResourceStore dst = ResourceStore.getStore(dstConfig);
 
@@ -181,23 +186,28 @@ public class ResourceTool {
         }
     }
 
-    
     public static void copy(KylinConfig srcConfig, KylinConfig dstConfig) throws IOException {
         copy(srcConfig, dstConfig, false);
     }
-    
-    //Do NOT invoke this method directly, unless you want to copy and possibly overwrite immutable resources such as UUID. 
-    public static void copy(KylinConfig srcConfig, KylinConfig dstConfig, boolean copyImmutableResource) throws IOException {
+
+    //Do NOT invoke this method directly, unless you want to copy and possibly overwrite immutable resources such as UUID.
+    public static void copy(KylinConfig srcConfig, KylinConfig dstConfig, boolean copyImmutableResource)
+            throws IOException {
         copy(srcConfig, dstConfig, "/", copyImmutableResource);
-    }    
-    
-    public static void copyR(ResourceStore src, ResourceStore dst, String path, boolean copyImmutableResource) throws IOException {
-        
+    }
+
+    public static void copyR(ResourceStore src, ResourceStore dst, String path, boolean copyImmutableResource)
+            throws IOException {
+
+        if (!copyImmutableResource && IMMUTABLE_PREFIX.contains(path)) {
+            return;
+        }
+
         NavigableSet<String> children = src.listResources(path);
 
         if (children == null) {
             // case of resource (not a folder)
-            if (copyImmutableResource || matchFilter(path)) {
+            if (matchFilter(path)) {
                 try {
                     RawResource res = src.getResource(path);
                     if (res != null) {
@@ -216,7 +226,7 @@ public class ResourceTool {
             for (String child : children)
                 copyR(src, dst, child, copyImmutableResource);
         }
-        
+
     }
 
     private static boolean matchFilter(String path) {