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