List of usage examples for java.util Properties stringPropertyNames
public Set<String> stringPropertyNames()
From source file:gobblin.util.SchedulerUtilsTest.java
@Test public void testLoadJobConfigsForCommonPropsFile() throws ConfigurationException, IOException { Path commonPropsPath = new Path(this.subDir1.getAbsolutePath() + "/test.properties"); Properties properties = new Properties(); properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY, this.jobConfigDir.getAbsolutePath()); List<Properties> jobConfigs = SchedulerUtils.loadGenericJobConfigs(properties, commonPropsPath, new Path(this.jobConfigDir.getAbsolutePath())); Assert.assertEquals(jobConfigs.size(), 3); // test-job-conf-dir/test1/test11/test111.pull Properties jobProps1 = getJobConfigForFile(jobConfigs, "test111.pull"); Assert.assertEquals(jobProps1.stringPropertyNames().size(), 7); Assert.assertEquals(jobProps1.getProperty("k1"), "d1"); Assert.assertEquals(jobProps1.getProperty("k2"), "a2"); Assert.assertEquals(jobProps1.getProperty("k3"), "a3"); Assert.assertEquals(jobProps1.getProperty("k8"), "a8"); Assert.assertEquals(jobProps1.getProperty("k9"), "a8"); // test-job-conf-dir/test1/test11.pull Properties jobProps2 = getJobConfigForFile(jobConfigs, "test11.pull"); Assert.assertEquals(jobProps2.stringPropertyNames().size(), 6); Assert.assertEquals(jobProps2.getProperty("k1"), "c1"); Assert.assertEquals(jobProps2.getProperty("k2"), "a2"); Assert.assertEquals(jobProps2.getProperty("k3"), "b3"); Assert.assertEquals(jobProps2.getProperty("k6"), "a6"); // test-job-conf-dir/test1/test12.PULL Properties jobProps3 = getJobConfigForFile(jobConfigs, "test12.PULL"); Assert.assertEquals(jobProps3.stringPropertyNames().size(), 6); Assert.assertEquals(jobProps3.getProperty("k1"), "b1"); Assert.assertEquals(jobProps3.getProperty("k2"), "a2"); Assert.assertEquals(jobProps3.getProperty("k3"), "a3"); Assert.assertEquals(jobProps3.getProperty("k7"), "a7"); }
From source file:alluxio.cli.validation.ClusterConfConsistencyValidationTask.java
@Override public TaskResult validate(Map<String, String> optionMap) throws InterruptedException { Set<String> masters = new HashSet<>(Utils.readNodeList("masters")); Set<String> workers = new HashSet<>(Utils.readNodeList("workers")); Set<String> nodes = Sets.union(masters, workers); Map<String, Properties> allProperties = new HashMap<>(); Set<String> propertyNames = new HashSet<>(); if (masters.isEmpty()) { System.err.println("No master nodes specified in conf/masters file"); return TaskResult.SKIPPED; }/*from w w w.ja va2 s. c o m*/ if (workers.isEmpty()) { System.err.println("No worker nodes specified in conf/workers file"); return TaskResult.SKIPPED; } TaskResult result = TaskResult.OK; for (String node : nodes) { Properties props = getNodeConf(node); if (props == null) { result = TaskResult.FAILED; continue; } allProperties.put(node, props); propertyNames.addAll(props.stringPropertyNames()); } for (String propertyName : propertyNames) { PropertyKey propertyKey = PropertyKey.fromString(propertyName); PropertyKey.ConsistencyCheckLevel level = propertyKey.getConsistencyLevel(); if (level == PropertyKey.ConsistencyCheckLevel.IGNORE) { continue; } PropertyKey.Scope scope = propertyKey.getScope(); Set<String> targetNodes = ImmutableSet.of(); if (scope.contains(PropertyKey.Scope.MASTER)) { targetNodes = masters; } if (scope.contains(PropertyKey.Scope.WORKER)) { targetNodes = Sets.union(targetNodes, workers); } if (targetNodes.size() < 2) { continue; } String baseNode = null; String baseValue = null; boolean isConsistent = true; String errLabel; TaskResult errLevel; switch (level) { case ENFORCE: errLabel = "Error"; errLevel = TaskResult.FAILED; break; case WARN: errLabel = "Warning"; errLevel = TaskResult.WARNING; break; default: System.err.format("Error: Consistency check level \"%s\" for property \"%s\" is invalid.%n", level.name(), propertyName); result = TaskResult.FAILED; continue; } for (String remoteNode : targetNodes) { if (baseNode == null) { baseNode = remoteNode; Properties baselineProps = allProperties.get(baseNode); baseValue = baselineProps.getProperty(propertyName); continue; } String remoteValue = allProperties.get(remoteNode).getProperty(propertyName); if (!StringUtils.equals(remoteValue, baseValue)) { System.err.format("%s: Property \"%s\" is inconsistent between node %s and %s.%n", errLabel, propertyName, baseNode, remoteNode); System.err.format(" %s: %s%n %s: %s%n", baseNode, Objects.toString(baseValue, "not set"), remoteNode, Objects.toString(remoteValue, "not set")); isConsistent = false; } } if (!isConsistent) { result = result == TaskResult.FAILED ? TaskResult.FAILED : errLevel; } } return result; }
From source file:org.fornax.toolsupport.sculptor.maven.plugin.AbstractSculptorMojo.java
/** * Returns the list of generated files from the StatusFile (defined via * {@link #statusFile}) or <code>null</code> if no StatusFile exists. *//*from w w w .j ava 2 s. c o m*/ protected Set<String> getGeneratedFiles() { File statusFile = getStatusFile(); if (statusFile != null) { try { // Read status file and return the list of generated files Properties statusFileProps = new Properties(); statusFileProps.load(new FileReader(statusFile)); return statusFileProps.stringPropertyNames(); } catch (IOException e) { getLog().warn("Reading status file failed: " + e.getMessage()); } } return null; }
From source file:org.apache.stratos.cartridge.agent.internal.CartridgeAgentServiceComponent.java
protected void activate(ComponentContext ctx) { RegistrantHealthChecker healthChecker; ConfigurationContext configurationContext = DataHolder.getServerConfigContext(); FileInputStream confFileIPStream = null; try {/*w w w . j a v a 2s . c om*/ long start = System.currentTimeMillis(); log.info("Starting WSO2 Cartridge Agent..."); Properties conf = new Properties(); confFileIPStream = new FileInputStream( CarbonUtils.getCarbonConfigDirPath() + File.separator + "agent.properties"); conf.load(confFileIPStream); for (String name : conf.stringPropertyNames()) { String value = conf.getProperty(name); System.setProperty(name, value); } RegistrantDatabase registrantDatabase = new RegistrantDatabase(); // AxisServer axisServer = new AxisServer(); // ConfigurationContext configurationContext = axisServer.getConfigurationContext(); ClusteringClient clusteringClient = new ClusteringClient(registrantDatabase); configurationContext.setProperty(CartridgeAgentConstants.CLUSTERING_CLIENT, clusteringClient); String healthCheckInterval = conf.getProperty("registrant.heathCheckInterval"); String threadPoolSize = conf.getProperty("registrant.healthCheckThreadPoolSize"); int healthCheckIntervalInt = (healthCheckInterval == null) ? 2000 : Integer.parseInt(healthCheckInterval); int threadPoolSizeInt = (threadPoolSize == null) ? 10 : Integer.parseInt(healthCheckInterval); log.info("Registrant health check interval: " + healthCheckIntervalInt + "s"); healthChecker = new RegistrantHealthChecker(registrantDatabase, clusteringClient, configurationContext, healthCheckIntervalInt, threadPoolSizeInt); clusteringClient.init(conf, configurationContext, new ELBMembershipListener(clusteringClient, configurationContext, registrantDatabase, healthChecker)); healthChecker.startAll(); DataHolder.setHealthChecker(healthChecker); /*configurationContext.deployService(AxisService.createService(CartridgeAgentService.class.getName().toString(), configurationContext.getAxisConfiguration()));*/ // axisServer.deployService(CartridgeAgentService.class.getName()); // Starting cliet.. // String trustStorePath = conf.getProperty("wso2.carbon.truststore"); // System.setProperty("javax.net.ssl.trustStore", trustStorePath); // System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon"); // // new InstanceStateNotificationClient().notify(null, null); // // System.setProperty("adc.host", conf.getProperty("adc.host")); // System.setProperty("adc.port", conf.getProperty("adc.port")); // ---------------------- Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { log.info("Shutting down WSO2 Cartridge Agent..."); } }); log.info("Started Cartridge Agent in " + (System.currentTimeMillis() - start) + "ms"); } catch (Exception e) { log.fatal("Could not start Cartridge Agent", e); //System.exit(1); } finally { if (confFileIPStream != null) { try { confFileIPStream.close(); } catch (IOException e) { log.error("Cannot close agent.properties file", e); } } } }
From source file:gobblin.util.SchedulerUtilsTest.java
@Test public void testloadGenericJobConfigs() throws ConfigurationException, IOException { Properties properties = new Properties(); properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY, this.jobConfigDir.getAbsolutePath()); List<Properties> jobConfigs = SchedulerUtils.loadGenericJobConfigs(properties); Assert.assertEquals(jobConfigs.size(), 4); // test-job-conf-dir/test1/test11/test111.pull Properties jobProps1 = getJobConfigForFile(jobConfigs, "test111.pull"); Assert.assertEquals(jobProps1.stringPropertyNames().size(), 7); Assert.assertTrue(jobProps1.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY) || jobProps1.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY)); Assert.assertTrue(jobProps1.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY)); Assert.assertEquals(jobProps1.getProperty("k1"), "d1"); Assert.assertEquals(jobProps1.getProperty("k2"), "a2"); Assert.assertEquals(jobProps1.getProperty("k3"), "a3"); Assert.assertEquals(jobProps1.getProperty("k8"), "a8"); Assert.assertEquals(jobProps1.getProperty("k9"), "a8"); // test-job-conf-dir/test1/test11.pull Properties jobProps2 = getJobConfigForFile(jobConfigs, "test11.pull"); Assert.assertEquals(jobProps2.stringPropertyNames().size(), 6); Assert.assertTrue(jobProps2.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY) || jobProps1.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY)); Assert.assertTrue(jobProps2.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY)); Assert.assertEquals(jobProps2.getProperty("k1"), "c1"); Assert.assertEquals(jobProps2.getProperty("k2"), "a2"); Assert.assertEquals(jobProps2.getProperty("k3"), "b3"); Assert.assertEquals(jobProps2.getProperty("k6"), "a6"); // test-job-conf-dir/test1/test12.PULL Properties jobProps3 = getJobConfigForFile(jobConfigs, "test12.PULL"); Assert.assertEquals(jobProps3.stringPropertyNames().size(), 6); Assert.assertTrue(jobProps3.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY) || jobProps1.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY)); Assert.assertTrue(jobProps3.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY)); Assert.assertEquals(jobProps3.getProperty("k1"), "b1"); Assert.assertEquals(jobProps3.getProperty("k2"), "a2"); Assert.assertEquals(jobProps3.getProperty("k3"), "a3"); Assert.assertEquals(jobProps3.getProperty("k7"), "a7"); // test-job-conf-dir/test2/test21.PULL Properties jobProps4 = getJobConfigForFile(jobConfigs, "test21.PULL"); Assert.assertEquals(jobProps4.stringPropertyNames().size(), 5); Assert.assertTrue(jobProps4.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY) || jobProps1.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY)); Assert.assertTrue(jobProps4.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY)); Assert.assertEquals(jobProps4.getProperty("k1"), "a1"); Assert.assertEquals(jobProps4.getProperty("k2"), "b2"); Assert.assertEquals(jobProps4.getProperty("k5"), "b5"); }
From source file:org.wso2.carbon.inbound.endpoint.protocol.rabbitmq.RabbitMQConnectionFactory.java
/** * Digest a AMQP CF definition from the configuration and construct *//*w w w .j a va2 s . co m*/ public RabbitMQConnectionFactory(Properties properties) { this.name = properties.getProperty(RabbitMQConstants.RABBITMQ_CON_FAC); for (final String name : properties.stringPropertyNames()) parameters.put(name, properties.getProperty(name)); initConnectionFactory(); }
From source file:weinre.server.ServerSettings.java
private Properties fromPropertiesFile() { Properties result = Utility.readPropertiesFile("server.properties"); // ya, Properties doesn't trim space off values for (String key : result.stringPropertyNames()) { String val = result.getProperty(key); result.setProperty(key, val.trim()); }//from w ww . j a v a 2 s .c o m return result; }
From source file:org.ow2.chameleon.core.activators.ConfigDeployer.java
private void readAndApplyConfiguration(File file, ConfigurationAdmin admin) throws Exception { synchronized (this) { if (admin == null) { LOGGER.warn("Cannot apply configuration " + file.getName() + " - no configuration admin"); configurations.put(file, UnmanagedConfiguration.INSTANCE); } else {//www .j a va 2s . c om Properties properties = read(file); String[] pid = parsePid(file.getName()); Dictionary<Object, Object> ht = new Properties(); for (String k : properties.stringPropertyNames()) { ht.put(k, properties.getProperty(k)); } Configuration config = configurations.get(file); if (config == null || config == UnmanagedConfiguration.INSTANCE) { config = getConfiguration(pid[0], pid[1], admin); if (config.getBundleLocation() != null) { config.setBundleLocation(null); } } LOGGER.info("Updating configuration {} in the configuration admin, configuration: {}", config.getPid(), configurations); config.update(ht); configurations.put(file, config); } } }
From source file:org.opencastproject.kernel.mail.SmtpService.java
/** * Callback from the OSGi <code>ConfigurationAdmin</code> on configuration changes. * // ww w .j a v a 2 s . c om * @param properties * the configuration properties * @throws ConfigurationException * if configuration fails */ @SuppressWarnings("rawtypes") @Override public void updated(Dictionary properties) throws ConfigurationException { // Read the mail server properties mailProperties.clear(); // Mail transport protocol mailTransport = StringUtils.trimToNull((String) properties.get(OPT_MAIL_TRANSPORT)); if (!("smtp".equals(mailTransport) || "smtps".equals(mailTransport))) { if (mailTransport != null) logger.warn("'{}' procotol not supported. Reverting to default: '{}'", mailTransport, DEFAULT_MAIL_TRANSPORT); mailTransport = DEFAULT_MAIL_TRANSPORT; logger.debug("Mail transport protocol defaults to '{}'", mailTransport); } else { logger.debug("Mail transport protocol is '{}'", mailTransport); } logger.info("Mail transport protocol is '{}'", mailTransport); mailProperties.put(OPT_MAIL_TRANSPORT, mailTransport); // The mail host is mandatory String propName = OPT_MAIL_PREFIX + mailTransport + OPT_MAIL_HOST_SUFFIX; mailHost = StringUtils.trimToNull((String) properties.get(propName)); if (mailHost == null) throw new ConfigurationException(propName, "is not set"); logger.debug("Mail host is {}", mailHost); mailProperties.put(propName, mailHost); // Mail port propName = OPT_MAIL_PREFIX + mailTransport + OPT_MAIL_PORT_SUFFIX; String mailPort = StringUtils.trimToNull((String) properties.get(propName)); if (mailPort == null) { mailPort = DEFAULT_MAIL_PORT; logger.debug("Mail server port defaults to '{}'", mailPort); } else { logger.debug("Mail server port is '{}'", mailPort); } mailProperties.put(propName, mailPort); // TSL over SMTP support propName = OPT_MAIL_PREFIX + mailTransport + OPT_MAIL_TLS_ENABLE_SUFFIX; String smtpStartTLSStr = StringUtils.trimToNull((String) properties.get(propName)); boolean smtpStartTLS = Boolean.parseBoolean(smtpStartTLSStr); if (smtpStartTLS) { mailProperties.put(propName, "true"); logger.debug("TLS over SMTP is enabled"); } else { logger.debug("TLS over SMTP is disabled"); } // Mail user mailUser = StringUtils.trimToNull((String) properties.get(OPT_MAIL_USER)); if (mailUser != null) { mailProperties.put(OPT_MAIL_USER, mailUser); logger.debug("Mail user is '{}'", mailUser); } else { logger.debug("Sending mails to {} without authentication", mailHost); } // Mail password mailPassword = StringUtils.trimToNull((String) properties.get(OPT_MAIL_PASSWORD)); if (mailPassword != null) { mailProperties.put(OPT_MAIL_PASSWORD, mailPassword); logger.debug("Mail password set"); } // Mail sender String mailFrom = StringUtils.trimToNull((String) properties.get(OPT_MAIL_FROM)); if (mailFrom == null) { logger.debug("Mail sender defaults to {}", mailFrom); } else { logger.debug("Mail sender is '{}'", mailFrom); } mailProperties.put(OPT_MAIL_FROM, mailFrom); // Authentication propName = OPT_MAIL_PREFIX + mailTransport + OPT_MAIL_AUTH_SUFFIX; mailProperties.put(propName, Boolean.toString(mailUser != null)); // Mail debugging String mailDebug = StringUtils.trimToNull((String) properties.get(OPT_MAIL_DEBUG)); if (mailDebug != null) { boolean mailDebugEnabled = Boolean.parseBoolean(mailDebug); mailProperties.put(OPT_MAIL_DEBUG, Boolean.toString(mailDebugEnabled)); logger.info("Mail debugging is {}", mailDebugEnabled ? "enabled" : "disabled"); } defaultMailSession = null; logger.info("Mail service configured with {}", mailHost); Properties props = getSession().getProperties(); for (String key : props.stringPropertyNames()) logger.info("{}: {}", key, props.getProperty(key)); // Test String mailTest = StringUtils.trimToNull((String) properties.get(OPT_MAIL_TEST)); if (mailTest != null && Boolean.parseBoolean(mailTest)) { logger.info("Sending test message to {}", mailFrom); try { sendTestMessage(mailFrom); } catch (MessagingException e) { logger.error("Error sending test message to " + mailFrom + ": " + e.getMessage()); while (e.getNextException() != null) { Exception ne = e.getNextException(); logger.error("Error sending test message to " + mailFrom + ": " + ne.getMessage()); if (ne instanceof MessagingException) e = (MessagingException) ne; else break; } throw new ConfigurationException(OPT_MAIL_PREFIX + mailTransport + OPT_MAIL_HOST_SUFFIX, "Failed to send test message to " + mailFrom); } } }
From source file:gobblin.runtime.job_catalog.FSJobCatalogHelperTest.java
@Test(dependsOnMethods = { "testloadGenericJobConfigs" }) public void testloadGenericJobConfig() throws ConfigurationException, IOException { Path jobConfigPath = new Path(this.subDir11.getAbsolutePath(), "test111.pull"); Properties jobProps = ConfigUtils .configToProperties(loader.loadPullFile(jobConfigPath, this.sysConfig, false)); Assert.assertEquals(jobProps.stringPropertyNames().size(), 5); Assert.assertEquals(jobProps.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY), this.jobConfigDir.getAbsolutePath()); Assert.assertEquals(jobProps.getProperty("k1"), "d1"); Assert.assertEquals(jobProps.getProperty("k8"), "a8"); Assert.assertEquals(jobProps.getProperty("k9"), "a8"); }