List of usage examples for java.util Properties containsKey
@Override public boolean containsKey(Object key)
From source file:nl.nn.adapterframework.extensions.esb.WsdlGeneratorPipe.java
private PipeLine createPipeLineFromPropertiesFile(File propertiesFile) throws IOException, ConfigurationException { Properties props = new Properties(); FileInputStream fis = null;// w w w.ja v a2 s . c o m try { fis = new FileInputStream(propertiesFile); props.load(fis); } finally { try { if (fis != null) { fis.close(); } } catch (IOException e) { log.warn("exception closing inputstream", e); } } PipeLine pipeLine = new PipeLine(); String inputXsd = null; if (props.containsKey("input.xsd")) { inputXsd = props.getProperty("input.xsd"); String inputNamespace = props.getProperty("input.namespace"); String inputRoot = props.getProperty("input.root"); String inputCmhString = props.getProperty("input.cmh", "1"); int inputCmh = Integer.valueOf(inputCmhString); File inputXsdFile = new File(propertiesFile.getParent(), inputXsd); EsbSoapValidator inputValidator = createValidator(inputXsdFile, inputNamespace, inputRoot, 1, inputCmh); pipeLine.setInputValidator(inputValidator); } if (props.containsKey("output.xsd")) { String outputXsd = props.getProperty("output.xsd"); String outputNamespace = props.getProperty("output.namespace"); String outputRoot = props.getProperty("output.root"); String outputCmhString = props.getProperty("output.cmh", "1"); int outputCmh = Integer.valueOf(outputCmhString); File outputXsdFile = new File(propertiesFile.getParent(), outputXsd); int rootPosition; if (inputXsd != null && inputXsd.equalsIgnoreCase(outputXsd)) { rootPosition = 2; } else { rootPosition = 1; } EsbSoapValidator outputValidator = createValidator(outputXsdFile, outputNamespace, outputRoot, rootPosition, outputCmh); pipeLine.setOutputValidator(outputValidator); } return pipeLine; }
From source file:org.apache.gobblin.scheduler.JobScheduler.java
/** * Schedule a job./*from w ww . j a va2 s . c o m*/ * * <p> * This method does what {@link #scheduleJob(Properties, JobListener)} does, and additionally it * allows the caller to pass in additional job data and the {@link Job} implementation class. * </p> * * @param jobProps Job configuration properties * @param jobListener {@link JobListener} used for callback, * can be <em>null</em> if no callback is needed. * @param additionalJobData additional job data in a {@link Map} * @param jobClass Quartz job class * @throws JobException when there is anything wrong * with scheduling the job */ public void scheduleJob(Properties jobProps, JobListener jobListener, Map<String, Object> additionalJobData, Class<? extends Job> jobClass) throws JobException { Preconditions.checkArgument(jobProps.containsKey(ConfigurationKeys.JOB_NAME_KEY), "A job must have a job name specified by job.name"); String jobName = jobProps.getProperty(ConfigurationKeys.JOB_NAME_KEY); if (this.scheduledJobs.containsKey(jobName)) { LOG.warn("Job " + jobName + " has already been scheduled"); return; } // Check if the job has been disabled boolean disabled = Boolean.valueOf(jobProps.getProperty(ConfigurationKeys.JOB_DISABLED_KEY, "false")); if (disabled) { LOG.info("Skipping disabled job " + jobName); return; } if (!jobProps.containsKey(ConfigurationKeys.JOB_SCHEDULE_KEY)) { // Submit the job to run this.jobExecutor.execute(new NonScheduledJobRunner(jobProps, jobListener)); return; } if (jobListener != null) { this.jobListenerMap.put(jobName, jobListener); } // Build a data map that gets passed to the job JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put(JOB_SCHEDULER_KEY, this); jobDataMap.put(PROPERTIES_KEY, jobProps); jobDataMap.put(JOB_LISTENER_KEY, jobListener); jobDataMap.putAll(additionalJobData); // Build a Quartz job JobDetail job = JobBuilder.newJob(jobClass) .withIdentity(jobName, Strings.nullToEmpty(jobProps.getProperty(ConfigurationKeys.JOB_GROUP_KEY))) .withDescription(Strings.nullToEmpty(jobProps.getProperty(ConfigurationKeys.JOB_DESCRIPTION_KEY))) .usingJobData(jobDataMap).build(); try { // Schedule the Quartz job with a trigger built from the job configuration Trigger trigger = getTrigger(job.getKey(), jobProps); this.scheduler.getScheduler().scheduleJob(job, trigger); LOG.info(String.format("Scheduled job %s. Next run: %s.", job.getKey(), trigger.getNextFireTime())); } catch (SchedulerException se) { LOG.error("Failed to schedule job " + jobName, se); throw new JobException("Failed to schedule job " + jobName, se); } this.scheduledJobs.put(jobName, job.getKey()); }
From source file:com.hortonworks.registries.schemaregistry.examples.avro.KafkaAvroSerDesApp.java
private Map<String, Object> createConsumerConfig(Properties props) { String bootstrapServers = props.getProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG); Map<String, Object> config = new HashMap<>(); config.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); config.putAll(Collections.singletonMap(SchemaRegistryClient.Configuration.SCHEMA_REGISTRY_URL.name(), props.get(SCHEMA_REGISTRY_URL))); config.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()); config.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, KafkaAvroDeserializer.class.getName()); if (props.containsKey(ConsumerConfig.GROUP_ID_CONFIG)) { config.put(ConsumerConfig.GROUP_ID_CONFIG, props.getProperty(ConsumerConfig.GROUP_ID_CONFIG)); } else {// w ww . j a v a 2 s. c om config.put(ConsumerConfig.GROUP_ID_CONFIG, UUID.randomUUID().toString()); } config.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); return config; }
From source file:org.apache.gobblin.metrics.GobblinMetrics.java
private void buildFileFailureEventReporter(Properties properties) { if (!properties.containsKey(ConfigurationKeys.FAILURE_LOG_DIR_KEY)) { LOGGER.error("Not reporting failure to log files because " + ConfigurationKeys.FAILURE_LOG_DIR_KEY + " is undefined"); return;//w w w . j av a2 s . c o m } try { String fsUri = properties.getProperty(ConfigurationKeys.FS_URI_KEY, ConfigurationKeys.LOCAL_FS_URI); FileSystem fs = FileSystem.get(URI.create(fsUri), new Configuration()); // Each job gets its own log subdirectory Path failureLogDir = new Path(properties.getProperty(ConfigurationKeys.FAILURE_LOG_DIR_KEY), this.getName()); if (!fs.exists(failureLogDir) && !fs.mkdirs(failureLogDir)) { LOGGER.error("Failed to create failure log directory for metrics " + this.getName()); return; } // Add a suffix to file name if specified in properties. String metricsFileSuffix = properties.getProperty(ConfigurationKeys.METRICS_FILE_SUFFIX, ConfigurationKeys.DEFAULT_METRICS_FILE_SUFFIX); if (!Strings.isNullOrEmpty(metricsFileSuffix) && !metricsFileSuffix.startsWith(".")) { metricsFileSuffix = "." + metricsFileSuffix; } // Each job run gets its own failure log file Path failureLogFile = new Path(failureLogDir, this.id + metricsFileSuffix + ".failure.log"); this.codahaleScheduledReporters.add(this.codahaleReportersCloser .register(new FileFailureEventReporter(RootMetricContext.get(), fs, failureLogFile))); LOGGER.info("Will start reporting failure to directory " + failureLogDir); } catch (IOException ioe) { LOGGER.error("Failed to build file failure event reporter for job " + this.id, ioe); } }
From source file:org.bultreebank.labpipe.utils.DataUtils.java
/** * Converts a token encoded in Line data format into CoNLL * /*from w w w. j a va2 s . c o m*/ * @param line Line encoded token * @param id ID of the current token * @param conllMap <code>Map</code> linking BTB tags to their CoNLL representation forms (features) * * @return String - CoNLL encoded token */ public static String lineTokenToConllToken(String line, int id, Properties conllMap) throws ArrayIndexOutOfBoundsException { ArrayList<String> conll = new ArrayList(10); line = line.replaceAll(" ", "\t"); String[] columns = line.split("\t"); String token = columns[0]; String tag = columns[1]; String lemma = null; if (columns.length > 2) { lemma = columns[2]; } // ID number conll.add(String.valueOf(id)); // Token conll.add(token); // Lemma if (lemma != null) { conll.add(lemma); } else { conll.add("_"); } // Short tag (BTB first letter) if (tag.contains("punct")) { conll.add("Punct"); } else { conll.add(String.valueOf(tag.charAt(0))); } // Long tag if (tag.contains("punct") || tag.contains("Punct")) { conll.add("Punct"); } else if (tag.length() > 2 && tag.charAt(1) != '-') { if (tag.startsWith("V")) { conll.add(tag.substring(0, 3)); } else { conll.add(tag.substring(0, 2)); } } else if (tag.length() > 2 && tag.charAt(1) == '-') { conll.add(String.valueOf(tag.charAt(0))); } else { conll.add(tag); } // Features (rest of the tag separated with pipe signs) if (conllMap.containsKey(tag)) { // using the map configuration conll.add(conllMap.getProperty(tag)); } else { // tags not listed in the map -- failsafe if (tag.length() > 2 && !tag.contains("unct")) { conll.add(Misc.join(tag.substring(2).split(""), "|").substring(1)); } else { conll.add("_"); } } return Misc.join(conll, "\t"); }
From source file:org.apache.zeppelin.jdbc.JDBCInterpreter.java
@Override public void open() { for (String propertyKey : property.stringPropertyNames()) { logger.debug("propertyKey: {}", propertyKey); String[] keyValue = propertyKey.split("\\.", 2); if (2 == keyValue.length) { logger.info("key: {}, value: {}", keyValue[0], keyValue[1]); Properties prefixProperties; if (basePropretiesMap.containsKey(keyValue[0])) { prefixProperties = basePropretiesMap.get(keyValue[0]); } else { prefixProperties = new Properties(); basePropretiesMap.put(keyValue[0].trim(), prefixProperties); }/*from ww w. j av a 2 s . com*/ prefixProperties.put(keyValue[1].trim(), property.getProperty(propertyKey)); } } Set<String> removeKeySet = new HashSet<>(); for (String key : basePropretiesMap.keySet()) { if (!COMMON_KEY.equals(key)) { Properties properties = basePropretiesMap.get(key); if (!properties.containsKey(DRIVER_KEY) || !properties.containsKey(URL_KEY)) { logger.error("{} will be ignored. {}.{} and {}.{} is mandatory.", key, DRIVER_KEY, key, key, URL_KEY); removeKeySet.add(key); } } } for (String key : removeKeySet) { basePropretiesMap.remove(key); } logger.debug("JDBC PropretiesMap: {}", basePropretiesMap); if (!isEmpty(property.getProperty("zeppelin.jdbc.auth.type"))) { JDBCSecurityImpl.createSecureConfiguration(property); } for (String propertyKey : basePropretiesMap.keySet()) { propertyKeySqlCompleterMap.put(propertyKey, createSqlCompleter(null)); } setMaxLineResults(); }
From source file:gobblin.runtime.job_catalog.FSJobCatalogHelperTest.java
@Test public void testloadGenericJobConfigs() throws ConfigurationException, IOException, URISyntaxException { Properties properties = new Properties(); properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY, this.jobConfigDir.getAbsolutePath()); List<JobSpec> jobSpecs = Lists.transform( Lists.newArrayList(/*from w ww . j a v a2 s. c o m*/ loader.loadPullFilesRecursively(loader.getRootDirectory(), this.sysConfig, false)), this.converter); List<Properties> jobConfigs = convertJobSpecList2PropList(jobSpecs); Assert.assertEquals(jobConfigs.size(), 4); // test-job-conf-dir/test1/test11/test111.pull Properties jobProps1 = getJobConfigForFile(jobConfigs, "test111.pull"); //5 is consisting of three attributes, plus ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY // which is on purpose to keep // plus ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY, which is not necessary to convert into JobSpec // but keep it here to avoid NullPointer exception and validation purpose for testing. Assert.assertEquals(jobProps1.stringPropertyNames().size(), 5); Assert.assertTrue(jobProps1.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY)); Assert.assertEquals(jobProps1.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY), this.jobConfigDir.getAbsolutePath()); Assert.assertEquals(jobProps1.getProperty("k1"), "d1"); 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(), 5); Assert.assertTrue(jobProps2.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY)); Assert.assertEquals(jobProps2.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY), this.jobConfigDir.getAbsolutePath()); Assert.assertEquals(jobProps2.getProperty("k1"), "c1"); 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(), 3); Assert.assertTrue(jobProps3.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY)); Assert.assertEquals(jobProps3.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY), this.jobConfigDir.getAbsolutePath()); Assert.assertEquals(jobProps3.getProperty("k7"), "a7"); // test-job-conf-dir/test2/test21.PULL Properties jobProps4 = getJobConfigForFile(jobConfigs, "test21.PULL"); Assert.assertEquals(jobProps4.stringPropertyNames().size(), 3); Assert.assertTrue(jobProps4.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY)); Assert.assertEquals(jobProps4.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY), this.jobConfigDir.getAbsolutePath()); Assert.assertEquals(jobProps4.getProperty("k5"), "b5"); }
From source file:org.apache.gobblin.runtime.job_catalog.FSJobCatalogHelperTest.java
@Test(enabled = false) public void testloadGenericJobConfigs() throws ConfigurationException, IOException, URISyntaxException { Properties properties = new Properties(); properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY, this.jobConfigDir.getAbsolutePath()); List<JobSpec> jobSpecs = Lists.transform( Lists.newArrayList(//from w ww . ja v a 2 s . co m loader.loadPullFilesRecursively(loader.getRootDirectory(), this.sysConfig, false)), this.converter); List<Properties> jobConfigs = convertJobSpecList2PropList(jobSpecs); Assert.assertEquals(jobConfigs.size(), 4); // test-job-conf-dir/test1/test11/test111.pull Properties jobProps1 = getJobConfigForFile(jobConfigs, "test111.pull"); //5 is consisting of three attributes, plus ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY // which is on purpose to keep // plus ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY, which is not necessary to convert into JobSpec // but keep it here to avoid NullPointer exception and validation purpose for testing. Assert.assertEquals(jobProps1.stringPropertyNames().size(), 5); Assert.assertTrue(jobProps1.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY)); Assert.assertEquals(jobProps1.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY), this.jobConfigDir.getAbsolutePath()); Assert.assertEquals(jobProps1.getProperty("k1"), "d1"); 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(), 5); Assert.assertTrue(jobProps2.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY)); Assert.assertEquals(jobProps2.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY), this.jobConfigDir.getAbsolutePath()); Assert.assertEquals(jobProps2.getProperty("k1"), "c1"); 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(), 3); Assert.assertTrue(jobProps3.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY)); Assert.assertEquals(jobProps3.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY), this.jobConfigDir.getAbsolutePath()); Assert.assertEquals(jobProps3.getProperty("k7"), "a7"); // test-job-conf-dir/test2/test21.PULL Properties jobProps4 = getJobConfigForFile(jobConfigs, "test21.PULL"); Assert.assertEquals(jobProps4.stringPropertyNames().size(), 3); Assert.assertTrue(jobProps4.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY)); Assert.assertEquals(jobProps4.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY), this.jobConfigDir.getAbsolutePath()); Assert.assertEquals(jobProps4.getProperty("k5"), "b5"); }
From source file:com.dm.estore.common.config.Cfg.java
public void print() { Properties systemProperties = System.getProperties(); final String eol = System.getProperty("line.separator"); StringBuilder sb = new StringBuilder(); sb.append("Configuration").append(eol).append("General configuration").append(eol); String key = null;//from w w w. ja v a 2 s . c om for (Iterator<String> iter = getConfig().getKeys(); iter.hasNext(); key = iter.next()) { if (key != null && !Cfg.CMD_PRINT_CONFIG.equalsIgnoreCase(key) && !systemProperties.containsKey(key)) { sb.append(" " + key + " = " + getConfig().getString(key)).append(eol); } } sb.append(eol).append("Akka configuration").append(eol); sb.append(actorSystem().settings().toString()); LOG.info(sb.toString()); }
From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.ResourceObjectProviderBase.java
/** * Copy all properties that not already exist in target from source. *//*from w w w.jav a2s .c o m*/ private void mergeProperties(Properties aTarget, Properties aSource) { for (Object key : aSource.keySet()) { if (!aTarget.containsKey(key)) { aTarget.put(key, aSource.get(key)); } } }