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