Search in sources :

Example 96 with Yaml

use of org.yaml.snakeyaml.Yaml in project spring-security by spring-projects.

the class GitHubMilestoneNextReleaseTask method calculateNextReleaseMilestone.

@TaskAction
public void calculateNextReleaseMilestone() throws IOException {
    String currentVersion = getProject().getVersion().toString();
    String nextPreRelease = this.milestones.getNextReleaseMilestone(this.repository, currentVersion);
    System.out.println("The next release milestone is: " + nextPreRelease);
    NextVersionYml nextVersionYml = new NextVersionYml();
    nextVersionYml.setVersion(nextPreRelease);
    File outputFile = getNextReleaseFile().get().getAsFile();
    FileWriter outputWriter = new FileWriter(outputFile);
    Yaml yaml = getYaml();
    yaml.dump(nextVersionYml, outputWriter);
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) OutputFile(org.gradle.api.tasks.OutputFile) Yaml(org.yaml.snakeyaml.Yaml) TaskAction(org.gradle.api.tasks.TaskAction)

Example 97 with Yaml

use of org.yaml.snakeyaml.Yaml in project storm by apache.

the class RuncLibContainerManager method saveRuncYaml.

// save runc.yaml in artifacts dir so we can track which image the worker was launched with
private void saveRuncYaml(String topologyId, int port, String containerId, String imageName, OciResource configResource) {
    String fname = String.format("runc-%s.yaml", containerId);
    File file = new File(ConfigUtils.workerArtifactsRoot(conf, topologyId, port), fname);
    DumperOptions options = new DumperOptions();
    options.setIndent(2);
    options.setPrettyFlow(true);
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
    Yaml yaml = new Yaml(options);
    Map<String, Object> data = new HashMap<>();
    data.put("imageName", imageName);
    data.put("manifest", configResource.getFileName());
    data.put("configPath", configResource.getPath());
    try (Writer writer = new FileWriter(file)) {
        yaml.dump(data, writer);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) FileWriter(java.io.FileWriter) DumperOptions(org.yaml.snakeyaml.DumperOptions) JSONObject(org.json.simple.JSONObject) IOException(java.io.IOException) File(java.io.File) Yaml(org.yaml.snakeyaml.Yaml) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 98 with Yaml

use of org.yaml.snakeyaml.Yaml in project cassandra by apache.

the class StressProfile method load.

public static StressProfile load(URI file) throws IOError {
    try {
        Constructor constructor = new Constructor(StressYaml.class);
        Yaml yaml = new Yaml(constructor);
        InputStream yamlStream = file.toURL().openStream();
        if (yamlStream.available() == 0)
            throw new IOException("Unable to load yaml file from: " + file);
        StressYaml profileYaml = yaml.loadAs(yamlStream, StressYaml.class);
        StressProfile profile = new StressProfile();
        profile.init(profileYaml);
        return profile;
    } catch (YAMLException | IOException | RequestValidationException e) {
        throw new IOError(e);
    }
}
Also used : IOError(java.io.IOError) Constructor(org.yaml.snakeyaml.constructor.Constructor) InputStream(java.io.InputStream) YAMLException(org.yaml.snakeyaml.error.YAMLException) IOException(java.io.IOException) RequestValidationException(org.apache.cassandra.exceptions.RequestValidationException) Yaml(org.yaml.snakeyaml.Yaml)

Example 99 with Yaml

use of org.yaml.snakeyaml.Yaml in project storm by apache.

the class Container method writeLogMetadata.

/**
 * Write out the file used by the log viewer to allow/reject log access.
 *
 * @param user the user this is going to run as
 * @throws IOException on any error
 */
protected void writeLogMetadata(String user) throws IOException {
    type.assertFull();
    Map<String, Object> data = new HashMap<>();
    data.put(Config.TOPOLOGY_SUBMITTER_USER, user);
    data.put("worker-id", workerId);
    Set<String> logsGroups = new HashSet<>();
    if (topoConf.get(DaemonConfig.LOGS_GROUPS) != null) {
        List<String> groups = ObjectReader.getStrings(topoConf.get(DaemonConfig.LOGS_GROUPS));
        logsGroups.addAll(groups);
    }
    if (topoConf.get(Config.TOPOLOGY_GROUPS) != null) {
        List<String> topGroups = ObjectReader.getStrings(topoConf.get(Config.TOPOLOGY_GROUPS));
        logsGroups.addAll(topGroups);
    }
    data.put(DaemonConfig.LOGS_GROUPS, logsGroups.toArray());
    Set<String> logsUsers = new HashSet<>();
    if (topoConf.get(DaemonConfig.LOGS_USERS) != null) {
        List<String> logUsers = ObjectReader.getStrings(topoConf.get(DaemonConfig.LOGS_USERS));
        logsUsers.addAll(logUsers);
    }
    if (topoConf.get(Config.TOPOLOGY_USERS) != null) {
        List<String> topUsers = ObjectReader.getStrings(topoConf.get(Config.TOPOLOGY_USERS));
        logsUsers.addAll(topUsers);
    }
    data.put(DaemonConfig.LOGS_USERS, logsUsers.toArray());
    if (topoConf.get(Config.TOPOLOGY_WORKER_TIMEOUT_SECS) != null) {
        int topoTimeout = ObjectReader.getInt(topoConf.get(Config.TOPOLOGY_WORKER_TIMEOUT_SECS));
        int defaultWorkerTimeout = ObjectReader.getInt(conf.get(Config.SUPERVISOR_WORKER_TIMEOUT_SECS));
        topoTimeout = Math.max(topoTimeout, defaultWorkerTimeout);
        data.put(Config.TOPOLOGY_WORKER_TIMEOUT_SECS, topoTimeout);
    }
    File file = ServerConfigUtils.getLogMetaDataFile(conf, topologyId, port);
    Yaml yaml = new Yaml();
    try (Writer writer = ops.getWriter(file)) {
        yaml.dump(data, writer);
    }
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) File(java.io.File) WorkerMetricPoint(org.apache.storm.generated.WorkerMetricPoint) Yaml(org.yaml.snakeyaml.Yaml) Writer(java.io.Writer) HashSet(java.util.HashSet)

Example 100 with Yaml

use of org.yaml.snakeyaml.Yaml in project storm by apache.

the class FileConfigLoaderTest method testValidFile.

@Test
public void testValidFile() throws Exception {
    File temp = File.createTempFile("FileLoader", ".yaml");
    temp.deleteOnExit();
    Map<String, Integer> testMap = new HashMap<>();
    testMap.put("a", 1);
    testMap.put("b", 2);
    testMap.put("c", 3);
    testMap.put("d", 4);
    testMap.put("e", 5);
    Map<String, Map<String, Integer>> confMap = new HashMap<>();
    confMap.put(DaemonConfig.MULTITENANT_SCHEDULER_USER_POOLS, testMap);
    Yaml yaml = new Yaml();
    FileWriter fw = new FileWriter(temp);
    yaml.dump(confMap, fw);
    fw.flush();
    fw.close();
    Config conf = new Config();
    conf.put(DaemonConfig.SCHEDULER_CONFIG_LOADER_URI, FILE_SCHEME_PREFIX + temp.getCanonicalPath());
    FileConfigLoader loader = new FileConfigLoader(conf);
    Map<String, Object> result = loader.load(DaemonConfig.MULTITENANT_SCHEDULER_USER_POOLS);
    Assert.assertNotNull("Unexpectedly returned null", result);
    Assert.assertEquals("Maps are a different size", testMap.keySet().size(), result.keySet().size());
    for (String key : testMap.keySet()) {
        Integer expectedValue = testMap.get(key);
        Integer returnedValue = (Integer) result.get(key);
        Assert.assertEquals("Bad value for key=" + key, expectedValue, returnedValue);
    }
}
Also used : HashMap(java.util.HashMap) DaemonConfig(org.apache.storm.DaemonConfig) Config(org.apache.storm.Config) FileWriter(java.io.FileWriter) Yaml(org.yaml.snakeyaml.Yaml) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) 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