Search in sources :

Example 11 with NMTokenIdentifier

use of org.apache.hadoop.yarn.security.NMTokenIdentifier in project hadoop by apache.

the class ContainerManagerImpl method stopContainers.

/**
   * Stop a list of containers running on this NodeManager.
   */
@Override
public StopContainersResponse stopContainers(StopContainersRequest requests) throws YarnException, IOException {
    List<ContainerId> succeededRequests = new ArrayList<ContainerId>();
    Map<ContainerId, SerializedException> failedRequests = new HashMap<ContainerId, SerializedException>();
    UserGroupInformation remoteUgi = getRemoteUgi();
    NMTokenIdentifier identifier = selectNMTokenIdentifier(remoteUgi);
    if (identifier == null) {
        throw RPCUtil.getRemoteException(INVALID_NMTOKEN_MSG);
    }
    for (ContainerId id : requests.getContainerIds()) {
        try {
            Container container = this.context.getContainers().get(id);
            authorizeGetAndStopContainerRequest(id, container, true, identifier);
            stopContainerInternal(id);
            succeededRequests.add(id);
        } catch (YarnException e) {
            failedRequests.put(id, SerializedException.newInstance(e));
        }
    }
    return StopContainersResponse.newInstance(succeededRequests, failedRequests);
}
Also used : NMTokenIdentifier(org.apache.hadoop.yarn.security.NMTokenIdentifier) Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) HashMap(java.util.HashMap) SerializedException(org.apache.hadoop.yarn.api.records.SerializedException) ArrayList(java.util.ArrayList) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 12 with NMTokenIdentifier

use of org.apache.hadoop.yarn.security.NMTokenIdentifier in project hadoop by apache.

the class ContainerManagerImpl method increaseContainersResource.

/**
   * Increase resource of a list of containers on this NodeManager.
   */
@Override
public IncreaseContainersResourceResponse increaseContainersResource(IncreaseContainersResourceRequest requests) throws YarnException, IOException {
    if (blockNewContainerRequests.get()) {
        throw new NMNotYetReadyException("Rejecting container resource increase as NodeManager has not" + " yet connected with ResourceManager");
    }
    UserGroupInformation remoteUgi = getRemoteUgi();
    NMTokenIdentifier nmTokenIdentifier = selectNMTokenIdentifier(remoteUgi);
    authorizeUser(remoteUgi, nmTokenIdentifier);
    List<ContainerId> successfullyIncreasedContainers = new ArrayList<ContainerId>();
    Map<ContainerId, SerializedException> failedContainers = new HashMap<ContainerId, SerializedException>();
    // map in NMContext.
    synchronized (this.context) {
        // Process container resource increase requests
        for (org.apache.hadoop.yarn.api.records.Token token : requests.getContainersToIncrease()) {
            ContainerId containerId = null;
            try {
                if (token.getIdentifier() == null) {
                    throw new IOException(INVALID_CONTAINERTOKEN_MSG);
                }
                ContainerTokenIdentifier containerTokenIdentifier = BuilderUtils.newContainerTokenIdentifier(token);
                verifyAndGetContainerTokenIdentifier(token, containerTokenIdentifier);
                authorizeStartAndResourceIncreaseRequest(nmTokenIdentifier, containerTokenIdentifier, false);
                containerId = containerTokenIdentifier.getContainerID();
                // Reuse the startContainer logic to update NMToken,
                // as container resource increase request will have come with
                // an updated NMToken.
                updateNMTokenIdentifier(nmTokenIdentifier);
                Resource resource = containerTokenIdentifier.getResource();
                changeContainerResourceInternal(containerId, containerTokenIdentifier.getVersion(), resource, true);
                successfullyIncreasedContainers.add(containerId);
            } catch (YarnException | InvalidToken e) {
                failedContainers.put(containerId, SerializedException.newInstance(e));
            } catch (IOException e) {
                throw RPCUtil.getRemoteException(e);
            }
        }
    }
    return IncreaseContainersResourceResponse.newInstance(successfullyIncreasedContainers, failedContainers);
}
Also used : NMTokenIdentifier(org.apache.hadoop.yarn.security.NMTokenIdentifier) HashMap(java.util.HashMap) SerializedException(org.apache.hadoop.yarn.api.records.SerializedException) ArrayList(java.util.ArrayList) Resource(org.apache.hadoop.yarn.api.records.Resource) NMNotYetReadyException(org.apache.hadoop.yarn.exceptions.NMNotYetReadyException) IOException(java.io.IOException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) ContainerTokenIdentifier(org.apache.hadoop.yarn.security.ContainerTokenIdentifier) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) InvalidToken(org.apache.hadoop.security.token.SecretManager.InvalidToken) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 13 with NMTokenIdentifier

use of org.apache.hadoop.yarn.security.NMTokenIdentifier in project hadoop by apache.

the class ContainerManagerImpl method selectNMTokenIdentifier.

// Obtain the needed ContainerTokenIdentifier from the remote-UGI. RPC layer
// currently sets only the required id, but iterate through anyways just to
// be sure.
@Private
@VisibleForTesting
protected NMTokenIdentifier selectNMTokenIdentifier(UserGroupInformation remoteUgi) {
    Set<TokenIdentifier> tokenIdentifiers = remoteUgi.getTokenIdentifiers();
    NMTokenIdentifier resultId = null;
    for (TokenIdentifier id : tokenIdentifiers) {
        if (id instanceof NMTokenIdentifier) {
            resultId = (NMTokenIdentifier) id;
            break;
        }
    }
    return resultId;
}
Also used : NMTokenIdentifier(org.apache.hadoop.yarn.security.NMTokenIdentifier) TokenIdentifier(org.apache.hadoop.security.token.TokenIdentifier) ContainerTokenIdentifier(org.apache.hadoop.yarn.security.ContainerTokenIdentifier) NMTokenIdentifier(org.apache.hadoop.yarn.security.NMTokenIdentifier) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Private(org.apache.hadoop.classification.InterfaceAudience.Private)

Example 14 with NMTokenIdentifier

use of org.apache.hadoop.yarn.security.NMTokenIdentifier in project hadoop by apache.

the class TestContainerManagerRecovery method increaseContainersResource.

private IncreaseContainersResourceResponse increaseContainersResource(Context context, final ContainerManagerImpl cm, ContainerId cid, Resource capability) throws Exception {
    UserGroupInformation user = UserGroupInformation.createRemoteUser(cid.getApplicationAttemptId().toString());
    // construct container resource increase request
    final List<Token> increaseTokens = new ArrayList<Token>();
    // add increase request
    Token containerToken = TestContainerManager.createContainerToken(cid, 0, context.getNodeId(), user.getShortUserName(), capability, context.getContainerTokenSecretManager(), null);
    increaseTokens.add(containerToken);
    final IncreaseContainersResourceRequest increaseRequest = IncreaseContainersResourceRequest.newInstance(increaseTokens);
    NMTokenIdentifier nmToken = new NMTokenIdentifier(cid.getApplicationAttemptId(), context.getNodeId(), user.getShortUserName(), context.getNMTokenSecretManager().getCurrentKey().getKeyId());
    user.addTokenIdentifier(nmToken);
    return user.doAs(new PrivilegedExceptionAction<IncreaseContainersResourceResponse>() {

        @Override
        public IncreaseContainersResourceResponse run() throws Exception {
            return cm.increaseContainersResource(increaseRequest);
        }
    });
}
Also used : NMTokenIdentifier(org.apache.hadoop.yarn.security.NMTokenIdentifier) ArrayList(java.util.ArrayList) IncreaseContainersResourceRequest(org.apache.hadoop.yarn.api.protocolrecords.IncreaseContainersResourceRequest) Token(org.apache.hadoop.yarn.api.records.Token) IncreaseContainersResourceResponse(org.apache.hadoop.yarn.api.protocolrecords.IncreaseContainersResourceResponse) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) UnsupportedFileSystemException(org.apache.hadoop.fs.UnsupportedFileSystemException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 15 with NMTokenIdentifier

use of org.apache.hadoop.yarn.security.NMTokenIdentifier in project hadoop by apache.

the class TestContainerManagerRecovery method startContainer.

private StartContainersResponse startContainer(Context context, final ContainerManagerImpl cm, ContainerId cid, ContainerLaunchContext clc, LogAggregationContext logAggregationContext) throws Exception {
    UserGroupInformation user = UserGroupInformation.createRemoteUser(cid.getApplicationAttemptId().toString());
    StartContainerRequest scReq = StartContainerRequest.newInstance(clc, TestContainerManager.createContainerToken(cid, 0, context.getNodeId(), user.getShortUserName(), context.getContainerTokenSecretManager(), logAggregationContext));
    final List<StartContainerRequest> scReqList = new ArrayList<StartContainerRequest>();
    scReqList.add(scReq);
    NMTokenIdentifier nmToken = new NMTokenIdentifier(cid.getApplicationAttemptId(), context.getNodeId(), user.getShortUserName(), context.getNMTokenSecretManager().getCurrentKey().getKeyId());
    user.addTokenIdentifier(nmToken);
    return user.doAs(new PrivilegedExceptionAction<StartContainersResponse>() {

        @Override
        public StartContainersResponse run() throws Exception {
            return cm.startContainers(StartContainersRequest.newInstance(scReqList));
        }
    });
}
Also used : NMTokenIdentifier(org.apache.hadoop.yarn.security.NMTokenIdentifier) StartContainersResponse(org.apache.hadoop.yarn.api.protocolrecords.StartContainersResponse) ArrayList(java.util.ArrayList) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) UnsupportedFileSystemException(org.apache.hadoop.fs.UnsupportedFileSystemException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) StartContainerRequest(org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest)

Aggregations

NMTokenIdentifier (org.apache.hadoop.yarn.security.NMTokenIdentifier)20 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)16 ArrayList (java.util.ArrayList)10 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)10 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)9 IOException (java.io.IOException)7 HashMap (java.util.HashMap)6 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)6 StartContainerRequest (org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest)5 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)5 ContainerTokenIdentifier (org.apache.hadoop.yarn.security.ContainerTokenIdentifier)5 InvalidToken (org.apache.hadoop.security.token.SecretManager.InvalidToken)4 NodeId (org.apache.hadoop.yarn.api.records.NodeId)4 SerializedException (org.apache.hadoop.yarn.api.records.SerializedException)4 Container (org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container)4 UnsupportedFileSystemException (org.apache.hadoop.fs.UnsupportedFileSystemException)3 GetContainerStatusesRequest (org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest)3 StartContainersRequest (org.apache.hadoop.yarn.api.protocolrecords.StartContainersRequest)3 ContainerStatus (org.apache.hadoop.yarn.api.records.ContainerStatus)3 Test (org.junit.Test)3