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;
}
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 + "-----------");
}
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);
}
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);
}
}
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>");
}
}
Aggregations