浏览代码

HADOOP-14927. ITestS3GuardTool failures in testDestroyNoBucket(). Contributed by Gabor Bota.

Sean Mackrory 6 年之前
父节点
当前提交
7eb0d3a324
共有 1 个文件被更改,包括 24 次插入14 次删除
  1. 24 14
      hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/s3guard/S3GuardTool.java

+ 24 - 14
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/s3guard/S3GuardTool.java

@@ -218,6 +218,27 @@ public abstract class S3GuardTool extends Configured implements Tool {
     format.addOptionWithValue(SECONDS_FLAG);
     format.addOptionWithValue(SECONDS_FLAG);
   }
   }
 
 
+  protected void checkMetadataStoreUri(List<String> paths) throws IOException {
+    // be sure that path is provided in params, so there's no IOoBE
+    String s3Path = "";
+    if(!paths.isEmpty()) {
+      s3Path = paths.get(0);
+    }
+
+    // Check if DynamoDB url is set from arguments.
+    String metadataStoreUri = getCommandFormat().getOptValue(META_FLAG);
+    if(metadataStoreUri == null || metadataStoreUri.isEmpty()) {
+      // If not set, check if filesystem is guarded by creating an
+      // S3AFileSystem and check if hasMetadataStore is true
+      try (S3AFileSystem s3AFileSystem = (S3AFileSystem)
+          S3AFileSystem.newInstance(toUri(s3Path), getConf())){
+        Preconditions.checkState(s3AFileSystem.hasMetadataStore(),
+            "The S3 bucket is unguarded. " + getName()
+                + " can not be used on an unguarded bucket.");
+      }
+    }
+  }
+
   /**
   /**
    * Parse metadata store from command line option or HDFS configuration.
    * Parse metadata store from command line option or HDFS configuration.
    *
    *
@@ -500,20 +521,7 @@ public abstract class S3GuardTool extends Configured implements Tool {
     public int run(String[] args, PrintStream out) throws Exception {
     public int run(String[] args, PrintStream out) throws Exception {
       List<String> paths = parseArgs(args);
       List<String> paths = parseArgs(args);
       Map<String, String> options = new HashMap<>();
       Map<String, String> options = new HashMap<>();
-      String s3Path = paths.get(0);
-
-      // Check if DynamoDB url is set from arguments.
-      String metadataStoreUri = getCommandFormat().getOptValue(META_FLAG);
-      if(metadataStoreUri == null || metadataStoreUri.isEmpty()) {
-        // If not set, check if filesystem is guarded by creating an
-        // S3AFileSystem and check if hasMetadataStore is true
-        try (S3AFileSystem s3AFileSystem = (S3AFileSystem)
-            S3AFileSystem.newInstance(toUri(s3Path), getConf())){
-          Preconditions.checkState(s3AFileSystem.hasMetadataStore(),
-              "The S3 bucket is unguarded. " + getName()
-                  + " can not be used on an unguarded bucket.");
-        }
-      }
+      checkMetadataStoreUri(paths);
 
 
       String readCap = getCommandFormat().getOptValue(READ_FLAG);
       String readCap = getCommandFormat().getOptValue(READ_FLAG);
       if (StringUtils.isNotEmpty(readCap)) {
       if (StringUtils.isNotEmpty(readCap)) {
@@ -590,6 +598,8 @@ public abstract class S3GuardTool extends Configured implements Tool {
         throw e;
         throw e;
       }
       }
 
 
+      checkMetadataStoreUri(paths);
+
       try {
       try {
         initMetadataStore(false);
         initMetadataStore(false);
       } catch (FileNotFoundException e) {
       } catch (FileNotFoundException e) {