Search in sources :

Example 46 with FileDoesNotExistException

use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.

the class AlluxioWorkerRestServiceHandler method getWebUIBlockInfo.

/**
 * Gets web ui block info page data.
 *
 * @param requestPath the request path
 * @param requestOffset the request offset
 * @param requestLimit the request limit
 * @return the response object
 */
@GET
@Path(WEBUI_BLOCKINFO)
public Response getWebUIBlockInfo(@QueryParam("path") String requestPath, @DefaultValue("0") @QueryParam("offset") String requestOffset, @DefaultValue("20") @QueryParam("limit") String requestLimit) {
    return RestUtils.call(() -> {
        WorkerWebUIBlockInfo response = new WorkerWebUIBlockInfo();
        if (!ServerConfiguration.getBoolean(PropertyKey.WEB_FILE_INFO_ENABLED)) {
            return response;
        }
        response.setFatalError("").setInvalidPathError("");
        if (!(requestPath == null || requestPath.isEmpty())) {
            // Display file block info
            try {
                URIStatus status = mFsClient.getStatus(new AlluxioURI(requestPath));
                UIFileInfo uiFileInfo = new UIFileInfo(status, ServerConfiguration.global(), new WorkerStorageTierAssoc().getOrderedStorageAliases());
                for (long blockId : status.getBlockIds()) {
                    if (mBlockWorker.hasBlockMeta(blockId)) {
                        BlockMeta blockMeta = mBlockWorker.getVolatileBlockMeta(blockId);
                        long blockSize = blockMeta.getBlockSize();
                        // The block last access time is not available. Use -1 for now.
                        // It's not necessary to show location information here since
                        // we are viewing at the context of this worker.
                        uiFileInfo.addBlock(blockMeta.getBlockLocation().tierAlias(), blockId, blockSize, -1);
                    }
                }
                List<ImmutablePair<String, List<UIFileBlockInfo>>> fileBlocksOnTier = new ArrayList<>();
                for (Map.Entry<String, List<UIFileBlockInfo>> e : uiFileInfo.getBlocksOnTier().entrySet()) {
                    fileBlocksOnTier.add(new ImmutablePair<>(e.getKey(), e.getValue()));
                }
                response.setFileBlocksOnTier(fileBlocksOnTier).setBlockSizeBytes(uiFileInfo.getBlockSizeBytes()).setPath(requestPath);
            } catch (FileDoesNotExistException e) {
                response.setFatalError("Error: Invalid Path " + e.getMessage());
            } catch (IOException e) {
                response.setInvalidPathError("Error: File " + requestPath + " is not available " + e.getMessage());
            } catch (BlockDoesNotExistException e) {
                response.setFatalError("Error: block not found. " + e.getMessage());
            } catch (AlluxioException e) {
                response.setFatalError("Error: alluxio exception. " + e.getMessage());
            }
        }
        Set<Long> unsortedFileIds = new HashSet<>();
        BlockStoreMeta storeMeta = mBlockWorker.getStoreMetaFull();
        for (List<Long> blockIds : storeMeta.getBlockList().values()) {
            for (long blockId : blockIds) {
                unsortedFileIds.add(BlockId.getFileId(blockId));
            }
        }
        List<Long> fileIds = new ArrayList<>(unsortedFileIds);
        Collections.sort(fileIds);
        response.setNTotalFile(unsortedFileIds.size()).setOrderedTierAliases(new WorkerStorageTierAssoc().getOrderedStorageAliases());
        try {
            int offset = Integer.parseInt(requestOffset);
            int limit = Integer.parseInt(requestLimit);
            // make the limit the total number of files if request limit is > than what is available
            limit = offset == 0 && limit > fileIds.size() ? fileIds.size() : limit;
            // offset+limit can't be greater than the size of the list
            limit = offset + limit > fileIds.size() ? fileIds.size() - offset : limit;
            int sum = Math.addExact(offset, limit);
            List<Long> subFileIds = fileIds.subList(offset, sum);
            List<UIFileInfo> uiFileInfos = new ArrayList<>(subFileIds.size());
            for (long fileId : subFileIds) {
                try {
                    URIStatus status = new URIStatus(mBlockWorker.getFileInfo(fileId));
                    UIFileInfo uiFileInfo = new UIFileInfo(status, ServerConfiguration.global(), new WorkerStorageTierAssoc().getOrderedStorageAliases());
                    for (long blockId : status.getBlockIds()) {
                        if (mBlockWorker.hasBlockMeta(blockId)) {
                            BlockMeta blockMeta = mBlockWorker.getVolatileBlockMeta(blockId);
                            long blockSize = blockMeta.getBlockSize();
                            // The block last access time is not available. Use -1 for now.
                            // It's not necessary to show location information here since
                            // we are viewing at the context of this worker.
                            uiFileInfo.addBlock(blockMeta.getBlockLocation().tierAlias(), blockId, blockSize, -1);
                        }
                    }
                    if (!uiFileInfo.getBlockIds().isEmpty()) {
                        uiFileInfos.add(uiFileInfo);
                    }
                } catch (Exception e) {
                    // The file might have been deleted, log a warning and ignore this file.
                    LOG.warn("Unable to get file info for fileId {}. {}", fileId, e.toString());
                }
            }
            response.setFileInfos(uiFileInfos);
        } catch (NumberFormatException e) {
            response.setFatalError("Error: offset or limit parse error, " + e.getLocalizedMessage());
        } catch (ArithmeticException e) {
            response.setFatalError("Error: offset or offset + limit is out ofbound, " + e.getLocalizedMessage());
        } catch (Exception e) {
            response.setFatalError(e.getLocalizedMessage());
        }
        return response;
    }, ServerConfiguration.global());
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) ArrayList(java.util.ArrayList) UIFileInfo(alluxio.util.webui.UIFileInfo) List(java.util.List) ArrayList(java.util.ArrayList) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) AlluxioException(alluxio.exception.AlluxioException) HashSet(java.util.HashSet) UIFileBlockInfo(alluxio.util.webui.UIFileBlockInfo) WorkerWebUIBlockInfo(alluxio.wire.WorkerWebUIBlockInfo) WorkerStorageTierAssoc(alluxio.WorkerStorageTierAssoc) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) AlluxioException(alluxio.exception.AlluxioException) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) IOException(java.io.IOException) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) BlockMeta(alluxio.worker.block.meta.BlockMeta) Map(java.util.Map) SortedMap(java.util.SortedMap) TreeMap(java.util.TreeMap) BlockStoreMeta(alluxio.worker.block.BlockStoreMeta) AlluxioURI(alluxio.AlluxioURI) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 47 with FileDoesNotExistException

use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.

the class MultipartUploadCleaner method tryAbortMultipartUpload.

/**
 * Try to abort a multipart upload if it was timeout.
 *
 * @param fs instance of {@link FileSystem}
 * @param bucket the bucket name
 * @param object the object name
 * @param uploadId multipart upload tmp directory fileId
 * @return delay time
 */
public long tryAbortMultipartUpload(FileSystem fs, String bucket, String object, Long uploadId) throws IOException, AlluxioException {
    long delay = 0;
    final String bucketPath = AlluxioURI.SEPARATOR + bucket;
    final String multipartTemporaryDir = S3RestUtils.getMultipartTemporaryDirForObject(bucketPath, object);
    final String objectPath = bucketPath + AlluxioURI.SEPARATOR + object;
    AlluxioURI tmpUri = new AlluxioURI(multipartTemporaryDir);
    try {
        URIStatus status = fs.getStatus(tmpUri);
        if ((uploadId == null || uploadId == status.getFileId()) && status.isFolder()) {
            final long curTime = System.currentTimeMillis();
            long lastModificationTimeMs = status.getLastModificationTimeMs();
            delay = lastModificationTimeMs + mTimeout - curTime;
            if (delay <= 0) {
                // check object, when merge multipart upload, it may be timeout
                try {
                    AlluxioURI uri = new AlluxioURI(objectPath);
                    status = fs.getStatus(uri);
                    lastModificationTimeMs = status.getLastModificationTimeMs();
                    delay = lastModificationTimeMs + mTimeout - curTime;
                    if (delay <= 0) {
                        fs.delete(tmpUri, DeletePOptions.newBuilder().setRecursive(true).build());
                        LOG.info("Abort multipart upload {} in bucket {} with uploadId {}.", object, bucket, uploadId);
                    }
                } catch (FileDoesNotExistException e) {
                    fs.delete(tmpUri, DeletePOptions.newBuilder().setRecursive(true).build());
                    LOG.info("Abort multipart upload {} in bucket {} with uploadId {}.", object, bucket, uploadId);
                }
            }
        }
    } catch (FileDoesNotExistException ignored) {
        return delay;
    }
    return delay;
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI)

Example 48 with FileDoesNotExistException

use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.

the class S3RestServiceHandler method getObjectMetadata.

/**
 * @summary retrieves an object's metadata
 * @param authorization header parameter authorization
 * @param bucket the bucket name
 * @param object the object name
 * @return the response object
 */
@HEAD
@Path(OBJECT_PARAM)
public Response getObjectMetadata(@HeaderParam("Authorization") String authorization, @PathParam("bucket") final String bucket, @PathParam("object") final String object) {
    return S3RestUtils.call(bucket, () -> {
        Preconditions.checkNotNull(bucket, "required 'bucket' parameter is missing");
        Preconditions.checkNotNull(object, "required 'object' parameter is missing");
        String bucketPath = S3RestUtils.parsePath(AlluxioURI.SEPARATOR + bucket);
        final FileSystem fs = getFileSystem(authorization);
        S3RestUtils.checkPathIsAlluxioDirectory(fs, bucketPath);
        String objectPath = bucketPath + AlluxioURI.SEPARATOR + object;
        AlluxioURI objectURI = new AlluxioURI(objectPath);
        try {
            URIStatus status = fs.getStatus(objectURI);
            if (status.isFolder() && !object.endsWith(AlluxioURI.SEPARATOR)) {
                throw new FileDoesNotExistException(status.getPath() + " is a directory");
            }
            // TODO(cc): Consider how to respond with the object's ETag.
            return Response.ok().lastModified(new Date(status.getLastModificationTimeMs())).header(S3Constants.S3_ETAG_HEADER, "\"" + status.getLastModificationTimeMs() + "\"").header(S3Constants.S3_CONTENT_LENGTH_HEADER, status.isFolder() ? 0 : status.getLength()).build();
        } catch (FileDoesNotExistException e) {
            // must be null entity (content length 0) for S3A Filesystem
            return Response.status(404).entity(null).header("Content-Length", "0").build();
        } catch (Exception e) {
            throw S3RestUtils.toObjectS3Exception(e, objectPath);
        }
    });
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileSystem(alluxio.client.file.FileSystem) URIStatus(alluxio.client.file.URIStatus) Date(java.util.Date) AlluxioException(alluxio.exception.AlluxioException) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) DirectoryNotEmptyException(alluxio.exception.DirectoryNotEmptyException) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) IOException(java.io.IOException) AlluxioURI(alluxio.AlluxioURI) Path(javax.ws.rs.Path) HEAD(javax.ws.rs.HEAD)

Example 49 with FileDoesNotExistException

use of alluxio.exception.FileDoesNotExistException 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 50 with FileDoesNotExistException

use of alluxio.exception.FileDoesNotExistException 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)

Aggregations

FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)126 AlluxioURI (alluxio.AlluxioURI)90 InvalidPathException (alluxio.exception.InvalidPathException)42 IOException (java.io.IOException)39 URIStatus (alluxio.client.file.URIStatus)34 Test (org.junit.Test)31 AlluxioException (alluxio.exception.AlluxioException)26 ArrayList (java.util.ArrayList)26 LockedInodePath (alluxio.master.file.meta.LockedInodePath)22 AccessControlException (alluxio.exception.AccessControlException)19 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)14 Inode (alluxio.master.file.meta.Inode)14 FileInfo (alluxio.wire.FileInfo)14 BlockInfoException (alluxio.exception.BlockInfoException)13 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)10 UnavailableException (alluxio.exception.status.UnavailableException)9 BlockInfo (alluxio.wire.BlockInfo)9 FileBlockInfo (alluxio.wire.FileBlockInfo)9 DirectoryNotEmptyException (alluxio.exception.DirectoryNotEmptyException)8 InodeFile (alluxio.master.file.meta.InodeFile)7