Search in sources :

Example 1 with FinishApplicationMasterRequest

use of org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest in project hadoop by apache.

the class RMCommunicator method doUnregistration.

@VisibleForTesting
protected void doUnregistration() throws YarnException, IOException, InterruptedException {
    FinalApplicationStatus finishState = FinalApplicationStatus.UNDEFINED;
    JobImpl jobImpl = (JobImpl) job;
    if (jobImpl.getInternalState() == JobStateInternal.SUCCEEDED) {
        finishState = FinalApplicationStatus.SUCCEEDED;
    } else if (jobImpl.getInternalState() == JobStateInternal.KILLED || (jobImpl.getInternalState() == JobStateInternal.RUNNING && isSignalled)) {
        finishState = FinalApplicationStatus.KILLED;
    } else if (jobImpl.getInternalState() == JobStateInternal.FAILED || jobImpl.getInternalState() == JobStateInternal.ERROR) {
        finishState = FinalApplicationStatus.FAILED;
    }
    StringBuffer sb = new StringBuffer();
    for (String s : job.getDiagnostics()) {
        sb.append(s).append("\n");
    }
    LOG.info("Setting job diagnostics to " + sb.toString());
    String historyUrl = MRWebAppUtil.getApplicationWebURLOnJHSWithScheme(getConfig(), context.getApplicationID());
    LOG.info("History url is " + historyUrl);
    FinishApplicationMasterRequest request = FinishApplicationMasterRequest.newInstance(finishState, sb.toString(), historyUrl);
    try {
        while (true) {
            FinishApplicationMasterResponse response = scheduler.finishApplicationMaster(request);
            if (response.getIsUnregistered()) {
                // When excepting ClientService, other services are already stopped,
                // it is safe to let clients know the final states. ClientService
                // should wait for some time so clients have enough time to know the
                // final states.
                RunningAppContext raContext = (RunningAppContext) context;
                raContext.markSuccessfulUnregistration();
                break;
            }
            LOG.info("Waiting for application to be successfully unregistered.");
            Thread.sleep(rmPollInterval);
        }
    } catch (ApplicationMasterNotRegisteredException e) {
        // RM might have restarted or failed over and so lost the fact that AM had
        // registered before.
        register();
        doUnregistration();
    }
}
Also used : ApplicationMasterNotRegisteredException(org.apache.hadoop.yarn.exceptions.ApplicationMasterNotRegisteredException) JobImpl(org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl) FinalApplicationStatus(org.apache.hadoop.yarn.api.records.FinalApplicationStatus) RunningAppContext(org.apache.hadoop.mapreduce.v2.app.MRAppMaster.RunningAppContext) FinishApplicationMasterResponse(org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterResponse) FinishApplicationMasterRequest(org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with FinishApplicationMasterRequest

use of org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest in project hadoop by apache.

the class MockAM method unregisterAppAttempt.

public void unregisterAppAttempt(boolean waitForStateRunning) throws Exception {
    final FinishApplicationMasterRequest req = FinishApplicationMasterRequest.newInstance(FinalApplicationStatus.SUCCEEDED, "", "");
    unregisterAppAttempt(req, waitForStateRunning);
}
Also used : FinishApplicationMasterRequest(org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest)

Example 3 with FinishApplicationMasterRequest

use of org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest in project hadoop by apache.

the class MockRM method finishAMAndVerifyAppState.

public static void finishAMAndVerifyAppState(RMApp rmApp, MockRM rm, MockNM nm, MockAM am) throws Exception {
    FinishApplicationMasterRequest req = FinishApplicationMasterRequest.newInstance(FinalApplicationStatus.SUCCEEDED, "", "");
    am.unregisterAppAttempt(req, true);
    rm.waitForState(am.getApplicationAttemptId(), RMAppAttemptState.FINISHING);
    nm.nodeHeartbeat(am.getApplicationAttemptId(), 1, ContainerState.COMPLETE);
    rm.drainEventsImplicitly();
    rm.waitForState(am.getApplicationAttemptId(), RMAppAttemptState.FINISHED);
    rm.waitForState(rmApp.getApplicationId(), RMAppState.FINISHED);
}
Also used : FinishApplicationMasterRequest(org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest)

Example 4 with FinishApplicationMasterRequest

use of org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest 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 5 with FinishApplicationMasterRequest

use of org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest in project hadoop by apache.

the class TestOpportunisticContainerAllocatorAMService method createService.

private OpportunisticContainerAllocatorAMService createService(final RecordFactory factory, final RMContext rmContext, final Container c) {
    return new OpportunisticContainerAllocatorAMService(rmContext, null) {

        @Override
        public RegisterApplicationMasterResponse registerApplicationMaster(RegisterApplicationMasterRequest request) throws YarnException, IOException {
            RegisterApplicationMasterResponse resp = factory.newRecordInstance(RegisterApplicationMasterResponse.class);
            // Dummy Entry to Assert that we get this object back
            resp.setQueue("dummyQueue");
            return resp;
        }

        @Override
        public FinishApplicationMasterResponse finishApplicationMaster(FinishApplicationMasterRequest request) throws YarnException, IOException {
            FinishApplicationMasterResponse resp = factory.newRecordInstance(FinishApplicationMasterResponse.class);
            // Dummy Entry to Assert that we get this object back
            resp.setIsUnregistered(false);
            return resp;
        }

        @Override
        public AllocateResponse allocate(AllocateRequest request) throws YarnException, IOException {
            AllocateResponse response = factory.newRecordInstance(AllocateResponse.class);
            response.setNumClusterNodes(12345);
            response.setAllocatedContainers(Arrays.asList(c));
            return response;
        }

        @Override
        public RegisterDistributedSchedulingAMResponse registerApplicationMasterForDistributedScheduling(RegisterApplicationMasterRequest request) throws YarnException, IOException {
            RegisterDistributedSchedulingAMResponse resp = factory.newRecordInstance(RegisterDistributedSchedulingAMResponse.class);
            resp.setContainerIdStart(54321L);
            resp.setMaxContainerResource(Resource.newInstance(4096, 4));
            resp.setMinContainerResource(Resource.newInstance(1024, 1));
            resp.setIncrContainerResource(Resource.newInstance(2048, 2));
            return resp;
        }

        @Override
        public DistributedSchedulingAllocateResponse allocateForDistributedScheduling(DistributedSchedulingAllocateRequest request) throws YarnException, IOException {
            List<ResourceRequest> askList = request.getAllocateRequest().getAskList();
            List<Container> allocatedContainers = request.getAllocatedContainers();
            Assert.assertEquals(1, allocatedContainers.size());
            Assert.assertEquals(ExecutionType.OPPORTUNISTIC, allocatedContainers.get(0).getExecutionType());
            Assert.assertEquals(1, askList.size());
            Assert.assertTrue(askList.get(0).getExecutionTypeRequest().getEnforceExecutionType());
            DistributedSchedulingAllocateResponse resp = factory.newRecordInstance(DistributedSchedulingAllocateResponse.class);
            resp.setNodesForScheduling(Arrays.asList(RemoteNode.newInstance(NodeId.newInstance("h1", 1234), "http://h1:4321")));
            return resp;
        }
    };
}
Also used : RegisterDistributedSchedulingAMResponse(org.apache.hadoop.yarn.server.api.protocolrecords.RegisterDistributedSchedulingAMResponse) DistributedSchedulingAllocateRequest(org.apache.hadoop.yarn.server.api.protocolrecords.DistributedSchedulingAllocateRequest) AllocateRequest(org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest) FinishApplicationMasterResponse(org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterResponse) DistributedSchedulingAllocateResponse(org.apache.hadoop.yarn.server.api.protocolrecords.DistributedSchedulingAllocateResponse) FinishApplicationMasterRequest(org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest) DistributedSchedulingAllocateResponse(org.apache.hadoop.yarn.server.api.protocolrecords.DistributedSchedulingAllocateResponse) AllocateResponse(org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse) RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer) Container(org.apache.hadoop.yarn.api.records.Container) RegisterApplicationMasterResponse(org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse) ResourceRequest(org.apache.hadoop.yarn.api.records.ResourceRequest) RegisterApplicationMasterRequest(org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterRequest) DistributedSchedulingAllocateRequest(org.apache.hadoop.yarn.server.api.protocolrecords.DistributedSchedulingAllocateRequest)

Aggregations

FinishApplicationMasterRequest (org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest)17 Test (org.junit.Test)8 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)6 FinishApplicationMasterResponse (org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterResponse)5 AllocateRequest (org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest)3 AllocateResponse (org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse)3 RegisterApplicationMasterRequest (org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterRequest)3 ApplicationMasterNotRegisteredException (org.apache.hadoop.yarn.exceptions.ApplicationMasterNotRegisteredException)3 IOException (java.io.IOException)2 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)2 ApplicationMasterProtocol (org.apache.hadoop.yarn.api.ApplicationMasterProtocol)2 RegisterApplicationMasterResponse (org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse)2 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)2 Container (org.apache.hadoop.yarn.api.records.Container)2 ResourceRequest (org.apache.hadoop.yarn.api.records.ResourceRequest)2 DrainDispatcher (org.apache.hadoop.yarn.event.DrainDispatcher)2 MemoryRMStateStore (org.apache.hadoop.yarn.server.resourcemanager.recovery.MemoryRMStateStore)2 RMState (org.apache.hadoop.yarn.server.resourcemanager.recovery.RMStateStore.RMState)2 ApplicationStateData (org.apache.hadoop.yarn.server.resourcemanager.recovery.records.ApplicationStateData)2 RMAppAttempt (org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt)2