Java Code Examples for org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest

The following examples show how to use org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Bats   Source File: StreamingAppMasterService.java    License: Apache License 2.0 6 votes vote down vote up
private void finishApplication(FinalApplicationStatus finalStatus) throws YarnException, IOException
{
  LOG.info("Application completed. Signalling finish to RM");
  FinishApplicationMasterRequest finishReq = Records.newRecord(FinishApplicationMasterRequest.class);
  finishReq.setFinalApplicationStatus(finalStatus);

  if (finalStatus != FinalApplicationStatus.SUCCEEDED) {
    String diagnostics = "Diagnostics." + " completed=" + numCompletedContainers.get() + ", allocated=" + allocatedContainers.size() + ", failed=" + numFailedContainers.get();
    if (!StringUtils.isEmpty(dnmgr.shutdownDiagnosticsMessage)) {
      diagnostics += "\n";
      diagnostics += dnmgr.shutdownDiagnosticsMessage;
    }
    // YARN-208 - as of 2.0.1-alpha dropped by the RM
    finishReq.setDiagnostics(diagnostics);
    // expected termination of the master process
    // application status and diagnostics message are set above
  }
  LOG.info("diagnostics: " + finishReq.getDiagnostics());
  amRmClient.unregisterApplicationMaster(finishReq.getFinalApplicationStatus(), finishReq.getDiagnostics(), null);
}
 
Example 2
Source Project: hadoop   Source File: TestRMRestart.java    License: Apache License 2.0 6 votes vote down vote up
private void finishApplicationMaster(RMApp rmApp, MockRM rm, MockNM nm,
    MockAM am, FinishApplicationMasterRequest req) throws Exception {
  RMState rmState =
      ((MemoryRMStateStore) rm.getRMContext().getStateStore()).getState();
  Map<ApplicationId, ApplicationStateData> rmAppState =
      rmState.getApplicationState();
  am.unregisterAppAttempt(req,true);
  am.waitForState(RMAppAttemptState.FINISHING);
  nm.nodeHeartbeat(am.getApplicationAttemptId(), 1, ContainerState.COMPLETE);
  am.waitForState(RMAppAttemptState.FINISHED);
  rm.waitForState(rmApp.getApplicationId(), RMAppState.FINISHED);
  // check that app/attempt is saved with the final state
  ApplicationStateData appState = rmAppState.get(rmApp.getApplicationId());
  Assert
    .assertEquals(RMAppState.FINISHED, appState.getState());
  Assert.assertEquals(RMAppAttemptState.FINISHED,
    appState.getAttempt(am.getApplicationAttemptId()).getState());
}
 
Example 3
Source Project: hadoop   Source File: MockAM.java    License: Apache License 2.0 6 votes vote down vote up
public void unregisterAppAttempt(final FinishApplicationMasterRequest req,
    boolean waitForStateRunning) throws Exception {
  if (waitForStateRunning) {
    waitForState(RMAppAttemptState.RUNNING);
  }
  if (ugi == null) {
    ugi =  UserGroupInformation.createRemoteUser(attemptId.toString());
    Token<AMRMTokenIdentifier> token =
        context.getRMApps()
            .get(attemptId.getApplicationId())
            .getRMAppAttempt(attemptId).getAMRMToken();
    ugi.addTokenIdentifier(token.decodeIdentifier());
  }
  try {
    ugi.doAs(new PrivilegedExceptionAction<Object>() {
      @Override
      public Object run() throws Exception {
        amRMProtocol.finishApplicationMaster(req);
        return null;
      }
    });
  } catch (UndeclaredThrowableException e) {
    throw (Exception) e.getCause();
  }
}
 
Example 4
Source Project: hadoop   Source File: TestUnmanagedAMLauncher.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  if (args[0].equals("success")) {
    ApplicationMasterProtocol client = ClientRMProxy.createRMProxy(conf,
        ApplicationMasterProtocol.class);
    client.registerApplicationMaster(RegisterApplicationMasterRequest
        .newInstance(NetUtils.getHostname(), -1, ""));
    Thread.sleep(1000);
    FinishApplicationMasterResponse resp =
        client.finishApplicationMaster(FinishApplicationMasterRequest
          .newInstance(FinalApplicationStatus.SUCCEEDED, "success", null));
    assertTrue(resp.getIsUnregistered());
    System.exit(0);
  } else {
    System.exit(1);
  }
}
 
Example 5
Source Project: big-c   Source File: TestRMRestart.java    License: Apache License 2.0 6 votes vote down vote up
private void finishApplicationMaster(RMApp rmApp, MockRM rm, MockNM nm,
    MockAM am, FinishApplicationMasterRequest req) throws Exception {
  RMState rmState =
      ((MemoryRMStateStore) rm.getRMContext().getStateStore()).getState();
  Map<ApplicationId, ApplicationStateData> rmAppState =
      rmState.getApplicationState();
  am.unregisterAppAttempt(req,true);
  am.waitForState(RMAppAttemptState.FINISHING);
  nm.nodeHeartbeat(am.getApplicationAttemptId(), 1, ContainerState.COMPLETE);
  am.waitForState(RMAppAttemptState.FINISHED);
  rm.waitForState(rmApp.getApplicationId(), RMAppState.FINISHED);
  // check that app/attempt is saved with the final state
  ApplicationStateData appState = rmAppState.get(rmApp.getApplicationId());
  Assert
    .assertEquals(RMAppState.FINISHED, appState.getState());
  Assert.assertEquals(RMAppAttemptState.FINISHED,
    appState.getAttempt(am.getApplicationAttemptId()).getState());
}
 
Example 6
Source Project: big-c   Source File: MockAM.java    License: Apache License 2.0 6 votes vote down vote up
public void unregisterAppAttempt(final FinishApplicationMasterRequest req,
    boolean waitForStateRunning) throws Exception {
  if (waitForStateRunning) {
    waitForState(RMAppAttemptState.RUNNING);
  }
  if (ugi == null) {
    ugi =  UserGroupInformation.createRemoteUser(attemptId.toString());
    Token<AMRMTokenIdentifier> token =
        context.getRMApps()
            .get(attemptId.getApplicationId())
            .getRMAppAttempt(attemptId).getAMRMToken();
    ugi.addTokenIdentifier(token.decodeIdentifier());
  }
  try {
    ugi.doAs(new PrivilegedExceptionAction<Object>() {
      @Override
      public Object run() throws Exception {
        amRMProtocol.finishApplicationMaster(req);
        return null;
      }
    });
  } catch (UndeclaredThrowableException e) {
    throw (Exception) e.getCause();
  }
}
 
Example 7
Source Project: big-c   Source File: TestUnmanagedAMLauncher.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  if (args[0].equals("success")) {
    ApplicationMasterProtocol client = ClientRMProxy.createRMProxy(conf,
        ApplicationMasterProtocol.class);
    client.registerApplicationMaster(RegisterApplicationMasterRequest
        .newInstance(NetUtils.getHostname(), -1, ""));
    Thread.sleep(1000);
    FinishApplicationMasterResponse resp =
        client.finishApplicationMaster(FinishApplicationMasterRequest
          .newInstance(FinalApplicationStatus.SUCCEEDED, "success", null));
    assertTrue(resp.getIsUnregistered());
    System.exit(0);
  } else {
    System.exit(1);
  }
}
 
Example 8
Source Project: attic-apex-core   Source File: StreamingAppMasterService.java    License: Apache License 2.0 6 votes vote down vote up
private void finishApplication(FinalApplicationStatus finalStatus) throws YarnException, IOException
{
  LOG.info("Application completed. Signalling finish to RM");
  FinishApplicationMasterRequest finishReq = Records.newRecord(FinishApplicationMasterRequest.class);
  finishReq.setFinalApplicationStatus(finalStatus);

  if (finalStatus != FinalApplicationStatus.SUCCEEDED) {
    String diagnostics = "Diagnostics." + " completed=" + numCompletedContainers.get() + ", allocated=" + allocatedContainers.size() + ", failed=" + numFailedContainers.get();
    if (!StringUtils.isEmpty(dnmgr.shutdownDiagnosticsMessage)) {
      diagnostics += "\n";
      diagnostics += dnmgr.shutdownDiagnosticsMessage;
    }
    // YARN-208 - as of 2.0.1-alpha dropped by the RM
    finishReq.setDiagnostics(diagnostics);
    // expected termination of the master process
    // application status and diagnostics message are set above
  }
  LOG.info("diagnostics: " + finishReq.getDiagnostics());
  amRmClient.unregisterApplicationMaster(finishReq.getFinalApplicationStatus(), finishReq.getDiagnostics(), null);
}
 
Example 9
Source Project: incubator-tajo   Source File: YarnTajoResourceManager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void stopQueryMaster(QueryId queryId) {
  try {
    FinalApplicationStatus appStatus = FinalApplicationStatus.UNDEFINED;
    QueryInProgress queryInProgress = masterContext.getQueryJobManager().getQueryInProgress(queryId);
    if(queryInProgress == null) {
      return;
    }
    TajoProtos.QueryState state = queryInProgress.getQueryInfo().getQueryState();
    if (state == TajoProtos.QueryState.QUERY_SUCCEEDED) {
      appStatus = FinalApplicationStatus.SUCCEEDED;
    } else if (state == TajoProtos.QueryState.QUERY_FAILED || state == TajoProtos.QueryState.QUERY_ERROR) {
      appStatus = FinalApplicationStatus.FAILED;
    } else if (state == TajoProtos.QueryState.QUERY_ERROR) {
      appStatus = FinalApplicationStatus.FAILED;
    }
    FinishApplicationMasterRequest request = recordFactory
        .newRecordInstance(FinishApplicationMasterRequest.class);
    request.setFinalApplicationStatus(appStatus);
    request.setDiagnostics("QueryMaster shutdown by TajoMaster.");
    rmClient.finishApplicationMaster(request);
  } catch (Exception e) {
    LOG.error(e.getMessage(), e);
  }
}
 
Example 10
@Override
public FinishApplicationMasterResponse finishApplicationMaster(
    FinishApplicationMasterRequest request) throws YarnException,
    IOException {
  FinishApplicationMasterRequestProto requestProto =
      ((FinishApplicationMasterRequestPBImpl) request).getProto();
  try {
    return new FinishApplicationMasterResponsePBImpl(
      proxy.finishApplicationMaster(null, requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 11
Source Project: hadoop   Source File: TestRPCFactories.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public FinishApplicationMasterResponse finishApplicationMaster(
    FinishApplicationMasterRequest request) throws YarnException,
    IOException {
  // TODO Auto-generated method stub
  return null;
}
 
Example 12
Source Project: hadoop   Source File: TestRMRestart.java    License: Apache License 2.0 5 votes vote down vote up
private void finishApplicationMaster(RMApp rmApp, MockRM rm, MockNM nm,
    MockAM am) throws Exception {
  final FinishApplicationMasterRequest req =
      FinishApplicationMasterRequest.newInstance(
        FinalApplicationStatus.SUCCEEDED, "", "");
  finishApplicationMaster(rmApp, rm, nm, am, req);
}
 
Example 13
Source Project: hadoop   Source File: MockRM.java    License: Apache License 2.0 5 votes vote down vote up
public static void finishAMAndVerifyAppState(RMApp rmApp, MockRM rm, MockNM nm,
    MockAM am) throws Exception {
  FinishApplicationMasterRequest req =
      FinishApplicationMasterRequest.newInstance(
        FinalApplicationStatus.SUCCEEDED, "", "");
  am.unregisterAppAttempt(req,true);
  am.waitForState(RMAppAttemptState.FINISHING);
  nm.nodeHeartbeat(am.getApplicationAttemptId(), 1, ContainerState.COMPLETE);
  am.waitForState(RMAppAttemptState.FINISHED);
  rm.waitForState(rmApp.getApplicationId(), RMAppState.FINISHED);
}
 
Example 14
Source Project: hadoop   Source File: MockAM.java    License: Apache License 2.0 5 votes vote down vote up
public void unregisterAppAttempt(boolean waitForStateRunning)
    throws Exception {
  final FinishApplicationMasterRequest req =
      FinishApplicationMasterRequest.newInstance(
          FinalApplicationStatus.SUCCEEDED, "", "");
  unregisterAppAttempt(req, waitForStateRunning);
}
 
Example 15
Source Project: hadoop   Source File: ProtocolHATestBase.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public FinishApplicationMasterResponse finishApplicationMaster(
    FinishApplicationMasterRequest request) throws YarnException,
    IOException {
  resetStartFailoverFlag(true);
  // make sure failover has been triggered
  Assert.assertTrue(waittingForFailOver());
  return createFakeFinishApplicationMasterResponse();
}
 
Example 16
@Test(timeout = 15000)
public void testFinishApplicationMasterOnHA() throws YarnException,
    IOException {
  FinishApplicationMasterRequest request =
      FinishApplicationMasterRequest.newInstance(
          FinalApplicationStatus.SUCCEEDED, "", "");
  FinishApplicationMasterResponse response =
      amClient.finishApplicationMaster(request);
  Assert.assertEquals(response,
      this.cluster.createFakeFinishApplicationMasterResponse());
}
 
Example 17
@Override
public FinishApplicationMasterResponse finishApplicationMaster(
    FinishApplicationMasterRequest request) throws YarnException,
    IOException {
  FinishApplicationMasterRequestProto requestProto =
      ((FinishApplicationMasterRequestPBImpl) request).getProto();
  try {
    return new FinishApplicationMasterResponsePBImpl(
      proxy.finishApplicationMaster(null, requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 18
Source Project: big-c   Source File: TestRPCFactories.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public FinishApplicationMasterResponse finishApplicationMaster(
    FinishApplicationMasterRequest request) throws YarnException,
    IOException {
  // TODO Auto-generated method stub
  return null;
}
 
Example 19
Source Project: big-c   Source File: TestRMRestart.java    License: Apache License 2.0 5 votes vote down vote up
private void finishApplicationMaster(RMApp rmApp, MockRM rm, MockNM nm,
    MockAM am) throws Exception {
  final FinishApplicationMasterRequest req =
      FinishApplicationMasterRequest.newInstance(
        FinalApplicationStatus.SUCCEEDED, "", "");
  finishApplicationMaster(rmApp, rm, nm, am, req);
}
 
Example 20
Source Project: big-c   Source File: MockRM.java    License: Apache License 2.0 5 votes vote down vote up
public static void finishAMAndVerifyAppState(RMApp rmApp, MockRM rm, MockNM nm,
    MockAM am) throws Exception {
  FinishApplicationMasterRequest req =
      FinishApplicationMasterRequest.newInstance(
        FinalApplicationStatus.SUCCEEDED, "", "");
  am.unregisterAppAttempt(req,true);
  am.waitForState(RMAppAttemptState.FINISHING);
  nm.nodeHeartbeat(am.getApplicationAttemptId(), 1, ContainerState.COMPLETE);
  am.waitForState(RMAppAttemptState.FINISHED);
  rm.waitForState(rmApp.getApplicationId(), RMAppState.FINISHED);
}
 
Example 21
Source Project: big-c   Source File: MockAM.java    License: Apache License 2.0 5 votes vote down vote up
public void unregisterAppAttempt(boolean waitForStateRunning)
    throws Exception {
  final FinishApplicationMasterRequest req =
      FinishApplicationMasterRequest.newInstance(
          FinalApplicationStatus.SUCCEEDED, "", "");
  unregisterAppAttempt(req, waitForStateRunning);
}
 
Example 22
Source Project: big-c   Source File: ProtocolHATestBase.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public FinishApplicationMasterResponse finishApplicationMaster(
    FinishApplicationMasterRequest request) throws YarnException,
    IOException {
  resetStartFailoverFlag(true);
  // make sure failover has been triggered
  Assert.assertTrue(waittingForFailOver());
  return createFakeFinishApplicationMasterResponse();
}
 
Example 23
@Test(timeout = 15000)
public void testFinishApplicationMasterOnHA() throws YarnException,
    IOException {
  FinishApplicationMasterRequest request =
      FinishApplicationMasterRequest.newInstance(
          FinalApplicationStatus.SUCCEEDED, "", "");
  FinishApplicationMasterResponse response =
      amClient.finishApplicationMaster(request);
  Assert.assertEquals(response,
      this.cluster.createFakeFinishApplicationMasterResponse());
}
 
Example 24
Source Project: hadoop   Source File: ApplicationMasterService.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public FinishApplicationMasterResponse finishApplicationMaster(
    FinishApplicationMasterRequest request) throws YarnException,
    IOException {

  ApplicationAttemptId applicationAttemptId =
      authorizeRequest().getApplicationAttemptId();
  ApplicationId appId = applicationAttemptId.getApplicationId();

  RMApp rmApp =
      rmContext.getRMApps().get(applicationAttemptId.getApplicationId());
  // checking whether the app exits in RMStateStore at first not to throw
  // ApplicationDoesNotExistInCacheException before and after
  // RM work-preserving restart.
  if (rmApp.isAppFinalStateStored()) {
    LOG.info(rmApp.getApplicationId() + " unregistered successfully. ");
    return FinishApplicationMasterResponse.newInstance(true);
  }

  AllocateResponseLock lock = responseMap.get(applicationAttemptId);
  if (lock == null) {
    throwApplicationDoesNotExistInCacheException(applicationAttemptId);
  }

  // Allow only one thread in AM to do finishApp at a time.
  synchronized (lock) {
    if (!hasApplicationMasterRegistered(applicationAttemptId)) {
      String message =
          "Application Master is trying to unregister before registering for: "
              + appId;
      LOG.error(message);
      RMAuditLogger.logFailure(
          this.rmContext.getRMApps()
              .get(appId).getUser(),
          AuditConstants.UNREGISTER_AM, "", "ApplicationMasterService",
          message, appId,
          applicationAttemptId);
      throw new ApplicationMasterNotRegisteredException(message);
    }

    this.amLivelinessMonitor.receivedPing(applicationAttemptId);

    rmContext.getDispatcher().getEventHandler().handle(
        new RMAppAttemptUnregistrationEvent(applicationAttemptId, request
            .getTrackingUrl(), request.getFinalApplicationStatus(), request
            .getDiagnostics()));

    // For UnmanagedAMs, return true so they don't retry
    return FinishApplicationMasterResponse.newInstance(
        rmApp.getApplicationSubmissionContext().getUnmanagedAM());
  }
}
 
Example 25
Source Project: hadoop   Source File: TestRM.java    License: Apache License 2.0 4 votes vote down vote up
@Test (timeout = 30000)
public void testKillFinishingApp() throws Exception{

  // this dispatcher ignores RMAppAttemptEventType.KILL event
  final Dispatcher dispatcher = new AsyncDispatcher() {
    @Override
    public EventHandler getEventHandler() {

      class EventArgMatcher extends ArgumentMatcher<AbstractEvent> {
        @Override
        public boolean matches(Object argument) {
          if (argument instanceof RMAppAttemptEvent) {
            if (((RMAppAttemptEvent) argument).getType().equals(
              RMAppAttemptEventType.KILL)) {
              return true;
            }
          }
          return false;
        }
      }

      EventHandler handler = spy(super.getEventHandler());
      doNothing().when(handler).handle(argThat(new EventArgMatcher()));
      return handler;
    }
  };

  MockRM rm1 = new MockRM(conf){
    @Override
    protected Dispatcher createDispatcher() {
      return dispatcher;
    }
  };
  rm1.start();
  MockNM nm1 =
      new MockNM("127.0.0.1:1234", 8192, rm1.getResourceTrackerService());
  nm1.registerNode();
  RMApp app1 = rm1.submitApp(200);
  MockAM am1 = MockRM.launchAndRegisterAM(app1, rm1, nm1);

  rm1.killApp(app1.getApplicationId());

  FinishApplicationMasterRequest req =
      FinishApplicationMasterRequest.newInstance(
        FinalApplicationStatus.SUCCEEDED, "", "");
  am1.unregisterAppAttempt(req,true);

  rm1.waitForState(am1.getApplicationAttemptId(), RMAppAttemptState.FINISHING);
  nm1.nodeHeartbeat(am1.getApplicationAttemptId(), 1, ContainerState.COMPLETE);
  rm1.waitForState(am1.getApplicationAttemptId(), RMAppAttemptState.FINISHED);
  rm1.waitForState(app1.getApplicationId(), RMAppState.FINISHED);
}
 
Example 26
Source Project: hadoop   Source File: TestRMRestart.java    License: Apache License 2.0 4 votes vote down vote up
@Test (timeout = 60000)
public void testRMRestartWaitForPreviousSucceededAttempt() throws Exception {
  conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 2);
  MemoryRMStateStore memStore = new MemoryRMStateStore() {
    int count = 0;

    @Override
    public void updateApplicationStateInternal(ApplicationId appId,
        ApplicationStateData appStateData) throws Exception {
      if (count == 0) {
        // do nothing; simulate app final state is not saved.
        LOG.info(appId + " final state is not saved.");
        count++;
      } else {
        super.updateApplicationStateInternal(appId, appStateData);
      }
    }
  };
  memStore.init(conf);
  RMState rmState = memStore.getState();
  Map<ApplicationId, ApplicationStateData> rmAppState =
      rmState.getApplicationState();

  // start RM
  MockRM rm1 = createMockRM(conf, memStore);
  rm1.start();
  MockNM nm1 = rm1.registerNode("127.0.0.1:1234", 15120);
  RMApp app0 = rm1.submitApp(200);
  MockAM am0 = MockRM.launchAndRegisterAM(app0, rm1, nm1);

  FinishApplicationMasterRequest req =
      FinishApplicationMasterRequest.newInstance(
        FinalApplicationStatus.SUCCEEDED, "", "");
  am0.unregisterAppAttempt(req, true);
  am0.waitForState(RMAppAttemptState.FINISHING);
  // app final state is not saved. This guarantees that RMApp cannot be
  // recovered via its own saved state, but only via the event notification
  // from the RMAppAttempt on recovery.
  Assert.assertNull(rmAppState.get(app0.getApplicationId()).getState());

  // start RM
  MockRM rm2 = createMockRM(conf, memStore);
  nm1.setResourceTrackerService(rm2.getResourceTrackerService());
  rm2.start();

  rm2.waitForState(app0.getCurrentAppAttempt().getAppAttemptId(),
    RMAppAttemptState.FINISHED);
  rm2.waitForState(app0.getApplicationId(), RMAppState.FINISHED);
  // app final state is saved via the finish event from attempt.
  Assert.assertEquals(RMAppState.FINISHED,
      rmAppState.get(app0.getApplicationId()).getState());
}
 
Example 27
Source Project: hadoop   Source File: TestRMRestart.java    License: Apache License 2.0 4 votes vote down vote up
@Test (timeout = 60000)
public void testRMRestartSucceededApp() throws Exception {
  conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS,
    YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS);
  MemoryRMStateStore memStore = new MemoryRMStateStore();
  memStore.init(conf);
  RMState rmState = memStore.getState();
  Map<ApplicationId, ApplicationStateData> rmAppState =
      rmState.getApplicationState();

  // start RM
  MockRM rm1 = createMockRM(conf, memStore);
  rm1.start();
  MockNM nm1 =
      new MockNM("127.0.0.1:1234", 15120, rm1.getResourceTrackerService());
  nm1.registerNode();

  // create an app and finish the app.
  RMApp app0 = rm1.submitApp(200);
  MockAM am0 = launchAM(app0, rm1, nm1);

  // unregister am
  FinishApplicationMasterRequest req =
      FinishApplicationMasterRequest.newInstance(
        FinalApplicationStatus.SUCCEEDED, "diagnostics", "trackingUrl");
  finishApplicationMaster(app0, rm1, nm1, am0, req);
 
  // check the state store about the unregistered info.
  ApplicationStateData appState = rmAppState.get(app0.getApplicationId());
  ApplicationAttemptStateData attemptState0 =
    appState.getAttempt(am0.getApplicationAttemptId());
  Assert.assertEquals("diagnostics", attemptState0.getDiagnostics());
  Assert.assertEquals(FinalApplicationStatus.SUCCEEDED,
    attemptState0.getFinalApplicationStatus());
  Assert.assertEquals("trackingUrl", attemptState0.getFinalTrackingUrl());
  Assert.assertEquals(app0.getFinishTime(), appState.getFinishTime());

  // restart rm
  MockRM rm2 = createMockRM(conf, memStore);
  rm2.start();

  // verify application report returns the same app info as the app info
  // before RM restarts.
  ApplicationReport appReport = verifyAppReportAfterRMRestart(app0, rm2);
  Assert.assertEquals(FinalApplicationStatus.SUCCEEDED,
    appReport.getFinalApplicationStatus());
  Assert.assertEquals("trackingUrl", appReport.getOriginalTrackingUrl());
}
 
Example 28
Source Project: hadoop   Source File: RMCommunicator.java    License: Apache License 2.0 4 votes vote down vote up
@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();
  }
}
 
Example 29
Source Project: hadoop   Source File: TestLocalContainerAllocator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public FinishApplicationMasterResponse finishApplicationMaster(
    FinishApplicationMasterRequest request) throws YarnException,
    IOException {
  return null;
}
 
Example 30
Source Project: hadoop   Source File: TestRMContainerAllocator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public FinishApplicationMasterResponse finishApplicationMaster(
    FinishApplicationMasterRequest request) throws YarnException,
    IOException {
  return FinishApplicationMasterResponse.newInstance(false);
}