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(); } } }
public void commitScript(Path path) { AtomicFileWriter writer = null; try { writer = new AtomicFileWriter(path); writer.write(script); 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(); } } path.toFile().setExecutable(true); scriptPath = path.toString(); } }
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(); } } }
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(); } } }
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(); } } }
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(); } } } }
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(); } } } }