public void start(String[] args) throws Exception { PropertiesManager pm = new PropertiesManager(new File(propFile)); jrds.JrdsLoggerConfiguration.configure(pm); System.getProperties().setProperty("java.awt.headless", "true"); System.getProperties().putAll(pm); HostsList hl = new HostsList(pm); logger.debug("Scanning dir"); for(Timer t: hl.getTimers()) { t.collectAll(); } }
@Override public void reload() { PropertiesManager pm = new PropertiesManager(); if(configfile != null && configfile.isFile()) pm.join(configfile); else if(ctxt != null) { StartListener sl = (StartListener) ctxt.getAttribute(StartListener.class.getName()); Properties p = sl.readProperties(ctxt); pm.join(p); } pm.importSystemProps(); Configuration.switchConf(pm); }
public static void main(String[] args) throws IOException { jrds.JrdsLoggerConfiguration.initLog4J(); PropertiesManager pm = new PropertiesManager(new File("jrds.properties")); pm.configureStores();
public void start(String args[]) throws Exception { PropertiesManager pm = new PropertiesManager(); File propFile = new File(propFileName); if(propFile.isFile()) {
@Test(expected = IllegalArgumentException.class) public void testConfigNoAutoCreate() throws IOException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException { PropertiesManager pm = new PropertiesManager(); Map<String, File> dirMap = new HashMap<String, File>(dirs.length); for(String dirname: dirs) { File dir = testFolder.newFolder(dirname); dir.delete(); pm.setProperty(dirname, dir.getPath()); dirMap.put(dirname, dir); } pm.setProperty("autocreate", "false"); pm.update(); }
@Test public void testTmpDir() throws IOException { String oldtmpdirpath = System.getProperty("java.io.tmpdir"); File newtmpdir = testFolder.newFile("tmp"); newtmpdir.delete(); newtmpdir.mkdir(); System.setProperty("java.io.tmpdir", newtmpdir.getPath()); PropertiesManager pm = new PropertiesManager(); pm.setProperty("configdir", testFolder.getRoot().getCanonicalPath()); pm.setProperty("rrddir", testFolder.getRoot().getCanonicalPath()); pm.update(); System.setProperty("java.io.tmpdir", oldtmpdirpath); File jrdstmpdir = new File(newtmpdir, "jrds"); Assert.assertEquals(jrdstmpdir.getCanonicalPath(), pm.tmpdir.getCanonicalPath()); Assert.assertTrue("tmpdir should have been created", newtmpdir.exists()); }
@Test public void testConfigAutoCreate() throws IOException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException { PropertiesManager pm = new PropertiesManager(); Map<String, File> dirMap = new HashMap<String, File>(dirs.length); for(String dirname: dirs) { File dir = testFolder.newFolder(dirname); pm.setProperty(dirname, dir.getPath()); dirMap.put(dirname, dir); } pm.setProperty("autocreate", "true"); pm.update(); // Match the given name and was created for(Map.Entry<String, File> e: dirMap.entrySet()) { File dir = e.getValue(); Assert.assertEquals(dir.getPath(), pm.getClass().getDeclaredField(e.getKey()).get(pm).toString()); Assert.assertTrue(dir.isDirectory()); } }
@Test(expected = RuntimeException.class) public void emptysum() throws Exception { HostsList hl = new HostsList(); hl.configure(new PropertiesManager()); ArrayList<String> graphlist = new ArrayList<String>(); graphlist.add("badhost/badgraph"); Sum s = new Sum("emptysum", graphlist); s.configure(hl); }
@Test public void testlog4jpropfile() throws IOException { try (InputStream is = getClass().getClassLoader().getResourceAsStream("log4j.properties")) { ReadableByteChannel isChannel = Channels.newChannel(is); File log4jprops = testFolder.newFile("log4j.properties"); try (FileOutputStream fos = new java.io.FileOutputStream(log4jprops)) { fos.getChannel().transferFrom(isChannel, 0, 4096); PropertiesManager pm = new PropertiesManager(); pm.setProperty("configdir", testFolder.getRoot().getCanonicalPath()); pm.setProperty("rrddir", testFolder.getRoot().getCanonicalPath()); pm.setProperty("tmpdir", testFolder.getRoot().getCanonicalPath()); pm.setProperty("log4jpropfile", log4jprops.getCanonicalPath()); pm.update(); logger.debug("log file created"); File logFile = new File("tmp/log4j.log"); Assert.assertTrue("Log4j file not created", logFile.canRead()); logFile.delete(); } } }
static final public <T> ProbeDesc<T> getProbeDesc(JrdsDocument node) throws Exception { ProbeDescBuilder builder = new ProbeDescBuilder(); builder.setPm(new PropertiesManager()); return builder.makeProbeDesc(node); } }
@Test public void testDefaultStoreEmpty() throws IOException { PropertiesManager pm = new PropertiesManager(); pm.setProperty("configdir", testFolder.getRoot().getCanonicalPath()); pm.setProperty("rrddir", testFolder.getRoot().getCanonicalPath()); pm.setProperty("tmpdir", testFolder.getRoot().getCanonicalPath()); pm.setProperty("storefactory", jrds.store.CacheStoreFactory.class.getCanonicalName()); pm.update(); pm.configureStores(); Assert.assertEquals("Default store configuration failed", jrds.store.CacheStoreFactory.class, pm.defaultStore.getClass()); }
@Test public void testDefaultStore() throws IOException { PropertiesManager pm = new PropertiesManager(); pm.setProperty("configdir", testFolder.getRoot().getCanonicalPath()); pm.setProperty("rrddir", testFolder.getRoot().getCanonicalPath()); pm.setProperty("tmpdir", testFolder.getRoot().getCanonicalPath()); pm.update(); pm.configureStores(); Assert.assertEquals("Default store configuration failed", jrds.store.RrdDbStoreFactory.class, pm.defaultStore.getClass()); }
static public final PropertiesManager makePm(TemporaryFolder testFolder, String... props) throws IOException { PropertiesManager pm = new PropertiesManager(); pm.setProperty("tmpdir", testFolder.newFolder("tmp").getCanonicalPath()); pm.setProperty("configdir", testFolder.newFolder("config").getCanonicalPath()); pm.setProperty("rrddir", testFolder.newFolder("rrddir").getCanonicalPath()); pm.setProperty("autocreate", "true"); pm.setProperty("usepool", "false"); return finishPm(pm, props); }
@Test public void testDefaultStoreList() throws IOException { PropertiesManager pm = new PropertiesManager(); pm.setProperty("configdir", testFolder.getRoot().getCanonicalPath()); pm.setProperty("rrddir", testFolder.getRoot().getCanonicalPath()); pm.setProperty("tmpdir", testFolder.getRoot().getCanonicalPath()); pm.setProperty("stores", "cache"); pm.setProperty("rrdbackend", "NIO"); pm.setProperty("store.cache.factory", EmptyStoreFactory.class.getCanonicalName()); pm.update(); pm.configureStores(); Assert.assertEquals("Addition store configuration failed", 1, pm.stores.size()); Assert.assertEquals("Addition store configuration failed", EmptyStoreFactory.class, pm.stores.get("cache").getClass()); }
@Test public void loadBadProbeDesc() throws Exception { JrdsDocument d = Tools.parseRessource("baddesc.xml"); PropertiesManager pm = new PropertiesManager(); List<LoggingEvent> logged = Tools.getLockChecker("jrds.configuration.ConfigObjectBuilder"); ProbeDescBuilder builder = new ProbeDescBuilder(); builder.setPm(pm); ProbeDesc<?> pd = builder.makeProbeDesc(d); logger.trace("Collect mapping: " + pd.getCollectMapping()); Assert.assertEquals(1, pd.getCollectMapping().size()); boolean found = false; for(LoggingEvent le: logged) { String message = le.getRenderedMessage(); if(message.contains("Invalid ds type specified")) { found = true; break; } } Assert.assertTrue("bad probe desc not detected", found); }
@Test public void testSecurity() throws IOException { PropertiesManager pm = new PropertiesManager(); pm.setProperty("configdir", testFolder.getRoot().getCanonicalPath()); pm.setProperty("rrddir", testFolder.getRoot().getCanonicalPath()); pm.setProperty("tmpdir", testFolder.getRoot().getCanonicalPath()); pm.setProperty("security", "true"); pm.setProperty("adminrole", "role1"); pm.setProperty("defaultroles", " role2 ,role3"); pm.update(); Assert.assertEquals("Bad default ACL class", RolesACL.class, pm.defaultACL.getClass()); RolesACL rolesacl = (RolesACL) pm.defaultACL; Assert.assertTrue("Admin role1 not found", rolesacl.getRoles().contains("role1")); Assert.assertTrue("default role role2 not found", rolesacl.getRoles().contains("role2")); Assert.assertTrue("default role role3 not found", rolesacl.getRoles().contains("role3")); Assert.assertEquals("Bad adminACL", AdminACL.class, pm.adminACL.getClass()); AdminACL adminacl = (AdminACL) pm.adminACL; Assert.assertEquals("Bad admin role", "role1", adminacl.getAdminRole()); }
@Test public void loadProbeDesc() throws Exception { JrdsDocument d = Tools.parseRessource("fulldesc.xml"); PropertiesManager pm = new PropertiesManager(); ProbeDescBuilder builder = new ProbeDescBuilder(); builder.setPm(new PropertiesManager()); ProbeDesc<?> pd = builder.makeProbeDesc(d); Assert.assertEquals("name", pd.getName()); Assert.assertEquals("probename", pd.getProbeName()); Assert.assertEquals(jrds.mockobjects.MokeProbe.class, pd.getProbeClass()); Assert.assertEquals("specificvalue1", pd.getSpecific("specificname1")); Assert.assertEquals("specificvalue2", pd.getSpecific("specificname2")); Assert.assertEquals(0.5, pd.getUptimefactor(), 0); Assert.assertEquals((long) pm.step * 2, pd.getHeartBeatDefault()); logger.trace(pd.getCollectMapping()); logger.trace(pd.getDefaultBeans()); // An empty collect string should not be collected Assert.assertEquals(5, pd.getCollectMapping().size()); }
@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)); }
@SuppressWarnings("unused") private void doTest(String proto, int port) throws Exception { mbi = new JrdsMBeanInfo(proto, "localhost", port); HostStarter host = new HostStarter(new HostInfo("localhost")) { public boolean isCollectRunning() { return true; } }; host.setTimeout(1); JMXConnection cnx = getCnx(proto, port); host.registerStarter(new SocketFactory()); host.registerStarter(new JmxSocketFactory()); host.registerStarter(cnx); host.configureStarters(new PropertiesManager()); host.startCollect(); Assert.assertTrue("JMX Connection failed to start", cnx.isStarted()); Assert.assertNotNull("Failed to read uptime", cnx.setUptime()); if(false) enumerate((NativeJmxSource)cnx.getConnection()); }