Author: stevel Date: Thu Jul 3 12:55:23 2014 New Revision: 1607625 URL: http://svn.apache.org/r1607625 Log: HADOOP-9361: Strictly define FileSystem APIs - OpenStack portion
Added: hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/contract/ - copied from r1607600, hadoop/common/trunk/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/contract/ hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/resources/contract/ - copied from r1607600, hadoop/common/trunk/hadoop-tools/hadoop-openstack/src/test/resources/contract/ Removed: hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/exceptions/SwiftNotDirectoryException.java hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/exceptions/SwiftPathExistsException.java Modified: hadoop/common/branches/branch-2/ (props changed) hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/StrictBufferedFSInputStream.java hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeFileSystem.java hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeFileSystemStore.java hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeInputStream.java hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeOutputStream.java hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/TestSwiftFileSystemBasicOps.java hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/TestSwiftFileSystemContract.java hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/TestSwiftFileSystemRename.java hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/hdfs2/TestV2LsOperations.java Propchange: hadoop/common/branches/branch-2/ ------------------------------------------------------------------------------ Merged /hadoop/common/trunk:r1607599-1607600 Modified: hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/StrictBufferedFSInputStream.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/StrictBufferedFSInputStream.java?rev=1607625&r1=1607624&r2=1607625&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/StrictBufferedFSInputStream.java (original) +++ hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/StrictBufferedFSInputStream.java Thu Jul 3 12:55:23 2014 @@ -19,9 +19,11 @@ package org.apache.hadoop.fs.swift.snative; import org.apache.hadoop.fs.BufferedFSInputStream; +import org.apache.hadoop.fs.FSExceptionMessages; import org.apache.hadoop.fs.FSInputStream; import org.apache.hadoop.fs.swift.exceptions.SwiftConnectionClosedException; +import java.io.EOFException; import java.io.IOException; /** @@ -37,10 +39,10 @@ public class StrictBufferedFSInputStream @Override public void seek(long pos) throws IOException { if (pos < 0) { - throw new IOException("Negative position"); + throw new EOFException(FSExceptionMessages.NEGATIVE_SEEK); } if (in == null) { - throw new SwiftConnectionClosedException("Stream closed"); + throw new SwiftConnectionClosedException(FSExceptionMessages.STREAM_IS_CLOSED); } super.seek(pos); } Modified: hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeFileSystem.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeFileSystem.java?rev=1607625&r1=1607624&r2=1607625&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeFileSystem.java (original) +++ hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeFileSystem.java Thu Jul 3 12:55:23 2014 @@ -25,14 +25,14 @@ import org.apache.hadoop.conf.Configurat import org.apache.hadoop.fs.BlockLocation; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataOutputStream; +import org.apache.hadoop.fs.FileAlreadyExistsException; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.ParentNotDirectoryException; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.swift.exceptions.SwiftConfigurationException; -import org.apache.hadoop.fs.swift.exceptions.SwiftNotDirectoryException; import org.apache.hadoop.fs.swift.exceptions.SwiftOperationFailedException; -import org.apache.hadoop.fs.swift.exceptions.SwiftPathExistsException; import org.apache.hadoop.fs.swift.exceptions.SwiftUnsupportedFeatureException; import org.apache.hadoop.fs.swift.http.SwiftProtocolConstants; import org.apache.hadoop.fs.swift.util.DurationStats; @@ -373,7 +373,7 @@ public class SwiftNativeFileSystem exten * @param directory path to query * @return true iff the directory should be created * @throws IOException IO problems - * @throws SwiftNotDirectoryException if the path references a file + * @throws ParentNotDirectoryException if the path references a file */ private boolean shouldCreate(Path directory) throws IOException { FileStatus fileStatus; @@ -388,9 +388,9 @@ public class SwiftNativeFileSystem exten if (!SwiftUtils.isDirectory(fileStatus)) { //if it's a file, raise an error - throw new SwiftNotDirectoryException(directory, - String.format(": can't mkdir since it exists and is not a directory: %s", - fileStatus)); + throw new ParentNotDirectoryException( + String.format("%s: can't mkdir since it exists and is not a directory: %s", + directory, fileStatus)); } else { //path exists, and it is a directory if (LOG.isDebugEnabled()) { @@ -488,7 +488,7 @@ public class SwiftNativeFileSystem exten //overwrite set -> delete the object. store.delete(absolutePath, true); } else { - throw new SwiftPathExistsException("Path exists: " + file); + throw new FileAlreadyExistsException("Path exists: " + file); } } else { // destination does not exist -trigger creation of the parent @@ -580,6 +580,9 @@ public class SwiftNativeFileSystem exten } catch (SwiftOperationFailedException e) { //downgrade to a failure return false; + } catch (FileAlreadyExistsException e) { + //downgrade to a failure + return false; } catch (FileNotFoundException e) { //downgrade to a failure return false; Modified: hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeFileSystemStore.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeFileSystemStore.java?rev=1607625&r1=1607624&r2=1607625&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeFileSystemStore.java (original) +++ hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeFileSystemStore.java Thu Jul 3 12:55:23 2014 @@ -22,6 +22,7 @@ import org.apache.commons.httpclient.Htt import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileAlreadyExistsException; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.swift.exceptions.SwiftConfigurationException; @@ -590,7 +591,7 @@ public class SwiftNativeFileSystemStore } else { //outcome #1 dest it's a file: fail if differeent if (!renamingOnToSelf) { - throw new SwiftOperationFailedException( + throw new FileAlreadyExistsException( "cannot rename a file over one that already exists"); } else { //is mv self self where self is a file. this becomes a no-op @@ -633,7 +634,7 @@ public class SwiftNativeFileSystemStore if (destExists && !destIsDir) { // #1 destination is a file: fail - throw new SwiftOperationFailedException( + throw new FileAlreadyExistsException( "the source is a directory, but not the destination"); } Path targetPath; Modified: hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeInputStream.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeInputStream.java?rev=1607625&r1=1607624&r2=1607625&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeInputStream.java (original) +++ hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeInputStream.java Thu Jul 3 12:55:23 2014 @@ -20,6 +20,7 @@ package org.apache.hadoop.fs.swift.snati import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.fs.FSExceptionMessages; import org.apache.hadoop.fs.FSInputStream; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; @@ -298,7 +299,8 @@ class SwiftNativeInputStream extends FSI @Override public synchronized void seek(long targetPos) throws IOException { if (targetPos < 0) { - throw new IOException("Negative Seek offset not supported"); + throw new EOFException( + FSExceptionMessages.NEGATIVE_SEEK); } //there's some special handling of near-local data //as the seek can be omitted if it is in/adjacent Modified: hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeOutputStream.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeOutputStream.java?rev=1607625&r1=1607624&r2=1607625&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeOutputStream.java (original) +++ hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeOutputStream.java Thu Jul 3 12:55:23 2014 @@ -22,6 +22,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.swift.exceptions.SwiftConnectionClosedException; import org.apache.hadoop.fs.swift.exceptions.SwiftException; import org.apache.hadoop.fs.swift.exceptions.SwiftInternalStateException; import org.apache.hadoop.fs.swift.util.SwiftUtils; @@ -109,7 +110,7 @@ class SwiftNativeOutputStream extends Ou */ private synchronized void verifyOpen() throws SwiftException { if (closed) { - throw new SwiftException("Output stream is closed"); + throw new SwiftConnectionClosedException(); } } Modified: hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/TestSwiftFileSystemBasicOps.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/TestSwiftFileSystemBasicOps.java?rev=1607625&r1=1607624&r2=1607625&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/TestSwiftFileSystemBasicOps.java (original) +++ hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/TestSwiftFileSystemBasicOps.java Thu Jul 3 12:55:23 2014 @@ -21,9 +21,9 @@ package org.apache.hadoop.fs.swift; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.ParentNotDirectoryException; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.swift.exceptions.SwiftBadRequestException; -import org.apache.hadoop.fs.swift.exceptions.SwiftNotDirectoryException; import org.apache.hadoop.fs.swift.snative.SwiftNativeFileSystem; import org.apache.hadoop.fs.swift.util.SwiftTestUtils; import org.junit.Test; @@ -245,7 +245,7 @@ public class TestSwiftFileSystemBasicOps writeTextFile(fs, path, "parent", true); try { fs.mkdirs(child); - } catch (SwiftNotDirectoryException expected) { + } catch (ParentNotDirectoryException expected) { LOG.debug("Expected Exception", expected); } } finally { Modified: hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/TestSwiftFileSystemContract.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/TestSwiftFileSystemContract.java?rev=1607625&r1=1607624&r2=1607625&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/TestSwiftFileSystemContract.java (original) +++ hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/TestSwiftFileSystemContract.java Thu Jul 3 12:55:23 2014 @@ -23,8 +23,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystemContractBaseTest; +import org.apache.hadoop.fs.ParentNotDirectoryException; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.fs.swift.exceptions.SwiftNotDirectoryException; import org.apache.hadoop.fs.swift.snative.SwiftNativeFileSystem; import org.apache.hadoop.fs.swift.util.SwiftTestUtils; @@ -47,6 +47,14 @@ public class TestSwiftFileSystemContract private static final Log LOG = LogFactory.getLog(TestSwiftFileSystemContract.class); + /** + * Override this if the filesystem is not case sensitive + * @return true if the case detection/preservation tests should run + */ + protected boolean filesystemIsCaseSensitive() { + return false; + } + @Override protected void setUp() throws Exception { final URI uri = getFilesystemURI(); @@ -89,9 +97,8 @@ public class TestSwiftFileSystemContract try { fs.mkdirs(testSubDir); fail("Should throw IOException."); - } catch (SwiftNotDirectoryException e) { + } catch (ParentNotDirectoryException e) { // expected - assertEquals(filepath,e.getPath()); } //now verify that the subdir path does not exist SwiftTestUtils.assertPathDoesNotExist(fs, "subdir after mkdir", testSubDir); @@ -100,7 +107,7 @@ public class TestSwiftFileSystemContract try { fs.mkdirs(testDeepSubDir); fail("Should throw IOException."); - } catch (SwiftNotDirectoryException e) { + } catch (ParentNotDirectoryException e) { // expected } SwiftTestUtils.assertPathDoesNotExist(fs, "testDeepSubDir after mkdir", Modified: hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/TestSwiftFileSystemRename.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/TestSwiftFileSystemRename.java?rev=1607625&r1=1607624&r2=1607625&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/TestSwiftFileSystemRename.java (original) +++ hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/TestSwiftFileSystemRename.java Thu Jul 3 12:55:23 2014 @@ -21,6 +21,7 @@ package org.apache.hadoop.fs.swift; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.swift.exceptions.SwiftOperationFailedException; import org.apache.hadoop.fs.swift.util.SwiftTestUtils; import org.junit.Test; @@ -220,7 +221,11 @@ public class TestSwiftFileSystemRename e fs.mkdirs(testdir); Path parent = testdir.getParent(); //the outcome here is ambiguous, so is not checked - fs.rename(testdir, parent); + try { + fs.rename(testdir, parent); + } catch (SwiftOperationFailedException e) { + // allowed + } assertExists("Source directory has been deleted ", testdir); } Modified: hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/hdfs2/TestV2LsOperations.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/hdfs2/TestV2LsOperations.java?rev=1607625&r1=1607624&r2=1607625&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/hdfs2/TestV2LsOperations.java (original) +++ hadoop/common/branches/branch-2/hadoop-tools/hadoop-openstack/src/test/java/org/apache/hadoop/fs/swift/hdfs2/TestV2LsOperations.java Thu Jul 3 12:55:23 2014 @@ -111,7 +111,7 @@ public class TestV2LsOperations extends @Test(timeout = SWIFT_TEST_TIMEOUT) public void testListFilesSubDir() throws Throwable { createTestSubdirs(); - Path dir = path("/test"); + Path dir = path("/test/subdir"); Path child = new Path(dir, "text.txt"); SwiftTestUtils.writeTextFile(fs, child, "text", false); assertListFilesFinds(fs, dir, child, false); @@ -120,7 +120,7 @@ public class TestV2LsOperations extends @Test(timeout = SWIFT_TEST_TIMEOUT) public void testListFilesRecursive() throws Throwable { createTestSubdirs(); - Path dir = path("/test"); + Path dir = path("/test/recursive"); Path child = new Path(dir, "hadoop/a/a.txt"); SwiftTestUtils.writeTextFile(fs, child, "text", false); assertListFilesFinds(fs, dir, child, true);