Search in sources :

Example 16 with FileDoesNotExistException

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

the class FileSystemClientRestApiTest method delete.

@Test
public void delete() throws Exception {
    AlluxioURI uri = new AlluxioURI("/file");
    writeFile(uri, null);
    new TestCase(mHostname, mPort, PATHS_PREFIX + uri.toString() + "/" + PathsRestServiceHandler.DELETE, NO_PARAMS, HttpMethod.POST, null, TestCaseOptions.defaults().setBody(DeleteOptions.defaults())).run();
    try {
        mFileSystemMaster.getFileInfo(uri);
        Assert.fail("file should have been removed");
    } catch (FileDoesNotExistException e) {
    // Expected
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) TestCase(alluxio.rest.TestCase) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) RestApiTest(alluxio.rest.RestApiTest)

Example 17 with FileDoesNotExistException

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

the class FileSystemClientRestApiTest method rename.

@Test
public void rename() throws Exception {
    AlluxioURI uri1 = new AlluxioURI("/file1");
    AlluxioURI uri2 = new AlluxioURI("/file2");
    writeFile(uri1, null);
    Map<String, String> params = new HashMap<>();
    params.put("dst", uri2.toString());
    new TestCase(mHostname, mPort, PATHS_PREFIX + uri1.toString() + "/" + PathsRestServiceHandler.RENAME, params, HttpMethod.POST, null, TestCaseOptions.defaults().setBody(RenameOptions.defaults())).run();
    try {
        mFileSystemMaster.getFileInfo(uri1);
        Assert.fail("file should have been removed");
    } catch (FileDoesNotExistException e) {
    // Expected
    }
    mFileSystemMaster.getFileInfo(uri2);
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) HashMap(java.util.HashMap) TestCase(alluxio.rest.TestCase) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) RestApiTest(alluxio.rest.RestApiTest)

Example 18 with FileDoesNotExistException

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

the class FileSystemMasterClientRestApiTest method rename.

@Test
public void rename() throws Exception {
    AlluxioURI uri1 = new AlluxioURI("/file1");
    AlluxioURI uri2 = new AlluxioURI("/file2");
    mFileSystemMaster.createFile(uri1, CreateFileOptions.defaults());
    mFileSystemMaster.completeFile(uri1, CompleteFileOptions.defaults());
    Map<String, String> params = new HashMap<>();
    params.put("srcPath", uri1.toString());
    params.put("dstPath", uri2.toString());
    new TestCase(mHostname, mPort, getEndpoint(FileSystemMasterClientRestServiceHandler.RENAME), params, HttpMethod.POST, null).run();
    try {
        mFileSystemMaster.getFileInfo(uri1);
        Assert.fail("file should have been removed");
    } catch (FileDoesNotExistException e) {
    // Expected
    }
    mFileSystemMaster.getFileInfo(uri2);
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) HashMap(java.util.HashMap) TestCase(alluxio.rest.TestCase) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) RestApiTest(alluxio.rest.RestApiTest)

Example 19 with FileDoesNotExistException

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

the class WebInterfaceWorkerBlockInfoServlet method getUiFileInfo.

/**
   * Gets the {@link UIFileInfo} object based on URI status.
   *
   * @param status the URI status to use
   * @return the {@link UIFileInfo} object of the file
   * @throws BlockDoesNotExistException if the block does not exist
   * @throws FileDoesNotExistException if the file does not exist
   */
private UIFileInfo getUiFileInfo(URIStatus status) throws BlockDoesNotExistException, FileDoesNotExistException {
    UIFileInfo uiFileInfo = new UIFileInfo(status);
    boolean blockExistOnWorker = false;
    for (long blockId : status.getBlockIds()) {
        if (mBlockWorker.hasBlockMeta(blockId)) {
            blockExistOnWorker = true;
            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 (!blockExistOnWorker) {
        throw new FileDoesNotExistException(status.getPath());
    }
    return uiFileInfo;
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) BlockMeta(alluxio.worker.block.meta.BlockMeta)

Example 20 with FileDoesNotExistException

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

the class WebInterfaceWorkerBlockInfoServlet method doGet.

/**
   * Populates attributes before redirecting to a jsp.
   *
   * @param request the {@link HttpServletRequest} object
   * @param response the {@link HttpServletResponse} object
   * @throws ServletException if the target resource throws this exception
   * @throws IOException if the target resource throws this exception
   */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.setAttribute("fatalError", "");
    String filePath = request.getParameter("path");
    if (!(filePath == null || filePath.isEmpty())) {
        // Display file block info
        try {
            UIFileInfo uiFileInfo = getUiFileInfo(new AlluxioURI(filePath));
            List<ImmutablePair<String, List<UIFileBlockInfo>>> fileBlocksOnTier = new ArrayList<>();
            for (Entry<String, List<UIFileBlockInfo>> e : uiFileInfo.getBlocksOnTier().entrySet()) {
                fileBlocksOnTier.add(new ImmutablePair<>(e.getKey(), e.getValue()));
            }
            request.setAttribute("fileBlocksOnTier", fileBlocksOnTier);
            request.setAttribute("blockSizeBytes", uiFileInfo.getBlockSizeBytes());
            request.setAttribute("path", filePath);
            getServletContext().getRequestDispatcher("/worker/viewFileBlocks.jsp").forward(request, response);
            return;
        } catch (FileDoesNotExistException e) {
            request.setAttribute("fatalError", "Error: Invalid Path " + e.getMessage());
            getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
            return;
        } catch (IOException e) {
            request.setAttribute("invalidPathError", "Error: File " + filePath + " is not available " + e.getMessage());
            getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
            return;
        } catch (BlockDoesNotExistException e) {
            request.setAttribute("fatalError", "Error: block not found. " + e.getMessage());
            getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
            return;
        } catch (AlluxioException e) {
            request.setAttribute("fatalError", "Error: alluxio exception. " + e.getMessage());
            getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
            return;
        }
    }
    List<Long> fileIds = getSortedFileIds();
    request.setAttribute("nTotalFile", fileIds.size());
    request.setAttribute("orderedTierAliases", new WorkerStorageTierAssoc().getOrderedStorageAliases());
    // URL can not determine offset and limit, let javascript in jsp determine and redirect
    if (request.getParameter("offset") == null && request.getParameter("limit") == null) {
        getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
        return;
    }
    try {
        int offset = Integer.parseInt(request.getParameter("offset"));
        int limit = Integer.parseInt(request.getParameter("limit"));
        List<Long> subFileIds = fileIds.subList(offset, offset + limit);
        List<UIFileInfo> uiFileInfos = new ArrayList<>(subFileIds.size());
        for (long fileId : subFileIds) {
            try {
                uiFileInfos.add(getUiFileInfo(fileId));
            } catch (IOException 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.getMessage());
            }
        }
        request.setAttribute("fileInfos", uiFileInfos);
    } catch (FileDoesNotExistException e) {
        request.setAttribute("fatalError", "Error: Invalid FileId " + e.getMessage());
        getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
        return;
    } catch (NumberFormatException e) {
        request.setAttribute("fatalError", "Error: offset or limit parse error, " + e.getLocalizedMessage());
        getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
        return;
    } catch (IndexOutOfBoundsException e) {
        request.setAttribute("fatalError", "Error: offset or offset + limit is out of bound, " + e.getLocalizedMessage());
        getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
        return;
    } catch (IllegalArgumentException | AlluxioException e) {
        request.setAttribute("fatalError", e.getLocalizedMessage());
        getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
        return;
    }
    getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) ArrayList(java.util.ArrayList) WorkerStorageTierAssoc(alluxio.WorkerStorageTierAssoc) IOException(java.io.IOException) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ArrayList(java.util.ArrayList) List(java.util.List) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Aggregations

FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)51 AlluxioURI (alluxio.AlluxioURI)36 InvalidPathException (alluxio.exception.InvalidPathException)20 IOException (java.io.IOException)19 AlluxioException (alluxio.exception.AlluxioException)16 Test (org.junit.Test)14 URIStatus (alluxio.client.file.URIStatus)13 ArrayList (java.util.ArrayList)10 AccessControlException (alluxio.exception.AccessControlException)7 FileInfo (alluxio.wire.FileInfo)7 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)5 BlockInfoException (alluxio.exception.BlockInfoException)4 RestApiTest (alluxio.rest.RestApiTest)4 TestCase (alluxio.rest.TestCase)4 HashMap (java.util.HashMap)4 FileAlreadyCompletedException (alluxio.exception.FileAlreadyCompletedException)3 InvalidFileSizeException (alluxio.exception.InvalidFileSizeException)3 UnexpectedAlluxioException (alluxio.exception.UnexpectedAlluxioException)3 Inode (alluxio.master.file.meta.Inode)3 LockedInodePath (alluxio.master.file.meta.LockedInodePath)3