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