use of alluxio.wire.MasterWebUIData in project alluxio by Alluxio.
the class AlluxioMasterRestServiceHandler method getWebUIData.
/**
* Gets Web UI data page data.
*
* @param requestOffset the request offset
* @param requestLimit the request limit
* @return the response object
*/
@GET
@Path(WEBUI_DATA)
public Response getWebUIData(@DefaultValue("0") @QueryParam("offset") String requestOffset, @DefaultValue("20") @QueryParam("limit") String requestLimit) {
return RestUtils.call(() -> {
MasterWebUIData response = new MasterWebUIData();
if (!ServerConfiguration.getBoolean(PropertyKey.WEB_FILE_INFO_ENABLED)) {
return response;
}
if (SecurityUtils.isSecurityEnabled(ServerConfiguration.global()) && AuthenticatedClientUser.get(ServerConfiguration.global()) == null) {
AuthenticatedClientUser.set(ServerUserState.global().getUser().getName());
}
response.setMasterNodeAddress(mMasterProcess.getRpcAddress().toString()).setFatalError("").setShowPermissions(ServerConfiguration.getBoolean(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_ENABLED));
List<AlluxioURI> inAlluxioFiles = mFileSystemMaster.getInAlluxioFiles();
Collections.sort(inAlluxioFiles);
List<UIFileInfo> fileInfos = new ArrayList<>(inAlluxioFiles.size());
for (AlluxioURI file : inAlluxioFiles) {
try {
long fileId = mFileSystemMaster.getFileId(file);
FileInfo fileInfo = mFileSystemMaster.getFileInfo(fileId);
if (fileInfo != null && fileInfo.getInAlluxioPercentage() == 100) {
fileInfos.add(new UIFileInfo(fileInfo, ServerConfiguration.global(), new MasterStorageTierAssoc().getOrderedStorageAliases()));
}
} catch (FileDoesNotExistException e) {
response.setFatalError("Error: File does not exist " + e.getLocalizedMessage());
return response;
} catch (AccessControlException e) {
response.setPermissionError("Error: File " + file + " cannot be accessed " + e.getMessage());
return response;
}
}
response.setInAlluxioFileNum(fileInfos.size());
try {
int offset = Integer.parseInt(requestOffset);
int limit = Integer.parseInt(requestLimit);
limit = offset == 0 && limit > fileInfos.size() ? fileInfos.size() : limit;
limit = offset + limit > fileInfos.size() ? fileInfos.size() - offset : limit;
int sum = Math.addExact(offset, limit);
fileInfos = fileInfos.subList(offset, sum);
response.setFileInfos(fileInfos);
} catch (NumberFormatException e) {
response.setFatalError("Error: offset or limit parse error, " + e.getLocalizedMessage());
return response;
} catch (ArithmeticException e) {
response.setFatalError("Error: offset or offset + limit is out of bound, " + e.getLocalizedMessage());
return response;
} catch (IllegalArgumentException e) {
response.setFatalError(e.getLocalizedMessage());
return response;
}
return response;
}, ServerConfiguration.global());
}
Aggregations