Search in sources :

Example 1 with DeletePOptions

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);
}
Also used : DeletePOptions(alluxio.grpc.DeletePOptions)

Example 2 with DeletePOptions

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);
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) DeletePOptions(alluxio.grpc.DeletePOptions) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 3 with DeletePOptions

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;
        }
    });
}
Also used : CreateFilePOptions(alluxio.grpc.CreateFilePOptions) Produces(javax.ws.rs.Produces) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) PropertyKey(alluxio.conf.PropertyKey) MediaType(javax.ws.rs.core.MediaType) FileSystem(alluxio.client.file.FileSystem) QueryParam(javax.ws.rs.QueryParam) User(alluxio.security.User) Consumes(javax.ws.rs.Consumes) HeaderParam(javax.ws.rs.HeaderParam) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) ServerConfiguration(alluxio.conf.ServerConfiguration) AlluxioException(alluxio.exception.AlluxioException) Collectors(java.util.stream.Collectors) IOUtils(org.apache.commons.io.IOUtils) ProxyWebServer(alluxio.web.ProxyWebServer) DigestOutputStream(java.security.DigestOutputStream) List(java.util.List) Response(javax.ws.rs.core.Response) ByteStreams(com.google.common.io.ByteStreams) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) InstancedConfiguration(alluxio.conf.InstancedConfiguration) HEAD(javax.ws.rs.HEAD) PathParam(javax.ws.rs.PathParam) CreateDirectoryPOptions(alluxio.grpc.CreateDirectoryPOptions) GET(javax.ws.rs.GET) MessageDigest(java.security.MessageDigest) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) Hex(org.apache.commons.codec.binary.Hex) FileOutStream(alluxio.client.file.FileOutStream) ArrayList(java.util.ArrayList) DeletePOptions(alluxio.grpc.DeletePOptions) Constants(alluxio.Constants) DirectoryNotEmptyException(alluxio.exception.DirectoryNotEmptyException) AlluxioURI(alluxio.AlluxioURI) FileInStream(alluxio.client.file.FileInStream) ListStatusPOptions(alluxio.grpc.ListStatusPOptions) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) BaseEncoding(com.google.common.io.BaseEncoding) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) IOException(java.io.IOException) Subject(javax.security.auth.Subject) URIStatus(alluxio.client.file.URIStatus) Preconditions(com.google.common.base.Preconditions) ServletContext(javax.servlet.ServletContext) PUT(javax.ws.rs.PUT) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) InputStream(java.io.InputStream) NotThreadSafe(javax.annotation.concurrent.NotThreadSafe) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) ArrayList(java.util.ArrayList) DirectoryNotEmptyException(alluxio.exception.DirectoryNotEmptyException) IOException(java.io.IOException) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) DeletePOptions(alluxio.grpc.DeletePOptions) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 4 with DeletePOptions

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);
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) DeletePOptions(alluxio.grpc.DeletePOptions) DirectoryNotEmptyException(alluxio.exception.DirectoryNotEmptyException) AlluxioException(alluxio.exception.AlluxioException) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) DirectoryNotEmptyException(alluxio.exception.DirectoryNotEmptyException) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) IOException(java.io.IOException) AlluxioURI(alluxio.AlluxioURI)

Example 5 with DeletePOptions

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");
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) DeletePOptions(alluxio.grpc.DeletePOptions) IOException(java.io.IOException)

Aggregations

DeletePOptions (alluxio.grpc.DeletePOptions)19 AlluxioURI (alluxio.AlluxioURI)15 Test (org.junit.Test)10 URIStatus (alluxio.client.file.URIStatus)6 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)6 IOException (java.io.IOException)6 AlluxioException (alluxio.exception.AlluxioException)5 AbstractFileSystemShellTest (alluxio.client.cli.fs.AbstractFileSystemShellTest)4 GetStatusPOptions (alluxio.grpc.GetStatusPOptions)4 DirectoryNotEmptyException (alluxio.exception.DirectoryNotEmptyException)3 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)3 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)3 FileSystem (alluxio.client.file.FileSystem)2 CreateDirectoryPOptions (alluxio.grpc.CreateDirectoryPOptions)2 CreateFilePOptions (alluxio.grpc.CreateFilePOptions)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Constants (alluxio.Constants)1 FileInStream (alluxio.client.file.FileInStream)1 FileOutStream (alluxio.client.file.FileOutStream)1 ConcurrentHashSet (alluxio.collections.ConcurrentHashSet)1