Search in sources :

Example 61 with Yaml

use of org.yaml.snakeyaml.Yaml in project fabric-sdk-java by hyperledger.

the class NetworkConfig method fromYamlStream.

/**
 * Creates a new NetworkConfig instance configured with details supplied in YAML format
 *
 * @param configStream A stream opened on a YAML document containing network configuration details
 * @return A new NetworkConfig instance
 * @throws InvalidArgumentException
 */
public static NetworkConfig fromYamlStream(InputStream configStream) throws InvalidArgumentException, NetworkConfigurationException {
    logger.trace("NetworkConfig.fromYamlStream...");
    // Sanity check
    if (configStream == null) {
        throw new InvalidArgumentException("configStream must be specified");
    }
    Yaml yaml = new Yaml();
    @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) yaml.load(configStream);
    JsonObjectBuilder builder = Json.createObjectBuilder(map);
    JsonObject jsonConfig = builder.build();
    return fromJsonObject(jsonConfig);
}
Also used : InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) JsonObject(javax.json.JsonObject) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString) JsonObjectBuilder(javax.json.JsonObjectBuilder) HashMap(java.util.HashMap) Map(java.util.Map) Yaml(org.yaml.snakeyaml.Yaml)

Example 62 with Yaml

use of org.yaml.snakeyaml.Yaml in project fabric-sdk-java by hyperledger.

the class ChaincodeEndorsementPolicy method fromYamlFile.

/**
 * From a yaml file
 *
 * @param yamlPolicyFile File location for the chaincode endorsement policy specification.
 * @throws IOException
 * @throws ChaincodeEndorsementPolicyParseException
 */
public void fromYamlFile(File yamlPolicyFile) throws IOException, ChaincodeEndorsementPolicyParseException {
    final Yaml yaml = new Yaml();
    final Map<?, ?> load = (Map<?, ?>) yaml.load(new FileInputStream(yamlPolicyFile));
    Map<?, ?> mp = (Map<?, ?>) load.get("policy");
    if (null == mp) {
        throw new ChaincodeEndorsementPolicyParseException("The policy file has no policy section");
    }
    IndexedHashMap<String, MSPPrincipal> identities = parseIdentities((Map<?, ?>) load.get("identities"));
    SignaturePolicy sp = parsePolicy(identities, mp);
    policyBytes = Policies.SignaturePolicyEnvelope.newBuilder().setVersion(0).addAllIdentities(identities.values()).setRule(sp).build().toByteArray();
}
Also used : ChaincodeEndorsementPolicyParseException(org.hyperledger.fabric.sdk.exception.ChaincodeEndorsementPolicyParseException) SignaturePolicy(org.hyperledger.fabric.protos.common.Policies.SignaturePolicy) MSPPrincipal(org.hyperledger.fabric.protos.common.MspPrincipal.MSPPrincipal) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Yaml(org.yaml.snakeyaml.Yaml) FileInputStream(java.io.FileInputStream)

Example 63 with Yaml

use of org.yaml.snakeyaml.Yaml in project jmx_exporter by prometheus.

the class JmxCollector method reloadConfig.

private void reloadConfig() {
    try {
        FileReader fr = new FileReader(configFile);
        try {
            Map<String, Object> newYamlConfig = (Map<String, Object>) new Yaml().load(fr);
            config = loadConfig(newYamlConfig);
            config.lastUpdate = configFile.lastModified();
            configReloadSuccess.inc();
        } catch (Exception e) {
            LOGGER.severe("Configuration reload failed: " + e.toString());
            configReloadFailure.inc();
        } finally {
            fr.close();
        }
    } catch (IOException e) {
        LOGGER.severe("Configuration reload failed: " + e.toString());
        configReloadFailure.inc();
    }
}
Also used : FileReader(java.io.FileReader) IOException(java.io.IOException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Yaml(org.yaml.snakeyaml.Yaml) IOException(java.io.IOException) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Example 64 with Yaml

use of org.yaml.snakeyaml.Yaml in project LogHub by fbacchella.

the class Parser method initialize.

private void initialize(InputStream regexYaml) {
    Yaml yaml = new Yaml(new SafeConstructor());
    @SuppressWarnings("unchecked") Map<String, List<Map<String, String>>> regexConfig = (Map<String, List<Map<String, String>>>) yaml.load(regexYaml);
    List<Map<String, String>> uaParserConfigs = regexConfig.get("user_agent_parsers");
    if (uaParserConfigs == null) {
        throw new IllegalArgumentException("user_agent_parsers is missing from yaml");
    }
    uaParser = UserAgentParser.fromList(uaParserConfigs);
    List<Map<String, String>> osParserConfigs = regexConfig.get("os_parsers");
    if (osParserConfigs == null) {
        throw new IllegalArgumentException("os_parsers is missing from yaml");
    }
    osParser = OSParser.fromList(osParserConfigs);
    List<Map<String, String>> deviceParserConfigs = regexConfig.get("device_parsers");
    if (deviceParserConfigs == null) {
        throw new IllegalArgumentException("device_parsers is missing from yaml");
    }
    deviceParser = DeviceParser.fromList(deviceParserConfigs);
}
Also used : SafeConstructor(org.yaml.snakeyaml.constructor.SafeConstructor) List(java.util.List) Map(java.util.Map) Yaml(org.yaml.snakeyaml.Yaml)

Example 65 with Yaml

use of org.yaml.snakeyaml.Yaml in project fabric8 by fabric8io.

the class Controller method convertYamlToJson.

private String convertYamlToJson(String yamlString) throws FileNotFoundException {
    Yaml yaml = new Yaml();
    Map<String, Object> map = (Map<String, Object>) yaml.load(yamlString);
    JSONObject jsonObject = new JSONObject(map);
    return jsonObject.toString();
}
Also used : JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) Map(java.util.Map) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Yaml(org.yaml.snakeyaml.Yaml)

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