use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class WebInterfaceBrowseServlet method doGet.
/**
* Populates attribute fields with data from the MasterInfo associated with this servlet. Errors
* will be displayed in an error field. Debugging can be enabled to display additional data. Will
* eventually redirect the request 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 {
if (SecurityUtils.isSecurityEnabled() && AuthenticatedClientUser.get() == null) {
AuthenticatedClientUser.set(LoginUser.get().getName());
}
request.setAttribute("debug", Configuration.getBoolean(PropertyKey.DEBUG));
request.setAttribute("showPermissions", Configuration.getBoolean(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_ENABLED));
request.setAttribute("masterNodeAddress", mMaster.getRpcAddress().toString());
request.setAttribute("invalidPathError", "");
List<FileInfo> filesInfo;
String requestPath = request.getParameter("path");
if (requestPath == null || requestPath.isEmpty()) {
requestPath = AlluxioURI.SEPARATOR;
}
AlluxioURI currentPath = new AlluxioURI(requestPath);
request.setAttribute("currentPath", currentPath.toString());
request.setAttribute("viewingOffset", 0);
try {
long fileId = mMaster.getFileSystemMaster().getFileId(currentPath);
FileInfo fileInfo = mMaster.getFileSystemMaster().getFileInfo(fileId);
UIFileInfo currentFileInfo = new UIFileInfo(fileInfo);
if (currentFileInfo.getAbsolutePath() == null) {
throw new FileDoesNotExistException(currentPath.toString());
}
request.setAttribute("currentDirectory", currentFileInfo);
request.setAttribute("blockSizeBytes", currentFileInfo.getBlockSizeBytes());
if (!currentFileInfo.getIsDirectory()) {
String offsetParam = request.getParameter("offset");
long relativeOffset = 0;
long offset;
try {
if (offsetParam != null) {
relativeOffset = Long.parseLong(offsetParam);
}
} catch (NumberFormatException e) {
relativeOffset = 0;
}
String endParam = request.getParameter("end");
// relative to the end of the file.
if (endParam == null) {
offset = relativeOffset;
} else {
offset = fileInfo.getLength() - relativeOffset;
}
if (offset < 0) {
offset = 0;
} else if (offset > fileInfo.getLength()) {
offset = fileInfo.getLength();
}
try {
displayFile(new AlluxioURI(currentFileInfo.getAbsolutePath()), request, offset);
} catch (AlluxioException e) {
throw new IOException(e);
}
request.setAttribute("viewingOffset", offset);
getServletContext().getRequestDispatcher("/viewFile.jsp").forward(request, response);
return;
}
setPathDirectories(currentPath, request);
filesInfo = mMaster.getFileSystemMaster().listStatus(currentPath, ListStatusOptions.defaults().setLoadMetadataType(LoadMetadataType.Always));
} catch (FileDoesNotExistException e) {
request.setAttribute("invalidPathError", "Error: Invalid Path " + e.getMessage());
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
return;
} catch (InvalidPathException e) {
request.setAttribute("invalidPathError", "Error: Invalid Path " + e.getLocalizedMessage());
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
return;
} catch (IOException e) {
request.setAttribute("invalidPathError", "Error: File " + currentPath + " is not available " + e.getMessage());
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
return;
} catch (AccessControlException e) {
request.setAttribute("invalidPathError", "Error: File " + currentPath + " cannot be accessed " + e.getMessage());
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
return;
}
List<UIFileInfo> fileInfos = new ArrayList<>(filesInfo.size());
for (FileInfo fileInfo : filesInfo) {
UIFileInfo toAdd = new UIFileInfo(fileInfo);
try {
if (!toAdd.getIsDirectory() && fileInfo.getLength() > 0) {
FileBlockInfo blockInfo = mMaster.getFileSystemMaster().getFileBlockInfoList(new AlluxioURI(toAdd.getAbsolutePath())).get(0);
List<String> locations = new ArrayList<>();
// add the in-memory block locations
for (BlockLocation location : blockInfo.getBlockInfo().getLocations()) {
WorkerNetAddress address = location.getWorkerAddress();
locations.add(address.getHost() + ":" + address.getDataPort());
}
// add underFS locations
locations.addAll(blockInfo.getUfsLocations());
toAdd.setFileLocations(locations);
}
} catch (FileDoesNotExistException e) {
request.setAttribute("FileDoesNotExistException", "Error: non-existing file " + e.getMessage());
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
return;
} catch (InvalidPathException e) {
request.setAttribute("InvalidPathException", "Error: invalid path " + e.getMessage());
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
} catch (AccessControlException e) {
request.setAttribute("AccessControlException", "Error: File " + currentPath + " cannot be accessed " + e.getMessage());
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
return;
}
fileInfos.add(toAdd);
}
Collections.sort(fileInfos, UIFileInfo.PATH_STRING_COMPARE);
request.setAttribute("nTotalFile", fileInfos.size());
// 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("/browse.jsp").forward(request, response);
return;
}
try {
int offset = Integer.parseInt(request.getParameter("offset"));
int limit = Integer.parseInt(request.getParameter("limit"));
List<UIFileInfo> sub = fileInfos.subList(offset, offset + limit);
request.setAttribute("fileInfos", sub);
} catch (NumberFormatException e) {
request.setAttribute("fatalError", "Error: offset or limit parse error, " + e.getLocalizedMessage());
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
return;
} catch (IndexOutOfBoundsException e) {
request.setAttribute("fatalError", "Error: offset or offset + limit is out of bound, " + e.getLocalizedMessage());
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
return;
} catch (IllegalArgumentException e) {
request.setAttribute("fatalError", e.getLocalizedMessage());
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
return;
}
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class WebInterfaceDownloadServlet method doGet.
/**
* Prepares for downloading a file.
*
* @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 {
if (SecurityUtils.isSecurityEnabled() && AuthenticatedClientUser.get() == null) {
AuthenticatedClientUser.set(LoginUser.get().getName());
}
String requestPath = request.getParameter("path");
if (requestPath == null || requestPath.isEmpty()) {
requestPath = AlluxioURI.SEPARATOR;
}
AlluxioURI currentPath = new AlluxioURI(requestPath);
try {
long fileId = mFsMaster.getFileId(currentPath);
FileInfo fileInfo = mFsMaster.getFileInfo(fileId);
if (fileInfo == null) {
throw new FileDoesNotExistException(currentPath.toString());
}
downloadFile(new AlluxioURI(fileInfo.getPath()), request, response);
} catch (FileDoesNotExistException e) {
request.setAttribute("invalidPathError", "Error: Invalid Path " + e.getMessage());
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
} catch (InvalidPathException e) {
request.setAttribute("invalidPathError", "Error: Invalid Path " + e.getLocalizedMessage());
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
} catch (AlluxioException e) {
request.setAttribute("invalidPathError", "Error: " + e.getLocalizedMessage());
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
}
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class FileSystemMasterTest method loadMetadata.
@Test
public void loadMetadata() throws Exception {
AlluxioURI ufsMount = new AlluxioURI(mTestFolder.newFolder().getAbsolutePath());
mFileSystemMaster.createDirectory(new AlluxioURI("/mnt/"), CreateDirectoryOptions.defaults());
// Create ufs file
Files.createFile(Paths.get(ufsMount.join("file").getPath()));
// Created nested file
Files.createDirectory(Paths.get(ufsMount.join("nested").getPath()));
Files.createFile(Paths.get(ufsMount.join("nested").join("file").getPath()));
mFileSystemMaster.mount(new AlluxioURI("/mnt/local"), ufsMount, MountOptions.defaults());
// Test simple file.
AlluxioURI uri = new AlluxioURI("/mnt/local/file");
mFileSystemMaster.loadMetadata(uri, LoadMetadataOptions.defaults().setCreateAncestors(false));
Assert.assertNotNull(mFileSystemMaster.getFileInfo(uri));
// Test nested file.
uri = new AlluxioURI("/mnt/local/nested/file");
try {
mFileSystemMaster.loadMetadata(uri, LoadMetadataOptions.defaults().setCreateAncestors(false));
Assert.fail("loadMetadata() without recursive, for a nested file should fail.");
} catch (FileDoesNotExistException e) {
// Expected case.
}
// Test the nested file with recursive flag.
mFileSystemMaster.loadMetadata(uri, LoadMetadataOptions.defaults().setCreateAncestors(true));
Assert.assertNotNull(mFileSystemMaster.getFileInfo(uri));
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class FileSystemMasterTest method renameToNonExistentParent.
@Test
public void renameToNonExistentParent() throws Exception {
CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(Constants.KB).setRecursive(true);
mFileSystemMaster.createFile(NESTED_URI, options);
try {
mFileSystemMaster.rename(NESTED_URI, new AlluxioURI("/testDNE/b"), RenameOptions.defaults());
Assert.fail("Rename to a non-existent parent path should not succeed.");
} catch (FileDoesNotExistException e) {
// Expected case
}
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class FileSystemMasterTest method mountUnmount.
@Test
public void mountUnmount() throws Exception {
AlluxioURI ufsMount = new AlluxioURI(mTestFolder.newFolder().getAbsolutePath());
mFileSystemMaster.createDirectory(new AlluxioURI("/mnt/"), CreateDirectoryOptions.defaults());
// Alluxio mount point should not exist before mounting.
try {
mFileSystemMaster.getFileInfo(new AlluxioURI("/mnt/local"));
Assert.fail("getFileInfo() for a non-existent URI (before mounting) should fail.");
} catch (FileDoesNotExistException e) {
// Expected case.
}
mFileSystemMaster.mount(new AlluxioURI("/mnt/local"), ufsMount, MountOptions.defaults());
// Alluxio mount point should exist after mounting.
Assert.assertNotNull(mFileSystemMaster.getFileInfo(new AlluxioURI("/mnt/local")));
mFileSystemMaster.unmount(new AlluxioURI("/mnt/local"));
// Alluxio mount point should not exist after unmounting.
try {
mFileSystemMaster.getFileInfo(new AlluxioURI("/mnt/local"));
Assert.fail("getFileInfo() for a non-existent URI (before mounting) should fail.");
} catch (FileDoesNotExistException e) {
// Expected case.
}
}
Aggregations