List of usage examples for org.apache.hadoop.security Credentials readTokenStorageStream
public void readTokenStorageStream(DataInputStream in) throws IOException
From source file:org.apache.twill.internal.yarn.YarnUtils.java
License:Apache License
/** * Decodes {@link Credentials} from the given buffer. * If the buffer is null or empty, it returns an empty Credentials. *//* w w w. ja v a2 s. c om*/ public static Credentials decodeCredentials(ByteBuffer buffer) throws IOException { Credentials credentials = new Credentials(); if (buffer != null && buffer.hasRemaining()) { DataInputByteBuffer in = new DataInputByteBuffer(); in.reset(buffer); credentials.readTokenStorageStream(in); } return credentials; }
From source file:org.apache.twill.yarn.YarnTwillRunnerService.java
License:Apache License
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()) { try (DataInputStream is = new DataInputStream( new BufferedInputStream(credentialsLocation.getInputStream()))) { credentials.readTokenStorageStream(is); }/*w w w . j av a 2 s . c o m*/ } // 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. try (DataOutputStream os = new DataOutputStream( new BufferedOutputStream(tmpLocation.getOutputStream("600")))) { credentials.writeTokenStorageToStream(os); } // Rename the tmp file into the credentials location tmpLocation.renameTo(credentialsLocation); LOG.debug("Secure store for {} {} saved to {}.", application, runId, credentialsLocation); }