Search in sources :

Example 6 with FileAlreadyExistsException

use of org.apache.hadoop.fs.FileAlreadyExistsException in project hadoop by apache.

the class TestLeaseRecovery2 method recoverLeaseUsingCreate.

private void recoverLeaseUsingCreate(Path filepath) throws IOException, InterruptedException {
    FileSystem dfs2 = getFSAsAnotherUser(conf);
    for (int i = 0; i < 10; i++) {
        AppendTestUtil.LOG.info("i=" + i);
        try {
            dfs2.create(filepath, false, BUF_SIZE, (short) 1, BLOCK_SIZE);
            fail("Creation of an existing file should never succeed.");
        } catch (FileAlreadyExistsException e) {
            // expected
            return;
        } catch (AlreadyBeingCreatedException e) {
            // expected
            return;
        } catch (IOException ioe) {
            AppendTestUtil.LOG.warn("UNEXPECTED ", ioe);
            AppendTestUtil.LOG.info("sleep " + 5000 + "ms");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
            }
        }
    }
    fail("recoverLeaseUsingCreate failed");
}
Also used : FileAlreadyExistsException(org.apache.hadoop.fs.FileAlreadyExistsException) AlreadyBeingCreatedException(org.apache.hadoop.hdfs.protocol.AlreadyBeingCreatedException) FileSystem(org.apache.hadoop.fs.FileSystem) IOException(java.io.IOException)

Example 7 with FileAlreadyExistsException

use of org.apache.hadoop.fs.FileAlreadyExistsException in project hadoop by apache.

the class JobHistoryEventHandler method mkdir.

private void mkdir(FileSystem fs, Path path, FsPermission fsp) throws IOException {
    if (!fs.exists(path)) {
        try {
            fs.mkdirs(path, fsp);
            FileStatus fsStatus = fs.getFileStatus(path);
            LOG.info("Perms after creating " + fsStatus.getPermission().toShort() + ", Expected: " + fsp.toShort());
            if (fsStatus.getPermission().toShort() != fsp.toShort()) {
                LOG.info("Explicitly setting permissions to : " + fsp.toShort() + ", " + fsp);
                fs.setPermission(path, fsp);
            }
        } catch (FileAlreadyExistsException e) {
            LOG.info("Directory: [" + path + "] already exists.");
        }
    }
}
Also used : FileAlreadyExistsException(org.apache.hadoop.fs.FileAlreadyExistsException) FileStatus(org.apache.hadoop.fs.FileStatus)

Example 8 with FileAlreadyExistsException

use of org.apache.hadoop.fs.FileAlreadyExistsException in project hadoop by apache.

the class AbstractContractMkdirTest method testNoMkdirOverFile.

@Test
public void testNoMkdirOverFile() throws Throwable {
    describe("try to mkdir over a file");
    FileSystem fs = getFileSystem();
    Path path = path("testNoMkdirOverFile");
    byte[] dataset = dataset(1024, ' ', 'z');
    createFile(getFileSystem(), path, false, dataset);
    try {
        boolean made = fs.mkdirs(path);
        fail("mkdirs did not fail over a file but returned " + made + "; " + ls(path));
    } catch (ParentNotDirectoryException | FileAlreadyExistsException e) {
        //parent is a directory
        handleExpectedException(e);
    } catch (IOException e) {
        //here the FS says "no create"
        handleRelaxedException("mkdirs", "FileAlreadyExistsException", e);
    }
    assertIsFile(path);
    byte[] bytes = ContractTestUtils.readDataset(getFileSystem(), path, dataset.length);
    ContractTestUtils.compareByteArrays(dataset, bytes, dataset.length);
    assertPathExists("mkdir failed", path);
    assertDeleted(path, true);
}
Also used : Path(org.apache.hadoop.fs.Path) FileAlreadyExistsException(org.apache.hadoop.fs.FileAlreadyExistsException) ParentNotDirectoryException(org.apache.hadoop.fs.ParentNotDirectoryException) FileSystem(org.apache.hadoop.fs.FileSystem) IOException(java.io.IOException) Test(org.junit.Test)

Example 9 with FileAlreadyExistsException

use of org.apache.hadoop.fs.FileAlreadyExistsException in project hadoop by apache.

the class AbstractContractMkdirTest method testMkdirOverParentFile.

@Test
public void testMkdirOverParentFile() throws Throwable {
    describe("try to mkdir where a parent is a file");
    FileSystem fs = getFileSystem();
    Path path = path("testMkdirOverParentFile");
    byte[] dataset = dataset(1024, ' ', 'z');
    createFile(getFileSystem(), path, false, dataset);
    Path child = new Path(path, "child-to-mkdir");
    try {
        boolean made = fs.mkdirs(child);
        fail("mkdirs did not fail over a file but returned " + made + "; " + ls(path));
    } catch (ParentNotDirectoryException | FileAlreadyExistsException e) {
        //parent is a directory
        handleExpectedException(e);
    } catch (IOException e) {
        handleRelaxedException("mkdirs", "ParentNotDirectoryException", e);
    }
    assertIsFile(path);
    byte[] bytes = ContractTestUtils.readDataset(getFileSystem(), path, dataset.length);
    ContractTestUtils.compareByteArrays(dataset, bytes, dataset.length);
    assertPathExists("mkdir failed", path);
    assertDeleted(path, true);
}
Also used : Path(org.apache.hadoop.fs.Path) FileAlreadyExistsException(org.apache.hadoop.fs.FileAlreadyExistsException) ParentNotDirectoryException(org.apache.hadoop.fs.ParentNotDirectoryException) FileSystem(org.apache.hadoop.fs.FileSystem) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with FileAlreadyExistsException

use of org.apache.hadoop.fs.FileAlreadyExistsException in project hadoop by apache.

the class TestAliyunOSSFileSystemContract method testRenameFileAsExistingFile.

@Override
public void testRenameFileAsExistingFile() throws Exception {
    if (this.renameSupported()) {
        Path src = this.path("/test/hadoop/file");
        this.createFile(src);
        Path dst = this.path("/test/new/newfile");
        this.createFile(dst);
        try {
            super.rename(src, dst, false, true, true);
            fail("Should throw FileAlreadyExistsException");
        } catch (FileAlreadyExistsException e) {
        // expected
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileAlreadyExistsException(org.apache.hadoop.fs.FileAlreadyExistsException)

Aggregations

FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)44 Path (org.apache.hadoop.fs.Path)31 IOException (java.io.IOException)22 FileNotFoundException (java.io.FileNotFoundException)16 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)13 FileStatus (org.apache.hadoop.fs.FileStatus)13 Test (org.junit.Test)10 FileSystem (org.apache.hadoop.fs.FileSystem)7 ParentNotDirectoryException (org.apache.hadoop.fs.ParentNotDirectoryException)4 RemoteException (org.apache.hadoop.ipc.RemoteException)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 FsPermission (org.apache.hadoop.fs.permission.FsPermission)3 AlreadyBeingCreatedException (org.apache.hadoop.hdfs.protocol.AlreadyBeingCreatedException)3 DataOutputStream (java.io.DataOutputStream)2 InterruptedIOException (java.io.InterruptedIOException)2 Configuration (org.apache.hadoop.conf.Configuration)2 PermissionStatus (org.apache.hadoop.fs.permission.PermissionStatus)2 SwiftOperationFailedException (org.apache.hadoop.fs.swift.exceptions.SwiftOperationFailedException)2 SwiftObjectPath (org.apache.hadoop.fs.swift.util.SwiftObjectPath)2