public List<GraphNode> enumerateChildsGraph() { return enumerateChildsGraph(null); }
@Override public GraphTree setRoot(GraphTree gt) { return gt.getByPath(GraphTree.SUMROOT); } };
/** * Create a new graph tree * * @param label The name of the tree * @param root The name of the first element in the tree * @return a graph tree */ private GraphTree addTree(String label, String root) { if(!treeMap.containsKey(label)) { GraphTree newTree = GraphTree.makeGraph(root); treeMap.put(label, newTree); return newTree; } return null; }
/** * The only way to get a new graph * * @param root the graph's root name * @return */ public static GraphTree makeGraph(String root) { GraphTree rootNode = new GraphTree(root); rootNode.pathsMap = new HashMap<Integer, GraphTree>(); rootNode.pathsMap.put(rootNode.getPath().hashCode(), rootNode); return rootNode; }
private void _addGraphByPath(LinkedList<String> path, GraphNode nodesGraph) { if(path.size() == 1 && nodesGraph != null) { graphsSet.put(path.getLast(), nodesGraph); } else if(!path.isEmpty()) { String pathElem = path.removeFirst(); addChild(pathElem); getChildbyName(pathElem)._addGraphByPath(path, nodesGraph); } }
@Test public void test1() { GraphTree gt1 = GraphTree.makeGraph("root"); GraphNode gn = new MockGraph(); gt1.addGraphByPath(doList("a", "b", gn.getName()), gn); Assert.assertNotNull("Graph node not found", gt1.getByPath("root", "a", "b")); }
private String sub(ParamsBean params, JrdsJSONWriter w, GraphTree gt, String type, Filter f, String path, int base) throws IOException { String id = null; String subpath = path + "/" + gt.getName(); boolean hasChild = false; Map<String, GraphTree> childs = gt.getChildsMap(); for(Map.Entry<String, GraphNode> leaf: gt.getGraphsSet().entrySet()) { GraphNode child = leaf.getValue(); if(getPropertiesManager().security && !child.getACL().check(params)) continue; String leafName = leaf.getKey(); if(f.acceptGraph(child, gt.getPath() + "/" + child.getName())) { hasChild = true; String graphid = base + "." + child.hashCode(); id = base + "." + gt.getPath().hashCode(); doTree(w, gt.getName(), id, type, childsref);
/** * @param f, can be null * @return */ public List<GraphNode> enumerateChildsGraph(Filter f) { List<GraphNode> retValue = new ArrayList<GraphNode>(); if(graphsSet != null) { if(f == null) retValue.addAll(graphsSet.values()); else { for(GraphNode g: graphsSet.values()) { String path = this.getPath() + "/" + g.getName(); if(f.acceptGraph(g, path)) retValue.add(g); } } } if(childsMap != null) { for(GraphTree child: childsMap.values()) { retValue.addAll(child.enumerateChildsGraph(f)); } } return retValue; }
logger.debug(hl.getTrees()); for(GraphTree graphTree: hl.getTrees()) { logger.trace("Tree found: " + graphTree.getName()); for(GraphNode gn: graphTree.enumerateChildsGraph(null)) { if(!done.contains(gn.hashCode())) { done.add(gn.hashCode());
public GraphTree getGraphTree() { GraphTree gt = GraphTree.makeGraph(name); for(Map.Entry<String, List<String>> e: paths.entrySet()) { String id = e.getKey(); List<String> path = e.getValue(); GraphNode gn = hostlist.getGraphById(id.hashCode()); if(gn == null) { logger.warn(jrds.Util.delayedFormatString("Graph not found for %s: %s", name, id)); continue; } gt.addGraphByPath(path, gn); } return gt; } }
void doCustomGraphs(Map<String, GraphDesc> graphs, Map<Integer, GraphNode> graphMap, Map<String, GraphTree> treeMap, Set<Tab> tabs) { log(Level.DEBUG, "Parsing graphs configuration"); // Let's build the tab with all the custom graphs if(!graphs.isEmpty()) { Tab customGraphsTab = new Tab.DynamicTree("Custom graphs", PropertiesManager.CUSTOMGRAPHTAB); customGraphsTab.setHostlist(this); for(GraphDesc gd: graphs.values()) { AutonomousGraphNode gn = new AutonomousGraphNode(gd); gn.configure(this); graphMap.put(gn.getQualifiedName().hashCode(), gn); customGraphsTab.add(gn.getQualifiedName(), Arrays.asList(new String[] { gd.getName() })); } GraphTree tree = customGraphsTab.getGraphTree(); treeMap.put(tree.getName(), tree); tabs.add(customGraphsTab); } }
public void addGraphs(Collection<GraphNode> graphs) { for(GraphNode currGraph: graphs) { LinkedList<String> path; path = currGraph.getTreePathByHost(); getGraphTreeByHost().addGraphByPath(path, currGraph); path = currGraph.getTreePathByView(); getGraphTreeByView().addGraphByPath(path, currGraph); graphMap.put(currGraph.hashCode(), currGraph); } }
private void init() { filters.put(Filter.EVERYTHING.getName(), Filter.EVERYTHING); addTree(Filter.ALLHOSTS.getName(), GraphTree.HOSTROOT); filters.put(Filter.ALLHOSTS.getName(), Filter.ALLHOSTS); GraphTree viewtree = addTree(Filter.ALLVIEWS.getName(), GraphTree.VIEWROOT); viewtree.addPath("Services"); filters.put(Filter.ALLVIEWS.getName(), Filter.ALLVIEWS); treeMap.put(Filter.ALLSERVICES.getName(), Filter.ALLSERVICES.setRoot(viewtree)); filters.put(Filter.ALLSERVICES.getName(), Filter.ALLSERVICES); addTree("All tags", GraphTree.TAGSROOT); }
public String getPath() { return _getPath().toString(); } }
/** * Create an empty path in a tree * * @param path */ public void addPath(String... path) { if(path.length < 1) { logger.error("Path is empty"); } else _addGraphByPath(new LinkedList<String>(Arrays.asList(path)), null); }
private boolean evaluateFilter(ParamsBean params, JrdsJSONWriter w, HostsList root, Filter f) throws IOException { Collection<GraphTree> level = root.getTrees(); // We construct the graph tree root to use // The tree is parsed twice, that's not optimal Collection<GraphTree> rootToDo = new HashSet<GraphTree>(level.size()); for(GraphTree tree: level) { GraphTree testTree = f.setRoot(tree); if(testTree != null && !rootToDo.contains(testTree) && testTree.enumerateChildsGraph(f).size() > 0) { rootToDo.add(testTree); } } for(GraphTree tree: findRoot(rootToDo)) { sub(params, w, tree, "tree", f, "", tree.getPath().hashCode()); } return true; }
void doSums(Map<String, Sum> sums, Map<Integer, GraphNode> graphMap, Map<String, GraphTree> treeMap, Set<Tab> tabs) { // Let's build the tab with all the sums if(sums.size() > 0) { Tab sumGraphsTab = new Tab.DynamicTree("Sums", PropertiesManager.SUMSTAB); sumGraphsTab.setHostlist(this); for(Sum s: sums.values()) { try { s.configure(this); graphMap.put(s.getQualifiedName().hashCode(), s); sumGraphsTab.add(s.getQualifiedName(), "Sums", s.getName()); } catch (Exception e1) { log(Level.ERROR, e1, "failed sum: %s", e1); } } GraphTree tree = sumGraphsTab.getGraphTree(); treeMap.put(tree.getName(), tree); tabs.add(sumGraphsTab); } }
private StringBuilder _getPath() { StringBuilder retValue; if(parent == null) retValue = new StringBuilder(); else retValue = parent._getPath(); retValue.append('/'); retValue.append(name); return retValue; }