public AutonomousGraphNode(GraphDesc gd) { this.name = gd.getName(); setGraphDesc(gd); setProbe(new ContainerProbe(name)); }
public Graph getGraph() { Class<Graph> gclass = gd.getGraphClass(); Graph g; Map<String, GenericBean> beansList; try { g = gclass.getConstructor(GraphNode.class).newInstance(this); beansList = ArgFactory.getBeanPropertiesMap(gclass, Graph.class); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { Util.log(this, logger, Level.ERROR, e, "Failed to build a graph instance %s", gclass.getCanonicalName()); return null; } // Resolve the beans for(Map.Entry<String, String> e: beans.entrySet()) { String name = Util.parseTemplate(e.getKey(), probe); String textValue = Util.parseTemplate(e.getValue(), probe); GenericBean bean = beansList.get(name); if(bean == null) { logger.error(String.format("Unknown bean for %s: %s", gd.getName(), name)); continue; } logger.trace(Util.delayedFormatString("Found attribute %s with value %s", name, textValue)); bean.set(g, textValue); } return g; }
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); } }
@Test public void testCustomGraph() throws IOException { PropertiesManager pm = Tools.makePm(testFolder); pm.setProperty("tabs", "filtertab"); pm.update(); HostsList hl = new HostsList(pm); GraphDesc gd = new GraphDesc(); gd.setName("truc"); gd.setGraphTitle("title"); Map<String, GraphDesc> gdmap = new HashMap<String, GraphDesc>(); gdmap.put(gd.getName(), gd); Set<Tab> tabs = new HashSet<Tab>(); Map<Integer, GraphNode> graphMap = new HashMap<Integer, GraphNode>(); Map<String, GraphTree> graphTrees = new HashMap<String, GraphTree>(); hl.doCustomGraphs(gdmap, graphMap, graphTrees, tabs); hl.addGraphs(graphMap.values()); boolean found = false; GraphNode node = null; for(Tab t: tabs) { if(PropertiesManager.CUSTOMGRAPHTAB.equals(t.id)) { found = true; t.setHostlist(hl); node = t.getGraphTree().enumerateChildsGraph().get(0); } } Assert.assertNotNull(graphMap.get(node.hashCode())); Assert.assertTrue(found); Assert.assertNotEquals(graphTrees.size(), 0); } }
Assert.assertEquals("graph name failed", "graphdesctest", gd.getName()); Assert.assertEquals("legend count failed", 5, gd.getLegendLines()); Assert.assertFalse("Graph unit should be binary", gd.isSiUnit());
@Test public void loadGraphDesc() throws Exception { JrdsDocument d = Tools.parseRessource("graphdesc2.xml"); GraphDescBuilder builder = new GraphDescBuilder(); builder.setPm(new PropertiesManager()); GraphDesc gd = (GraphDesc) builder.build(d); Assert.assertEquals("mokegraph", gd.getName()); Assert.assertEquals("mokegraphname", gd.getGraphName()); Assert.assertEquals("mokegraphtitle", gd.getGraphTitle()); Assert.assertTrue(gd.isSiUnit()); Assert.assertEquals("verticallabel", gd.getVerticalLabel()); GraphNode gn = new GraphNode(GetMoke.getProbe(), gd); logger.debug(gd.getHostTree(gn)); logger.debug(gd.getViewTree(gn)); }
@Test public void loadGraph() throws Exception { JrdsDocument d = Tools.parseRessource("customgraph.xml"); GraphDescBuilder builder = new GraphDescBuilder(); builder.setPm(new PropertiesManager()); GraphDesc gd = (GraphDesc) builder.build(d); Assert.assertEquals("name", gd.getName()); Assert.assertEquals("graphName", gd.getGraphName()); Assert.assertEquals("", gd.getGraphTitle()); Assert.assertTrue(gd.isSiUnit()); Assert.assertEquals("verticalLabel", gd.getVerticalLabel()); GraphNode gn = new GraphNode(GetMoke.getProbe(), gd); logger.debug(gd.getHostTree(gn)); logger.debug(gd.getViewTree(gn)); }
@Test public void testCustomGraph() throws Exception { JrdsDocument d = Tools.parseRessource("customgraph.xml"); GraphDescBuilder gdbuild = new GraphDescBuilder(); gdbuild.setPm(Tools.makePm(testFolder)); GraphDesc gd = gdbuild.makeGraphDesc(d); Assert.assertEquals("graph name failed", "graphName", gd.getGraphName()); Assert.assertEquals("graph title failed", "", gd.getGraphTitle()); Assert.assertEquals("graph name failed", "name", gd.getName()); Assert.assertEquals("graph height invalid", 800, gd.getHeight()); Assert.assertEquals("graph width invalid", 600, gd.getWidth()); Assert.assertTrue("Lower limit is a number (not a NaN)" + gd.getUpperLimit(), Double.isNaN(gd.getUpperLimit())); Assert.assertEquals("graph lower limit is invalid", 1000, gd.getLowerLimit(), 0.1); Assert.assertFalse("graph is with legend", gd.withLegend()); Assert.assertFalse("graph is with summary", gd.withSummary()); Assert.assertEquals("legend count failed", 0, gd.getLegendLines()); }