Search in sources :

Example 11 with AMRMTokenIdentifier

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

the class OpportunisticContainerAllocatorAMService method getAppAttemptId.

private static ApplicationAttemptId getAppAttemptId() throws YarnException {
    AMRMTokenIdentifier amrmTokenIdentifier = YarnServerSecurityUtils.authorizeRequest();
    ApplicationAttemptId applicationAttemptId = amrmTokenIdentifier.getApplicationAttemptId();
    return applicationAttemptId;
}
Also used : AMRMTokenIdentifier(org.apache.hadoop.yarn.security.AMRMTokenIdentifier) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId)

Example 12 with AMRMTokenIdentifier

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

the class MockAM method allocate.

public AllocateResponse allocate(AllocateRequest allocateRequest) throws Exception {
    UserGroupInformation ugi = UserGroupInformation.createRemoteUser(attemptId.toString());
    Token<AMRMTokenIdentifier> token = context.getRMApps().get(attemptId.getApplicationId()).getRMAppAttempt(attemptId).getAMRMToken();
    ugi.addTokenIdentifier(token.decodeIdentifier());
    lastResponse = doAllocateAs(ugi, allocateRequest);
    return lastResponse;
}
Also used : AMRMTokenIdentifier(org.apache.hadoop.yarn.security.AMRMTokenIdentifier) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 13 with AMRMTokenIdentifier

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

the class AMSimulator method lastStep.

@Override
public void lastStep() throws Exception {
    LOG.info(MessageFormat.format("Application {0} is shutting down.", appId));
    // unregister tracking
    if (isTracked) {
        untrackApp();
    }
    // Finish AM container
    if (amContainer != null) {
        LOG.info("AM container = " + amContainer.getId() + " reported to finish");
        se.getNmMap().get(amContainer.getNodeId()).cleanupContainer(amContainer.getId());
    } else {
        LOG.info("AM container is null");
    }
    if (null == appAttemptId) {
        // it's unnecessary to finish am as well
        return;
    }
    // unregister application master
    final FinishApplicationMasterRequest finishAMRequest = recordFactory.newRecordInstance(FinishApplicationMasterRequest.class);
    finishAMRequest.setFinalApplicationStatus(FinalApplicationStatus.SUCCEEDED);
    UserGroupInformation ugi = UserGroupInformation.createRemoteUser(appAttemptId.toString());
    Token<AMRMTokenIdentifier> token = rm.getRMContext().getRMApps().get(appId).getRMAppAttempt(appAttemptId).getAMRMToken();
    ugi.addTokenIdentifier(token.decodeIdentifier());
    ugi.doAs(new PrivilegedExceptionAction<Object>() {

        @Override
        public Object run() throws Exception {
            rm.getApplicationMasterService().finishApplicationMaster(finishAMRequest);
            return null;
        }
    });
    simulateFinishTimeMS = System.currentTimeMillis() - SLSRunner.getRunner().getStartTimeMS();
    // record job running information
    ((SchedulerWrapper) rm.getResourceScheduler()).addAMRuntime(appId, traceStartTimeMS, traceFinishTimeMS, simulateStartTimeMS, simulateFinishTimeMS);
}
Also used : AMRMTokenIdentifier(org.apache.hadoop.yarn.security.AMRMTokenIdentifier) SchedulerWrapper(org.apache.hadoop.yarn.sls.scheduler.SchedulerWrapper) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) FinishApplicationMasterRequest(org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 14 with AMRMTokenIdentifier

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

the class MRAMSimulator method sendContainerRequest.

@Override
protected void sendContainerRequest() throws YarnException, IOException, InterruptedException {
    if (isFinished) {
        return;
    }
    // send out request
    List<ResourceRequest> ask = null;
    if (mapFinished != mapTotal) {
        // map phase
        if (!pendingMaps.isEmpty()) {
            ask = packageRequests(mergeLists(pendingMaps, scheduledMaps), PRIORITY_MAP);
            LOG.debug(MessageFormat.format("Application {0} sends out " + "request for {1} mappers.", appId, pendingMaps.size()));
            scheduledMaps.addAll(pendingMaps);
            pendingMaps.clear();
        } else if (!pendingFailedMaps.isEmpty()) {
            ask = packageRequests(mergeLists(pendingFailedMaps, scheduledMaps), PRIORITY_MAP);
            LOG.debug(MessageFormat.format("Application {0} sends out " + "requests for {1} failed mappers.", appId, pendingFailedMaps.size()));
            scheduledMaps.addAll(pendingFailedMaps);
            pendingFailedMaps.clear();
        }
    } else if (reduceFinished != reduceTotal) {
        // reduce phase
        if (!pendingReduces.isEmpty()) {
            ask = packageRequests(mergeLists(pendingReduces, scheduledReduces), PRIORITY_REDUCE);
            LOG.debug(MessageFormat.format("Application {0} sends out " + "requests for {1} reducers.", appId, pendingReduces.size()));
            scheduledReduces.addAll(pendingReduces);
            pendingReduces.clear();
        } else if (!pendingFailedReduces.isEmpty()) {
            ask = packageRequests(mergeLists(pendingFailedReduces, scheduledReduces), PRIORITY_REDUCE);
            LOG.debug(MessageFormat.format("Application {0} sends out " + "request for {1} failed reducers.", appId, pendingFailedReduces.size()));
            scheduledReduces.addAll(pendingFailedReduces);
            pendingFailedReduces.clear();
        }
    }
    if (ask == null) {
        ask = new ArrayList<>();
    }
    final AllocateRequest request = createAllocateRequest(ask);
    if (totalContainers == 0) {
        request.setProgress(1.0f);
    } else {
        request.setProgress((float) finishedContainers / totalContainers);
    }
    UserGroupInformation ugi = UserGroupInformation.createRemoteUser(appAttemptId.toString());
    Token<AMRMTokenIdentifier> token = rm.getRMContext().getRMApps().get(appAttemptId.getApplicationId()).getRMAppAttempt(appAttemptId).getAMRMToken();
    ugi.addTokenIdentifier(token.decodeIdentifier());
    AllocateResponse response = ugi.doAs(new PrivilegedExceptionAction<AllocateResponse>() {

        @Override
        public AllocateResponse run() throws Exception {
            return rm.getApplicationMasterService().allocate(request);
        }
    });
    if (response != null) {
        responseQueue.put(response);
    }
}
Also used : AllocateResponse(org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse) AMRMTokenIdentifier(org.apache.hadoop.yarn.security.AMRMTokenIdentifier) AllocateRequest(org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest) ResourceRequest(org.apache.hadoop.yarn.api.records.ResourceRequest) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 15 with AMRMTokenIdentifier

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

the class AMLauncher method setupTokens.

@Private
@VisibleForTesting
protected void setupTokens(ContainerLaunchContext container, ContainerId containerID) throws IOException {
    Map<String, String> environment = container.getEnvironment();
    environment.put(ApplicationConstants.APPLICATION_WEB_PROXY_BASE_ENV, application.getWebProxyBase());
    // Set AppSubmitTime to be consumable by the AM.
    ApplicationId applicationId = application.getAppAttemptId().getApplicationId();
    environment.put(ApplicationConstants.APP_SUBMIT_TIME_ENV, String.valueOf(rmContext.getRMApps().get(applicationId).getSubmitTime()));
    Credentials credentials = new Credentials();
    DataInputByteBuffer dibb = new DataInputByteBuffer();
    ByteBuffer tokens = container.getTokens();
    if (tokens != null) {
        // TODO: Don't do this kind of checks everywhere.
        dibb.reset(tokens);
        credentials.readTokenStorageStream(dibb);
        tokens.rewind();
    }
    // Add AMRMToken
    Token<AMRMTokenIdentifier> amrmToken = createAndSetAMRMToken();
    if (amrmToken != null) {
        credentials.addToken(amrmToken.getService(), amrmToken);
    }
    DataOutputBuffer dob = new DataOutputBuffer();
    credentials.writeTokenStorageToStream(dob);
    container.setTokens(ByteBuffer.wrap(dob.getData(), 0, dob.getLength()));
}
Also used : AMRMTokenIdentifier(org.apache.hadoop.yarn.security.AMRMTokenIdentifier) DataInputByteBuffer(org.apache.hadoop.io.DataInputByteBuffer) DataOutputBuffer(org.apache.hadoop.io.DataOutputBuffer) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ByteBuffer(java.nio.ByteBuffer) DataInputByteBuffer(org.apache.hadoop.io.DataInputByteBuffer) Credentials(org.apache.hadoop.security.Credentials) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Private(org.apache.hadoop.classification.InterfaceAudience.Private)

Aggregations

AMRMTokenIdentifier (org.apache.hadoop.yarn.security.AMRMTokenIdentifier)48 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)21 Text (org.apache.hadoop.io.Text)17 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)17 Test (org.junit.Test)13 IOException (java.io.IOException)12 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)11 Token (org.apache.hadoop.security.token.Token)9 AllocateResponse (org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse)9 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)7 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)7 Credentials (org.apache.hadoop.security.Credentials)6 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)6 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)6 File (java.io.File)5 ArrayList (java.util.ArrayList)5 Configuration (org.apache.hadoop.conf.Configuration)5 AllocateRequest (org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest)5 NMToken (org.apache.hadoop.yarn.api.records.NMToken)5 Token (org.apache.hadoop.yarn.api.records.Token)5