use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class BlockMasterSync method registerWithMaster.
/**
* Registers with the Alluxio master. This should be called before the continuous heartbeat thread
* begins.
*
* @throws IOException when workerId cannot be found
* @throws ConnectionFailedException if network connection failed
*/
private void registerWithMaster() throws IOException, ConnectionFailedException {
BlockStoreMeta storeMeta = mBlockWorker.getStoreMetaFull();
try {
StorageTierAssoc storageTierAssoc = new WorkerStorageTierAssoc();
mMasterClient.register(mWorkerId.get(), storageTierAssoc.getOrderedStorageAliases(), storeMeta.getCapacityBytesOnTiers(), storeMeta.getUsedBytesOnTiers(), storeMeta.getBlockList());
} catch (IOException e) {
LOG.error("Failed to register with master.", e);
throw e;
} catch (AlluxioException e) {
LOG.error("Failed to register with master.", e);
throw new IOException(e);
}
}
use of alluxio.exception.AlluxioException 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);
}
use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class FileWorkerMasterSyncExecutor method heartbeat.
@Override
public void heartbeat() {
List<Long> persistedFiles = mFileDataManager.getPersistedFiles();
if (!persistedFiles.isEmpty()) {
LOG.info("files {} persisted", persistedFiles);
}
FileSystemCommand command;
try {
command = mMasterClient.heartbeat(mWorkerId.get(), persistedFiles);
} catch (IOException | AlluxioException e) {
LOG.error("Failed to heartbeat to master", e);
return;
}
// removes the persisted files that are confirmed
mFileDataManager.clearPersistedFiles(persistedFiles);
if (command == null) {
LOG.error("The command sent from master is null");
return;
} else if (command.getCommandType() != CommandType.Persist) {
LOG.error("The command sent from master should be PERSIST type, but was {}", command.getCommandType());
return;
}
for (PersistFile persistFile : command.getCommandOptions().getPersistOptions().getPersistFiles()) {
// Enqueue the persist request.
mPersistFileService.execute(new FilePersister(mFileDataManager, persistFile.getFileId(), persistFile.getBlockIds()));
}
}
use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class AlluxioFuseFileSystem method getattr.
/**
* Retrieves file attributes.
*
* @param path The path on the FS of the file
* @param stat FUSE data structure to fill with file attrs
* @return 0 on success, negative value on error
*/
@Override
public int getattr(String path, FileStat stat) {
final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
LOG.trace("getattr({}) [Alluxio: {}]", path, turi);
try {
if (!mFileSystem.exists(turi)) {
return -ErrorCodes.ENOENT();
}
final URIStatus status = mFileSystem.getStatus(turi);
stat.st_size.set(status.getLength());
final long ctime_sec = status.getLastModificationTimeMs() / 1000;
//keeps only the "residual" nanoseconds not caputred in
// citme_sec
final long ctime_nsec = (status.getLastModificationTimeMs() % 1000) * 1000;
stat.st_ctim.tv_sec.set(ctime_sec);
stat.st_ctim.tv_nsec.set(ctime_nsec);
stat.st_mtim.tv_sec.set(ctime_sec);
stat.st_mtim.tv_nsec.set(ctime_nsec);
// TODO(andreareale): understand how to map FileInfo#getOwner()
// and FileInfo#getGroup() to UIDs and GIDs of the node
// where alluxio-fuse is mounted.
// While this is not done, just use uid and gid of the user
// running alluxio-fuse.
stat.st_uid.set(UID_AND_GID[0]);
stat.st_gid.set(UID_AND_GID[1]);
final int mode;
if (status.isFolder()) {
mode = FileStat.S_IFDIR;
} else {
mode = FileStat.S_IFREG;
}
stat.st_mode.set(mode);
} catch (InvalidPathException e) {
LOG.debug("Invalid path {}", path, e);
return -ErrorCodes.ENOENT();
} catch (FileDoesNotExistException e) {
LOG.debug("File does not exist {}", path, e);
return -ErrorCodes.ENOENT();
} catch (IOException e) {
LOG.error("IOException on {}", path, e);
return -ErrorCodes.EIO();
} catch (AlluxioException e) {
LOG.error("AlluxioException on {}", path, e);
return -ErrorCodes.EFAULT();
} catch (Throwable e) {
LOG.error("Unexpected exception on {}", path, e);
return -ErrorCodes.EFAULT();
}
return 0;
}
use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class AlluxioFuseFileSystem method rmInternal.
/**
* Convenience internal method to remove files or directories.
*
* @param path The path to remove
* @param mustBeFile When true, returns an error when trying to
* remove a directory
* @return 0 on success, a negative value on error
*/
private int rmInternal(String path, boolean mustBeFile) {
final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
try {
if (!mFileSystem.exists(turi)) {
LOG.error("File {} does not exist", turi);
return -ErrorCodes.ENOENT();
}
final URIStatus status = mFileSystem.getStatus(turi);
if (mustBeFile && status.isFolder()) {
LOG.error("File {} is a directory", turi);
return -ErrorCodes.EISDIR();
}
mFileSystem.delete(turi);
} catch (FileDoesNotExistException e) {
LOG.debug("File does not exist {}", path, e);
return -ErrorCodes.ENOENT();
} catch (IOException e) {
LOG.error("IOException on {}", path, e);
return -ErrorCodes.EIO();
} catch (AlluxioException e) {
LOG.error("AlluxioException on {}", path, e);
return -ErrorCodes.EFAULT();
} catch (Throwable e) {
LOG.error("Unexpected exception on {}", path, e);
return -ErrorCodes.EFAULT();
}
return 0;
}
Aggregations