Repository: incubator-ranger
Updated Branches:
  refs/heads/master 2836dea0b -> 9fd63d006


RANGER-149: If the HDFS file system is empty then repository configurator gives 
confusing message


Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/9fd63d00
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/9fd63d00
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/9fd63d00

Branch: refs/heads/master
Commit: 9fd63d0061997bb2d20f860f5df70c195363a0f0
Parents: 2836dea
Author: rmani <[email protected]>
Authored: Wed Mar 23 13:20:08 2016 -0700
Committer: rmani <[email protected]>
Committed: Wed Mar 23 13:20:08 2016 -0700

----------------------------------------------------------------------
 .../ranger/services/hdfs/client/HdfsClient.java | 42 +++++++++++---------
 1 file changed, 24 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/9fd63d00/hdfs-agent/src/main/java/org/apache/ranger/services/hdfs/client/HdfsClient.java
----------------------------------------------------------------------
diff --git 
a/hdfs-agent/src/main/java/org/apache/ranger/services/hdfs/client/HdfsClient.java
 
b/hdfs-agent/src/main/java/org/apache/ranger/services/hdfs/client/HdfsClient.java
index 0a86c50..bc4f05a 100644
--- 
a/hdfs-agent/src/main/java/org/apache/ranger/services/hdfs/client/HdfsClient.java
+++ 
b/hdfs-agent/src/main/java/org/apache/ranger/services/hdfs/client/HdfsClient.java
@@ -28,6 +28,7 @@ import java.util.*;
 import javax.security.auth.Subject;
 
 import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
@@ -75,31 +76,36 @@ public class HdfsClient extends BaseClient {
                        
 
                        UserGroupInformation.setConfiguration(conf);
-                       
+
                        FileSystem fs = null ;
                        try {
                                fs = FileSystem.get(conf) ;
-                               
-                               FileStatus[] fileStats = fs.listStatus(new 
Path(baseDir)) ;
-                               
+
+                               Path basePath = new Path(baseDir);
+                               FileStatus[] fileStats = 
fs.listStatus(basePath) ;
+
                                if(LOG.isDebugEnabled()) {
                                        LOG.debug("<== HdfsClient fileStatus : 
" + fileStats + " PathList :" + pathList) ;
                                }
-                               
+
                                if (fileStats != null) {
-                                       for(FileStatus stat : fileStats) {
-                                               Path path = stat.getPath() ;
-                                               String pathComponent = 
path.getName() ;
-                                               String prefixedPath = dirPrefix 
+ pathComponent;
-                                       if ( pathList != null && 
pathList.contains(prefixedPath)) {
-                                               continue;
-                                       }
-                                               if (filterRegEx == null) {
-                                                       
fileList.add(prefixedPath) ;
-                                               }
-                                               else if 
(FilenameUtils.wildcardMatch(pathComponent, fileMatching)) {
-                                                       
fileList.add(prefixedPath) ;
-                                               }
+                                       if (fs.exists(basePath) && 
ArrayUtils.isEmpty(fileStats))  {
+                                               
fileList.add(basePath.toString()) ;
+                                       } else {
+                                               for(FileStatus stat : 
fileStats) {
+                                                               Path path = 
stat.getPath() ;
+                                                               String 
pathComponent = path.getName() ;
+                                                               String 
prefixedPath = dirPrefix + pathComponent;
+                                                       if ( pathList != null 
&& pathList.contains(prefixedPath)) {
+                                   continue;
+                                                       }
+                                                               if (filterRegEx 
== null) {
+                                                                       
fileList.add(prefixedPath) ;
+                                                               }
+                                                               else if 
(FilenameUtils.wildcardMatch(pathComponent, fileMatching)) {
+                                                                       
fileList.add(prefixedPath) ;
+                                                               }
+                                                       }
                                        }
                                }
                        } catch (UnknownHostException uhe) {

Reply via email to