use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class CpCommand method copyWildcard.
/**
* Copies a list of files or directories specified by srcPaths to the destination specified by
* dstPath. This method is used when the original source path contains wildcards.
*
* @param srcPaths a list of files or directories in the Alluxio filesystem
* @param dstPath the destination in the Alluxio filesystem
* @param recursive indicates whether directories should be copied recursively
* @throws AlluxioException when Alluxio exception occurs
* @throws IOException when non-Alluxio exception occurs
*/
private void copyWildcard(List<AlluxioURI> srcPaths, AlluxioURI dstPath, boolean recursive) throws AlluxioException, IOException {
URIStatus dstStatus = null;
try {
dstStatus = mFileSystem.getStatus(dstPath);
} catch (FileDoesNotExistException e) {
// if the destination does not exist, it will be created
}
if (dstStatus != null && !dstStatus.isFolder()) {
throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage());
}
if (dstStatus == null) {
mFileSystem.createDirectory(dstPath);
System.out.println("Created directory: " + dstPath);
}
List<String> errorMessages = new ArrayList<>();
for (AlluxioURI srcPath : srcPaths) {
try {
copy(srcPath, new AlluxioURI(dstPath.getScheme(), dstPath.getAuthority(), PathUtils.concatPath(dstPath.getPath(), srcPath.getName())), recursive);
} catch (AlluxioException | IOException e) {
errorMessages.add(e.getMessage());
}
}
if (errorMessages.size() != 0) {
throw new IOException(Joiner.on('\n').join(errorMessages));
}
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class CatCommand method runCommand.
@Override
protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException {
URIStatus status = mFileSystem.getStatus(path);
if (status.isFolder()) {
throw new FileDoesNotExistException(ExceptionMessage.PATH_MUST_BE_FILE.getMessage(path));
}
OpenFileOptions options = OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE);
byte[] buf = new byte[512];
try (FileInStream is = mFileSystem.openFile(path, options)) {
int read = is.read(buf);
while (read != -1) {
System.out.write(buf, 0, read);
read = is.read(buf);
}
}
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class WebInterfaceMemoryServlet 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
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (SecurityUtils.isSecurityEnabled() && AuthenticatedClientUser.get() == null) {
AuthenticatedClientUser.set(LoginUser.get().getName());
}
request.setAttribute("masterNodeAddress", mMaster.getRpcAddress().toString());
request.setAttribute("fatalError", "");
request.setAttribute("showPermissions", Configuration.getBoolean(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_ENABLED));
List<AlluxioURI> inMemoryFiles = mMaster.getFileSystemMaster().getInMemoryFiles();
Collections.sort(inMemoryFiles);
List<UIFileInfo> fileInfos = new ArrayList<>(inMemoryFiles.size());
for (AlluxioURI file : inMemoryFiles) {
try {
long fileId = mMaster.getFileSystemMaster().getFileId(file);
FileInfo fileInfo = mMaster.getFileSystemMaster().getFileInfo(fileId);
if (fileInfo != null && fileInfo.getInMemoryPercentage() == 100) {
fileInfos.add(new UIFileInfo(fileInfo));
}
} catch (FileDoesNotExistException e) {
request.setAttribute("fatalError", "Error: File does not exist " + e.getLocalizedMessage());
getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
return;
} catch (AccessControlException e) {
request.setAttribute("permissionError", "Error: File " + file + " cannot be accessed " + e.getMessage());
getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
return;
}
}
request.setAttribute("inMemoryFileNum", fileInfos.size());
// and redirect to "./memory?offset=xxx&limit=xxx"
if (request.getParameter("offset") == null && request.getParameter("limit") == null) {
getServletContext().getRequestDispatcher("/memory.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("/memory.jsp").forward(request, response);
return;
} catch (IndexOutOfBoundsException e) {
request.setAttribute("fatalError", "Error: offset or offset + limit is out of bound, " + e.getLocalizedMessage());
getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
return;
} catch (IllegalArgumentException e) {
request.setAttribute("fatalError", e.getLocalizedMessage());
getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
return;
}
getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class LineageMaster method reinitializeFile.
/**
* Reinitializes the file when the file is lost or not completed.
*
* @param path the path to the file
* @param blockSizeBytes the block size
* @param ttl the TTL
* @param ttlAction action to perform on ttl expiry
* @return the id of the reinitialized file when the file is lost or not completed, -1 otherwise
* @throws InvalidPathException the file path is invalid
* @throws LineageDoesNotExistException when the file does not exist
* @throws AccessControlException if permission checking fails
* @throws FileDoesNotExistException if the path does not exist
*/
public synchronized long reinitializeFile(String path, long blockSizeBytes, long ttl, TtlAction ttlAction) throws InvalidPathException, LineageDoesNotExistException, AccessControlException, FileDoesNotExistException {
long fileId = mFileSystemMaster.getFileId(new AlluxioURI(path));
FileInfo fileInfo;
try {
fileInfo = mFileSystemMaster.getFileInfo(fileId);
if (!fileInfo.isCompleted() || mFileSystemMaster.getLostFiles().contains(fileId)) {
LOG.info("Recreate the file {} with block size of {} bytes", path, blockSizeBytes);
return mFileSystemMaster.reinitializeFile(new AlluxioURI(path), blockSizeBytes, ttl, ttlAction);
}
} catch (FileDoesNotExistException e) {
throw new LineageDoesNotExistException(ExceptionMessage.MISSING_REINITIALIZE_FILE.getMessage(path));
}
return -1;
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class CheckpointLatestPlanner method generatePlan.
@Override
public CheckpointPlan generatePlan(LineageStoreView store, FileSystemMasterView fileSystemMasterView) {
Lineage toCheckpoint = null;
long latestCreated = 0;
for (Lineage lineage : store.getAllLineagesInTopologicalOrder()) {
try {
if (!LineageStateUtils.isCompleted(lineage, fileSystemMasterView) || LineageStateUtils.isPersisted(lineage, fileSystemMasterView) || LineageStateUtils.needRecompute(lineage, fileSystemMasterView) || LineageStateUtils.isInCheckpointing(lineage, fileSystemMasterView)) {
continue;
}
} catch (FileDoesNotExistException | AccessControlException e) {
LOG.error("The lineage file does not exist", e);
continue;
}
if (lineage.getCreationTime() > latestCreated) {
latestCreated = lineage.getCreationTime();
toCheckpoint = lineage;
}
}
return toCheckpoint == null ? new CheckpointPlan(new ArrayList<Long>()) : new CheckpointPlan(Lists.newArrayList(toCheckpoint.getId()));
}
Aggregations