use of com.continuuity.weave.filesystem.Location in project weave by continuuity.
the class YarnWeaveRunnerService method updateCredentials.
private void updateCredentials(String application, RunId runId, Credentials updates) throws IOException {
Location credentialsLocation = locationFactory.create(String.format("/%s/%s/%s", application, runId.getId(), Constants.Files.CREDENTIALS));
// Try to read the old credentials.
Credentials credentials = new Credentials();
if (credentialsLocation.exists()) {
DataInputStream is = new DataInputStream(new BufferedInputStream(credentialsLocation.getInputStream()));
try {
credentials.readTokenStorageStream(is);
} finally {
is.close();
}
}
// Overwrite with the updates.
credentials.addAll(updates);
// Overwrite the credentials.
Location tmpLocation = credentialsLocation.getTempFile(Constants.Files.CREDENTIALS);
// Save the credentials store with user-only permission.
DataOutputStream os = new DataOutputStream(new BufferedOutputStream(tmpLocation.getOutputStream("600")));
try {
credentials.writeTokenStorageToStream(os);
} finally {
os.close();
}
// Rename the tmp file into the credentials location
tmpLocation.renameTo(credentialsLocation);
LOG.debug("Secure store for {} {} saved to {}.", application, runId, credentialsLocation.toURI());
}
use of com.continuuity.weave.filesystem.Location in project weave by continuuity.
the class YarnWeavePreparer method saveLogback.
private void saveLogback(Map<String, LocalFile> localFiles) throws IOException {
LOG.debug("Create and copy {}", Constants.Files.LOGBACK_TEMPLATE);
Location location = copyFromURL(getClass().getClassLoader().getResource(Constants.Files.LOGBACK_TEMPLATE), createTempLocation(Constants.Files.LOGBACK_TEMPLATE));
LOG.debug("Done {}", Constants.Files.LOGBACK_TEMPLATE);
localFiles.put(Constants.Files.LOGBACK_TEMPLATE, createLocalFile(Constants.Files.LOGBACK_TEMPLATE, location));
}
use of com.continuuity.weave.filesystem.Location in project weave by continuuity.
the class YarnWeavePreparer method saveVmOptions.
private void saveVmOptions(String opts, Map<String, LocalFile> localFiles) throws IOException {
if (opts.isEmpty()) {
// If no vm options, no need to localize the file.
return;
}
LOG.debug("Copy {}", Constants.Files.JVM_OPTIONS);
final Location location = createTempLocation(Constants.Files.JVM_OPTIONS);
CharStreams.write(opts, new OutputSupplier<Writer>() {
@Override
public Writer getOutput() throws IOException {
return new OutputStreamWriter(location.getOutputStream(), Charsets.UTF_8);
}
});
LOG.debug("Done {}", Constants.Files.JVM_OPTIONS);
localFiles.put(Constants.Files.JVM_OPTIONS, createLocalFile(Constants.Files.JVM_OPTIONS, location));
}
Aggregations