浏览代码

HADOOP-9093. Move all the Exception in PathExceptions to o.a.h.fs package. Contributed by Suresh Srinivas.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1413960 13f79535-47bb-0310-9956-ffa450edef68
Suresh Srinivas 12 年之前
父节点
当前提交
3b3a72e622
共有 24 个文件被更改,包括 373 次插入232 次删除
  1. 3 0
      hadoop-common-project/hadoop-common/CHANGES.txt
  2. 27 0
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathAccessDeniedException.java
  3. 33 0
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathExistsException.java
  4. 117 0
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathIOException.java
  5. 27 0
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathIsDirectoryException.java
  6. 27 0
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathIsNotDirectoryException.java
  7. 26 0
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathIsNotEmptyDirectoryException.java
  8. 29 0
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathNotFoundException.java
  9. 27 0
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathOperationException.java
  10. 29 0
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathPermissionException.java
  11. 1 1
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Command.java
  12. 6 6
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java
  13. 1 1
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CopyCommands.java
  14. 4 4
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Delete.java
  15. 1 1
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Display.java
  16. 4 4
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Mkdir.java
  17. 1 1
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/MoveCommands.java
  18. 4 4
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathData.java
  19. 0 203
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathExceptions.java
  20. 1 1
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/SetReplication.java
  21. 1 1
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Tail.java
  22. 0 1
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Test.java
  23. 3 3
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Touchz.java
  24. 1 1
      hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestPathExceptions.java

+ 3 - 0
hadoop-common-project/hadoop-common/CHANGES.txt

@@ -138,6 +138,9 @@ Trunk (Unreleased)
     HADOOP-9075. FileContext#FSLinkResolver should be made static.
     (Arpit Agarwal via suresh)
 
+    HADOOP-9093. Move all the Exception in PathExceptions to o.a.h.fs package.
+    (suresh)
+
   BUG FIXES
 
     HADOOP-8177. MBeans shouldn't try to register when it fails to create MBeanName.

+ 27 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathAccessDeniedException.java

@@ -0,0 +1,27 @@
+/**
+ * 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.hadoop.fs;
+
+/** EACCES */
+public class PathAccessDeniedException extends PathIOException {
+  static final long serialVersionUID = 0L;
+  /** @param path for the exception */
+  public PathAccessDeniedException(String path) {
+    super(path, "Permission denied");
+  }
+}

+ 33 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathExistsException.java

@@ -0,0 +1,33 @@
+/**
+ * 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.hadoop.fs;
+
+/**
+ * Exception corresponding to File Exists - EEXISTS
+ */
+public class PathExistsException extends PathIOException {
+  static final long serialVersionUID = 0L;
+  /** @param path for the exception */
+  public PathExistsException(String path) {
+    super(path, "File exists");
+  }
+  
+  protected PathExistsException(String path, String error) {
+    super(path, error);
+  }
+}

+ 117 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathIOException.java

@@ -0,0 +1,117 @@
+/**
+ * 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.hadoop.fs;
+
+import java.io.IOException;
+
+/**
+ * Exceptions based on standard posix/linux style exceptions for path related
+ * errors. Returns an exception with the format "path: standard error string".
+ * 
+ * This exception corresponds to Error Input/ouput(EIO)
+ */
+public class PathIOException extends IOException {
+  static final long serialVersionUID = 0L;
+  private static final String EIO = "Input/output error";
+  // NOTE: this really should be a Path, but a Path is buggy and won't
+  // return the exact string used to construct the path, and it mangles
+  // uris with no authority
+  private String operation;
+  private String path;
+  private String targetPath;
+
+  /**
+   * Constructor a generic I/O error exception
+   *  @param path for the exception
+   */
+  public PathIOException(String path) {
+    this(path, EIO, null);
+  }
+
+  /**
+   * Appends the text of a Throwable to the default error message
+   * @param path for the exception
+   * @param cause a throwable to extract the error message
+   */
+  public PathIOException(String path, Throwable cause) {
+    this(path, EIO, cause);
+  }
+
+  /**
+   * Avoid using this method.  Use a subclass of PathIOException if
+   * possible.
+   * @param path for the exception
+   * @param error custom string to use an the error text
+   */
+  public PathIOException(String path, String error) {
+    this(path, error, null);
+  }
+
+  protected PathIOException(String path, String error, Throwable cause) {
+    super(error, cause);
+    this.path = path;
+  }
+
+  /** Format:
+   * cmd: {operation} `path' {to `target'}: error string
+   */
+  @Override
+  public String getMessage() {
+    StringBuilder message = new StringBuilder();
+    if (operation != null) {
+      message.append(operation + " ");
+    }
+    message.append(formatPath(path));
+    if (targetPath != null) {
+      message.append(" to " + formatPath(targetPath));
+    }
+    message.append(": " + super.getMessage());
+    if (getCause() != null) {
+      message.append(": " + getCause().getMessage());
+    }
+    return message.toString();
+  }
+
+  /** @return Path that generated the exception */
+  public Path getPath()  { return new Path(path); }
+
+  /** @return Path if the operation involved copying or moving, else null */
+  public Path getTargetPath() {
+    return (targetPath != null) ? new Path(targetPath) : null;
+  }    
+  
+  /**
+   * Optional operation that will preface the path
+   * @param operation a string
+   */
+  public void setOperation(String operation) {
+    this.operation = operation;
+  }
+  
+  /**
+   * Optional path if the exception involved two paths, ex. a copy operation
+   * @param targetPath the of the operation
+   */
+  public void setTargetPath(String targetPath) {
+    this.targetPath = targetPath;
+  }
+  
+  private String formatPath(String path) {
+    return "`" + path + "'";
+  }
+}

+ 27 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathIsDirectoryException.java

@@ -0,0 +1,27 @@
+/**
+ * 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.hadoop.fs;
+
+/** EISDIR */
+public class PathIsDirectoryException extends PathExistsException {
+  static final long serialVersionUID = 0L;
+  /** @param path for the exception */
+  public PathIsDirectoryException(String path) {
+    super(path, "Is a directory");
+  }
+}

+ 27 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathIsNotDirectoryException.java

@@ -0,0 +1,27 @@
+/**
+ * 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.hadoop.fs;
+
+/** ENOTDIR */
+public class PathIsNotDirectoryException extends PathExistsException {
+  static final long serialVersionUID = 0L;
+  /** @param path for the exception */
+  public PathIsNotDirectoryException(String path) {
+    super(path, "Is not a directory");
+  }
+}

+ 26 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathIsNotEmptyDirectoryException.java

@@ -0,0 +1,26 @@
+/**
+ * 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.hadoop.fs;
+
+/** Generated by rm commands */
+public class PathIsNotEmptyDirectoryException extends PathExistsException {
+  /** @param path for the exception */
+  public PathIsNotEmptyDirectoryException(String path) {
+    super(path, "Directory is not empty");
+  }
+}

+ 29 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathNotFoundException.java

@@ -0,0 +1,29 @@
+/**
+ * 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.hadoop.fs;
+
+/**
+ * Exception corresponding to Permission denied - ENOENT
+ */
+public class PathNotFoundException extends PathIOException {
+  static final long serialVersionUID = 0L;
+  /** @param path for the exception */
+  public PathNotFoundException(String path) {
+    super(path, "No such file or directory");
+  }    
+}

+ 27 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathOperationException.java

@@ -0,0 +1,27 @@
+/**
+ * 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.hadoop.fs;
+
+/** ENOTSUP */
+public class PathOperationException extends PathExistsException {
+  static final long serialVersionUID = 0L;
+  /** @param path for the exception */
+  public PathOperationException(String path) {
+    super(path, "Operation not supported");
+  }
+}

+ 29 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathPermissionException.java

@@ -0,0 +1,29 @@
+/**
+ * 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.hadoop.fs;
+
+/**
+ * Exception corresponding to Operation Not Permitted - EPERM
+ */
+public class PathPermissionException extends PathIOException {
+  static final long serialVersionUID = 0L;
+  /** @param path for the exception */
+  public PathPermissionException(String path) {
+    super(path, "Operation not permitted");
+  }
+}

+ 1 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Command.java

@@ -34,7 +34,7 @@ import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.conf.Configured;
 import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.fs.shell.PathExceptions.PathNotFoundException;
+import org.apache.hadoop.fs.PathNotFoundException;
 import org.apache.hadoop.util.StringUtils;
 
 /**

+ 6 - 6
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java

@@ -27,12 +27,12 @@ import org.apache.hadoop.fs.FSDataOutputStream;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.FilterFileSystem;
 import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.fs.shell.PathExceptions.PathExistsException;
-import org.apache.hadoop.fs.shell.PathExceptions.PathIOException;
-import org.apache.hadoop.fs.shell.PathExceptions.PathIsDirectoryException;
-import org.apache.hadoop.fs.shell.PathExceptions.PathIsNotDirectoryException;
-import org.apache.hadoop.fs.shell.PathExceptions.PathNotFoundException;
-import org.apache.hadoop.fs.shell.PathExceptions.PathOperationException;
+import org.apache.hadoop.fs.PathExistsException;
+import org.apache.hadoop.fs.PathIOException;
+import org.apache.hadoop.fs.PathIsDirectoryException;
+import org.apache.hadoop.fs.PathIsNotDirectoryException;
+import org.apache.hadoop.fs.PathNotFoundException;
+import org.apache.hadoop.fs.PathOperationException;
 import org.apache.hadoop.io.IOUtils;
 
 /**

+ 1 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CopyCommands.java

@@ -27,7 +27,7 @@ import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.fs.FSDataInputStream;
 import org.apache.hadoop.fs.FSDataOutputStream;
-import org.apache.hadoop.fs.shell.PathExceptions.PathIsDirectoryException;
+import org.apache.hadoop.fs.PathIsDirectoryException;
 import org.apache.hadoop.io.IOUtils;
 
 /** Various commands for copy files */

+ 4 - 4
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Delete.java

@@ -24,11 +24,11 @@ import java.util.LinkedList;
 
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.fs.PathIOException;
+import org.apache.hadoop.fs.PathIsDirectoryException;
+import org.apache.hadoop.fs.PathIsNotDirectoryException;
+import org.apache.hadoop.fs.PathIsNotEmptyDirectoryException;
 import org.apache.hadoop.fs.Trash;
-import org.apache.hadoop.fs.shell.PathExceptions.PathIOException;
-import org.apache.hadoop.fs.shell.PathExceptions.PathIsDirectoryException;
-import org.apache.hadoop.fs.shell.PathExceptions.PathIsNotDirectoryException;
-import org.apache.hadoop.fs.shell.PathExceptions.PathIsNotEmptyDirectoryException;
 
 /**
  * Classes that delete paths

+ 1 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Display.java

@@ -38,7 +38,7 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FSDataInputStream;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.fs.shell.PathExceptions.PathIsDirectoryException;
+import org.apache.hadoop.fs.PathIsDirectoryException;
 import org.apache.hadoop.io.DataInputBuffer;
 import org.apache.hadoop.io.DataOutputBuffer;
 import org.apache.hadoop.io.IOUtils;

+ 4 - 4
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Mkdir.java

@@ -24,10 +24,10 @@ import java.util.LinkedList;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.fs.shell.PathExceptions.PathExistsException;
-import org.apache.hadoop.fs.shell.PathExceptions.PathIOException;
-import org.apache.hadoop.fs.shell.PathExceptions.PathIsNotDirectoryException;
-import org.apache.hadoop.fs.shell.PathExceptions.PathNotFoundException;
+import org.apache.hadoop.fs.PathExistsException;
+import org.apache.hadoop.fs.PathIOException;
+import org.apache.hadoop.fs.PathIsNotDirectoryException;
+import org.apache.hadoop.fs.PathNotFoundException;
 
 /**
  * Create the given dir

+ 1 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/MoveCommands.java

@@ -23,8 +23,8 @@ import java.util.LinkedList;
 
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.fs.PathIOException;
 import org.apache.hadoop.fs.shell.CopyCommands.CopyFromLocal;
-import org.apache.hadoop.fs.shell.PathExceptions.PathIOException;
 
 /** Various commands for moving files */
 @InterfaceAudience.Private

+ 4 - 4
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathData.java

@@ -32,10 +32,10 @@ import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.LocalFileSystem;
 import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.fs.shell.PathExceptions.PathIOException;
-import org.apache.hadoop.fs.shell.PathExceptions.PathIsDirectoryException;
-import org.apache.hadoop.fs.shell.PathExceptions.PathIsNotDirectoryException;
-import org.apache.hadoop.fs.shell.PathExceptions.PathNotFoundException;
+import org.apache.hadoop.fs.PathIOException;
+import org.apache.hadoop.fs.PathIsDirectoryException;
+import org.apache.hadoop.fs.PathIsNotDirectoryException;
+import org.apache.hadoop.fs.PathNotFoundException;
 
 /**
  * Encapsulates a Path (path), its FileStatus (stat), and its FileSystem (fs).

+ 0 - 203
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathExceptions.java

@@ -1,203 +0,0 @@
-/**
- * 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.hadoop.fs.shell;
-
-import java.io.IOException;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.classification.InterfaceStability;
-import org.apache.hadoop.fs.Path;
-
-/**
- * Standardized posix/linux style exceptions for path related errors.
- * Returns an IOException with the format "path: standard error string".
- */
-@InterfaceAudience.Private
-@InterfaceStability.Unstable
-
-@SuppressWarnings("serial")
-public class PathExceptions {
-
-  /** EIO */
-  public static class PathIOException extends IOException {
-    static final long serialVersionUID = 0L;
-    private static final String EIO = "Input/output error";
-    // NOTE: this really should be a Path, but a Path is buggy and won't
-    // return the exact string used to construct the path, and it mangles
-    // uris with no authority
-    private String operation;
-    private String path;
-    private String targetPath;
-
-    /**
-     * Constructor a generic I/O error exception
-     *  @param path for the exception
-     */
-    public PathIOException(String path) {
-      this(path, EIO, null);
-    }
-
-    /**
-     * Appends the text of a Throwable to the default error message
-     * @param path for the exception
-     * @param cause a throwable to extract the error message
-     */
-    public PathIOException(String path, Throwable cause) {
-      this(path, EIO, cause);
-    }
-
-    /**
-     * Avoid using this method.  Use a subclass of PathIOException if
-     * possible.
-     * @param path for the exception
-     * @param error custom string to use an the error text
-     */
-    public PathIOException(String path, String error) {
-      this(path, error, null);
-    }
-
-    protected PathIOException(String path, String error, Throwable cause) {
-      super(error, cause);
-      this.path = path;
-    }
-
-    /** Format:
-     * cmd: {operation} `path' {to `target'}: error string
-     */
-    @Override
-    public String getMessage() {
-      StringBuilder message = new StringBuilder();
-      if (operation != null) {
-        message.append(operation + " ");
-      }
-      message.append(formatPath(path));
-      if (targetPath != null) {
-        message.append(" to " + formatPath(targetPath));
-      }
-      message.append(": " + super.getMessage());
-      if (getCause() != null) {
-        message.append(": " + getCause().getMessage());
-      }
-      return message.toString();
-    }
-
-    /** @return Path that generated the exception */
-    public Path getPath()  { return new Path(path); }
-
-    /** @return Path if the operation involved copying or moving, else null */
-    public Path getTargetPath() {
-      return (targetPath != null) ? new Path(targetPath) : null;
-    }    
-    
-    /**
-     * Optional operation that will preface the path
-     * @param operation a string
-     */
-    public void setOperation(String operation) {
-      this.operation = operation;
-    }
-    
-    /**
-     * Optional path if the exception involved two paths, ex. a copy operation
-     * @param targetPath the of the operation
-     */
-    public void setTargetPath(String targetPath) {
-      this.targetPath = targetPath;
-    }
-    
-    private String formatPath(String path) {
-      return "`" + path + "'";
-    }
-  }
-
-  /** ENOENT */
-  public static class PathNotFoundException extends PathIOException {
-    static final long serialVersionUID = 0L;
-    /** @param path for the exception */
-    public PathNotFoundException(String path) {
-      super(path, "No such file or directory");
-    }    
-  }
-
-  /** EEXISTS */
-  public static class PathExistsException extends PathIOException {
-    static final long serialVersionUID = 0L;
-    /** @param path for the exception */
-    public PathExistsException(String path) {
-      super(path, "File exists");
-    }
-    
-    protected PathExistsException(String path, String error) {
-      super(path, error);
-    }
-  }
-
-  /** EISDIR */
-  public static class PathIsDirectoryException extends PathExistsException {
-    static final long serialVersionUID = 0L;
-    /** @param path for the exception */
-    public PathIsDirectoryException(String path) {
-      super(path, "Is a directory");
-    }
-  }
-
-  /** ENOTDIR */
-  public static class PathIsNotDirectoryException extends PathExistsException {
-    static final long serialVersionUID = 0L;
-    /** @param path for the exception */
-    public PathIsNotDirectoryException(String path) {
-      super(path, "Is not a directory");
-    }
-  }
-
-  /** Generated by rm commands */
-  public static class PathIsNotEmptyDirectoryException extends PathExistsException {
-    /** @param path for the exception */
-    public PathIsNotEmptyDirectoryException(String path) {
-      super(path, "Directory is not empty");
-    }
-  }  
-
-  /** EACCES */
-  public static class PathAccessDeniedException extends PathIOException {
-    static final long serialVersionUID = 0L;
-    /** @param path for the exception */
-    public PathAccessDeniedException(String path) {
-      super(path, "Permission denied");
-    }
-  }
-
-  /** EPERM */
-  public static class PathPermissionException extends PathIOException {
-    static final long serialVersionUID = 0L;
-    /** @param path for the exception */
-    public PathPermissionException(String path) {
-      super(path, "Operation not permitted");
-    }
-  }
-  
-  /** ENOTSUP */
-  public static class PathOperationException extends PathExistsException {
-    static final long serialVersionUID = 0L;
-    /** @param path for the exception */
-    public PathOperationException(String path) {
-      super(path, "Operation not supported");
-    }
-  }
-}

+ 1 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/SetReplication.java

@@ -25,7 +25,7 @@ import java.util.List;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.fs.BlockLocation;
-import org.apache.hadoop.fs.shell.PathExceptions.PathIOException;
+import org.apache.hadoop.fs.PathIOException;
 
 /**
  * Modifies the replication factor

+ 1 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Tail.java

@@ -25,7 +25,7 @@ import java.util.List;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.fs.FSDataInputStream;
-import org.apache.hadoop.fs.shell.PathExceptions.PathIsDirectoryException;
+import org.apache.hadoop.fs.PathIsDirectoryException;
 import org.apache.hadoop.io.IOUtils;
 
 /**

+ 0 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Test.java

@@ -23,7 +23,6 @@ import java.util.LinkedList;
 
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
-import org.apache.hadoop.fs.shell.PathExceptions.PathNotFoundException;
 
 /**
  * Perform shell-like file tests 

+ 3 - 3
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Touchz.java

@@ -23,9 +23,9 @@ import java.util.LinkedList;
 
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
-import org.apache.hadoop.fs.shell.PathExceptions.PathIOException;
-import org.apache.hadoop.fs.shell.PathExceptions.PathIsDirectoryException;
-import org.apache.hadoop.fs.shell.PathExceptions.PathNotFoundException;
+import org.apache.hadoop.fs.PathIOException;
+import org.apache.hadoop.fs.PathIsDirectoryException;
+import org.apache.hadoop.fs.PathNotFoundException;
 
 /**
  * Unix touch like commands 

+ 1 - 1
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestPathExceptions.java

@@ -23,7 +23,7 @@ import static org.junit.Assert.assertEquals;
 import java.io.IOException;
 
 import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.fs.shell.PathExceptions.PathIOException;
+import org.apache.hadoop.fs.PathIOException;
 import org.junit.Test;
 
 public class TestPathExceptions {