Search in sources :

Example 11 with Location

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());
}
Also used : BufferedInputStream(java.io.BufferedInputStream) DataOutputStream(java.io.DataOutputStream) DataInputStream(java.io.DataInputStream) BufferedOutputStream(java.io.BufferedOutputStream) Credentials(org.apache.hadoop.security.Credentials) Location(com.continuuity.weave.filesystem.Location)

Example 12 with Location

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));
}
Also used : Location(com.continuuity.weave.filesystem.Location)

Example 13 with 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));
}
Also used : OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Location(com.continuuity.weave.filesystem.Location)

Aggregations

Location (com.continuuity.weave.filesystem.Location)13 OutputStreamWriter (java.io.OutputStreamWriter)4 Writer (java.io.Writer)4 RuntimeSpecification (com.continuuity.weave.api.RuntimeSpecification)3 DefaultRuntimeSpecification (com.continuuity.weave.internal.DefaultRuntimeSpecification)3 IOException (java.io.IOException)3 LocalFile (com.continuuity.weave.api.LocalFile)2 DefaultLocalFile (com.continuuity.weave.internal.DefaultLocalFile)2 BufferedInputStream (java.io.BufferedInputStream)2 DataInputStream (java.io.DataInputStream)2 URL (java.net.URL)2 Credentials (org.apache.hadoop.security.Credentials)2 EventHandlerSpecification (com.continuuity.weave.api.EventHandlerSpecification)1 LocalLocationFactory (com.continuuity.weave.filesystem.LocalLocationFactory)1 ApplicationBundler (com.continuuity.weave.internal.ApplicationBundler)1 DefaultWeaveSpecification (com.continuuity.weave.internal.DefaultWeaveSpecification)1 LogOnlyEventHandler (com.continuuity.weave.internal.LogOnlyEventHandler)1 LocalFileCodec (com.continuuity.weave.internal.json.LocalFileCodec)1 Dependencies (com.continuuity.weave.internal.utils.Dependencies)1 WeaveLauncher (com.continuuity.weave.launcher.WeaveLauncher)1