Example usage for com.fasterxml.jackson.dataformat.yaml YAMLFactory YAMLFactory

List of usage examples for com.fasterxml.jackson.dataformat.yaml YAMLFactory YAMLFactory

Introduction

In this page you can find the example usage for com.fasterxml.jackson.dataformat.yaml YAMLFactory YAMLFactory.

Prototype

public YAMLFactory() 

Source Link

Document

Default constructor used to create factory instances.

Usage

From source file:io.rodeo.chute.ChuteMain.java

public static void main(String[] args)
        throws SQLException, JsonParseException, JsonMappingException, IOException {
    InputStream is = new FileInputStream(new File(CONFIG_FILENAME));
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
    ChuteConfiguration config = mapper.readValue(is, ChuteConfiguration.class);
    Map<String, Importer> importManagers = new HashMap<String, Importer>(config.importerConfigurations.size());
    for (Entry<String, ImporterConfiguration> importerConfig : config.importerConfigurations.entrySet()) {
        importManagers.put(importerConfig.getKey(), importerConfig.getValue().createImporter());
    }// w  w  w  .ja  va  2s. c o  m
    Map<String, Exporter> exportManagers = new HashMap<String, Exporter>(config.exporterConfigurations.size());
    for (Entry<String, ExporterConfiguration> exporterConfig : config.exporterConfigurations.entrySet()) {
        exportManagers.put(exporterConfig.getKey(), exporterConfig.getValue().createExporter());
    }
    for (Entry<String, ConnectionConfiguration> connectionConfig : config.connectionConfigurations.entrySet()) {
        importManagers.get(connectionConfig.getValue().in)
                .addProcessor(exportManagers.get(connectionConfig.getValue().out));
    }

    for (Entry<String, Exporter> exportManager : exportManagers.entrySet()) {
        exportManager.getValue().start();
    }

    for (Entry<String, Importer> importManager : importManagers.entrySet()) {
        importManager.getValue().start();
    }
}

From source file:com.chiralBehaviors.autoconfigure.debug.TemplateDebugger.java

public static void main(String[] argv) throws JsonParseException, JsonMappingException, IOException {
    if (argv.length == 0) {
        System.out.println("Usage: TemplateDebugger <scenario file>+");
        System.exit(1);//from   w ww . j  a  v a  2  s . co m
    }
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    for (String fileName : argv) {
        FileInputStream yaml = new FileInputStream(fileName);
        TemplateDebugger debugger = mapper.readValue(yaml, TemplateDebugger.class);
        System.out.println("======================================");
        System.out.println(String.format("Rendered output of %s", yaml));
        System.out.println("======================================");
        System.out.println();
        System.out.println(debugger.render());
        System.out.println();
        System.out.println("======================================");
        System.out.println();
        System.out.println();
    }
}

From source file:io.rhiot.spec.IoTSpec.java

public static void main(String[] args) throws Exception {

    CommandLineParser parser = new DefaultParser();

    Options options = new Options();
    options.addOption(Option.builder("c").longOpt(CONFIG).desc(
            "Location of the test configuration file. A default value is 'src/main/resources/test.yaml' for easy IDE testing")
            .hasArg().build());/*from ww  w  .  j  av a2 s. c  om*/

    options.addOption(Option.builder("i").longOpt(INSTANCE).desc("Instance of the test; A default value is 1")
            .hasArg().build());

    options.addOption(Option.builder("r").longOpt(REPORT)
            .desc("Location of the test report. A default value is 'target/report.csv'").hasArg().build());

    CommandLine line = parser.parse(options, args);
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    TestProfile test = mapper.readValue(new File(line.getOptionValue(CONFIG, "src/main/resources/test.yaml")),
            TestProfile.class);
    int instance = Integer.valueOf(line.getOptionValue(INSTANCE, "1"));
    test.setInstance(instance);
    String report = line.getOptionValue(REPORT, "target/report.csv");
    test.setReport(new CSVReport(report));

    LOG.info("Test '" + test.getName() + "' instance " + instance + " started");
    final List<Driver> drivers = test.getDrivers();
    ExecutorService executorService = Executors.newFixedThreadPool(drivers.size());
    List<Future<Void>> results = executorService.invokeAll(drivers, test.getDuration(), TimeUnit.MILLISECONDS);
    executorService.shutdownNow();
    executorService.awaitTermination(5, TimeUnit.SECONDS);

    results.forEach(result -> {
        try {
            result.get();
        } catch (ExecutionException execution) {
            LOG.warn("Exception running driver", execution);
        } catch (Exception interrupted) {
        }
    });

    drivers.forEach(driver -> {
        driver.stop();

        try {
            test.getReport().print(driver);
        } catch (Exception e) {
            LOG.warn("Failed to write reports for the driver " + driver);
        }
        LOG.debug("Driver " + driver);
        LOG.debug("\t " + driver.getResult());
    });
    test.getReport().close();

    LOG.info("Test '" + test.getName() + "' instance " + instance + " finished");

}

From source file:org.anhonesteffort.p25.ACAP25.java

public static void main(String[] args) {
    try {//from w w  w . j  a va  2 s.  com

        File systemsFile = new File("test.yml");
        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        List<System> systems = Arrays.asList(mapper.readValue(systemsFile, System[].class));

        new ACAP25(systems).run();

    } catch (IOException | SamplesSourceException e) {
        e.printStackTrace();
    }
}

From source file:edu.sdsc.scigraph.owlapi.loader.BatchOwlLoader.java

public static void main(String[] args) throws Exception {
    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;//from   ww w .j  av a2 s  .c o  m
    try {
        cmd = parser.parse(getOptions(), args);
    } catch (ParseException e) {
        System.err.println(e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(BatchOwlLoader.class.getSimpleName(), getOptions());
        System.exit(-1);
    }

    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    OwlLoadConfiguration config = mapper.readValue(new File(cmd.getOptionValue('c').trim()),
            OwlLoadConfiguration.class);
    load(config);
    // TODO: Is Guice causing this to hang? #44
    System.exit(0);
}

From source file:com.almende.eve.config.YamlReader.java

/**
 * Load./*from   w w  w .  ja  v a  2s  .  com*/
 * 
 * @param is
 *            the is
 * @return the config
 */
public static Config load(final InputStream is) {
    final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    try {
        return Config.decorate((ObjectNode) mapper.readTree(is));
    } catch (final JsonProcessingException e) {
        LOG.log(Level.WARNING, "Couldn't parse Yaml file", e);
    } catch (final IOException e) {
        LOG.log(Level.WARNING, "Couldn't read Yaml file", e);
    }
    return null;
}

From source file:com.huangyunkun.jviff.config.ConfigManager.java

public static Config getConfigFromFile(String filePath) throws IOException {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    Config config = mapper.readValue(new File(filePath), Config.class);
    if (StringUtils.isEmpty(config.getOutputDir())) {
        config.setOutputDir(Files.createTempDir().getAbsolutePath());
    }/*  w w w.  j  av a2  s . co  m*/
    return config;
}

From source file:com.hurence.logisland.config.ConfigReader.java

/**
 * Loads a YAML config file//from w  ww.ja va2 s  .c  om
 *
 * @param configFilePath the path of the config file
 * @return a LogislandSessionConfiguration
 * @throws Exception
 */
public static LogislandConfiguration loadConfig(String configFilePath) throws Exception {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    File configFile = new File(configFilePath);

    if (!configFile.exists()) {
        throw new FileNotFoundException("Error: File " + configFilePath + " not found!");
    }

    return mapper.readValue(configFile, LogislandConfiguration.class);
}

From source file:com.chiralbehaviors.scout.server.ScoutConfiguration.java

public static ScoutConfiguration fromYaml(InputStream yaml)
        throws JsonParseException, JsonMappingException, IOException {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    return mapper.readValue(yaml, ScoutConfiguration.class);
}

From source file:com.chiral.oauth.OAuthConfiguration.java

public static OAuthConfiguration fromYaml(InputStream yaml)
        throws JsonParseException, JsonMappingException, IOException {
    OAuthConfiguration configuration = new ObjectMapper(new YAMLFactory()).readValue(yaml,
            OAuthConfiguration.class);
    yaml.close();/* w ww.  ja v a2 s.  com*/
    return configuration;
}