List of usage examples for java.util Properties putAll
@Override public synchronized void putAll(Map<?, ?> t)
From source file:eu.eidas.auth.commons.attribute.AttributeSetPropertiesConverter.java
/** * Converts the given Iterable of <code>AttributeDefinition</code>s to a Properties. * * @param properties the Iterable of <code>AttributeDefinition</code>s * @return a Properties.//w ww . j a v a 2s . c o m */ @Nonnull public static Properties toProperties(@Nonnull Iterable<AttributeDefinition<?>> attributes) { ImmutableSortedMap<String, String> sortedMap = toMap(attributes); Properties properties = new PrintSortedProperties(); //noinspection UseOfPropertiesAsHashtable properties.putAll(sortedMap); return properties; }
From source file:it.serverSystem.ClusterTest.java
private static void updateSonarPropertiesFile(Orchestrator orchestrator, Map<String, String> props) throws IOException { Properties propsFile = new Properties(); try (FileInputStream conf = FileUtils .openInputStream(new File(orchestrator.getServer().getHome(), CONF_FILE_PATH))) { propsFile.load(conf);/*w w w . j a va2s .co m*/ propsFile.putAll(props); } try (FileOutputStream conf = FileUtils .openOutputStream(new File(orchestrator.getServer().getHome(), CONF_FILE_PATH))) { propsFile.store(conf, ""); } }
From source file:org.apache.flink.streaming.connectors.kafka.KafkaTestBase.java
@BeforeClass public static void prepare() throws IOException { LOG.info("-------------------------------------------------------------------------"); LOG.info(" Starting KafkaITCase "); LOG.info("-------------------------------------------------------------------------"); LOG.info("Starting KafkaITCase.prepare()"); File tempDir = new File(System.getProperty("java.io.tmpdir")); tmpZkDir = new File(tempDir, "kafkaITcase-zk-dir-" + (UUID.randomUUID().toString())); assertTrue("cannot create zookeeper temp dir", tmpZkDir.mkdirs()); tmpKafkaParent = new File(tempDir, "kafkaITcase-kafka-dir*" + (UUID.randomUUID().toString())); assertTrue("cannot create kafka temp dir", tmpKafkaParent.mkdirs()); List<File> tmpKafkaDirs = new ArrayList<>(NUMBER_OF_KAFKA_SERVERS); for (int i = 0; i < NUMBER_OF_KAFKA_SERVERS; i++) { File tmpDir = new File(tmpKafkaParent, "server-" + i); assertTrue("cannot create kafka temp dir", tmpDir.mkdir()); tmpKafkaDirs.add(tmpDir);/*from w w w .j av a 2 s . c o m*/ } String kafkaHost = "localhost"; int zkPort = NetUtils.getAvailablePort(); zookeeperConnectionString = "localhost:" + zkPort; zookeeper = null; brokers = null; try { LOG.info("Starting Zookeeper"); zookeeper = new TestingServer(zkPort, tmpZkDir); LOG.info("Starting KafkaServer"); brokers = new ArrayList<>(NUMBER_OF_KAFKA_SERVERS); for (int i = 0; i < NUMBER_OF_KAFKA_SERVERS; i++) { brokers.add(getKafkaServer(i, tmpKafkaDirs.get(i), kafkaHost, zookeeperConnectionString)); SocketServer socketServer = brokers.get(i).socketServer(); String host = socketServer.host() == null ? "localhost" : socketServer.host(); brokerConnectionStrings += host + ":" + socketServer.port() + ","; } LOG.info("ZK and KafkaServer started."); } catch (Throwable t) { t.printStackTrace(); fail("Test setup failed: " + t.getMessage()); } standardProps = new Properties(); standardProps.setProperty("zookeeper.connect", zookeeperConnectionString); standardProps.setProperty("bootstrap.servers", brokerConnectionStrings); standardProps.setProperty("group.id", "flink-tests"); standardProps.setProperty("auto.commit.enable", "false"); standardProps.setProperty("zookeeper.session.timeout.ms", "12000"); // 6 seconds is default. Seems to be too small for travis. standardProps.setProperty("zookeeper.connection.timeout.ms", "20000"); standardProps.setProperty("auto.offset.reset", "earliest"); // read from the beginning. standardProps.setProperty("fetch.message.max.bytes", "256"); // make a lot of fetches (MESSAGES MUST BE SMALLER!) Properties consumerConfigProps = new Properties(); consumerConfigProps.putAll(standardProps); consumerConfigProps.setProperty("auto.offset.reset", "smallest"); standardCC = new ConsumerConfig(consumerConfigProps); // start also a re-usable Flink mini cluster Configuration flinkConfig = new Configuration(); flinkConfig.setInteger(ConfigConstants.LOCAL_NUMBER_TASK_MANAGER, 1); flinkConfig.setInteger(ConfigConstants.TASK_MANAGER_NUM_TASK_SLOTS, 8); flinkConfig.setInteger(ConfigConstants.TASK_MANAGER_MEMORY_SIZE_KEY, 16); flinkConfig.setString(ConfigConstants.DEFAULT_EXECUTION_RETRY_DELAY_KEY, "0 s"); flink = new ForkableFlinkMiniCluster(flinkConfig, false, StreamingMode.STREAMING); flink.start(); flinkPort = flink.getLeaderRPCPort(); }
From source file:net.firejack.platform.core.utils.MiscUtils.java
/** * @param properties// www .j a v a2 s . c o m * @param append * @throws java.io.IOException */ public static void setProperties(File properties, Map<String, String> append) throws IOException { Properties props = new Properties(); if (properties.exists()) { FileReader reader = new FileReader(properties); props.load(reader); reader.close(); } else { FileUtils.forceMkdir(properties.getParentFile()); } if (properties.exists() || properties.createNewFile()) { props.putAll(append); FileWriter writer = new FileWriter(properties); props.store(writer, null); writer.flush(); writer.close(); } }
From source file:org.apache.ranger.common.PropertiesUtil.java
public static Properties getProps() { Properties ret = new Properties(); if (propertiesMap != null) { ret.putAll(propertiesMap); }//from www . jav a 2 s . c om return ret; }
From source file:org.esigate.DriverFactory.java
/** * Loads all instances according to the properties parameter. * // w ww. ja v a2 s. com * @param props * properties to use for configuration */ public static void configure(Properties props) { Properties defaultProperties = new Properties(); HashMap<String, Properties> driversProps = new HashMap<String, Properties>(); for (Enumeration<?> enumeration = props.propertyNames(); enumeration.hasMoreElements();) { String propertyName = (String) enumeration.nextElement(); String value = props.getProperty(propertyName); int idx = propertyName.lastIndexOf('.'); if (idx < 0) { defaultProperties.put(propertyName, value); } else { String prefix = propertyName.substring(0, idx); String name = propertyName.substring(idx + 1); Properties driverProperties = driversProps.get(prefix); if (driverProperties == null) { driverProperties = new Properties(); driversProps.put(prefix, driverProperties); } driverProperties.put(name, value); } } // Merge with default properties Map<String, Driver> newInstances = new HashMap<String, Driver>(); for (Entry<String, Properties> entry : driversProps.entrySet()) { String name = entry.getKey(); Properties properties = new Properties(); properties.putAll(defaultProperties); properties.putAll(entry.getValue()); newInstances.put(name, createDriver(name, properties)); } if (newInstances.get(DEFAULT_INSTANCE_NAME) == null && Parameters.REMOTE_URL_BASE.getValue(defaultProperties) != null) { newInstances.put(DEFAULT_INSTANCE_NAME, createDriver(DEFAULT_INSTANCE_NAME, defaultProperties)); } instances = new IndexedInstances(newInstances); }
From source file:io.druid.query.extraction.namespace.TestKafkaExtractionCluster.java
@BeforeClass public static void setupStatic() throws Exception { zkTestServer = new TestingServer(-1, new File(tmpDir.getAbsolutePath() + "/zk"), true); zkClient = new ZkClient(zkTestServer.getConnectString(), 10000, 10000, ZKStringSerializer$.MODULE$); if (!zkClient.exists("/kafka")) { zkClient.create("/kafka", null, CreateMode.PERSISTENT); }//from w w w . j a va2 s . co m log.info("---------------------------Started ZK---------------------------"); final Properties serverProperties = new Properties(); serverProperties.putAll(kafkaProperties); serverProperties.put("broker.id", "0"); serverProperties.put("log.dir", tmpDir.getAbsolutePath() + "/log"); serverProperties.put("log.cleaner.enable", "true"); serverProperties.put("host.name", "127.0.0.1"); serverProperties.put("zookeeper.connect", zkTestServer.getConnectString() + "/kafka"); serverProperties.put("zookeeper.session.timeout.ms", "10000"); serverProperties.put("zookeeper.sync.time.ms", "200"); kafkaConfig = new KafkaConfig(serverProperties); final long time = DateTime.parse("2015-01-01").getMillis(); kafkaServer = new KafkaServer(kafkaConfig, new Time() { @Override public long milliseconds() { return time; } @Override public long nanoseconds() { return milliseconds() * 1_000_000; } @Override public void sleep(long ms) { try { Thread.sleep(ms); } catch (InterruptedException e) { throw Throwables.propagate(e); } } }); kafkaServer.startup(); int sleepCount = 0; while (!kafkaServer.kafkaController().isActive()) { Thread.sleep(10); if (++sleepCount > 100) { throw new InterruptedException("Controller took to long to awaken"); } } log.info("---------------------------Started Kafka Server---------------------------"); ZkClient zkClient = new ZkClient(zkTestServer.getConnectString() + "/kafka", 10000, 10000, ZKStringSerializer$.MODULE$); try { final Properties topicProperties = new Properties(); topicProperties.put("cleanup.policy", "compact"); if (!AdminUtils.topicExists(zkClient, topicName)) { AdminUtils.createTopic(zkClient, topicName, 1, 1, topicProperties); } log.info("---------------------------Created topic---------------------------"); Assert.assertTrue(AdminUtils.topicExists(zkClient, topicName)); } finally { zkClient.close(); } fnCache.clear(); final Properties kafkaProducerProperties = makeProducerProperties(); Producer<byte[], byte[]> producer = new Producer<byte[], byte[]>( new ProducerConfig(kafkaProducerProperties)); try { producer.send(new KeyedMessage<byte[], byte[]>(topicName, StringUtils.toUtf8("abcdefg"), StringUtils.toUtf8("abcdefg"))); } catch (Exception e) { throw Throwables.propagate(e); } finally { producer.close(); } System.setProperty("druid.extensions.searchCurrentClassloader", "false"); injector = Initialization.makeInjectorWithModules( GuiceInjectors.makeStartupInjectorWithModules(ImmutableList.<Module>of()), ImmutableList.of(new Module() { @Override public void configure(Binder binder) { binder.bindConstant().annotatedWith(Names.named("serviceName")).to("test"); binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0); } }, new NamespacedExtractionModule(), new KafkaExtractionNamespaceModule() { @Override public Properties getProperties(@Json ObjectMapper mapper, Properties systemProperties) { final Properties consumerProperties = new Properties(kafkaProperties); consumerProperties.put("zookeeper.connect", zkTestServer.getConnectString() + "/kafka"); consumerProperties.put("zookeeper.session.timeout.ms", "10000"); consumerProperties.put("zookeeper.sync.time.ms", "200"); return consumerProperties; } })); renameManager = injector.getInstance(KafkaExtractionManager.class); log.info("--------------------------- placed default item via producer ---------------------------"); extractionCacheManager = injector.getInstance(NamespaceExtractionCacheManager.class); extractionCacheManager.schedule(new KafkaExtractionNamespace(topicName, namespace)); long start = System.currentTimeMillis(); while (renameManager.getBackgroundTaskCount() < 1) { Thread.sleep(10); // wait for map populator to start up if (System.currentTimeMillis() > start + 60_000) { throw new ISE("renameManager took too long to start"); } } log.info("--------------------------- started rename manager ---------------------------"); }
From source file:com.jkoolcloud.tnt4j.streams.custom.kafka.interceptors.reporters.trace.MsgTraceReporter.java
protected static void pollConfigQueue(Map<String, ?> config, Properties kafkaProperties, Map<String, TraceCommandDeserializer.TopicTraceCommand> traceConfig) { Properties props = new Properties(); if (config != null) { props.putAll(config); }/*from ww w. j a v a2 s.com*/ if (kafkaProperties != null) { props.putAll(extractKafkaProperties(kafkaProperties)); } if (!props.isEmpty()) { props.put(ConsumerConfig.CLIENT_ID_CONFIG, "kafka-x-ray-message-trace-reporter-config-listener"); // NON-NLS props.remove(ConsumerConfig.INTERCEPTOR_CLASSES_CONFIG); KafkaConsumer<String, TraceCommandDeserializer.TopicTraceCommand> consumer = getKafkaConsumer(props); while (true) { ConsumerRecords<String, TraceCommandDeserializer.TopicTraceCommand> records = consumer.poll(100); if (records.count() > 0) { LOGGER.log(OpLevel.DEBUG, StreamsResources.getBundle(KafkaStreamConstants.RESOURCE_BUNDLE_NAME), "MsgTraceReporter.polled.commands", records.count(), records.iterator().next()); for (ConsumerRecord<String, TraceCommandDeserializer.TopicTraceCommand> record : records) { if (record.value() != null) { traceConfig.put(record.value().topic, record.value()); } } break; } } } }
From source file:org.bonitasoft.engine.util.APITypeManager.java
private static void addPropertiesFrom(File clientFolder, Properties result, String... strings) throws IOException { File folder = FileUtils.getFile(clientFolder, strings); if (folder.exists()) { final Properties defaultProperties = PropertiesManager.getProperties(folder); result.putAll(defaultProperties); }//from w w w .j a v a2 s . c o m }
From source file:com.ikanow.aleph2.distributed_services.utils.KafkaUtils.java
/** * Checks if a topic exists, if not creates a new kafka queue for it. * /*from ww w. j a va 2 s . com*/ * After creating a new topic, waits to see if a leader gets elected (it always seems to fail), * then creates a consumer as a hack to get a leader elected and the offset set correctly. * * I haven't found a way to create a topic and then immediately be able to produce on it without * crashing a consumer first. This is horrible. * * @param topic */ public synchronized static void createTopic(String topic, Optional<Map<String, Object>> options, final ZkUtils zk_client1) { //TODO (ALEPH-10): need to handle topics getting deleted but not being removed from this map //TODO (ALEPH-10): override options if they change? not sure if that's possible if (!my_topics.containsKey(topic)) { logger.debug("CREATE TOPIC"); //http://stackoverflow.com/questions/27036923/how-to-create-a-topic-in-kafka-through-java // For some reason need to create a new zk_client in here for the createTopic call, otherwise the partitions aren't set correctly?! final ZkUtils zk_client = getNewZkClient(); try { if (!AdminUtils.topicExists(zk_client, topic)) { final Properties props = options.map(o -> { final Properties p = new Properties(); p.putAll(o); return p; }).orElse(new Properties()); AdminUtils.createTopic(zk_client, topic, 1, 1, props); boolean leader_elected = waitUntilLeaderElected(zk_client, topic, 1000); logger.debug("LEADER WAS ELECTED: " + leader_elected); //create a consumer to fix offsets (this is a hack, idk why it doesn't work until we create a consumer) WrappedConsumerIterator iter = new WrappedConsumerIterator( getKafkaConsumer(topic, Optional.empty()), topic, 1); iter.hasNext(); //debug info if (logger.isDebugEnabled()) { logger.error("DONE CREATING TOPIC"); //(this was removed in 0.9): //logger.debug(AdminUtils.fetchTopicConfig(zk_client, topic).toString()); TopicMetadata meta = AdminUtils.fetchTopicMetadataFromZk(topic, zk_client); logger.error("META: " + meta); } // (close resources) iter.close(); } } finally { zk_client.close(); } my_topics.put(topic, true); //topic either already existed or was created } }