Search in sources :

Example 1 with MasterWebUIData

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());
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) ArrayList(java.util.ArrayList) AccessControlException(alluxio.exception.AccessControlException) MasterWebUIData(alluxio.wire.MasterWebUIData) MasterStorageTierAssoc(alluxio.MasterStorageTierAssoc) UIFileInfo(alluxio.util.webui.UIFileInfo) FileInfo(alluxio.wire.FileInfo) UIFileInfo(alluxio.util.webui.UIFileInfo) AlluxioURI(alluxio.AlluxioURI) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

AlluxioURI (alluxio.AlluxioURI)1 MasterStorageTierAssoc (alluxio.MasterStorageTierAssoc)1 AccessControlException (alluxio.exception.AccessControlException)1 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)1 UIFileInfo (alluxio.util.webui.UIFileInfo)1 FileInfo (alluxio.wire.FileInfo)1 MasterWebUIData (alluxio.wire.MasterWebUIData)1 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1