Search in sources :

Example 1 with AtomicFileWriter

use of com.netflix.spinnaker.halyard.core.AtomicFileWriter in project halyard by spinnaker.

the class ConfigParser method atomicWrite.

public void atomicWrite(Path path, Object obj) {
    String contents = yamlToString(obj);
    AtomicFileWriter writer = null;
    try {
        writer = new AtomicFileWriter(path);
        writer.write(contents);
        writer.commit();
    } catch (IOException ioe) {
        ioe.printStackTrace();
        throw new HalException(new ProblemBuilder(Problem.Severity.FATAL, "Failed to write config for profile " + path.toFile().getName() + ": " + ioe.getMessage()).build());
    } finally {
        if (writer != null) {
            writer.close();
        }
    }
}
Also used : AtomicFileWriter(com.netflix.spinnaker.halyard.core.AtomicFileWriter) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) IOException(java.io.IOException) ProblemBuilder(com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder)

Example 2 with AtomicFileWriter

use of com.netflix.spinnaker.halyard.core.AtomicFileWriter in project halyard by spinnaker.

the class Profile method writeStagedFile.

public void writeStagedFile(String stagingPath) {
    AtomicFileWriter writer = null;
    Path path = Paths.get(stagingPath, name);
    log.info("Writing profile to " + path.toString() + " with " + requiredFiles.size() + " required files");
    try {
        writer = new AtomicFileWriter(path);
        writer.write(contents);
        writer.commit();
    } catch (IOException ioe) {
        ioe.printStackTrace();
        throw new HalException(Problem.Severity.FATAL, "Failed to write config for profile " + path.toFile().getName() + ": " + ioe.getMessage());
    } finally {
        if (writer != null) {
            writer.close();
        }
    }
}
Also used : Path(java.nio.file.Path) AtomicFileWriter(com.netflix.spinnaker.halyard.core.AtomicFileWriter) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) IOException(java.io.IOException)

Example 3 with AtomicFileWriter

use of com.netflix.spinnaker.halyard.core.AtomicFileWriter in project halyard by spinnaker.

the class HalconfigParser method saveConfigTo.

private void saveConfigTo(Path path) {
    Halconfig local = (Halconfig) DaemonTaskHandler.getContext();
    if (local == null) {
        throw new HalException(new ConfigProblemBuilder(Severity.WARNING, "No halconfig changes have been made, nothing to write").build());
    }
    AtomicFileWriter writer = null;
    try {
        writer = new AtomicFileWriter(path);
        writer.write(yamlParser.dump(objectMapper.convertValue(local, Map.class)));
        writer.commit();
    } catch (IOException e) {
        throw new HalException(Severity.FATAL, "Failure writing your halconfig to path \"" + halconfigPath + "\": " + e.getMessage(), e);
    } finally {
        DaemonTaskHandler.setContext(null);
        if (writer != null) {
            writer.close();
        }
    }
}
Also used : Halconfig(com.netflix.spinnaker.halyard.config.model.v1.node.Halconfig) AtomicFileWriter(com.netflix.spinnaker.halyard.core.AtomicFileWriter) ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) IOException(java.io.IOException)

Aggregations

AtomicFileWriter (com.netflix.spinnaker.halyard.core.AtomicFileWriter)3 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)3 IOException (java.io.IOException)3 Halconfig (com.netflix.spinnaker.halyard.config.model.v1.node.Halconfig)1 ConfigProblemBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder)1 ProblemBuilder (com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder)1 Path (java.nio.file.Path)1