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();
}
}
}
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);
}
}
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");
}
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();
}
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);
}
}
Aggregations