Example usage for org.apache.hadoop.security Credentials addAll

List of usage examples for org.apache.hadoop.security Credentials addAll

Introduction

In this page you can find the example usage for org.apache.hadoop.security Credentials addAll.

Prototype

public void addAll(Credentials other) 

Source Link

Document

Copy all of the credentials from one credential object into another.

Usage

From source file:org.apache.tez.dag.app.taskcomm.TezTestServiceTaskCommunicatorImpl.java

License:Apache License

private SubmitWorkRequestProto constructSubmitWorkRequest(ContainerId containerId, TaskSpec taskSpec)
        throws IOException {
    SubmitWorkRequestProto.Builder builder = SubmitWorkRequestProto.newBuilder(BASE_SUBMIT_WORK_REQUEST);
    builder.setContainerIdString(containerId.toString());
    builder.setAmHost(getAddress().getHostName());
    builder.setAmPort(getAddress().getPort());
    Credentials taskCredentials = new Credentials();
    // Credentials can change across DAGs. Ideally construct only once per DAG.
    taskCredentials.addAll(getContext().getAMCredentials());

    ByteBuffer credentialsBinary = credentialMap.get(taskSpec.getDAGName());
    if (credentialsBinary == null) {
        credentialsBinary = serializeCredentials(getContext().getAMCredentials());
        credentialMap.putIfAbsent(taskSpec.getDAGName(), credentialsBinary.duplicate());
    } else {/*from w  ww  .  j  a  v a2s .  co m*/
        credentialsBinary = credentialsBinary.duplicate();
    }
    builder.setCredentialsBinary(ByteString.copyFrom(credentialsBinary));
    builder.setTaskSpec(ProtoConverters.convertTaskSpecToProto(taskSpec));
    return builder.build();
}

From source file:org.apache.tez.dag.app.taskcomm.TezTestServiceTaskCommunicatorImpl.java

License:Apache License

private ByteBuffer serializeCredentials(Credentials credentials) throws IOException {
    Credentials containerCredentials = new Credentials();
    containerCredentials.addAll(credentials);
    DataOutputBuffer containerTokens_dob = new DataOutputBuffer();
    containerCredentials.writeTokenStorageToStream(containerTokens_dob);
    ByteBuffer containerCredentialsBuffer = ByteBuffer.wrap(containerTokens_dob.getData(), 0,
            containerTokens_dob.getLength());
    return containerCredentialsBuffer;
}

From source file:org.apache.twill.internal.appmaster.ApplicationMasterService.java

License:Apache License

private Credentials createCredentials() {
    Credentials credentials = new Credentials();
    if (!UserGroupInformation.isSecurityEnabled()) {
        return credentials;
    }/*  w  ww  .  j ava  2  s .  c  o  m*/

    try {
        credentials.addAll(UserGroupInformation.getCurrentUser().getCredentials());

        // Remove the AM->RM tokens
        Iterator<Token<?>> iter = credentials.getAllTokens().iterator();
        while (iter.hasNext()) {
            Token<?> token = iter.next();
            if (token.getKind().equals(AMRM_TOKEN_KIND_NAME)) {
                iter.remove();
            }
        }
    } catch (IOException e) {
        LOG.warn("Failed to get current user. No credentials will be provided to containers.", e);
    }

    return credentials;
}

From source file:org.apache.twill.yarn.YarnTwillPreparer.java

License:Apache License

private Credentials createCredentials() {
    Credentials credentials = new Credentials();

    try {/*from  www.  j  av a 2  s .  c  om*/
        credentials.addAll(UserGroupInformation.getCurrentUser().getCredentials());

        List<Token<?>> tokens = YarnUtils.addDelegationTokens(yarnConfig, locationFactory, credentials);
        for (Token<?> token : tokens) {
            LOG.debug("Delegation token acquired for {}, {}", locationFactory.getHomeLocation(), token);
        }
    } catch (IOException e) {
        LOG.warn("Failed to check for secure login type. Not gathering any delegation token.", e);
    }
    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);
        }//from w w  w. j  a  v  a  2 s .com
    }

    // 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);
}