本文整理了Java中org.apache.hadoop.security.Credentials.readTokenStorageStream()
方法的一些代码示例,展示了Credentials.readTokenStorageStream()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Credentials.readTokenStorageStream()
方法的具体详情如下:
包路径:org.apache.hadoop.security.Credentials
类名称:Credentials
方法名:readTokenStorageStream
[英]Convenience method for reading a token storage file directly from a datainputstream
[中]直接从datainputstream读取令牌存储文件的简便方法
代码示例来源:origin: org.apache.hadoop/hadoop-common
/**
* Convenience method for reading a token storage file and loading its Tokens.
* @param filename
* @param conf
* @throws IOException
*/
public static Credentials readTokenStorageFile(File filename,
Configuration conf)
throws IOException {
DataInputStream in = null;
Credentials credentials = new Credentials();
try {
in = new DataInputStream(new BufferedInputStream(
new FileInputStream(filename)));
credentials.readTokenStorageStream(in);
return credentials;
} catch(IOException ioe) {
throw new IOException("Exception reading " + filename, ioe);
} finally {
IOUtils.cleanupWithLogger(LOG, in);
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
/**
* Convenience method for reading a token storage file and loading its Tokens.
* @param filename
* @param conf
* @throws IOException
*/
public static Credentials readTokenStorageFile(Path filename,
Configuration conf)
throws IOException {
FSDataInputStream in = null;
Credentials credentials = new Credentials();
try {
in = filename.getFileSystem(conf).open(filename);
credentials.readTokenStorageStream(in);
in.close();
return credentials;
} catch(IOException ioe) {
throw IOUtils.wrapException(filename.toString(), "Credentials"
+ ".readTokenStorageFile", ioe);
} finally {
IOUtils.cleanupWithLogger(LOG, in);
}
}
代码示例来源:origin: apache/hive
/**
* transform a byte of crendetials to a hadoop Credentials object.
* @param binaryCredentials credentials in byte format as they would
* usually be when received from protobuffers
* @return a hadoop Credentials object
*/
public static Credentials credentialsFromByteArray(byte[] binaryCredentials)
throws IOException {
Credentials credentials = new Credentials();
DataInputBuffer dib = new DataInputBuffer();
dib.reset(binaryCredentials, binaryCredentials.length);
credentials.readTokenStorageStream(dib);
return credentials;
}
}
代码示例来源:origin: cloudera-labs/envelope
/**
* Read the token aliases and {@link Credentials} from a Hadoop FileSystem.
* @param file path of the file to be read
* @param conf a Hadoop {@link} Configuration for the Hadoop FileSystem
* @throws IOException if file cannot be read
*/
public void read(String file, Configuration conf) throws IOException {
Path inFile = new Path(file);
try (FSDataInputStream fis = inFile.getFileSystem(conf).open(inFile)) {
tokenAliases.addAll(Arrays.asList(WritableUtils.readStringArray(fis)));
credentials.readTokenStorageStream(fis);
}
}
代码示例来源:origin: cdapio/cdap
private static Credentials readCredentials(Location location) throws IOException {
Credentials credentials = new Credentials();
try (DataInputStream input = new DataInputStream(new BufferedInputStream(location.getInputStream()))) {
credentials.readTokenStorageStream(input);
}
LOG.debug("Read credentials from {}", location);
return credentials;
}
}
代码示例来源:origin: org.apache.twill/twill-yarn
private static void loadSecureStore() throws IOException {
if (!UserGroupInformation.isSecurityEnabled()) {
return;
}
File file = new File(Constants.Files.CREDENTIALS);
if (file.exists()) {
Credentials credentials = new Credentials();
try (DataInputStream input = new DataInputStream(new FileInputStream(file))) {
credentials.readTokenStorageStream(input);
}
UserGroupInformation.getCurrentUser().addCredentials(credentials);
LOG.info("Secure store updated from {}", file);
}
}
代码示例来源:origin: apache/twill
private static void loadSecureStore() throws IOException {
if (!UserGroupInformation.isSecurityEnabled()) {
return;
}
File file = new File(Constants.Files.CREDENTIALS);
if (file.exists()) {
Credentials credentials = new Credentials();
try (DataInputStream input = new DataInputStream(new FileInputStream(file))) {
credentials.readTokenStorageStream(input);
}
UserGroupInformation.getCurrentUser().addCredentials(credentials);
LOG.info("Secure store updated from {}", file);
}
}
代码示例来源:origin: org.apache.twill/twill-yarn
/**
* Decodes {@link Credentials} from the given buffer.
* If the buffer is null or empty, it returns an empty Credentials.
*/
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;
}
代码示例来源:origin: apache/twill
/**
* Decodes {@link Credentials} from the given buffer.
* If the buffer is null or empty, it returns an empty Credentials.
*/
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;
}
代码示例来源:origin: org.apache.reef/reef-runtime-yarn
/**
* Add serialized token to teh credentials.
* @param tokens ByteBuffer containing token.
*/
@Override
public void addTokens(final byte[] tokens) {
try (final DataInputBuffer buf = new DataInputBuffer()) {
buf.reset(tokens, tokens.length);
final Credentials credentials = new Credentials();
credentials.readTokenStorageStream(buf);
final UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
ugi.addCredentials(credentials);
LOG.log(Level.FINEST, "Added {0} tokens for user {1}", new Object[] {credentials.numberOfTokens(), ugi});
} catch (final IOException ex) {
LOG.log(Level.SEVERE, "Could not access tokens in user credentials.", ex);
throw new RuntimeException(ex);
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager
private static Credentials convertCredentialsFromByteBuffer(
ByteBuffer appAttemptTokens) {
DataInputByteBuffer dibb = new DataInputByteBuffer();
try {
Credentials credentials = null;
if (appAttemptTokens != null) {
credentials = new Credentials();
appAttemptTokens.rewind();
dibb.reset(appAttemptTokens);
credentials.readTokenStorageStream(dibb);
}
return credentials;
} catch (IOException e) {
LOG.error("Failed to convert Credentials from ByteBuffer.");
assert false;
return null;
} finally {
IOUtils.closeStream(dibb);
}
}
代码示例来源:origin: com.github.jiayuhan-it/hadoop-yarn-server-resourcemanager
protected Credentials parseCredentials(
ApplicationSubmissionContext application) throws IOException {
Credentials credentials = new Credentials();
DataInputByteBuffer dibb = new DataInputByteBuffer();
ByteBuffer tokens = application.getAMContainerSpec().getTokens();
if (tokens != null) {
dibb.reset(tokens);
credentials.readTokenStorageStream(dibb);
tokens.rewind();
}
return credentials;
}
代码示例来源:origin: ch.cern.hadoop/hadoop-yarn-server-resourcemanager
protected Credentials parseCredentials(
ApplicationSubmissionContext application) throws IOException {
Credentials credentials = new Credentials();
DataInputByteBuffer dibb = new DataInputByteBuffer();
ByteBuffer tokens = application.getAMContainerSpec().getTokens();
if (tokens != null) {
dibb.reset(tokens);
credentials.readTokenStorageStream(dibb);
tokens.rewind();
}
return credentials;
}
代码示例来源:origin: com.github.jiayuhan-it/hadoop-yarn-server-resourcemanager
protected Credentials parseCredentials() throws IOException {
Credentials credentials = new Credentials();
DataInputByteBuffer dibb = new DataInputByteBuffer();
ByteBuffer tokens = submissionContext.getAMContainerSpec().getTokens();
if (tokens != null) {
dibb.reset(tokens);
credentials.readTokenStorageStream(dibb);
tokens.rewind();
}
return credentials;
}
}
代码示例来源:origin: ch.cern.hadoop/hadoop-yarn-server-resourcemanager
protected Credentials parseCredentials() throws IOException {
Credentials credentials = new Credentials();
DataInputByteBuffer dibb = new DataInputByteBuffer();
ByteBuffer tokens = submissionContext.getAMContainerSpec().getTokens();
if (tokens != null) {
dibb.reset(tokens);
credentials.readTokenStorageStream(dibb);
tokens.rewind();
}
return credentials;
}
}
代码示例来源:origin: org.apache.tez/tez-api
public static Credentials parseCredentialsBytes(byte[] credentialsBytes) throws IOException {
Credentials credentials = new Credentials();
DataInputBuffer dib = new DataInputBuffer();
try {
byte[] tokenBytes = credentialsBytes;
dib.reset(tokenBytes, tokenBytes.length);
credentials.readTokenStorageStream(dib);
return credentials;
} finally {
dib.close();
}
}
代码示例来源:origin: ch.cern.hadoop/hadoop-yarn-server-nodemanager
private Credentials parseCredentials(ContainerLaunchContext launchContext)
throws IOException {
Credentials credentials = new Credentials();
// //////////// Parse credentials
ByteBuffer tokens = launchContext.getTokens();
if (tokens != null) {
DataInputByteBuffer buf = new DataInputByteBuffer();
tokens.rewind();
buf.reset(tokens);
credentials.readTokenStorageStream(buf);
if (LOG.isDebugEnabled()) {
for (Token<? extends TokenIdentifier> tk : credentials.getAllTokens()) {
LOG.debug(tk.getService() + " = " + tk.toString());
}
}
}
// //////////// End of parsing credentials
return credentials;
}
代码示例来源:origin: org.apache.tez/tez-api
public static Credentials convertByteStringToCredentials(ByteString byteString) {
if (byteString == null) {
return null;
}
DataInputByteBuffer dib = new DataInputByteBuffer();
dib.reset(byteString.asReadOnlyByteBuffer());
Credentials credentials = new Credentials();
try {
credentials.readTokenStorageStream(dib);
return credentials;
} catch (IOException e) {
throw new TezUncheckedException("Failed to deserialize Credentials", e);
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager
public Credentials getContainerCredentials() throws IOException {
Credentials credentials = new Credentials();
DataInputByteBuffer buf = new DataInputByteBuffer();
containerTokens.rewind();
buf.reset(containerTokens);
credentials.readTokenStorageStream(buf);
return credentials;
}
代码示例来源:origin: ch.cern.hadoop/hadoop-yarn-server-resourcemanager
public Credentials getContainerCredentials() throws IOException {
Credentials credentials = new Credentials();
DataInputByteBuffer buf = new DataInputByteBuffer();
containerTokens.rewind();
buf.reset(containerTokens);
credentials.readTokenStorageStream(buf);
return credentials;
}
}
内容来源于网络,如有侵权,请联系作者删除!