You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ji...@apache.org on 2015/05/14 22:12:17 UTC

[16/37] hadoop git commit: HADOOP-9723. Improve error message when hadoop archive output path already exists. Contributed by Jean-Baptiste Onofré and Yongjun Zhang.

HADOOP-9723. Improve error message when hadoop archive output path already exists. Contributed by Jean-Baptiste Onofré and Yongjun Zhang.


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

Branch: refs/heads/HDFS-7240
Commit: 92c38e41e1fffb9d60d4fa5d4d2212777af9e9a5
Parents: e82067b
Author: Akira Ajisaka <aa...@apache.org>
Authored: Wed May 13 17:28:57 2015 +0900
Committer: Akira Ajisaka <aa...@apache.org>
Committed: Wed May 13 17:28:57 2015 +0900

----------------------------------------------------------------------
 hadoop-common-project/hadoop-common/CHANGES.txt |  3 ++
 .../org/apache/hadoop/tools/HadoopArchives.java | 13 ++++--
 .../apache/hadoop/tools/TestHadoopArchives.java | 44 +++++++++++++++++++-
 3 files changed, 54 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/92c38e41/hadoop-common-project/hadoop-common/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt
index a15444e..2fbecbb 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -560,6 +560,9 @@ Release 2.8.0 - UNRELEASED
     HADOOP-11948. test-patch's issue matching regex should be configurable.
     (Sean Busbey via aw)
 
+    HADOOP-9723. Improve error message when hadoop archive output path already
+    exists. (Jean-Baptiste Onofré and Yongjun Zhang via aajisak)
+
   OPTIMIZATIONS
 
     HADOOP-11785. Reduce the number of listStatus operation in distcp

http://git-wip-us.apache.org/repos/asf/hadoop/blob/92c38e41/hadoop-tools/hadoop-archives/src/main/java/org/apache/hadoop/tools/HadoopArchives.java
----------------------------------------------------------------------
diff --git a/hadoop-tools/hadoop-archives/src/main/java/org/apache/hadoop/tools/HadoopArchives.java b/hadoop-tools/hadoop-archives/src/main/java/org/apache/hadoop/tools/HadoopArchives.java
index c5c42b1..f00bb6d 100644
--- a/hadoop-tools/hadoop-archives/src/main/java/org/apache/hadoop/tools/HadoopArchives.java
+++ b/hadoop-tools/hadoop-archives/src/main/java/org/apache/hadoop/tools/HadoopArchives.java
@@ -469,8 +469,13 @@ public class HadoopArchives implements Tool {
     Path outputPath = new Path(dest, archiveName);
     FileOutputFormat.setOutputPath(conf, outputPath);
     FileSystem outFs = outputPath.getFileSystem(conf);
-    if (outFs.exists(outputPath) || outFs.isFile(dest)) {
-      throw new IOException("Invalid Output: " + outputPath);
+    if (outFs.exists(outputPath)) {
+      throw new IOException("Archive path: "
+          + outputPath.toString() + " already exists");
+    }
+    if (outFs.isFile(dest)) {
+      throw new IOException("Destination " + dest.toString()
+          + " should be a directory but is a file");
     }
     conf.set(DST_DIR_LABEL, outputPath.toString());
     Path stagingArea;
@@ -846,8 +851,8 @@ public class HadoopArchives implements Tool {
           Path argPath = new Path(args[i]);
           if (argPath.isAbsolute()) {
             System.out.println(usage);
-            throw new IOException("source path " + argPath +
-                " is not relative  to "+ parentPath);
+            throw new IOException("Source path " + argPath +
+                " is not relative to "+ parentPath);
           }
           srcPaths.add(new Path(parentPath, argPath));
         }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/92c38e41/hadoop-tools/hadoop-archives/src/test/java/org/apache/hadoop/tools/TestHadoopArchives.java
----------------------------------------------------------------------
diff --git a/hadoop-tools/hadoop-archives/src/test/java/org/apache/hadoop/tools/TestHadoopArchives.java b/hadoop-tools/hadoop-archives/src/test/java/org/apache/hadoop/tools/TestHadoopArchives.java
index 3fa5919..101cb06 100644
--- a/hadoop-tools/hadoop-archives/src/test/java/org/apache/hadoop/tools/TestHadoopArchives.java
+++ b/hadoop-tools/hadoop-archives/src/test/java/org/apache/hadoop/tools/TestHadoopArchives.java
@@ -21,6 +21,7 @@ package org.apache.hadoop.tools;
 import java.io.ByteArrayOutputStream;
 import java.io.FilterInputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.io.PrintStream;
 import java.net.URI;
 import java.util.ArrayList;
@@ -175,8 +176,47 @@ public class TestHadoopArchives {
     final List<String> harPaths = lsr(shell, fullHarPathStr);
     Assert.assertEquals(originalPaths, harPaths);
   }
-  
-@Test
+
+  @Test
+  public void testOutputPathValidity() throws Exception {
+    final String inputPathStr = inputPath.toUri().getPath();
+    final URI uri = fs.getUri();
+    final String harName = "foo.har";
+    System.setProperty(HadoopArchives.TEST_HADOOP_ARCHIVES_JAR_PATH,
+        HADOOP_ARCHIVES_JAR);
+    final HadoopArchives har = new HadoopArchives(conf);
+
+    PrintStream stderr = System.err;
+    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
+    PrintStream newErr = new PrintStream(byteStream);
+    System.setErr(newErr);
+
+    // fail if the archive path already exists
+    createFile(archivePath, fs, harName);
+    final String[] args = { "-archiveName", harName, "-p", inputPathStr, "*",
+        archivePath.toString() };
+    Assert.assertEquals(-1, ToolRunner.run(har, args));
+    String output = byteStream.toString();
+    final Path outputPath = new Path(archivePath, harName);
+    Assert.assertTrue(output.indexOf("Archive path: " + outputPath.toString()
+        + " already exists") != -1);
+
+    byteStream.reset();
+
+    // fail if the destination directory is a file
+    createFile(archivePath, fs, "sub1");
+    final Path archivePath2 = new Path(archivePath, "sub1");
+    final String[] args2 = { "-archiveName", harName, "-p", inputPathStr, "*",
+        archivePath2.toString() };
+    Assert.assertEquals(-1, ToolRunner.run(har, args2));
+    output = byteStream.toString();
+    Assert.assertTrue(output.indexOf("Destination " + archivePath2.toString()
+        + " should be a directory but is a file") != -1);
+
+    System.setErr(stderr);
+  }
+
+  @Test
   public void testPathWithSpaces() throws Exception {
     // create files/directories with spaces
     createFile(inputPath, fs, "c c");