List of usage examples for java.util Properties containsKey
@Override public boolean containsKey(Object key)
From source file:gobblin.source.extractor.extract.kafka.ConfigStoreUtils.java
/** * Shortlist topics from config store based on whitelist/blacklist tags and * add it to {@param whitelist}/{@param blacklist} * * If tags are not provided, blacklist and whitelist won't be modified *///from ww w . ja v a 2 s. c om public static void setTopicsFromConfigStore(Properties properties, Set<String> blacklist, Set<String> whitelist, final String _blacklistTopicKey, final String _whitelistTopicKey) { Optional<String> configStoreUri = getConfigStoreUri(properties); if (!configStoreUri.isPresent()) { return; } ConfigClient configClient = ConfigClient.createConfigClient(VersionStabilityPolicy.WEAK_LOCAL_STABILITY); Optional<Config> runtimeConfig = ConfigClientUtils.getOptionalRuntimeConfig(properties); if (properties.containsKey(GOBBLIN_CONFIG_TAGS_WHITELIST)) { Preconditions.checkArgument(properties.containsKey(GOBBLIN_CONFIG_FILTER), "Missing required property " + GOBBLIN_CONFIG_FILTER); String filterString = properties.getProperty(GOBBLIN_CONFIG_FILTER); Path whiteListTagUri = PathUtils.mergePaths(new Path(configStoreUri.get()), new Path(properties.getProperty(GOBBLIN_CONFIG_TAGS_WHITELIST))); getTopicsURIFromConfigStore(configClient, whiteListTagUri, filterString, runtimeConfig).stream() .filter((URI u) -> ConfigUtils.getBoolean(getConfig(configClient, u, runtimeConfig), _whitelistTopicKey, false)) .forEach(((URI u) -> whitelist.add(getTopicNameFromURI(u)))); } else if (properties.containsKey(GOBBLIN_CONFIG_TAGS_BLACKLIST)) { Preconditions.checkArgument(properties.containsKey(GOBBLIN_CONFIG_FILTER), "Missing required property " + GOBBLIN_CONFIG_FILTER); String filterString = properties.getProperty(GOBBLIN_CONFIG_FILTER); Path blackListTagUri = PathUtils.mergePaths(new Path(configStoreUri.get()), new Path(properties.getProperty(GOBBLIN_CONFIG_TAGS_BLACKLIST))); getTopicsURIFromConfigStore(configClient, blackListTagUri, filterString, runtimeConfig).stream() .filter((URI u) -> ConfigUtils.getBoolean(getConfig(configClient, u, runtimeConfig), _blacklistTopicKey, false)) .forEach(((URI u) -> blacklist.add(getTopicNameFromURI(u)))); } else { log.warn("None of the blacklist or whitelist tags are provided"); } }
From source file:net.certifi.audittablegen.PostgresqlDMR.java
/** * Generate a Postgresql DataSource from Properties * @param props//from ww w . j a v a 2 s . c om * @return BasicDataSource as DataSource */ static DataSource getRunTimeDataSource(Properties props) { //BasicDataSource dataSource = new BasicDataSource(); PGPoolingDataSource dataSource = new PGPoolingDataSource(); //PGSimpleDataSource dataSource = new PGSimpleDataSource(); int port; dataSource.setUser(props.getProperty("username")); dataSource.setPassword(props.getProperty("password")); //dataSource.setInitialConnections(2); //dataSource.setApplicationName("AuditTableGen"); dataSource.setServerName(props.getProperty("server")); dataSource.setDatabaseName(props.getProperty("database")); if (props.containsKey("port")) { port = Integer.getInteger(props.getProperty("port", "5432")); dataSource.setPortNumber(port); } //dataSource.setDriverClassName("org.postgresql.Driver"); //dataSource.setUsername(props.getProperty("username")); //dataSource.setPassword(props.getProperty("password")); //dataSource.setUrl(props.getProperty("url")); //dataSource.setMaxActive(10); //dataSource.setMaxIdle(5); //dataSource.setInitialSize(5); //dataSource.setValidationQuery("SELECT 1"); return dataSource; }
From source file:org.darkstar.batch.utils.DarkstarUtils.java
/** * Checks if a Zone is Mapped in the Batch Config Properties * @param configProperties Handle to the Batch Config Properties * @param zoneId Zone ID//w ww. j a va2 s. co m * @return TRUE if mapped, FALSE otherwise. */ public static boolean isZoneMapped(final Properties configProperties, final int zoneId) { boolean isMapped = false; final String zoneIdString = String.format("%03d", zoneId); if (configProperties.containsKey(zoneIdString)) { isMapped = true; } return isMapped; }
From source file:com.microsoft.tfs.core.clients.build.internal.utils.XamlHelper.java
public static String updateProperties(final String originalXaml, final Properties properties) { final ArrayList keys = new ArrayList(properties.keySet()); final Document document = DOMCreateUtils.parseString(originalXaml); final Element root = document.getDocumentElement(); // first update any properties that we already have final NodeList nodes = root.getElementsByTagName("x:String"); //$NON-NLS-1$ for (int i = 0; i < nodes.getLength(); i++) { final Element element = (Element) nodes.item(i); final String key = element.getAttribute("x:Key"); //$NON-NLS-1$ element.getFirstChild().getNodeValue(); if (properties.containsKey(key)) { keys.remove(key);//w w w. ja v a 2 s. com element.getFirstChild().setNodeValue(properties.getProperty(key)); } } // now add any new properties to the xaml for (final Iterator it = keys.iterator(); it.hasNext();) { final String key = (String) it.next(); final Element element = DOMUtils.appendChild(root, "x:String"); //$NON-NLS-1$ element.setAttributeNS(XAML_NAMESPACE, "x:Key", key); //$NON-NLS-1$ element.setAttributeNS(XML_NAMESPACE, "xml:space", "preserve"); //$NON-NLS-1$ //$NON-NLS-2$ DOMUtils.appendText(element, properties.getProperty(key)); } return DOMSerializeUtils.toString(root, DOMSerializeUtils.INDENT).trim(); }
From source file:com.meltmedia.cadmium.servlets.guice.CadmiumListener.java
public static File getSshDir(Properties configProperties, File sharedContentRoot, Logger log) { File sshDir = null;/*from ww w . j av a2 s. co m*/ if (configProperties.containsKey(SSH_PATH_ENV)) { sshDir = new File(configProperties.getProperty(SSH_PATH_ENV)); if (!sshDir.exists() && !sshDir.isDirectory()) { sshDir = null; } } if (sshDir == null) { sshDir = new File(sharedContentRoot, ".ssh"); if (!sshDir.exists() && !sshDir.isDirectory()) { sshDir = null; } } log.debug("Using ssh dir {}", sshDir); return sshDir; }
From source file:com.meltmedia.cadmium.servlets.guice.CadmiumListener.java
public static File sharedContextRoot(Properties configProperties, ServletContext context, Logger log) { File sharedContentRoot = null; if (configProperties.containsKey(BASE_PATH_ENV)) { sharedContentRoot = new File(configProperties.getProperty(BASE_PATH_ENV)); if (!sharedContentRoot.exists() || !sharedContentRoot.canRead() || !sharedContentRoot.canWrite()) { if (!sharedContentRoot.mkdirs()) { sharedContentRoot = null; }// w ww . jav a 2 s . co m } } if (sharedContentRoot == null) { log.warn("Could not access cadmium content root. Using the tempdir."); sharedContentRoot = (File) context.getAttribute("javax.servlet.context.tempdir"); configProperties.setProperty(BASE_PATH_ENV, sharedContentRoot.getAbsoluteFile().getAbsolutePath()); } return sharedContentRoot; }
From source file:com.linkedin.kmf.common.Utils.java
/** * Create the topic that the monitor uses to monitor the cluster. This method attempts to create a topic so that all * the brokers in the cluster will have partitionToBrokerRatio partitions. If the topic exists, but has different parameters * then this does nothing to update the parameters. * * TODO: Do we care about rack aware mode? I would think no because we want to spread the topic over all brokers. * @param zkUrl zookeeper connection url * @param topic topic name/*from w w w. j av a2 s .co m*/ * @param replicationFactor the replication factor for the topic * @param partitionToBrokerRatio This is multiplied by the number brokers to compute the number of partitions in the topic. * @param topicConfig additional parameters for the topic for example min.insync.replicas * @return the number of partitions created */ public static int createMonitoringTopicIfNotExists(String zkUrl, String topic, int replicationFactor, double partitionToBrokerRatio, Properties topicConfig) { ZkUtils zkUtils = ZkUtils.apply(zkUrl, ZK_SESSION_TIMEOUT_MS, ZK_CONNECTION_TIMEOUT_MS, JaasUtils.isZkSecurityEnabled()); try { if (AdminUtils.topicExists(zkUtils, topic)) { LOG.info("Monitoring topic \"" + topic + "\" already exists."); return getPartitionNumForTopic(zkUrl, topic); } int brokerCount = zkUtils.getAllBrokersInCluster().size(); int partitionCount = (int) Math.ceil(brokerCount * partitionToBrokerRatio); int defaultMinIsr = Math.max(replicationFactor - 1, 1); if (!topicConfig.containsKey(KafkaConfig.MinInSyncReplicasProp())) { topicConfig.setProperty(KafkaConfig.MinInSyncReplicasProp(), Integer.toString(defaultMinIsr)); } try { AdminUtils.createTopic(zkUtils, topic, partitionCount, replicationFactor, topicConfig, RackAwareMode.Enforced$.MODULE$); } catch (TopicExistsException tee) { //There is a race condition with the consumer. LOG.info("Monitoring topic \"" + topic + "\" already exists (caught exception)."); return getPartitionNumForTopic(zkUrl, topic); } LOG.info("Created monitoring topic \"" + topic + "\" with " + partitionCount + " partitions, min ISR of " + topicConfig.get(KafkaConfig.MinInSyncReplicasProp()) + " and replication factor of " + replicationFactor + "."); return partitionCount; } finally { zkUtils.close(); } }
From source file:de.dal33t.powerfolder.util.ConfigurationLoader.java
/** * Merges the give pre configuration properties into the target config * properties. It can be choosen if existing keys in the target properties * should be replaced or not./* w ww. j a va 2s . co m*/ * * @param preConfig * the pre config * @param targetConfig * the config file to set the pre-configuration values into. * @param replaceExisting * if existing key/value pairs will be overwritten by pairs of * pre config. * @return the number of merged entries. */ private static int mergeConfigs(Properties preConfig, Properties targetConfig, boolean replaceExisting) { Reject.ifNull(preConfig, "PreConfig is null"); Reject.ifNull(targetConfig, "TargetConfig is null"); int n = 0; for (Object obj : preConfig.keySet()) { String key = (String) obj; String value = preConfig.getProperty(key); if (!targetConfig.containsKey(key) || replaceExisting) { Object oldValue = targetConfig.setProperty(key, value); if (!key.startsWith(PREFERENCES_PREFIX) && !value.equals(oldValue)) { n++; } LOG.finer("Preconfigured " + key + "=" + value); } } if (n > 0) { LOG.fine(n + " default configurations set"); } else { LOG.finer("No additional default configurations set"); } return n; }
From source file:dk.hippogrif.prettyxml.PrettyPrint.java
/** * Do the prettyprint according to properties. * * @param input holds xml document as text if present * @return prettyprinted document as text if input param present * @throws Exception if something goes wrong *///from w w w .j a va2 s . c om public static String execute(Properties prop, String input) throws Exception { try { checkProperties(prop, true); logger.log(Level.FINEST, "input=" + input + " properties=" + prop); Format format = initFormat(prop); PrettyXMLOutputter outp = new PrettyXMLOutputter(format); outp.setSortAttributes(prop.containsKey(SORT_ATTRIBUTES)); outp.setIndentAttributes(prop.containsKey(INDENT_ATTRIBUTES)); SAXBuilder builder = new SAXBuilder(); Document doc; if (input != null) { doc = builder.build(new StringReader(input)); } else if (prop.containsKey(INPUT)) { doc = builder.build(new File(prop.getProperty(INPUT))); } else if (prop.containsKey(URL)) { doc = builder.build(new URL(prop.getProperty(URL))); } else { doc = builder.build(System.in); } if (prop.containsKey(TRANSFORM)) { String[] sa = prop.getProperty(TRANSFORM).split(";"); for (int i = 0; i < sa.length; i++) { XSLTransformer transformer = mkTransformer(sa[i].trim()); doc = transformer.transform(doc); } } if (prop.containsKey(OUTPUT)) { FileOutputStream fos = null; try { fos = new FileOutputStream(new File(prop.getProperty(OUTPUT))); outp.output(doc, fos); } finally { IOUtils.closeQuietly(fos); } } else if (input != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); outp.output(doc, baos); return baos.toString(prop.getProperty(ENCODING, "UTF-8")); } else { outp.output(doc, System.out); } return null; } catch (Exception e) { logger.log(Level.FINER, "properties=" + prop, e); throw e; } }
From source file:com.openteach.diamond.container.Container.java
/** * ????//from ww w . j av a2 s . c om * * @return Map<String, Class<?>> key: ?? Class<?> Class */ public static Map<String, Class<?>> getExportedClasses() throws Exception { Map<String, Class<?>> exportedClasses = new HashMap<String, Class<?>>(); Properties exportedClassesProps = new Properties(); InputStream is = null; Bundle[] bundles = context.getBundles(); for (int i = 0; i < bundles.length; i++) { String bundleName = bundles[i].getSymbolicName().toLowerCase(); URL url = bundles[i].getResource(BUNDLE_PROPERTY_FILE); if (url != null) { is = url.openStream(); exportedClassesProps.load(is); is.close(); } if (exportedClassesProps.containsKey(bundleName)) { String value = exportedClassesProps.getProperty(bundleName); String[] classes = value.split(","); for (int j = 0; j < classes.length; j++) { exportedClasses.put(classes[j], bundles[i].loadClass(classes[j].trim())); } } } return exportedClasses; }