private AbstractNode getResponseLevelAtDepth(final AbstractNode response, final UrlPath path) throws ResourceNotFoundException { if (path.getDepth() != UrlPath.INFINITE_DEPTH && !response.isLeaf() && response instanceof ItemNode) { return path.cutTreeToDepth((ItemNode) response); } else { return response; } }
@Override public AbstractNode process(final Account account, final HttpServletRequest request) throws IOException { final UrlPath path = new UrlPath(request); final PluginConfig config = account.getPluginConfig(path.getPluginId()); final Plugin plugin = pluginLoader.get(config.getKey().getType()); return getResponseLevelAtDepth( dispatchToPlugin( account, new WrappedHttpRequest(request, getPluginBaseRequestPath(request), "/"), path, plugin, config), path); }
@Override public ItemNode toAbstractNode(String urlPrefix) { ItemNode result = new ItemNode(); result.setLayout(Layout.LIST); result.setVersion(ItemNode.API_VERSION); result.setPath(UrlPath.normalizePath(path)); result.setDescriptionAlign(Alignment.BOTTOM); result.setTitle(displayName); result.setIcon( result.getPath() + "?image=" + (isOffline() ? "icons/computer_offline.png" : "icons/computer_online.png")); if (getMonitorData().getArchitectureMonitor() != null) { result.setDescription( getNumExecutors() + " executors - " + getMonitorData().getArchitectureMonitor()); } else { result.setDescription(getNumExecutors() + " executors - N/A"); } if (getMonitorData().getArchitectureMonitor() != null) { ItemNode childNode = new ItemNode("Operating System", getMonitorData().getArchitectureMonitor()); childNode.setDescriptionAlign(Alignment.RIGHT); result.addNode(childNode); } ItemNode childNode = new ItemNode("Status", isOffline() ? "OFF-LINE" : "ON-LINE"); childNode.setDescriptionAlign(Alignment.RIGHT); childNode.setDescriptionColor(isOffline() ? "#FF0000" : "#00FF00"); result.addNode(childNode); childNode = new ItemNode("Number of executors", Integer.toString(getNumExecutors())); childNode.setDescriptionAlign(Alignment.RIGHT); result.addNode(childNode); if (getMonitorData().getSwapSpaceMonitor() != null) { long totRam = getMonitorData().getSwapSpaceMonitor().getTotalPhysicalMemory() / 1024 / 1024; long availRam = getMonitorData().getSwapSpaceMonitor().getAvailablePhysicalMemory() / 1024 / 1024; childNode = new ItemNode("RAM", "" + availRam + "/" + totRam + " MB"); childNode.setDescriptionAlign(Alignment.RIGHT); result.addNode(childNode); long totSwap = getMonitorData().getSwapSpaceMonitor().getTotalSwapSpace() / 1024 / 1024; long availSwap = getMonitorData().getSwapSpaceMonitor().getAvailableSwapSpace() / 1024 / 1024; childNode = new ItemNode("SWAP", "" + availSwap + "/" + totSwap + " MB"); childNode.setDescriptionAlign(Alignment.RIGHT); result.addNode(childNode); } result.setLeaf(true); return result; }
private AbstractNode dispatchToPlugin( final Account account, final HttpServletRequest request, final UrlPath urlPath, final Plugin pluginInstance, final PluginConfig pluginConf) throws IOException { AbstractNode response = pluginInstance.processRequest(account, request, pluginConf); if (response == null) { throw new ResourceNotFoundException( "Plugin " + pluginInstance + " did not produce any response"); } if ("application/json".equals(response.getHttpContentType()) && response instanceof ItemNode) { response = urlPath.followPath((ItemNode) response); } return response; }