List of usage examples for java.util Properties putAll
@Override public synchronized void putAll(Map<?, ?> t)
From source file:gobblin.scheduler.SchedulerDaemon.java
public static void main(String[] args) throws Exception { if (args.length < 1 || args.length > 2) { System.err.println(//from ww w .ja v a2 s. c o m "Usage: SchedulerDaemon <default configuration properties file> [custom configuration properties file]"); System.exit(1); } // Load default framework configuration properties Properties defaultProperties = ConfigurationConverter.getProperties(new PropertiesConfiguration(args[0])); // Load custom framework configuration properties (if any) Properties customProperties = new Properties(); if (args.length == 2) { customProperties.putAll(ConfigurationConverter.getProperties(new PropertiesConfiguration(args[1]))); } log.debug("Scheduler Daemon::main starting with defaultProperties: {}, customProperties: {}", defaultProperties, customProperties); // Start the scheduler daemon new SchedulerDaemon(defaultProperties, customProperties).start(); }
From source file:com.github.jcustenborder.kafka.connect.spooldir.SchemaGenerator.java
public static void main(String... args) throws Exception { ArgumentParser parser = ArgumentParsers.newArgumentParser("CsvSchemaGenerator").defaultHelp(true) .description("Generate a schema based on a file."); parser.addArgument("-t", "--type").required(true).choices("csv", "json") .help("The type of generator to use."); parser.addArgument("-c", "--config").type(File.class); parser.addArgument("-f", "--file").type(File.class).required(true) .help("The data file to generate the schema from."); parser.addArgument("-i", "--id").nargs("*").help("Field(s) to use as an identifier."); parser.addArgument("-o", "--output").type(File.class) .help("Output location to write the configuration to. Stdout is default."); Namespace ns = null;/* www . ja v a 2s . co m*/ try { ns = parser.parseArgs(args); } catch (ArgumentParserException ex) { parser.handleError(ex); System.exit(1); } File inputFile = ns.get("file"); List<String> ids = ns.getList("id"); if (null == ids) { ids = ImmutableList.of(); } Map<String, Object> settings = new LinkedHashMap<>(); File inputPropertiesFile = ns.get("config"); if (null != inputPropertiesFile) { Properties inputProperties = new Properties(); try (FileInputStream inputStream = new FileInputStream(inputPropertiesFile)) { inputProperties.load(inputStream); } for (String s : inputProperties.stringPropertyNames()) { Object v = inputProperties.getProperty(s); settings.put(s, v); } } final SchemaGenerator generator; final String type = ns.getString("type"); if ("csv".equalsIgnoreCase(type)) { generator = new CsvSchemaGenerator(settings); } else if ("json".equalsIgnoreCase(type)) { generator = new JsonSchemaGenerator(settings); } else { throw new UnsupportedOperationException( String.format("'%s' is not a supported schema generator type", type)); } Map.Entry<Schema, Schema> kvp = generator.generate(inputFile, ids); Properties properties = new Properties(); properties.putAll(settings); properties.setProperty(SpoolDirSourceConnectorConfig.KEY_SCHEMA_CONF, ObjectMapperFactory.INSTANCE.writeValueAsString(kvp.getKey())); properties.setProperty(SpoolDirSourceConnectorConfig.VALUE_SCHEMA_CONF, ObjectMapperFactory.INSTANCE.writeValueAsString(kvp.getValue())); String output = ns.getString("output"); final String comment = "Configuration was dynamically generated. Please verify before submitting."; if (Strings.isNullOrEmpty(output)) { properties.store(System.out, comment); } else { try (FileOutputStream outputStream = new FileOutputStream(output)) { properties.store(outputStream, comment); } } }
From source file:org.apache.ctakes.ytex.kernel.CytoscapeHelperImpl.java
/** * @param args//from ww w . j a v a 2 s. c o m */ @SuppressWarnings("static-access") public static void main(String args[]) throws ParseException, IOException { Options options = new Options(); options.addOption(OptionBuilder.withArgName("prop").hasArg() .withDescription("property file with queries and other parameters. todo desc").create("prop")); OptionGroup og = new OptionGroup(); og.addOption(OptionBuilder.withArgName("network").hasArg().withDescription( "create network using specified concept graph and corpus. creates prefix.sif with edges and prefix.node.txt with node data in working directory.") .create("network")); og.addOption(OptionBuilder.withArgName("concept id").hasArg().withDescription( "get all descendants of specified concept, creates concept_id.tree file in working directory") .create("subtree")); og.setRequired(true); options.addOptionGroup(og); try { CommandLineParser parser = new GnuParser(); CommandLine line = parser.parse(options, args); CytoscapeHelper cytHelper = KernelContextHolder.getApplicationContext().getBean(CytoscapeHelper.class); Properties props = new Properties(System.getProperties()); props.putAll(FileUtil.loadProperties(line.getOptionValue("prop"), true)); if (!cytHelper.validateProps(props)) { printHelp(options); } else { if (line.hasOption("network")) { cytHelper.exportNetwork(line.getOptionValue("network"), props); } else if (line.hasOption("subtree")) { cytHelper.exportSubtree(line.getOptionValue("subtree"), props); } else { printHelp(options); } } } catch (ParseException pe) { printHelp(options); } }
From source file:gobblin.test.TestWorker.java
@SuppressWarnings("all") public static void main(String[] args) throws Exception { // Build command-line options Option configOption = OptionBuilder.withArgName("framework config file") .withDescription("Configuration properties file for the framework").hasArgs().withLongOpt("config") .create('c'); Option jobConfigsOption = OptionBuilder.withArgName("job config files") .withDescription("Comma-separated list of job configuration files").hasArgs() .withLongOpt("jobconfigs").create('j'); Option modeOption = OptionBuilder.withArgName("run mode") .withDescription("Test mode (schedule|run); 'schedule' means scheduling the jobs, " + "whereas 'run' means running the jobs immediately") .hasArg().withLongOpt("mode").create('m'); Option helpOption = OptionBuilder.withArgName("help").withDescription("Display usage information") .withLongOpt("help").create('h'); Options options = new Options(); options.addOption(configOption);/*from www . ja v a 2s .c o m*/ options.addOption(jobConfigsOption); options.addOption(modeOption); options.addOption(helpOption); // Parse command-line options CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption('h')) { printUsage(options); System.exit(0); } // Start the test worker with the given configuration properties Configuration config = new PropertiesConfiguration(cmd.getOptionValue('c')); Properties properties = ConfigurationConverter.getProperties(config); TestWorker testWorker = new TestWorker(properties); testWorker.start(); // Job running mode Mode mode = Mode.valueOf(cmd.getOptionValue('m').toUpperCase()); // Get the list of job configuration files List<String> jobConfigFiles = Lists .newArrayList(Splitter.on(',').omitEmptyStrings().trimResults().split(cmd.getOptionValue('j'))); CountDownLatch latch = new CountDownLatch(jobConfigFiles.size()); for (String jobConfigFile : jobConfigFiles) { // For each job, load the job configuration, then run or schedule the job. Properties jobProps = new Properties(); jobProps.load(new FileReader(jobConfigFile)); jobProps.putAll(properties); testWorker.runJob(jobProps, mode, new TestJobListener(latch)); } // Wait for all jobs to finish latch.await(); testWorker.stop(); }
From source file:com.jivesoftware.os.routing.bird.deployable.config.extractor.ConfigExtractor.java
public static void main(String[] args) { String configHost = args[0];//w w w. j a va 2s.com String configPort = args[1]; String instanceKey = args[2]; String instanceVersion = args[3]; String setPath = args[4]; String getPath = args[5]; HttpRequestHelper buildRequestHelper = buildRequestHelper(null, configHost, Integer.parseInt(configPort)); try { Set<URL> packages = new HashSet<>(); for (int i = 5; i < args.length; i++) { packages.addAll(ClasspathHelper.forPackage(args[i])); } Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(packages) .setScanners(new SubTypesScanner(), new TypesScanner())); Set<Class<? extends Config>> subTypesOf = reflections.getSubTypesOf(Config.class); File configDir = new File("./config"); configDir.mkdirs(); Set<Class<? extends Config>> serviceConfig = new HashSet<>(); Set<Class<? extends Config>> healthConfig = new HashSet<>(); for (Class<? extends Config> type : subTypesOf) { if (HealthCheckConfig.class.isAssignableFrom(type)) { healthConfig.add(type); } else { serviceConfig.add(type); } } Map<String, String> defaultServiceConfig = extractAndPublish(serviceConfig, new File(configDir, "default-service-config.properties"), "default", instanceKey, instanceVersion, buildRequestHelper, setPath); DeployableConfig getServiceOverrides = new DeployableConfig("override", instanceKey, instanceVersion, defaultServiceConfig); DeployableConfig gotSerivceConfig = buildRequestHelper.executeRequest(getServiceOverrides, getPath, DeployableConfig.class, null); if (gotSerivceConfig == null) { System.out.println("Failed to publish default service config for " + Arrays.deepToString(args)); } else { Properties override = createKeySortedProperties(); override.putAll(gotSerivceConfig.properties); override.store(new FileOutputStream("config/override-service-config.properties"), ""); } Map<String, String> defaultHealthConfig = extractAndPublish(healthConfig, new File(configDir, "default-health-config.properties"), "default-health", instanceKey, instanceVersion, buildRequestHelper, setPath); DeployableConfig getHealthOverrides = new DeployableConfig("override-health", instanceKey, instanceVersion, defaultHealthConfig); DeployableConfig gotHealthConfig = buildRequestHelper.executeRequest(getHealthOverrides, getPath, DeployableConfig.class, null); if (gotHealthConfig == null) { System.out.println("Failed to publish default health config for " + Arrays.deepToString(args)); } else { Properties override = createKeySortedProperties(); override.putAll(gotHealthConfig.properties); override.store(new FileOutputStream("config/override-health-config.properties"), ""); } Properties instanceProperties = createKeySortedProperties(); File configFile = new File("config/instance.properties"); if (configFile.exists()) { instanceProperties.load(new FileInputStream(configFile)); } Properties serviceOverrideProperties = createKeySortedProperties(); configFile = new File("config/override-service-config.properties"); if (configFile.exists()) { serviceOverrideProperties.load(new FileInputStream(configFile)); } Properties healthOverrideProperties = createKeySortedProperties(); configFile = new File("config/override-health-config.properties"); if (configFile.exists()) { healthOverrideProperties.load(new FileInputStream(configFile)); } Properties properties = createKeySortedProperties(); properties.putAll(defaultServiceConfig); properties.putAll(defaultHealthConfig); properties.putAll(serviceOverrideProperties); properties.putAll(healthOverrideProperties); properties.putAll(instanceProperties); properties.store(new FileOutputStream("config/config.properties"), ""); System.exit(0); } catch (Exception x) { x.printStackTrace(); System.exit(1); } }
From source file:kafka.benchmark.AdvertisingTopology.java
public static void main(final String[] args) throws Exception { Options opts = new Options(); opts.addOption("conf", true, "Path to the config file."); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(opts, args); String configPath = cmd.getOptionValue("conf"); Map<?, ?> conf = Utils.findAndReadConfigFile(configPath, true); Map<String, ?> benchmarkParams = getKafkaConfs(conf); LOG.info("conf: {}", conf); LOG.info("Parameters used: {}", benchmarkParams); KStreamBuilder builder = new KStreamBuilder(); // builder.addStateStore( // Stores.create("config-params") // .withStringKeys().withStringValues() // .inMemory().maxEntries(10).build(), "redis"); String topicsArr[] = { (String) benchmarkParams.get("topic") }; KStream<String, ?> source1 = builder.stream(topicsArr); Properties props = new Properties(); props.putAll(benchmarkParams); // props.put(StreamsConfig.APPLICATION_ID_CONFIG, "kafka-benchmarks"); // props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); //// props.put(StreamsConfig.ZOOKEEPER_CONNECT_CONFIG, "localhost:2181"); props.put(StreamsConfig.KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName()); props.put(StreamsConfig.VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName()); // setting offset reset to earliest so that we can re-run the demo code with the same pre-loaded data // props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); source1/* ww w. java 2 s .c o m*/ // Parse the String as JSON .mapValues(input -> { JSONObject obj = new JSONObject(input.toString()); //System.out.println(obj.toString()); String[] tuple = { obj.getString("user_id"), obj.getString("page_id"), obj.getString("ad_id"), obj.getString("ad_type"), obj.getString("event_type"), obj.getString("event_time"), obj.getString("ip_address") }; return tuple; }) // Filter the records if event type is "view" .filter(new Predicate<String, String[]>() { @Override public boolean test(String key, String[] value) { return value[4].equals("view"); // "event_type" } }) // project the event .mapValues(input -> { String[] arr = (String[]) input; return new String[] { arr[2], arr[5] }; // "ad_id" and "event_time" }) // perform join with redis data .transformValues(new RedisJoinBolt(benchmarkParams)).filter((key, value) -> value != null) // create key from value .map((key, value) -> { String[] arr = (String[]) value; return new KeyValue<String, String[]>(arr[0], arr); }) // process campaign .aggregateByKey(new Initializer<List<String[]>>() { @Override public List<String[]> apply() { return new ArrayList<String[]>(); } }, new Aggregator<String, String[], List<String[]>>() { @Override public List<String[]> apply(String aggKey, String[] value, List<String[]> aggregate) { aggregate.add(value); return aggregate; } }, // UnlimitedWindows.of("kafka-test-unlim"), // HoppingWindows.of("kafka-test-hopping").with(12L).every(5L), TumblingWindows.of("kafka-test-tumbling").with(WINDOW_SIZE), strSerde, arrSerde) .toStream().process(new CampaignProcessor(benchmarkParams)); KafkaStreams streams = new KafkaStreams(builder, props); streams.start(); }
From source file:com.arainfor.thermostat.daemon.HvacMonitor.java
/** * @param args The Program Arguments/*from w ww .j a va 2 s. c o m*/ */ public static void main(String[] args) throws IOException { Logger log = LoggerFactory.getLogger(HvacMonitor.class); //System.err.println(APPLICATION_NAME + " v" + APPLICATION_VERSION_MAJOR + "." + APPLICATION_VERSION_MINOR + "." + APPLICATION_VERSION_BUILD); Options options = new Options(); options.addOption("help", false, "This message isn't very helpful"); options.addOption("version", false, "Print the version number"); options.addOption("monitor", false, "Start GUI Monitor"); options.addOption("config", true, "The configuration file"); CommandLineParser parser = new GnuParser(); CommandLine cmd; try { cmd = parser.parse(options, args); if (cmd.hasOption("help")) { HelpFormatter hf = new HelpFormatter(); hf.printHelp(APPLICATION_NAME, options); return; } if (cmd.hasOption("version")) { System.out.println("The " + APPLICATION_NAME + " v" + APPLICATION_VERSION_MAJOR + "." + APPLICATION_VERSION_MINOR + "." + APPLICATION_VERSION_BUILD); } } catch (ParseException e) { e.printStackTrace(); return; } String propFileName = "thermostat.properties"; if (cmd.getOptionValue("config") != null) propFileName = cmd.getOptionValue("config"); log.info("loading...{}", propFileName); try { Properties props = new PropertiesLoader(propFileName).getProps(); // Append the system properties with our application properties props.putAll(System.getProperties()); System.setProperties(props); } catch (FileNotFoundException fnfe) { log.warn("Cannot load file:", fnfe); } new HvacMonitor().start(); }
From source file:com.adobe.aem.demomachine.Checksums.java
public static void main(String[] args) { String rootFolder = null;//from w w w . java 2 s .c o m // Command line options for this tool Options options = new Options(); options.addOption("f", true, "Demo Machine root folder"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("f")) { rootFolder = cmd.getOptionValue("f"); } } catch (Exception e) { System.exit(-1); } Properties md5properties = new Properties(); List<String[]> listPaths = Arrays.asList(AemDemoConstants.demoPaths); for (String[] path : listPaths) { if (path.length == 5) { logger.debug(path[1]); File pathFolder = new File(rootFolder + (path[1].length() > 0 ? (File.separator + path[1]) : "")); if (pathFolder.exists()) { String md5 = AemDemoUtils.calcMD5HashForDir(pathFolder, Boolean.parseBoolean(path[3]), false); logger.debug("MD5 is: " + md5); md5properties.setProperty("demo.path." + path[0], path[1]); md5properties.setProperty("demo.md5." + path[0], md5); } else { logger.error("Folder cannot be found"); } } } File md5 = new File(rootFolder + File.separator + "conf" + File.separator + "checksums.properties"); try { @SuppressWarnings("serial") Properties tmpProperties = new Properties() { @Override public synchronized Enumeration<Object> keys() { return Collections.enumeration(new TreeSet<Object>(super.keySet())); } }; tmpProperties.putAll(md5properties); tmpProperties.store(new FileOutputStream(md5), null); } catch (Exception e) { logger.error(e.getMessage()); } System.out.println("MD5 checkums generated"); }
From source file:org.apache.ctakes.ytex.kernel.InfoContentEvaluatorImpl.java
/** * @param args//from w w w . j a v a 2 s . c o m * @throws IOException */ @SuppressWarnings("static-access") public static void main(String[] args) throws IOException { Options options = new Options(); options.addOption(OptionBuilder.withArgName("property file").hasArg().isRequired() .withDescription("property file with queries and other parameters. todo desc").create("prop")); try { CommandLineParser parser = new GnuParser(); CommandLine line = parser.parse(options, args); Properties props = (Properties) KernelContextHolder.getApplicationContext().getBean("ytexProperties"); Properties propsArgs = FileUtil.loadProperties(line.getOptionValue("prop"), true); props.putAll(propsArgs); if (!props.containsKey("org.apache.ctakes.ytex.conceptGraphName") || !props.containsKey("org.apache.ctakes.ytex.corpusName") || !props.containsKey("org.apache.ctakes.ytex.freqQuery")) { System.err.println("error: required parameter not specified"); System.exit(1); } else { InfoContentEvaluator corpusEvaluator = KernelContextHolder.getApplicationContext() .getBean(InfoContentEvaluator.class); corpusEvaluator.evaluateCorpusInfoContent(props.getProperty("org.apache.ctakes.ytex.freqQuery"), props.getProperty("org.apache.ctakes.ytex.corpusName"), props.getProperty("org.apache.ctakes.ytex.conceptGraphName"), props.getProperty("org.apache.ctakes.ytex.conceptSetName")); System.exit(0); } } catch (ParseException pe) { printHelp(options); System.exit(1); } }
From source file:com.marklogic.client.tutorial.util.Bootstrapper.java
/** * Command-line invocation.//from w w w . j a va2 s .co m * @param args command-line arguments specifying the configuration and REST server */ public static void main(String[] args) throws ClientProtocolException, IOException, XMLStreamException, FactoryConfigurationError { Properties properties = new Properties(); for (int i = 0; i < args.length; i++) { String name = args[i]; if (name.startsWith("-") && name.length() > 1 && ++i < args.length) { name = name.substring(1); if ("properties".equals(name)) { InputStream propsStream = Bootstrapper.class.getClassLoader().getResourceAsStream(name); if (propsStream == null) throw new IOException("Could not read bootstrapper properties"); Properties props = new Properties(); props.load(propsStream); props.putAll(properties); properties = props; } else { properties.put(name, args[i]); } } else { System.err.println("invalid argument: " + name); System.err.println(getUsage()); System.exit(1); } } String invalid = joinList(listInvalidKeys(properties)); if (invalid != null && invalid.length() > 0) { System.err.println("invalid arguments: " + invalid); System.err.println(getUsage()); System.exit(1); } new Bootstrapper().makeServer(properties); System.out.println("Created " + properties.getProperty("restserver") + " server on " + properties.getProperty("restport") + " port for " + properties.getProperty("restdb") + " database"); }