@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()); }
@Override public void configure(PropertiesManager pm) { super.configure(pm); protocol = pm.getProperty("ssl.protocol", null); // Default is false, because it was the default setting in previous release strict = pm.parseBoolean(pm.getProperty("ssl.strict", "false")); truststore = pm.getProperty("ssl.truststore", null); trustpassword = pm.getProperty("ssl.trustpassword", ""); format = pm.getProperty("ssl.trusttype", KeyStore.getDefaultType()); securerandom = pm.getProperty("ssl.securerandom", null); }
public void start(String args[]) throws Exception { PropertiesManager pm = new PropertiesManager(); File propFile = new File(propFileName); if(propFile.isFile()) { pm.join(propFile); pm.importSystemProps(); try { pm.update(); } catch (IllegalArgumentException e) { System.err.println("invalid configuration, can't start: " + e.getMessage());
private Configuration(Properties p) { propertiesManager.join(p); propertiesManager.importSystemProps(); propertiesManager.update(); hostsList = new HostsList(propertiesManager); }
@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(); }
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(); } }
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; }
@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 void start(String[] args) throws Exception { PropertiesManager pm = new PropertiesManager(); pm.importSystemProps(); pm.update(); pm.configdir = null; pm.strictparsing = true;
@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()); }
String libspathString = getProperty("libspath", ""); if(!"".equals(libspathString.trim())) { for(String libName: libspathString.split(";")) { extensionClassLoader = doClassLoader(getProperty("classpath", "")); boolean nologging = parseBoolean(getProperty("nologging", "false")); String log4jXmlFile = getProperty("log4jxmlfile", ""); String log4jPropFile = getProperty("log4jpropfile", ""); if(log4jXmlFile != null && !log4jXmlFile.trim().isEmpty()) { File xmlfile = new File(log4jXmlFile.trim()); for(String ls: new String[] { "trace", "debug", "info", "error", "fatal", "warn" }) { Level l = Level.toLevel(ls); String param = getProperty("log." + ls, ""); if(!"".equals(param)) { String[] loggersName = param.split(","); loglevel = Level.toLevel(getProperty("loglevel", "info")); logfile = getProperty("logfile"); legacymode = parseBoolean(getProperty("legacymode", "1")); strictparsing = parseBoolean(getProperty("strictparsing", "false")); autocreate = parseBoolean(getProperty("autocreate", "false")); try { configdir = prepareDir(getProperty("configdir"), autocreate, true); } catch (IOException e) {
public static void main(String[] args) throws IOException { jrds.JrdsLoggerConfiguration.initLog4J(); PropertiesManager pm = new PropertiesManager(new File("jrds.properties")); pm.configureStores();
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); }
@SuppressWarnings("unchecked") public void importSystemProps() { String localPropFile = System.getProperty("jrds.propertiesFile"); if(localPropFile != null) join(new File(localPropFile)); Pattern jrdsPropPattern = Pattern.compile("jrds\\.(.+)"); Properties p = System.getProperties(); for(String name: Collections.list((Enumeration<String>) p.propertyNames())) { Matcher m = jrdsPropPattern.matcher(name); if(m.matches()) { String prop = System.getProperty(name); if(prop != null) setProperty(m.group(1), prop); } } }
public void configureStores() { String defaultStorename = getProperty("defaultstore", StoreFactory.DEFAULTNAME); Map<String, Properties> storesConfig = new HashMap<String, Properties>(1); storesConfig.put(defaultStorename, new Properties()); if(getProperty(oldProps) != null) defaultStoreProps.put(oldProps, getProperty(oldProps)); if(getProperty("storefactory") != null) { String defaultstorefactoryclassname = getProperty("storefactory"); defaultStoreProps.put("factory", defaultstorefactoryclassname); String propertiesListStores = getProperty("stores", ""); if(!propertiesListStores.trim().isEmpty()) { for(String storeName: propertiesListStores.split(",")) { storeName = storeName.trim(); Map<String, String> storeInfo = subKey("store." + storeName); Properties props = new Properties(); props.putAll(storeInfo);
@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); } }
pm.configureStores(); setTimeout(pm.timeout); setStep(pm.step);
@Override public void readProperties(PropertiesManager pm) { cmd = resolvCmdPath(pm.getProperty("path", "")); }
public Map<String, String> subKey(String prefix) { Pattern regex = Pattern.compile("^" + prefix + "\\."); Map<String, String> props = new HashMap<String, String>(); for(Map.Entry<Object, Object> e: entrySet()) { String key = (String) e.getKey(); Matcher m = regex.matcher(key); if(m.find()) { String value = (String) e.getValue(); props.put(m.replaceFirst(""), value); } } return props; }