public PropertiesManager(File propFile) { join(propFile); update(); }
private Configuration(Properties p) { propertiesManager.join(p); propertiesManager.importSystemProps(); propertiesManager.update(); hostsList = new HostsList(propertiesManager); }
pm.update(); } catch (IllegalArgumentException e) { System.err.println("invalid configuration, can't start: " + e.getMessage());
public void start(String[] args) throws Exception { PropertiesManager pm = new PropertiesManager(); pm.importSystemProps(); pm.update(); pm.configdir = null; pm.strictparsing = true;
@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 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 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()); }
propertiesManager.join(props); propertiesManager.importSystemProps(); propertiesManager.update(); HostsList hostsList = new HostsList(propertiesManager); GraphTree gt = hostsList.getGraphTreeByHost();
static private final PropertiesManager finishPm(PropertiesManager pm, String... props) { pm.setProperty("strictparsing", "true"); pm.setProperty("tabs", "hoststab"); for(String prop: props) { int pos = prop.indexOf('='); if(pos == 0 || pos == (prop.length() - 1)) continue; String key = prop.substring(0, pos); String value = prop.substring(pos + 1); pm.setProperty(key, value); } pm.update(); pm.configureStores(); pm.libspath.clear(); pm.defaultStore.configureStore(pm, new Properties()); pm.defaultStore.start(); return pm; }
@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(); } } }
pm.importSystemProps(); try { pm.update(); } catch (IllegalArgumentException e) { System.err.println("invalid configuration, can't start: " + e.getMessage());
@Test public void testTagsTab() throws IOException { PropertiesManager pm = Tools.makePm(testFolder); pm.setProperty("tabs", "filtertab"); pm.update(); HostsList hl = new HostsList(pm); Set<String> hostsTags = Collections.singleton("tag"); Set<Tab> tabs = new HashSet<Tab>(); hl.doTagsTabs(hostsTags, tabs); Tab tab = (Tab) tabs.toArray()[0]; Assert.assertTrue(tab.isFilters()); }
@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 enumerateProbe() throws IOException { PropertiesManager pm = Tools.makePm(testFolder, "autocreate=false", "strictparsing=true"); pm.update(); pm.libspath.clear(); File descpath = new File("desc"); if(descpath.exists()) pm.libspath.add(descpath.toURI()); ConfigObjectFactory conf = new ConfigObjectFactory(pm); Set<String> failed = new HashSet<String>(); for(JrdsDocument n: conf.getNodeMap(ConfigType.PROBEDESC).values()) { JrdsElement root = n.getRootElement(); JrdsElement classElem = root.getElementbyName("probeClass"); ProbeDesc<String> pd = new ProbeDesc<>(); String name = ""; try { String className = classElem.getTextContent().trim(); name = root.getElementbyName("name").getTextContent(); @SuppressWarnings("unchecked") Class<? extends Probe<String, ?>> c = (Class<? extends Probe<String, ?>>) pm.extensionClassLoader.loadClass(className); pd.setProbeClass(c); } catch (Exception e) { logger.error("Failed probedesc " + name + ": " + e.getMessage()); failed.add(name); } } if(!failed.isEmpty()) { Assert.fail("Invalid class:" + failed); } }
@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()); }
@Test public void testOther() throws IOException { PropertiesManager pm = Tools.makePm(testFolder); pm.setProperty("tabs", "filtertab"); pm.update(); HostsList hl = new HostsList(pm); Assert.assertEquals("First tab not found", pm.tabsList.get(0), hl.getFirstTab()); Assert.assertEquals("Missing tabs", pm.tabsList.size(), hl.getTabsId().size()); }
@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 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); } }
@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()); }