Example usage for org.apache.commons.configuration ConfigurationConverter getProperties

List of usage examples for org.apache.commons.configuration ConfigurationConverter getProperties

Introduction

In this page you can find the example usage for org.apache.commons.configuration ConfigurationConverter getProperties.

Prototype

public static Properties getProperties(Configuration config) 

Source Link

Document

Convert a Configuration class into a Properties class.

Usage

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 w  ww  .j  a v a2 s  .com
                "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:gobblin.compaction.CompactionRunner.java

public static void main(String[] args) throws ConfigurationException, IOException, SQLException {

    if (args.length != 1) {
        LOG.info("Proper usage: java -jar compaction.jar <global-config-file>\n" + "or\n"
                + "hadoop jar compaction.jar <global-config-file>\n" + "or\n"
                + "yarn jar compaction.jar <global-config-file>\n");
        System.exit(1);/*  w  w  w . j  ava 2  s  .c  o  m*/
    }

    Configuration globalConfig = new PropertiesConfiguration(args[0]);
    properties = ConfigurationConverter.getProperties(globalConfig);

    File compactionConfigDir = new File(properties.getProperty(COMPACTION_CONFIG_DIR));
    File[] listOfFiles = compactionConfigDir.listFiles();
    if (listOfFiles == null || listOfFiles.length == 0) {
        System.err.println("No compaction configuration files found under " + compactionConfigDir);
        System.exit(1);
    }

    int numOfJobs = 0;
    for (File file : listOfFiles) {
        if (file.isFile() && !file.getName().startsWith(".")) {
            numOfJobs++;
        }
    }
    LOG.info("Found " + numOfJobs + " compaction tasks.");
    PrintWriter pw = new PrintWriter(new OutputStreamWriter(
            new FileOutputStream(properties.getProperty(TIMING_FILE, TIMING_FILE_DEFAULT)),
            Charset.forName("UTF-8")));

    for (File file : listOfFiles) {
        if (file.isFile() && !file.getName().startsWith(".")) {
            Configuration jobConfig = new PropertiesConfiguration(file.getAbsolutePath());
            jobProperties = ConfigurationConverter.getProperties(jobConfig);
            long startTime = System.nanoTime();
            compact();
            long endTime = System.nanoTime();
            long elapsedTime = endTime - startTime;
            double seconds = TimeUnit.NANOSECONDS.toSeconds(elapsedTime);
            pw.printf("%s: %f%n", file.getAbsolutePath(), seconds);
        }
    }

    pw.close();
}

From source file:gobblin.compaction.hive.CompactionRunner.java

public static void main(String[] args) throws IOException, ConfigurationException {

    properties = CliOptions.parseArgs(MRCompactionRunner.class, args);

    File compactionConfigDir = new File(properties.getProperty(COMPACTION_CONFIG_DIR));
    File[] listOfFiles = compactionConfigDir.listFiles();
    if (listOfFiles == null || listOfFiles.length == 0) {
        System.err.println("No compaction configuration files found under " + compactionConfigDir);
        System.exit(1);//from  ww w. j a va2  s .co  m
    }

    int numOfJobs = 0;
    for (File file : listOfFiles) {
        if (file.isFile() && !file.getName().startsWith(".")) {
            numOfJobs++;
        }
    }
    LOG.info("Found " + numOfJobs + " compaction tasks.");
    try (PrintWriter pw = new PrintWriter(new OutputStreamWriter(
            new FileOutputStream(properties.getProperty(TIMING_FILE, TIMING_FILE_DEFAULT)),
            Charset.forName("UTF-8")))) {

        for (File file : listOfFiles) {
            if (file.isFile() && !file.getName().startsWith(".")) {
                Configuration jobConfig = new PropertiesConfiguration(file.getAbsolutePath());
                jobProperties = ConfigurationConverter.getProperties(jobConfig);
                long startTime = System.nanoTime();
                compact();
                long endTime = System.nanoTime();
                long elapsedTime = endTime - startTime;
                double seconds = TimeUnit.NANOSECONDS.toSeconds(elapsedTime);
                pw.printf("%s: %f%n", file.getAbsolutePath(), seconds);
            }
        }
    }
}

From source file:gobblin.scheduler.Worker.java

public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.err.println("Usage: Worker <work configuration properties file>");
        System.exit(1);/*from   w ww  . ja  va 2 s.c  om*/
    }

    // Load framework configuration properties
    Configuration config = new PropertiesConfiguration(args[0]);
    // Start the worker
    new Worker(ConfigurationConverter.getProperties(config)).start();
}

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);/*w  w w  .j a v a  2  s.  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:io.fluo.stress.trie.NumberIngest.java

public static void main(String[] args) throws IOException, ConfigurationException {

    // Parse arguments
    if (args.length != 4) {
        log.error("Usage: NumberIngest <numMappers> <numbersPerMapper> <nodeSize> <fluoProps>");
        System.exit(-1);/*from   w  ww.j  av a2s. co  m*/
    }
    int numMappers = Integer.parseInt(args[0]);
    int numPerMapper = Integer.parseInt(args[1]);
    int nodeSize = Integer.parseInt(args[2]);
    String fluoPropsPath = args[3];

    String hadoopPrefix = System.getenv("HADOOP_PREFIX");
    if (hadoopPrefix == null) {
        hadoopPrefix = System.getenv("HADOOP_HOME");
        if (hadoopPrefix == null) {
            log.error("HADOOP_PREFIX or HADOOP_HOME needs to be set!");
            System.exit(-1);
        }
    }

    // create test name
    String testId = String.format("test-%d", (new Date().getTime() / 1000));
    String testDir = "/trie-stress/" + testId;

    setupHdfs(hadoopPrefix, testDir, numMappers, numPerMapper);

    JobConf ingestConf = new JobConf(NumberIngest.class);
    ingestConf.setJobName("NumberIngest");

    FluoConfiguration config = new FluoConfiguration(new File(fluoPropsPath));

    loadConfig(ingestConf, ConfigurationConverter.getProperties(config));
    ingestConf.setInt(TRIE_NODE_SIZE_PROP, nodeSize);

    ingestConf.setOutputKeyClass(LongWritable.class);
    ingestConf.setOutputValueClass(IntWritable.class);
    ingestConf.setMapperClass(NumberIngest.IngestMapper.class);
    ingestConf.setReducerClass(NumberIngest.UniqueReducer.class);

    FileInputFormat.setInputPaths(ingestConf, new Path(testDir + "/input/"));
    FileOutputFormat.setOutputPath(ingestConf, new Path(testDir + "/unique/"));

    RunningJob ingestJob = JobClient.runJob(ingestConf);
    ingestJob.waitForCompletion();
    if (ingestJob.isSuccessful()) {

        JobConf countConf = new JobConf(NumberIngest.class);
        countConf.setJobName("NumberCount");

        countConf.setOutputKeyClass(Text.class);
        countConf.setOutputValueClass(LongWritable.class);
        countConf.setMapperClass(NumberIngest.CountMapper.class);
        countConf.setReducerClass(NumberIngest.CountReducer.class);

        FileInputFormat.setInputPaths(countConf, new Path(testDir + "/unique/"));
        FileOutputFormat.setOutputPath(countConf, new Path(testDir + "/output/"));

        RunningJob countJob = JobClient.runJob(countConf);
        countJob.waitForCompletion();
        if (countJob.isSuccessful()) {
            log.info("Ingest and count jobs were successful");
            log.info("Output can be viewed @ " + testDir);
            System.exit(0);
        } else {
            log.error("Count job failed for " + testId);
        }
    } else {
        log.error("Ingest job failed.  Skipping count job for " + testId);
    }

    System.exit(-1);
}

From source file:com.gs.obevo.db.impl.core.compare.data.DbDataComparisonConfigFactory.java

public static DbDataComparisonConfig createFromProperties(final Configuration config) {
    Properties propsView = ConfigurationConverter.getProperties(config); // config.getString() automatically parses
    // for commas...would like to avoid this
    DbDataComparisonConfig compConfig = new DbDataComparisonConfig();
    compConfig.setInputTables(Lists.mutable.with(propsView.getProperty("tables.include").split(",")));
    compConfig//  w ww .j a v  a 2s.  c o  m
            .setExcludedTables(Lists.mutable.with(propsView.getProperty("tables.exclude").split(",")).toSet());
    String comparisonsStr = propsView.getProperty("comparisons");

    MutableList<Pair<String, String>> compCmdPairs = Lists.mutable.empty();
    MutableSet<String> dsNames = UnifiedSet.newSet();
    for (String compPairStr : comparisonsStr.split(";")) {
        String[] pairParts = compPairStr.split(",");
        compCmdPairs.add(Tuples.pair(pairParts[0], pairParts[1]));

        // note - if I knew where the Pair.TO_ONE TO_TWO selectors were, I'd use those
        dsNames.add(pairParts[0]);
        dsNames.add(pairParts[1]);
    }

    compConfig.setComparisonCommandNamePairs(compCmdPairs);

    MutableList<DbDataSource> dbDataSources = dsNames.toList().collect(new Function<String, DbDataSource>() {
        @Override
        public DbDataSource valueOf(String dsName) {
            Configuration dsConfig = config.subset(dsName);

            DbDataSource dbDataSource = new DbDataSource();
            dbDataSource.setName(dsName);
            dbDataSource.setUrl(dsConfig.getString("url"));
            dbDataSource.setSchema(dsConfig.getString("schema"));
            dbDataSource.setUsername(dsConfig.getString("username"));
            dbDataSource.setPassword(dsConfig.getString("password"));
            dbDataSource.setDriverClassName(dsConfig.getString("driverClass"));

            return dbDataSource;
        }
    });
    compConfig.setDbDataSources(dbDataSources);
    return compConfig;
}

From source file:io.s4.example.model.Module.java

private void loadProperties(Binder binder) {

    try {/*from  ww  w  .  j  ava2 s  .c  o  m*/
        InputStream is = this.getClass().getResourceAsStream("/model.properties");
        config = new PropertiesConfiguration();
        config.load(is);

        System.out.println(ConfigurationUtils.toString(config));
        // TODO - validate properties.

        /* Make all properties injectable. Do we need this? */
        Names.bindProperties(binder, ConfigurationConverter.getProperties(config));
    } catch (ConfigurationException e) {
        binder.addError(e);
        e.printStackTrace();
    }
}

From source file:io.fluo.cluster.main.MainOptions.java

public void validateConfig() throws IOException {
    if (getConfigDir() == null) {
        System.err.println(//from   www.  ja  va2s  . c  o m
                "Please set -config-dir option to directory containing fluo.properties file like below: ");
        System.err.println();
        Properties defaults = ConfigurationConverter.getProperties(FluoConfiguration.getDefaultConfiguration());
        defaults.store(System.err, "Fluo properties");
        System.exit(-1);
    }
}

From source file:io.s4.meter.controller.ControllerModule.java

private void loadProperties(Binder binder) {

    try {//ww  w . ja v  a2s .  com
        InputStream is = this.getClass().getResourceAsStream("/s4-meter.properties");
        config = new PropertiesConfiguration();
        config.load(is);

        System.out.println(ConfigurationUtils.toString(config));
        // TODO - validate properties.

        /* Make all properties injectable. Do we need this? */
        Names.bindProperties(binder, ConfigurationConverter.getProperties(config));
    } catch (ConfigurationException e) {
        binder.addError(e);
        e.printStackTrace();
    }
}