Search in sources :

Example 86 with FileDoesNotExistException

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.
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileInfo(alluxio.wire.FileInfo) Test(org.junit.Test)

Example 87 with FileDoesNotExistException

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());
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 88 with FileDoesNotExistException

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.
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 89 with FileDoesNotExistException

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);
    });
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) ListStatusPOptions(alluxio.grpc.ListStatusPOptions) FileSystem(alluxio.client.file.FileSystem) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 90 with FileDoesNotExistException

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;
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Nullable(javax.annotation.Nullable)

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