From 5b7d4c8c6cbd71a86c68223ade023a23ded3b814 Mon Sep 17 00:00:00 2001 From: Suresh Srinivas Date: Tue, 27 Nov 2012 03:36:33 +0000 Subject: [PATCH] HADOOP-9093. Merge change r1413960 from trunk. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1413985 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 3 + .../hadoop/fs/PathAccessDeniedException.java | 27 +++ .../apache/hadoop/fs/PathExistsException.java | 33 +++ .../org/apache/hadoop/fs/PathIOException.java | 117 ++++++++++ .../hadoop/fs/PathIsDirectoryException.java | 27 +++ .../fs/PathIsNotDirectoryException.java | 27 +++ .../fs/PathIsNotEmptyDirectoryException.java | 26 +++ .../hadoop/fs/PathNotFoundException.java | 29 +++ .../hadoop/fs/PathOperationException.java | 27 +++ .../hadoop/fs/PathPermissionException.java | 29 +++ .../org/apache/hadoop/fs/shell/Command.java | 2 +- .../fs/shell/CommandWithDestination.java | 12 +- .../apache/hadoop/fs/shell/CopyCommands.java | 2 +- .../org/apache/hadoop/fs/shell/Delete.java | 8 +- .../org/apache/hadoop/fs/shell/Display.java | 2 +- .../org/apache/hadoop/fs/shell/Mkdir.java | 8 +- .../apache/hadoop/fs/shell/MoveCommands.java | 2 +- .../org/apache/hadoop/fs/shell/PathData.java | 8 +- .../hadoop/fs/shell/PathExceptions.java | 203 ------------------ .../hadoop/fs/shell/SetReplication.java | 2 +- .../java/org/apache/hadoop/fs/shell/Tail.java | 2 +- .../java/org/apache/hadoop/fs/shell/Test.java | 1 - .../org/apache/hadoop/fs/shell/Touchz.java | 6 +- .../hadoop/fs/shell/TestPathExceptions.java | 2 +- 24 files changed, 373 insertions(+), 232 deletions(-) create mode 100644 hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathAccessDeniedException.java create mode 100644 hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathExistsException.java create mode 100644 hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathIOException.java create mode 100644 hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathIsDirectoryException.java create mode 100644 hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathIsNotDirectoryException.java create mode 100644 hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathIsNotEmptyDirectoryException.java create mode 100644 hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathNotFoundException.java create mode 100644 hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathOperationException.java create mode 100644 hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathPermissionException.java delete mode 100644 hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathExceptions.java diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index cb9e02ef117..710127cf6d7 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -83,6 +83,9 @@ Release 2.0.3-alpha - Unreleased HADOOP-9035. Generalize setup of LoginContext (daryn via bobby) + HADOOP-9093. Move all the Exception in PathExceptions to o.a.h.fs package. + (suresh) + OPTIMIZATIONS HADOOP-8866. SampleQuantiles#query is O(N^2) instead of O(N). (Andrew Wang diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathAccessDeniedException.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathAccessDeniedException.java new file mode 100644 index 00000000000..5277507e150 --- /dev/null +++ b/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"); + } +} \ No newline at end of file diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathExistsException.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathExistsException.java new file mode 100644 index 00000000000..ccc1f0c46ad --- /dev/null +++ b/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); + } +} \ No newline at end of file diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathIOException.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathIOException.java new file mode 100644 index 00000000000..2c73f11ff2d --- /dev/null +++ b/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 + "'"; + } +} \ No newline at end of file diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathIsDirectoryException.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathIsDirectoryException.java new file mode 100644 index 00000000000..ec2958892ff --- /dev/null +++ b/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"); + } +} \ No newline at end of file diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathIsNotDirectoryException.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathIsNotDirectoryException.java new file mode 100644 index 00000000000..9de17aa5386 --- /dev/null +++ b/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"); + } +} \ No newline at end of file diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathIsNotEmptyDirectoryException.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathIsNotEmptyDirectoryException.java new file mode 100644 index 00000000000..e457e445c63 --- /dev/null +++ b/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"); + } +} \ No newline at end of file diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathNotFoundException.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathNotFoundException.java new file mode 100644 index 00000000000..c5a083837e5 --- /dev/null +++ b/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"); + } +} \ No newline at end of file diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathOperationException.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathOperationException.java new file mode 100644 index 00000000000..b020cb00292 --- /dev/null +++ b/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"); + } +} \ No newline at end of file diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathPermissionException.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/PathPermissionException.java new file mode 100644 index 00000000000..483b1de4535 --- /dev/null +++ b/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"); + } +} \ No newline at end of file diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Command.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Command.java index b24d47e02b1..a5ce158cddd 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Command.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Command.java @@ -33,7 +33,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; /** diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java index a861840f07c..f6899307359 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java +++ b/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; /** diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CopyCommands.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CopyCommands.java index 15155fac80c..4e3aab08160 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CopyCommands.java +++ b/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 */ diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Delete.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Delete.java index bc1d8af9510..4dc550501c8 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Delete.java +++ b/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 diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Display.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Display.java index 5f349b16062..e62bb63edab 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Display.java +++ b/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; diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Mkdir.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Mkdir.java index d92a5343c94..050011582fd 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Mkdir.java +++ b/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 diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/MoveCommands.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/MoveCommands.java index 5f7d474fbc1..e1ad1a2ef6d 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/MoveCommands.java +++ b/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 diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathData.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathData.java index 04574cf6730..6e86af7cc19 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathData.java +++ b/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). diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathExceptions.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathExceptions.java deleted file mode 100644 index 66d2a35e27e..00000000000 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathExceptions.java +++ /dev/null @@ -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"); - } - } -} \ No newline at end of file diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/SetReplication.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/SetReplication.java index 3266bd2b408..3a5f919b78e 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/SetReplication.java +++ b/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 diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Tail.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Tail.java index e95d4d1cec8..e6139dbde9d 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Tail.java +++ b/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; /** diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Test.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Test.java index 3acb4b2df25..31f16ea1540 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Test.java +++ b/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 diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Touchz.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Touchz.java index 9e0844e0f41..a37df995b20 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Touchz.java +++ b/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 diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestPathExceptions.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestPathExceptions.java index f3b7e88a41e..f0a0f46acb9 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestPathExceptions.java +++ b/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 {