Search in sources :

Example 1 with DeleteOptions

use of alluxio.client.file.options.DeleteOptions in project alluxio by Alluxio.

the class CheckConsistencyCommand method checkConsistency.

private void checkConsistency(AlluxioURI path, boolean repairConsistency) throws AlluxioException, IOException {
    CheckConsistencyOptions options = CheckConsistencyOptions.defaults();
    List<AlluxioURI> inconsistentUris = FileSystemUtils.checkConsistency(path, options);
    if (inconsistentUris.isEmpty()) {
        System.out.println(path + " is consistent with the under storage system.");
        return;
    }
    if (!repairConsistency) {
        Collections.sort(inconsistentUris);
        System.out.println("The following files are inconsistent:");
        for (AlluxioURI uri : inconsistentUris) {
            System.out.println(uri);
        }
    } else {
        Collections.sort(inconsistentUris);
        System.out.println(path + " has: " + inconsistentUris.size() + " inconsistent files.");
        List<AlluxioURI> inconsistentDirs = new ArrayList<AlluxioURI>();
        for (int i = 0; i < inconsistentUris.size(); i++) {
            AlluxioURI inconsistentUri = inconsistentUris.get(i);
            URIStatus status = mFileSystem.getStatus(inconsistentUri);
            if (status.isFolder()) {
                inconsistentDirs.add(inconsistentUri);
                continue;
            }
            System.out.println("repairing path: " + inconsistentUri);
            DeleteOptions deleteOptions = DeleteOptions.defaults().setAlluxioOnly(true);
            mFileSystem.delete(inconsistentUri, deleteOptions);
            mFileSystem.exists(inconsistentUri);
            System.out.println(inconsistentUri + " repaired");
            System.out.println();
        }
        for (AlluxioURI uri : inconsistentDirs) {
            DeleteOptions deleteOptions = DeleteOptions.defaults().setAlluxioOnly(true).setRecursive(true);
            System.out.println("repairing path: " + uri);
            mFileSystem.delete(uri, deleteOptions);
            mFileSystem.exists(uri);
            System.out.println(uri + "repaired");
            System.out.println();
        }
    }
}
Also used : DeleteOptions(alluxio.client.file.options.DeleteOptions) ArrayList(java.util.ArrayList) CheckConsistencyOptions(alluxio.client.file.options.CheckConsistencyOptions) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI)

Example 2 with DeleteOptions

use of alluxio.client.file.options.DeleteOptions in project alluxio by Alluxio.

the class AbstractFileSystem method delete.

/**
   * Attempts to delete the file or directory with the specified path.
   *
   * @param path path to delete
   * @param recursive if true, will attempt to delete all children of the path
   * @return true if one or more files/directories were deleted; false otherwise
   * @throws IOException if the path failed to be deleted due to some constraint (ie. non empty
   *         directory with recursive flag disabled)
   */
@Override
public boolean delete(Path path, boolean recursive) throws IOException {
    LOG.debug("delete({}, {})", path, recursive);
    if (mStatistics != null) {
        mStatistics.incrementWriteOps(1);
    }
    AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path));
    DeleteOptions options = DeleteOptions.defaults().setRecursive(recursive);
    try {
        mFileSystem.delete(uri, options);
        return true;
    } catch (InvalidPathException | FileDoesNotExistException e) {
        LOG.error("delete failed: {}", e.getMessage());
        return false;
    } catch (AlluxioException e) {
        throw new IOException(e);
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) DeleteOptions(alluxio.client.file.options.DeleteOptions) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 3 with DeleteOptions

use of alluxio.client.file.options.DeleteOptions in project alluxio by Alluxio.

the class RmCommand method runCommand.

@Override
protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException {
    // TODO(calvin): Remove explicit state checking.
    boolean recursive = cl.hasOption("R");
    if (!mFileSystem.exists(path)) {
        throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path));
    }
    if (!recursive && mFileSystem.getStatus(path).isFolder()) {
        throw new IOException(path.getPath() + " is a directory, to remove it, please use \"rm -R <path>\"");
    }
    DeleteOptions options = DeleteOptions.defaults().setRecursive(recursive);
    mFileSystem.delete(path, options);
    System.out.println(path + " has been removed");
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) DeleteOptions(alluxio.client.file.options.DeleteOptions) IOException(java.io.IOException)

Example 4 with DeleteOptions

use of alluxio.client.file.options.DeleteOptions in project alluxio by Alluxio.

the class JournalIntegrationTest method delete.

/**
   * Tests file and directory creation and deletion.
   */
@Test
public void delete() throws Exception {
    CreateDirectoryOptions recMkdir = CreateDirectoryOptions.defaults().setRecursive(true);
    DeleteOptions recDelete = DeleteOptions.defaults().setRecursive(true);
    for (int i = 0; i < 10; i++) {
        String dirPath = "/i" + i;
        mFileSystem.createDirectory(new AlluxioURI(dirPath), recMkdir);
        for (int j = 0; j < 10; j++) {
            CreateFileOptions option = CreateFileOptions.defaults().setBlockSizeBytes((i + j + 1) * 64);
            String filePath = dirPath + "/j" + j;
            mFileSystem.createFile(new AlluxioURI(filePath), option).close();
            if (j >= 5) {
                mFileSystem.delete(new AlluxioURI(filePath), recDelete);
            }
        }
        if (i >= 5) {
            mFileSystem.delete(new AlluxioURI(dirPath), recDelete);
        }
    }
    mLocalAlluxioCluster.stopFS();
    deleteTestUtil();
    deleteFsMasterJournalLogs();
    deleteTestUtil();
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) DeleteOptions(alluxio.client.file.options.DeleteOptions) CreateDirectoryOptions(alluxio.client.file.options.CreateDirectoryOptions) Matchers.anyString(org.mockito.Matchers.anyString) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 5 with DeleteOptions

use of alluxio.client.file.options.DeleteOptions in project alluxio by Alluxio.

the class BaseFileSystemTest method deleteException.

/**
   * Ensures that an exception is propagated correctly when deleting a file.
   */
@Test
public void deleteException() throws Exception {
    AlluxioURI file = new AlluxioURI("/file");
    DeleteOptions deleteOptions = DeleteOptions.defaults().setRecursive(true);
    Mockito.doThrow(EXCEPTION).when(mFileSystemMasterClient).delete(file, deleteOptions);
    try {
        mFileSystem.delete(file, deleteOptions);
        Assert.fail(SHOULD_HAVE_PROPAGATED_MESSAGE);
    } catch (Exception e) {
        Assert.assertSame(EXCEPTION, e);
    }
}
Also used : DeleteOptions(alluxio.client.file.options.DeleteOptions) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

DeleteOptions (alluxio.client.file.options.DeleteOptions)6 AlluxioURI (alluxio.AlluxioURI)5 Test (org.junit.Test)3 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)2 IOException (java.io.IOException)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 URIStatus (alluxio.client.file.URIStatus)1 CheckConsistencyOptions (alluxio.client.file.options.CheckConsistencyOptions)1 CreateDirectoryOptions (alluxio.client.file.options.CreateDirectoryOptions)1 CreateFileOptions (alluxio.client.file.options.CreateFileOptions)1 AlluxioException (alluxio.exception.AlluxioException)1 InvalidPathException (alluxio.exception.InvalidPathException)1 ArrayList (java.util.ArrayList)1 Matchers.anyString (org.mockito.Matchers.anyString)1