use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class FileSystemMasterTest method getFileInfo.
/**
* Tests the {@link FileSystemMaster#getFileInfo(AlluxioURI, GetStatusContext)} method.
*/
@Test
public void getFileInfo() throws Exception {
createFileWithSingleBlock(NESTED_FILE_URI);
long fileId;
FileInfo info;
fileId = mFileSystemMaster.getFileId(ROOT_URI);
info = mFileSystemMaster.getFileInfo(fileId);
assertEquals(ROOT_URI.getPath(), info.getPath());
assertEquals(ROOT_URI.getPath(), mFileSystemMaster.getFileInfo(ROOT_URI, GET_STATUS_CONTEXT).getPath());
fileId = mFileSystemMaster.getFileId(NESTED_URI);
info = mFileSystemMaster.getFileInfo(fileId);
assertEquals(NESTED_URI.getPath(), info.getPath());
assertEquals(NESTED_URI.getPath(), mFileSystemMaster.getFileInfo(NESTED_URI, GET_STATUS_CONTEXT).getPath());
fileId = mFileSystemMaster.getFileId(NESTED_FILE_URI);
info = mFileSystemMaster.getFileInfo(fileId);
assertEquals(NESTED_FILE_URI.getPath(), info.getPath());
assertEquals(NESTED_FILE_URI.getPath(), mFileSystemMaster.getFileInfo(NESTED_FILE_URI, GET_STATUS_CONTEXT).getPath());
// Test non-existent id.
try {
mFileSystemMaster.getFileInfo(fileId + 1234);
fail("getFileInfo() for a non-existent id should fail.");
} catch (FileDoesNotExistException e) {
// Expected case.
}
// Test non-existent URIs.
try {
mFileSystemMaster.getFileInfo(ROOT_FILE_URI, GET_STATUS_CONTEXT);
fail("getFileInfo() for a non-existent URI should fail.");
} catch (FileDoesNotExistException e) {
// Expected case.
}
try {
mFileSystemMaster.getFileInfo(TEST_URI, GET_STATUS_CONTEXT);
fail("getFileInfo() for a non-existent URI should fail.");
} catch (FileDoesNotExistException e) {
// Expected case.
}
try {
mFileSystemMaster.getFileInfo(NESTED_URI.join("DNE"), GET_STATUS_CONTEXT);
fail("getFileInfo() for a non-existent URI should fail.");
} catch (FileDoesNotExistException e) {
// Expected case.
}
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class FileSystemMasterTest method listStatusWithLoadMetadataNever.
@Test
public void listStatusWithLoadMetadataNever() throws Exception {
AlluxioURI ufsMount = new AlluxioURI(mTestFolder.newFolder().getAbsolutePath());
mFileSystemMaster.createDirectory(new AlluxioURI("/mnt/"), CreateDirectoryContext.defaults());
// Create ufs file.
Files.createDirectory(Paths.get(ufsMount.join("dir1").getPath()));
Files.createFile(Paths.get(ufsMount.join("dir1").join("file1").getPath()));
Files.createFile(Paths.get(ufsMount.join("dir1").join("file2").getPath()));
mFileSystemMaster.mount(new AlluxioURI("/mnt/local"), ufsMount, MountContext.defaults());
// 3 directories exist.
assertEquals(3, countPaths());
// getFileId should load metadata automatically.
AlluxioURI uri = new AlluxioURI("/mnt/local/dir1");
try {
mFileSystemMaster.listStatus(uri, ListStatusContext.mergeFrom(ListStatusPOptions.newBuilder().setLoadMetadataType(LoadMetadataPType.NEVER)));
fail("Exception expected");
} catch (FileDoesNotExistException e) {
// Expected case.
}
assertEquals(3, countPaths());
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class FileSystemMasterTest method getPath.
@Test
public void getPath() throws Exception {
AlluxioURI rootUri = new AlluxioURI("/");
long rootId = mFileSystemMaster.getFileId(rootUri);
assertEquals(rootUri, mFileSystemMaster.getPath(rootId));
// get non-existent id
try {
mFileSystemMaster.getPath(rootId + 1234);
fail("getPath() for a non-existent id should fail.");
} catch (FileDoesNotExistException e) {
// Expected case.
}
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class S3RestServiceHandler method getBucket.
/**
* @summary gets a bucket and lists all the objects in it
* @param authorization header parameter authorization
* @param bucket the bucket name
* @param markerParam the optional marker param
* @param prefixParam the optional prefix param
* @param delimiterParam the optional delimiter param
* @param encodingTypeParam optional encoding type param
* @param maxKeysParam the optional max keys param
* @param listTypeParam if listObjectV2 request
* @param continuationTokenParam the optional continuationToken param for listObjectV2
* @param startAfterParam the optional startAfter param for listObjectV2
* @return the response object
*/
@GET
@Path(BUCKET_PARAM)
public Response getBucket(@HeaderParam("Authorization") String authorization, @PathParam("bucket") final String bucket, @QueryParam("marker") final String markerParam, @QueryParam("prefix") final String prefixParam, @QueryParam("delimiter") final String delimiterParam, @QueryParam("encoding-type") final String encodingTypeParam, @QueryParam("max-keys") final int maxKeysParam, @QueryParam("list-type") final int listTypeParam, @QueryParam("continuation-token") final String continuationTokenParam, @QueryParam("start-after") final String startAfterParam) {
return S3RestUtils.call(bucket, () -> {
Preconditions.checkNotNull(bucket, "required 'bucket' parameter is missing");
String marker = markerParam == null ? "" : markerParam;
String prefix = prefixParam == null ? "" : prefixParam;
String encodingType = encodingTypeParam == null ? "url" : encodingTypeParam;
int maxKeys = maxKeysParam <= 0 ? ListBucketOptions.DEFAULT_MAX_KEYS : maxKeysParam;
String continuationToken = continuationTokenParam == null ? "" : continuationTokenParam;
String startAfter = startAfterParam == null ? "" : startAfterParam;
ListBucketOptions listBucketOptions = ListBucketOptions.defaults().setMarker(marker).setPrefix(prefix).setMaxKeys(maxKeys).setDelimiter(delimiterParam).setEncodingType(encodingType).setListType(listTypeParam).setContinuationToken(continuationToken).setStartAfter(startAfter);
String path = S3RestUtils.parsePath(AlluxioURI.SEPARATOR + bucket);
final FileSystem fs = getFileSystem(authorization);
List<URIStatus> children;
try {
// only list the direct children if delimiter is not null
if (delimiterParam != null) {
path = parsePath(path, prefix, delimiterParam);
children = fs.listStatus(new AlluxioURI(path));
} else {
ListStatusPOptions options = ListStatusPOptions.newBuilder().setRecursive(true).build();
children = fs.listStatus(new AlluxioURI(path), options);
}
} catch (FileDoesNotExistException e) {
// returned which does not match the S3 response behavior
throw new S3Exception(e, bucket, S3ErrorCode.NO_SUCH_BUCKET);
} catch (IOException | AlluxioException e) {
throw new RuntimeException(e);
}
return new ListBucketResult(bucket, children, listBucketOptions);
});
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class MultipartUploadCleaner method getMultipartUploadId.
/**
* Get multipart uploadId.
*
* @param bucket the bucket name
* @param object the object name
*/
@Nullable
private Long getMultipartUploadId(FileSystem fs, String bucket, String object) throws IOException, AlluxioException {
final String bucketPath = AlluxioURI.SEPARATOR + bucket;
String multipartTemporaryDir = S3RestUtils.getMultipartTemporaryDirForObject(bucketPath, object);
try {
URIStatus status = fs.getStatus(new AlluxioURI(multipartTemporaryDir));
return status.getFileId();
} catch (FileDoesNotExistException e) {
return null;
}
}
Aggregations