Search in sources :

Example 86 with Yaml

use of org.yaml.snakeyaml.Yaml in project universa by UniversaBlockchain.

the class NodeInfo method loadYaml.

public static NodeInfo loadYaml(Path fileName) {
    try {
        Yaml yaml = new Yaml();
        Binder b = Binder.from(yaml.load(new FileInputStream(fileName.toString())));
        // System.out.println(fileName);
        int count = fileName.getNameCount();
        String n = fileName.getName(count - 1).toString();
        n = n.substring(0, n.length() - 5) + ".public.unikey";
        String keyPath = "/" + fileName.subpath(0, count - 2) + "/keys/" + n;
        System.out.println("expected key file path: <" + keyPath + ">");
        // System.out.println(keyPath);
        // System.out.println(b);
        PublicKey key = new PublicKey(Do.read(keyPath));
        return new NodeInfo(key, b.getIntOrThrow("node_number"), b.getStringOrThrow("node_name"), (String) b.getListOrThrow("ip").get(0), b.getStringOrThrow("public_host"), b.getIntOrThrow("udp_server_port"), b.getIntOrThrow("http_client_port"), b.getIntOrThrow("http_server_port"));
    } catch (Exception e) {
        System.err.println("failed to load node: " + fileName + ": " + e);
        e.printStackTrace();
    }
    return null;
}
Also used : Binder(net.sergeych.tools.Binder) PublicKey(com.icodici.crypto.PublicKey) Yaml(org.yaml.snakeyaml.Yaml) FileInputStream(java.io.FileInputStream) SQLException(java.sql.SQLException)

Example 87 with Yaml

use of org.yaml.snakeyaml.Yaml in project betca-tpv-spring by miw-upm.

the class DatabaseSeederService method seedDatabase.

public void seedDatabase(String ymlFileName) throws IOException {
    assert ymlFileName != null && !ymlFileName.isEmpty();
    Yaml yamlParser = new Yaml(new Constructor(DatabaseGraph.class));
    InputStream input = new ClassPathResource(ymlFileName).getInputStream();
    DatabaseGraph tpvGraph = (DatabaseGraph) yamlParser.load(input);
    // Save Repositories -----------------------------------------------------
    if (tpvGraph.getUserList() != null) {
        this.userRepository.save(tpvGraph.getUserList());
    }
    if (tpvGraph.getVoucherList() != null) {
        this.voucherRepository.save(tpvGraph.getVoucherList());
    }
    if (tpvGraph.getCashMovementList() != null) {
        this.cashMovementRepository.save(tpvGraph.getCashMovementList());
    }
    if (tpvGraph.getCashierClosureList() != null) {
        this.cashierClosureRepository.save(tpvGraph.getCashierClosureList());
    }
    if (tpvGraph.getProviderList() != null) {
        this.providerRepository.save(tpvGraph.getProviderList());
    }
    if (tpvGraph.getArticleList() != null) {
        this.articleRepository.save(tpvGraph.getArticleList());
    }
    if (tpvGraph.getTicketList() != null) {
        this.ticketRepository.save(tpvGraph.getTicketList());
    }
    if (tpvGraph.getInvoiceList() != null) {
        this.invoiceRepository.save(tpvGraph.getInvoiceList());
    }
    if (tpvGraph.getOfferList() != null) {
        this.offerRepository.save(tpvGraph.getOfferList());
    }
    // -----------------------------------------------------------------------
    Logger.getLogger(this.getClass()).warn("------------------------- Seed: " + ymlFileName + "-----------");
}
Also used : Constructor(org.yaml.snakeyaml.constructor.Constructor) InputStream(java.io.InputStream) Yaml(org.yaml.snakeyaml.Yaml) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 88 with Yaml

use of org.yaml.snakeyaml.Yaml in project opentest by mcdcorp.

the class Factory method getYaml.

/**
 * Returns a YAML parser object pre-configured with some defaults.
 */
public static Yaml getYaml() {
    final DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
    options.setPrettyFlow(true);
    SkipNullRepresenter representer = new SkipNullRepresenter();
    representer.addClassTag(TestDefAction.class, Tag.MAP);
    return new Yaml(representer, options);
}
Also used : SkipNullRepresenter(org.getopentest.serialization.yaml.SkipNullRepresenter) DumperOptions(org.yaml.snakeyaml.DumperOptions) Yaml(org.yaml.snakeyaml.Yaml)

Example 89 with Yaml

use of org.yaml.snakeyaml.Yaml in project incubator-heron by apache.

the class ConfigUtilsTests method testApplyEmptyOverrides.

@Test
@SuppressWarnings("unchecked")
public void testApplyEmptyOverrides() throws IOException {
    final Properties overrideProperties = createOverrideProperties(Pair.create("heron.statemgr.connection.string", "zookeeper:2181"), Pair.create("heron.kubernetes.scheduler.uri", "http://127.0.0.1:8001"));
    final String overridesPath = ConfigUtils.createOverrideConfiguration(overrideProperties);
    ConfigUtils.applyOverrides(Paths.get(overridesPath), new HashMap<>());
    final Map<String, String> overrides = new HashMap<>();
    for (String key : overrideProperties.stringPropertyNames()) {
        overrides.put(key, overrideProperties.getProperty(key));
    }
    try (Reader reader = Files.newBufferedReader(Paths.get(overridesPath))) {
        final Map<String, Object> newOverrides = (Map<String, Object>) new Yaml().loadAs(reader, Map.class);
        assertEquals(newOverrides, overrides);
    }
}
Also used : HashMap(java.util.HashMap) Reader(java.io.Reader) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map) Yaml(org.yaml.snakeyaml.Yaml) Test(org.junit.Test)

Example 90 with Yaml

use of org.yaml.snakeyaml.Yaml in project incubator-heron by apache.

the class ConfigUtilsTests method testNoOverridesAppliedToStateManager.

@Test
@SuppressWarnings("unchecked")
public void testNoOverridesAppliedToStateManager() throws IOException {
    final Properties overrideProperties = createOverrideProperties(Pair.create("heron.kubernetes.scheduler.uri", "http://127.0.0.1:8001"));
    final String overridesPath = ConfigUtils.createOverrideConfiguration(overrideProperties);
    // write default state manager config
    final Path stateManagerPath = Files.createTempFile("statemgr-", ".yaml");
    stateManagerPath.toFile().deleteOnExit();
    try (Writer writer = Files.newBufferedWriter(stateManagerPath)) {
        final Map<String, String> config = new HashMap<>();
        config.put("heron.statemgr.connection.string", "<host>:<port>");
        new Yaml().dump(config, writer);
    }
    // apply the overrides
    ConfigUtils.applyOverridesToStateManagerConfig(Paths.get(overridesPath), stateManagerPath);
    try (Reader reader = Files.newBufferedReader(stateManagerPath)) {
        final Map<String, Object> stateManagerWithOverrides = (Map<String, Object>) new Yaml().loadAs(reader, Map.class);
        assertEquals(stateManagerWithOverrides.size(), 1);
        assertEquals(stateManagerWithOverrides.get("heron.statemgr.connection.string"), "<host>:<port>");
    }
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) Reader(java.io.Reader) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map) Writer(java.io.Writer) Yaml(org.yaml.snakeyaml.Yaml) Test(org.junit.Test)

Aggregations

Yaml (org.yaml.snakeyaml.Yaml)276 Map (java.util.Map)104 HashMap (java.util.HashMap)85 IOException (java.io.IOException)58 FileInputStream (java.io.FileInputStream)49 InputStream (java.io.InputStream)49 File (java.io.File)43 DumperOptions (org.yaml.snakeyaml.DumperOptions)42 Constructor (org.yaml.snakeyaml.constructor.Constructor)30 Test (org.junit.Test)26 ArrayList (java.util.ArrayList)25 FileNotFoundException (java.io.FileNotFoundException)22 SafeConstructor (org.yaml.snakeyaml.constructor.SafeConstructor)22 List (java.util.List)21 Writer (java.io.Writer)18 Path (java.nio.file.Path)17 LinkedHashMap (java.util.LinkedHashMap)17 Reader (java.io.Reader)16 Properties (java.util.Properties)14 InputStreamReader (java.io.InputStreamReader)13