use of alluxio.wire.WorkerWebUIBlockInfo in project alluxio by Alluxio.
the class AlluxioWorkerRestServiceHandler method getWebUIBlockInfo.
/**
* Gets web ui block info page data.
*
* @param requestPath the request path
* @param requestOffset the request offset
* @param requestLimit the request limit
* @return the response object
*/
@GET
@Path(WEBUI_BLOCKINFO)
public Response getWebUIBlockInfo(@QueryParam("path") String requestPath, @DefaultValue("0") @QueryParam("offset") String requestOffset, @DefaultValue("20") @QueryParam("limit") String requestLimit) {
return RestUtils.call(() -> {
WorkerWebUIBlockInfo response = new WorkerWebUIBlockInfo();
if (!ServerConfiguration.getBoolean(PropertyKey.WEB_FILE_INFO_ENABLED)) {
return response;
}
response.setFatalError("").setInvalidPathError("");
if (!(requestPath == null || requestPath.isEmpty())) {
// Display file block info
try {
URIStatus status = mFsClient.getStatus(new AlluxioURI(requestPath));
UIFileInfo uiFileInfo = new UIFileInfo(status, ServerConfiguration.global(), new WorkerStorageTierAssoc().getOrderedStorageAliases());
for (long blockId : status.getBlockIds()) {
if (mBlockWorker.hasBlockMeta(blockId)) {
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);
}
}
List<ImmutablePair<String, List<UIFileBlockInfo>>> fileBlocksOnTier = new ArrayList<>();
for (Map.Entry<String, List<UIFileBlockInfo>> e : uiFileInfo.getBlocksOnTier().entrySet()) {
fileBlocksOnTier.add(new ImmutablePair<>(e.getKey(), e.getValue()));
}
response.setFileBlocksOnTier(fileBlocksOnTier).setBlockSizeBytes(uiFileInfo.getBlockSizeBytes()).setPath(requestPath);
} catch (FileDoesNotExistException e) {
response.setFatalError("Error: Invalid Path " + e.getMessage());
} catch (IOException e) {
response.setInvalidPathError("Error: File " + requestPath + " is not available " + e.getMessage());
} catch (BlockDoesNotExistException e) {
response.setFatalError("Error: block not found. " + e.getMessage());
} catch (AlluxioException e) {
response.setFatalError("Error: alluxio exception. " + e.getMessage());
}
}
Set<Long> unsortedFileIds = new HashSet<>();
BlockStoreMeta storeMeta = mBlockWorker.getStoreMetaFull();
for (List<Long> blockIds : storeMeta.getBlockList().values()) {
for (long blockId : blockIds) {
unsortedFileIds.add(BlockId.getFileId(blockId));
}
}
List<Long> fileIds = new ArrayList<>(unsortedFileIds);
Collections.sort(fileIds);
response.setNTotalFile(unsortedFileIds.size()).setOrderedTierAliases(new WorkerStorageTierAssoc().getOrderedStorageAliases());
try {
int offset = Integer.parseInt(requestOffset);
int limit = Integer.parseInt(requestLimit);
// make the limit the total number of files if request limit is > than what is available
limit = offset == 0 && limit > fileIds.size() ? fileIds.size() : limit;
// offset+limit can't be greater than the size of the list
limit = offset + limit > fileIds.size() ? fileIds.size() - offset : limit;
int sum = Math.addExact(offset, limit);
List<Long> subFileIds = fileIds.subList(offset, sum);
List<UIFileInfo> uiFileInfos = new ArrayList<>(subFileIds.size());
for (long fileId : subFileIds) {
try {
URIStatus status = new URIStatus(mBlockWorker.getFileInfo(fileId));
UIFileInfo uiFileInfo = new UIFileInfo(status, ServerConfiguration.global(), new WorkerStorageTierAssoc().getOrderedStorageAliases());
for (long blockId : status.getBlockIds()) {
if (mBlockWorker.hasBlockMeta(blockId)) {
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 (!uiFileInfo.getBlockIds().isEmpty()) {
uiFileInfos.add(uiFileInfo);
}
} catch (Exception 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.toString());
}
}
response.setFileInfos(uiFileInfos);
} catch (NumberFormatException e) {
response.setFatalError("Error: offset or limit parse error, " + e.getLocalizedMessage());
} catch (ArithmeticException e) {
response.setFatalError("Error: offset or offset + limit is out ofbound, " + e.getLocalizedMessage());
} catch (Exception e) {
response.setFatalError(e.getLocalizedMessage());
}
return response;
}, ServerConfiguration.global());
}
Aggregations