use of alluxio.grpc.DeletePOptions in project alluxio by Alluxio.
the class DeleteContext method mergeFrom.
/**
* Merges and embeds the given {@link DeletePOptions} with the corresponding master options.
*
* @param optionsBuilder Builder for proto {@link DeletePOptions} to merge with defaults
* @return the instance of {@link DeleteContext} with default values for master
*/
public static DeleteContext mergeFrom(DeletePOptions.Builder optionsBuilder) {
DeletePOptions masterOptions = FileSystemOptions.deleteDefaults(ServerConfiguration.global());
DeletePOptions.Builder mergedOptionsBuilder = masterOptions.toBuilder().mergeFrom(optionsBuilder.build());
return create(mergedOptionsBuilder);
}
use of alluxio.grpc.DeletePOptions 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
*/
@Override
public boolean delete(Path path, boolean recursive) throws IOException {
LOG.debug("delete({}, {})", path, recursive);
if (mStatistics != null) {
mStatistics.incrementWriteOps(1);
}
AlluxioURI uri = getAlluxioPath(path);
DeletePOptions options = DeletePOptions.newBuilder().setRecursive(recursive).build();
try {
mFileSystem.delete(uri, options);
return true;
} catch (InvalidPathException | FileDoesNotExistException e) {
LOG.debug("delete failed: {}", e.toString());
return false;
} catch (AlluxioException e) {
throw new IOException(e);
}
}
use of alluxio.grpc.DeletePOptions in project alluxio by Alluxio.
the class S3RestServiceHandler method postBucket.
/**
* Currently implements the DeleteObjects request type if the query parameter "delete" exists.
*
* @param bucket the bucket name
* @param delete the delete query parameter. Existence indicates to run the DeleteObjects impl
* @param contentLength body content length
* @param is the input stream to read the request
*
* @return a {@link DeleteObjectsResult} if this was a DeleteObjects request
*/
@POST
@Path(BUCKET_PARAM)
public Response postBucket(@PathParam("bucket") final String bucket, @QueryParam("delete") String delete, @HeaderParam("Content-Length") int contentLength, final InputStream is) {
return S3RestUtils.call(bucket, () -> {
if (delete != null) {
try {
DeleteObjectsRequest request = new XmlMapper().readerFor(DeleteObjectsRequest.class).readValue(is);
List<DeleteObjectsRequest.DeleteObject> objs = request.getToDelete();
List<DeleteObjectsResult.DeletedObject> success = new ArrayList<>();
List<DeleteObjectsResult.ErrorObject> errored = new ArrayList<>();
objs.sort(Comparator.comparingInt(x -> -1 * x.getKey().length()));
objs.forEach(obj -> {
try {
AlluxioURI uri = new AlluxioURI(AlluxioURI.SEPARATOR + bucket).join(AlluxioURI.SEPARATOR + obj.getKey());
DeletePOptions options = DeletePOptions.newBuilder().build();
mFileSystem.delete(uri, options);
DeleteObjectsResult.DeletedObject del = new DeleteObjectsResult.DeletedObject();
del.setKey(obj.getKey());
success.add(del);
} catch (FileDoesNotExistException | DirectoryNotEmptyException e) {
/*
FDNE - delete on FDNE should be counted as a success, as there's nothing to do
DNE - s3 has no concept dirs - if it _is_ a dir, nothing to delete.
*/
DeleteObjectsResult.DeletedObject del = new DeleteObjectsResult.DeletedObject();
del.setKey(obj.getKey());
success.add(del);
} catch (IOException | AlluxioException e) {
DeleteObjectsResult.ErrorObject err = new DeleteObjectsResult.ErrorObject();
err.setKey(obj.getKey());
err.setMessage(e.getMessage());
errored.add(err);
}
});
DeleteObjectsResult result = new DeleteObjectsResult();
if (!request.getQuiet()) {
result.setDeleted(success);
}
result.setErrored(errored);
return result;
} catch (IOException e) {
LOG.debug("Failed to parse DeleteObjects request:", e);
return Response.Status.BAD_REQUEST;
}
} else {
return Response.Status.OK;
}
});
}
use of alluxio.grpc.DeletePOptions in project alluxio by Alluxio.
the class S3RestServiceHandler method deleteObject.
private void deleteObject(FileSystem fs, String bucket, String object) throws S3Exception {
String bucketPath = S3RestUtils.parsePath(AlluxioURI.SEPARATOR + bucket);
// Delete the object.
String objectPath = bucketPath + AlluxioURI.SEPARATOR + object;
DeletePOptions options = DeletePOptions.newBuilder().setAlluxioOnly(ServerConfiguration.get(PropertyKey.PROXY_S3_DELETE_TYPE).equals(Constants.S3_DELETE_IN_ALLUXIO_ONLY)).build();
try {
fs.delete(new AlluxioURI(objectPath), options);
} catch (FileDoesNotExistException | DirectoryNotEmptyException e) {
// intentionally do nothing, this is ok. It should result in a 204 error
// This is the same response behavior as AWS's S3.
} catch (Exception e) {
throw S3RestUtils.toObjectS3Exception(e, objectPath);
}
}
use of alluxio.grpc.DeletePOptions in project alluxio by Alluxio.
the class RmCommand method runPlainPath.
@Override
protected void runPlainPath(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException {
// TODO(calvin): Remove explicit state checking.
boolean recursive = cl.hasOption(RECURSIVE_OPTION.getOpt()) || cl.hasOption(RECURSIVE_ALIAS_OPTION.getOpt());
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/-r/--recursive <path>\"");
}
boolean isAlluxioOnly = cl.hasOption(REMOVE_ALLUXIO_ONLY.getLongOpt());
DeletePOptions options = DeletePOptions.newBuilder().setRecursive(recursive).setAlluxioOnly(isAlluxioOnly).setUnchecked(cl.hasOption(REMOVE_UNCHECKED_OPTION_CHAR)).build();
mFileSystem.delete(path, options);
if (!isAlluxioOnly) {
System.out.println(path + " has been removed");
} else {
System.out.println(path + " has been removed only from Alluxio space");
}
}
Aggregations