org.apache.hadoop.yarn.api.records.YarnApplicationAttemptState Java Examples

The following examples show how to use org.apache.hadoop.yarn.api.records.YarnApplicationAttemptState. 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 File: RMAppAttemptImpl.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public ApplicationAttemptReport createApplicationAttemptReport() {
  this.readLock.lock();
  ApplicationAttemptReport attemptReport = null;
  try {
    // AM container maybe not yet allocated. and also unmangedAM doesn't have
    // am container.
    ContainerId amId =
        masterContainer == null ? null : masterContainer.getId();
    attemptReport = ApplicationAttemptReport.newInstance(this
        .getAppAttemptId(), this.getHost(), this.getRpcPort(), this
        .getTrackingUrl(), this.getOriginalTrackingUrl(), this.getDiagnostics(),
        YarnApplicationAttemptState .valueOf(this.getState().toString()), amId);
  } finally {
    this.readLock.unlock();
  }
  return attemptReport;
}
 
Example #2
Source File: ApplicationAttemptHistoryData.java    From ambari-metrics with Apache License 2.0 6 votes vote down vote up
@Public
@Unstable
public static ApplicationAttemptHistoryData newInstance(
    ApplicationAttemptId appAttemptId, String host, int rpcPort,
    ContainerId masterContainerId, String diagnosticsInfo,
    String trackingURL, FinalApplicationStatus finalApplicationStatus,
    YarnApplicationAttemptState yarnApplicationAttemptState) {
  ApplicationAttemptHistoryData appAttemptHD =
      new ApplicationAttemptHistoryData();
  appAttemptHD.setApplicationAttemptId(appAttemptId);
  appAttemptHD.setHost(host);
  appAttemptHD.setRPCPort(rpcPort);
  appAttemptHD.setMasterContainerId(masterContainerId);
  appAttemptHD.setDiagnosticsInfo(diagnosticsInfo);
  appAttemptHD.setTrackingURL(trackingURL);
  appAttemptHD.setFinalApplicationStatus(finalApplicationStatus);
  appAttemptHD.setYarnApplicationAttemptState(yarnApplicationAttemptState);
  return appAttemptHD;
}
 
Example #3
Source File: TestRMAppAttemptTransitions.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testFinalSavingToFinishedWithExpire() {
  Container amContainer = allocateApplicationAttempt();
  launchApplicationAttempt(amContainer);
  runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false);
  FinalApplicationStatus finalStatus = FinalApplicationStatus.SUCCEEDED;
  String trackingUrl = "mytrackingurl";
  String diagnostics = "Successssseeeful";
  applicationAttempt.handle(new RMAppAttemptUnregistrationEvent(
    applicationAttempt.getAppAttemptId(), trackingUrl, finalStatus,
    diagnostics));
  assertEquals(RMAppAttemptState.FINAL_SAVING,
    applicationAttempt.getAppAttemptState());
  assertEquals(YarnApplicationAttemptState.RUNNING,
      applicationAttempt.createApplicationAttemptState());
  // Expire event comes before Attempt_saved event.
  applicationAttempt.handle(new RMAppAttemptEvent(applicationAttempt
    .getAppAttemptId(), RMAppAttemptEventType.EXPIRE));
  assertEquals(RMAppAttemptState.FINAL_SAVING,
    applicationAttempt.getAppAttemptState());
  // send attempt_saved
  sendAttemptUpdateSavedEvent(applicationAttempt);
  testAppAttemptFinishedState(amContainer, finalStatus, trackingUrl,
    diagnostics, 0, false);
}
 
Example #4
Source File: RMAppAttemptBlock.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
protected void createAttemptHeadRoomTable(Block html) {
  RMAppAttempt attempt = getRMAppAttempt();
  if (attempt != null) {
    if (!isApplicationInFinalState(YarnApplicationAttemptState
        .valueOf(attempt.getAppAttemptState().toString()))) {
      RMAppAttemptMetrics metrics = attempt.getRMAppAttemptMetrics();
      DIV<Hamlet> pdiv = html._(InfoBlock.class).div(_INFO_WRAP);
      info("Application Attempt Overview").clear();
      info("Application Attempt Metrics")._(
        "Application Attempt Headroom : ", metrics == null ? "N/A" :
          metrics.getApplicationAttemptHeadroom());
      pdiv._();
    }
  }
}
 
Example #5
Source File: ApplicationAttemptHistoryData.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Public
@Unstable
public static ApplicationAttemptHistoryData newInstance(
    ApplicationAttemptId appAttemptId, String host, int rpcPort,
    ContainerId masterContainerId, String diagnosticsInfo,
    String trackingURL, FinalApplicationStatus finalApplicationStatus,
    YarnApplicationAttemptState yarnApplicationAttemptState) {
  ApplicationAttemptHistoryData appAttemptHD =
      new ApplicationAttemptHistoryData();
  appAttemptHD.setApplicationAttemptId(appAttemptId);
  appAttemptHD.setHost(host);
  appAttemptHD.setRPCPort(rpcPort);
  appAttemptHD.setMasterContainerId(masterContainerId);
  appAttemptHD.setDiagnosticsInfo(diagnosticsInfo);
  appAttemptHD.setTrackingURL(trackingURL);
  appAttemptHD.setFinalApplicationStatus(finalApplicationStatus);
  appAttemptHD.setYarnApplicationAttemptState(yarnApplicationAttemptState);
  return appAttemptHD;
}
 
Example #6
Source File: AppAttemptFinishedEvent.java    From big-c with Apache License 2.0 6 votes vote down vote up
public AppAttemptFinishedEvent(
    ApplicationAttemptId appAttemptId,
    String trackingUrl,
    String originalTrackingUrl,
    String diagnosticsInfo,
    FinalApplicationStatus appStatus,
    YarnApplicationAttemptState state,
    long finishedTime) {
  super(SystemMetricsEventType.APP_ATTEMPT_FINISHED, finishedTime);
  this.appAttemptId = appAttemptId;
  // This is the tracking URL after the application attempt is finished
  this.trackingUrl = trackingUrl;
  this.originalTrackingUrl = originalTrackingUrl;
  this.diagnosticsInfo = diagnosticsInfo;
  this.appStatus = appStatus;
  this.state = state;
}
 
Example #7
Source File: TestRMAppAttemptTransitions.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnmanagedAMContainersCleanup() {
  unmanagedAM = true;
  when(submissionContext.getUnmanagedAM()).thenReturn(true);
  when(submissionContext.getKeepContainersAcrossApplicationAttempts())
    .thenReturn(true);
  // submit AM and check it goes to SUBMITTED state
  submitApplicationAttempt();
  // launch AM and verify attempt failed
  applicationAttempt.handle(new RMAppAttemptRegistrationEvent(
    applicationAttempt.getAppAttemptId(), "host", 8042, "oldtrackingurl"));
  assertEquals(YarnApplicationAttemptState.SUBMITTED,
      applicationAttempt.createApplicationAttemptState());
  sendAttemptUpdateSavedEvent(applicationAttempt);
  assertFalse(transferStateFromPreviousAttempt);
}
 
Example #8
Source File: ApplicationAttemptHistoryData.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Public
@Unstable
public static ApplicationAttemptHistoryData newInstance(
    ApplicationAttemptId appAttemptId, String host, int rpcPort,
    ContainerId masterContainerId, String diagnosticsInfo,
    String trackingURL, FinalApplicationStatus finalApplicationStatus,
    YarnApplicationAttemptState yarnApplicationAttemptState) {
  ApplicationAttemptHistoryData appAttemptHD =
      new ApplicationAttemptHistoryData();
  appAttemptHD.setApplicationAttemptId(appAttemptId);
  appAttemptHD.setHost(host);
  appAttemptHD.setRPCPort(rpcPort);
  appAttemptHD.setMasterContainerId(masterContainerId);
  appAttemptHD.setDiagnosticsInfo(diagnosticsInfo);
  appAttemptHD.setTrackingURL(trackingURL);
  appAttemptHD.setFinalApplicationStatus(finalApplicationStatus);
  appAttemptHD.setYarnApplicationAttemptState(yarnApplicationAttemptState);
  return appAttemptHD;
}
 
Example #9
Source File: AppAttemptFinishedEvent.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public AppAttemptFinishedEvent(
    ApplicationAttemptId appAttemptId,
    String trackingUrl,
    String originalTrackingUrl,
    String diagnosticsInfo,
    FinalApplicationStatus appStatus,
    YarnApplicationAttemptState state,
    long finishedTime) {
  super(SystemMetricsEventType.APP_ATTEMPT_FINISHED, finishedTime);
  this.appAttemptId = appAttemptId;
  // This is the tracking URL after the application attempt is finished
  this.trackingUrl = trackingUrl;
  this.originalTrackingUrl = originalTrackingUrl;
  this.diagnosticsInfo = diagnosticsInfo;
  this.appStatus = appStatus;
  this.state = state;
}
 
Example #10
Source File: RMAppAttemptImpl.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public ApplicationAttemptReport createApplicationAttemptReport() {
  this.readLock.lock();
  ApplicationAttemptReport attemptReport = null;
  try {
    // AM container maybe not yet allocated. and also unmangedAM doesn't have
    // am container.
    ContainerId amId =
        masterContainer == null ? null : masterContainer.getId();
    attemptReport = ApplicationAttemptReport.newInstance(this
        .getAppAttemptId(), this.getHost(), this.getRpcPort(), this
        .getTrackingUrl(), this.getOriginalTrackingUrl(), this.getDiagnostics(),
        YarnApplicationAttemptState .valueOf(this.getState().toString()), amId);
  } finally {
    this.readLock.unlock();
  }
  return attemptReport;
}
 
Example #11
Source File: TestRMAppAttemptTransitions.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test(timeout=10000)
public void testLaunchedExpire() {
  Container amContainer = allocateApplicationAttempt();
  launchApplicationAttempt(amContainer);
  applicationAttempt.handle(new RMAppAttemptEvent(
      applicationAttempt.getAppAttemptId(), RMAppAttemptEventType.EXPIRE));
  assertEquals(YarnApplicationAttemptState.LAUNCHED,
      applicationAttempt.createApplicationAttemptState());
  sendAttemptUpdateSavedEvent(applicationAttempt);
  assertEquals(RMAppAttemptState.FAILED,
      applicationAttempt.getAppAttemptState());
  assertTrue("expire diagnostics missing",
      applicationAttempt.getDiagnostics().contains("timed out"));
  String rmAppPageUrl = pjoin(RM_WEBAPP_ADDR, "cluster", "app",
      applicationAttempt.getAppAttemptId().getApplicationId());
  assertEquals(rmAppPageUrl, applicationAttempt.getOriginalTrackingUrl());
  assertEquals(rmAppPageUrl, applicationAttempt.getTrackingUrl());
  verifyTokenCount(applicationAttempt.getAppAttemptId(), 1);
  verifyApplicationAttemptFinished(RMAppAttemptState.FAILED);
}
 
Example #12
Source File: TestRMAppAttemptTransitions.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnmanagedAMContainersCleanup() {
  unmanagedAM = true;
  when(submissionContext.getUnmanagedAM()).thenReturn(true);
  when(submissionContext.getKeepContainersAcrossApplicationAttempts())
    .thenReturn(true);
  // submit AM and check it goes to SUBMITTED state
  submitApplicationAttempt();
  // launch AM and verify attempt failed
  applicationAttempt.handle(new RMAppAttemptRegistrationEvent(
    applicationAttempt.getAppAttemptId(), "host", 8042, "oldtrackingurl"));
  assertEquals(YarnApplicationAttemptState.SUBMITTED,
      applicationAttempt.createApplicationAttemptState());
  sendAttemptUpdateSavedEvent(applicationAttempt);
  assertFalse(transferStateFromPreviousAttempt);
}
 
Example #13
Source File: TestRMAppAttemptTransitions.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test(timeout=20000)
public void testRunningExpire() {
  Container amContainer = allocateApplicationAttempt();
  launchApplicationAttempt(amContainer);
  runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false);
  applicationAttempt.handle(new RMAppAttemptEvent(
      applicationAttempt.getAppAttemptId(), RMAppAttemptEventType.EXPIRE));
  assertEquals(YarnApplicationAttemptState.RUNNING,
      applicationAttempt.createApplicationAttemptState());
  sendAttemptUpdateSavedEvent(applicationAttempt);
  assertEquals(RMAppAttemptState.FAILED,
      applicationAttempt.getAppAttemptState());
  assertTrue("expire diagnostics missing",
      applicationAttempt.getDiagnostics().contains("timed out"));
  String rmAppPageUrl = pjoin(RM_WEBAPP_ADDR, "cluster", "app",
      applicationAttempt.getAppAttemptId().getApplicationId());
  assertEquals(rmAppPageUrl, applicationAttempt.getOriginalTrackingUrl());
  assertEquals(rmAppPageUrl, applicationAttempt.getTrackingUrl());
  verifyTokenCount(applicationAttempt.getAppAttemptId(), 1);
  verifyAMHostAndPortInvalidated();
  verifyApplicationAttemptFinished(RMAppAttemptState.FAILED);
}
 
Example #14
Source File: TestRMAppAttemptTransitions.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test(timeout=10000)
public void testLaunchedExpire() {
  Container amContainer = allocateApplicationAttempt();
  launchApplicationAttempt(amContainer);
  applicationAttempt.handle(new RMAppAttemptEvent(
      applicationAttempt.getAppAttemptId(), RMAppAttemptEventType.EXPIRE));
  assertEquals(YarnApplicationAttemptState.LAUNCHED,
      applicationAttempt.createApplicationAttemptState());
  sendAttemptUpdateSavedEvent(applicationAttempt);
  assertEquals(RMAppAttemptState.FAILED,
      applicationAttempt.getAppAttemptState());
  assertTrue("expire diagnostics missing",
      applicationAttempt.getDiagnostics().contains("timed out"));
  String rmAppPageUrl = pjoin(RM_WEBAPP_ADDR, "cluster", "app",
      applicationAttempt.getAppAttemptId().getApplicationId());
  assertEquals(rmAppPageUrl, applicationAttempt.getOriginalTrackingUrl());
  assertEquals(rmAppPageUrl, applicationAttempt.getTrackingUrl());
  verifyTokenCount(applicationAttempt.getAppAttemptId(), 1);
  verifyApplicationAttemptFinished(RMAppAttemptState.FAILED);
}
 
Example #15
Source File: TestRMAppAttemptTransitions.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testAMCrashAtScheduled() {
  // This is to test sending CONTAINER_FINISHED event at SCHEDULED state.
  // Verify the state transition is correct.
  scheduleApplicationAttempt();
  ContainerStatus cs =
      SchedulerUtils.createAbnormalContainerStatus(
          BuilderUtils.newContainerId(
              applicationAttempt.getAppAttemptId(), 1),
          SchedulerUtils.LOST_CONTAINER);
  // send CONTAINER_FINISHED event at SCHEDULED state,
  // The state should be FINAL_SAVING with previous state SCHEDULED
  NodeId anyNodeId = NodeId.newInstance("host", 1234);
  applicationAttempt.handle(new RMAppAttemptContainerFinishedEvent(
      applicationAttempt.getAppAttemptId(), cs, anyNodeId));
  // createApplicationAttemptState will return previous state (SCHEDULED),
  // if the current state is FINAL_SAVING.
  assertEquals(YarnApplicationAttemptState.SCHEDULED,
      applicationAttempt.createApplicationAttemptState());
  // send ATTEMPT_UPDATE_SAVED event,
  // verify the state is changed to state FAILED.
  sendAttemptUpdateSavedEvent(applicationAttempt);
  assertEquals(RMAppAttemptState.FAILED,
      applicationAttempt.getAppAttemptState());
  verifyApplicationAttemptFinished(RMAppAttemptState.FAILED);
}
 
Example #16
Source File: TestRMAppAttemptTransitions.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testAMCrashAtAllocated() {
  Container amContainer = allocateApplicationAttempt();
  String containerDiagMsg = "some error";
  int exitCode = 123;
  ContainerStatus cs =
      BuilderUtils.newContainerStatus(amContainer.getId(),
        ContainerState.COMPLETE, containerDiagMsg, exitCode);
  NodeId anyNodeId = NodeId.newInstance("host", 1234);
  applicationAttempt.handle(new RMAppAttemptContainerFinishedEvent(
    applicationAttempt.getAppAttemptId(), cs, anyNodeId));
  assertEquals(YarnApplicationAttemptState.ALLOCATED,
      applicationAttempt.createApplicationAttemptState());
  sendAttemptUpdateSavedEvent(applicationAttempt);
  assertEquals(RMAppAttemptState.FAILED,
    applicationAttempt.getAppAttemptState());
  verifyTokenCount(applicationAttempt.getAppAttemptId(), 1);
  verifyApplicationAttemptFinished(RMAppAttemptState.FAILED);
  boolean shouldCheckURL = (applicationAttempt.getTrackingUrl() != null);
  verifyAMCrashAtAllocatedDiagnosticInfo(applicationAttempt.getDiagnostics(),
    exitCode, shouldCheckURL);
}
 
Example #17
Source File: TestYarnCLI.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetApplicationAttemptReport() throws Exception {
  ApplicationCLI cli = createAndGetAppCLI();
  ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
  ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(
      applicationId, 1);
  ApplicationAttemptReport attemptReport = ApplicationAttemptReport
      .newInstance(attemptId, "host", 124, "url", "oUrl", "diagnostics",
          YarnApplicationAttemptState.FINISHED, ContainerId.newContainerId(
              attemptId, 1));
  when(
      client
          .getApplicationAttemptReport(any(ApplicationAttemptId.class)))
      .thenReturn(attemptReport);
  int result = cli.run(new String[] { "applicationattempt", "-status",
      attemptId.toString() });
  assertEquals(0, result);
  verify(client).getApplicationAttemptReport(attemptId);
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  PrintWriter pw = new PrintWriter(baos);
  pw.println("Application Attempt Report : ");
  pw.println("\tApplicationAttempt-Id : appattempt_1234_0005_000001");
  pw.println("\tState : FINISHED");
  pw.println("\tAMContainer : container_1234_0005_01_000001");
  pw.println("\tTracking-URL : url");
  pw.println("\tRPC Port : 124");
  pw.println("\tAM Host : host");
  pw.println("\tDiagnostics : diagnostics");
  pw.close();
  String appReportStr = baos.toString("UTF-8");
  Assert.assertEquals(appReportStr, sysOutStream.toString());
  verify(sysOut, times(1)).println(isA(String.class));
}
 
Example #18
Source File: UnmanagedAMLauncher.java    From big-c with Apache License 2.0 5 votes vote down vote up
private ApplicationAttemptReport monitorCurrentAppAttempt(
    ApplicationId appId, YarnApplicationAttemptState attemptState)
    throws YarnException, IOException {
  long startTime = System.currentTimeMillis();
  ApplicationAttemptId attemptId = null;
  while (true) {
    if (attemptId == null) {
      attemptId =
          rmClient.getApplicationReport(appId)
            .getCurrentApplicationAttemptId();
    }
    ApplicationAttemptReport attemptReport = null;
    if (attemptId != null) {
      attemptReport = rmClient.getApplicationAttemptReport(attemptId);
      if (attemptState.equals(attemptReport.getYarnApplicationAttemptState())) {
        return attemptReport;
      }
    }
    LOG.info("Current attempt state of " + appId + " is " + (attemptReport == null
          ? " N/A " : attemptReport.getYarnApplicationAttemptState())
              + ", waiting for current attempt to reach " + attemptState);
    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      LOG.warn("Interrupted while waiting for current attempt of " + appId
          + " to reach " + attemptState);
    }
    if (System.currentTimeMillis() - startTime > AM_STATE_WAIT_TIMEOUT_MS) {
      String errmsg =
          "Timeout for waiting current attempt of " + appId + " to reach "
              + attemptState;
      LOG.error(errmsg);
      throw new RuntimeException(errmsg);
    }
  }
}
 
Example #19
Source File: ApplicationAttemptFinishData.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Public
@Unstable
public static ApplicationAttemptFinishData newInstance(
    ApplicationAttemptId appAttemptId, String diagnosticsInfo,
    String trackingURL, FinalApplicationStatus finalApplicationStatus,
    YarnApplicationAttemptState yarnApplicationAttemptState) {
  ApplicationAttemptFinishData appAttemptFD =
      Records.newRecord(ApplicationAttemptFinishData.class);
  appAttemptFD.setApplicationAttemptId(appAttemptId);
  appAttemptFD.setDiagnosticsInfo(diagnosticsInfo);
  appAttemptFD.setTrackingURL(trackingURL);
  appAttemptFD.setFinalApplicationStatus(finalApplicationStatus);
  appAttemptFD.setYarnApplicationAttemptState(yarnApplicationAttemptState);
  return appAttemptFD;
}
 
Example #20
Source File: ApplicationAttemptReportPBImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public YarnApplicationAttemptState getYarnApplicationAttemptState() {
  ApplicationAttemptReportProtoOrBuilder p = viaProto ? proto : builder;
  if (!p.hasYarnApplicationAttemptState()) {
    return null;
  }
  return convertFromProtoFormat(p.getYarnApplicationAttemptState());
}
 
Example #21
Source File: TestRMAppAttemptTransitions.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testScheduledToKilled() {
  scheduleApplicationAttempt();
  applicationAttempt.handle(        
      new RMAppAttemptEvent(
          applicationAttempt.getAppAttemptId(), 
          RMAppAttemptEventType.KILL));
  assertEquals(YarnApplicationAttemptState.SCHEDULED,
      applicationAttempt.createApplicationAttemptState());
  testAppAttemptKilledState(null, EMPTY_DIAGNOSTICS);
}
 
Example #22
Source File: TestAHSWebServices.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleAttempt() throws Exception {
  ApplicationId appId = ApplicationId.newInstance(0, 1);
  ApplicationAttemptId appAttemptId =
      ApplicationAttemptId.newInstance(appId, 1);
  WebResource r = resource();
  ClientResponse response =
      r.path("ws").path("v1").path("applicationhistory").path("apps")
        .path(appId.toString()).path("appattempts")
        .path(appAttemptId.toString())
        .queryParam("user.name", USERS[round])
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
  if (round == 1) {
    assertEquals(
        Status.FORBIDDEN, response.getClientResponseStatus());
    return;
  }
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  assertEquals("incorrect number of elements", 1, json.length());
  JSONObject appAttempt = json.getJSONObject("appAttempt");
  assertEquals(appAttemptId.toString(), appAttempt.getString("appAttemptId"));
  assertEquals("test host", appAttempt.getString("host"));
  assertEquals("test diagnostics info",
    appAttempt.getString("diagnosticsInfo"));
  assertEquals("test tracking url", appAttempt.getString("trackingUrl"));
  assertEquals(YarnApplicationAttemptState.FINISHED.toString(),
    appAttempt.get("appAttemptState"));
}
 
Example #23
Source File: TestRMAppAttemptTransitions.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testApplicationAttemptMasterKey() throws Exception {
  Container amContainer = allocateApplicationAttempt();
  ApplicationAttemptId appid = applicationAttempt.getAppAttemptId();
  boolean isMasterKeyExisted = false;

  // before attempt is launched, can not get MasterKey
  isMasterKeyExisted = clientToAMTokenManager.hasMasterKey(appid);
  Assert.assertFalse(isMasterKeyExisted);

  launchApplicationAttempt(amContainer);
  // after attempt is launched and in secure mode, can get MasterKey
  isMasterKeyExisted = clientToAMTokenManager.hasMasterKey(appid);
  if (isSecurityEnabled) {
    Assert.assertTrue(isMasterKeyExisted);
    Assert.assertNotNull(clientToAMTokenManager.getMasterKey(appid));
  } else {
    Assert.assertFalse(isMasterKeyExisted);
  }

  applicationAttempt.handle(new RMAppAttemptEvent(applicationAttempt
    .getAppAttemptId(), RMAppAttemptEventType.KILL));
  assertEquals(YarnApplicationAttemptState.LAUNCHED,
      applicationAttempt.createApplicationAttemptState());
  sendAttemptUpdateSavedEvent(applicationAttempt);
  // after attempt is killed, can not get MasterKey
  isMasterKeyExisted = clientToAMTokenManager.hasMasterKey(appid);
  Assert.assertFalse(isMasterKeyExisted);
}
 
Example #24
Source File: TestRMAppAttemptTransitions.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetClientToken() throws Exception {
  assumeTrue(isSecurityEnabled);
  Container amContainer = allocateApplicationAttempt();

  // before attempt is launched, can not get ClientToken
  Token<ClientToAMTokenIdentifier> token =
      applicationAttempt.createClientToken(null);
  Assert.assertNull(token);
  token = applicationAttempt.createClientToken("clientuser");
  Assert.assertNull(token);

  launchApplicationAttempt(amContainer);
  // after attempt is launched , can get ClientToken
  token = applicationAttempt.createClientToken(null);
  Assert.assertNull(token);
  token = applicationAttempt.createClientToken("clientuser");
  Assert.assertNotNull(token);

  applicationAttempt.handle(new RMAppAttemptEvent(applicationAttempt
    .getAppAttemptId(), RMAppAttemptEventType.KILL));
  assertEquals(YarnApplicationAttemptState.LAUNCHED,
      applicationAttempt.createApplicationAttemptState());
  sendAttemptUpdateSavedEvent(applicationAttempt);
  // after attempt is killed, can not get Client Token
  token = applicationAttempt.createClientToken(null);
  Assert.assertNull(token);
  token = applicationAttempt.createClientToken("clientuser");
  Assert.assertNull(token);
}
 
Example #25
Source File: TestRMAppAttemptTransitions.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testAllocatedToFailed() {
  Container amContainer = allocateApplicationAttempt();
  String diagnostics = "Launch Failed";
  applicationAttempt.handle(
      new RMAppAttemptLaunchFailedEvent(
          applicationAttempt.getAppAttemptId(), 
          diagnostics));
  assertEquals(YarnApplicationAttemptState.ALLOCATED,
      applicationAttempt.createApplicationAttemptState());
  testAppAttemptFailedState(amContainer, diagnostics);
}
 
Example #26
Source File: TestRMAppAttemptTransitions.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testRunningToKilled() {
  Container amContainer = allocateApplicationAttempt();
  launchApplicationAttempt(amContainer);
  runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false);
  applicationAttempt.handle(
      new RMAppAttemptEvent(
          applicationAttempt.getAppAttemptId(),
          RMAppAttemptEventType.KILL));

  // ignored ContainerFinished and Expire at FinalSaving if we were supposed
  // to Killed state.
  assertEquals(RMAppAttemptState.FINAL_SAVING,
    applicationAttempt.getAppAttemptState());
  NodeId anyNodeId = NodeId.newInstance("host", 1234);
  applicationAttempt.handle(new RMAppAttemptContainerFinishedEvent(
    applicationAttempt.getAppAttemptId(), BuilderUtils.newContainerStatus(
      amContainer.getId(), ContainerState.COMPLETE, "", 0), anyNodeId));
  applicationAttempt.handle(new RMAppAttemptEvent(
    applicationAttempt.getAppAttemptId(), RMAppAttemptEventType.EXPIRE));
  assertEquals(RMAppAttemptState.FINAL_SAVING,
    applicationAttempt.getAppAttemptState()); 
  assertEquals(YarnApplicationAttemptState.RUNNING,
      applicationAttempt.createApplicationAttemptState());
  sendAttemptUpdateSavedEvent(applicationAttempt);
  assertEquals(RMAppAttemptState.KILLED,
      applicationAttempt.getAppAttemptState());
  assertEquals(0, applicationAttempt.getJustFinishedContainers().size());
  assertEquals(amContainer, applicationAttempt.getMasterContainer());
  assertEquals(0, application.getRanNodes().size());
  String rmAppPageUrl = pjoin(RM_WEBAPP_ADDR, "cluster", "app",
      applicationAttempt.getAppAttemptId().getApplicationId());
  assertEquals(rmAppPageUrl, applicationAttempt.getOriginalTrackingUrl());
  assertEquals(rmAppPageUrl, applicationAttempt.getTrackingUrl());
  verifyTokenCount(applicationAttempt.getAppAttemptId(), 1);
  verifyAMHostAndPortInvalidated();
  verifyApplicationAttemptFinished(RMAppAttemptState.KILLED);
}
 
Example #27
Source File: TestRMAppAttemptTransitions.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testRunningToKilled() {
  Container amContainer = allocateApplicationAttempt();
  launchApplicationAttempt(amContainer);
  runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false);
  applicationAttempt.handle(
      new RMAppAttemptEvent(
          applicationAttempt.getAppAttemptId(),
          RMAppAttemptEventType.KILL));

  // ignored ContainerFinished and Expire at FinalSaving if we were supposed
  // to Killed state.
  assertEquals(RMAppAttemptState.FINAL_SAVING,
    applicationAttempt.getAppAttemptState());
  NodeId anyNodeId = NodeId.newInstance("host", 1234);
  applicationAttempt.handle(new RMAppAttemptContainerFinishedEvent(
    applicationAttempt.getAppAttemptId(), BuilderUtils.newContainerStatus(
      amContainer.getId(), ContainerState.COMPLETE, "", 0), anyNodeId));
  applicationAttempt.handle(new RMAppAttemptEvent(
    applicationAttempt.getAppAttemptId(), RMAppAttemptEventType.EXPIRE));
  assertEquals(RMAppAttemptState.FINAL_SAVING,
    applicationAttempt.getAppAttemptState()); 
  assertEquals(YarnApplicationAttemptState.RUNNING,
      applicationAttempt.createApplicationAttemptState());
  sendAttemptUpdateSavedEvent(applicationAttempt);
  assertEquals(RMAppAttemptState.KILLED,
      applicationAttempt.getAppAttemptState());
  assertEquals(0, applicationAttempt.getJustFinishedContainers().size());
  assertEquals(amContainer, applicationAttempt.getMasterContainer());
  assertEquals(0, application.getRanNodes().size());
  String rmAppPageUrl = pjoin(RM_WEBAPP_ADDR, "cluster", "app",
      applicationAttempt.getAppAttemptId().getApplicationId());
  assertEquals(rmAppPageUrl, applicationAttempt.getOriginalTrackingUrl());
  assertEquals(rmAppPageUrl, applicationAttempt.getTrackingUrl());
  verifyTokenCount(applicationAttempt.getAppAttemptId(), 1);
  verifyAMHostAndPortInvalidated();
  verifyApplicationAttemptFinished(RMAppAttemptState.KILLED);
}
 
Example #28
Source File: TestRMAppAttemptTransitions.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testRunningToFailed() {
  Container amContainer = allocateApplicationAttempt();
  launchApplicationAttempt(amContainer);
  runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false);
  String containerDiagMsg = "some error";
  int exitCode = 123;
  ContainerStatus cs = BuilderUtils.newContainerStatus(amContainer.getId(),
      ContainerState.COMPLETE, containerDiagMsg, exitCode);
  ApplicationAttemptId appAttemptId = applicationAttempt.getAppAttemptId();
  NodeId anyNodeId = NodeId.newInstance("host", 1234);
  applicationAttempt.handle(new RMAppAttemptContainerFinishedEvent(
      appAttemptId, cs, anyNodeId));

  // ignored ContainerFinished and Expire at FinalSaving if we were supposed
  // to Failed state.
  assertEquals(RMAppAttemptState.FINAL_SAVING,
    applicationAttempt.getAppAttemptState());
  applicationAttempt.handle(new RMAppAttemptContainerFinishedEvent(
    applicationAttempt.getAppAttemptId(), BuilderUtils.newContainerStatus(
      amContainer.getId(), ContainerState.COMPLETE, "", 0), anyNodeId));
  applicationAttempt.handle(new RMAppAttemptEvent(
    applicationAttempt.getAppAttemptId(), RMAppAttemptEventType.EXPIRE));
  assertEquals(RMAppAttemptState.FINAL_SAVING,
    applicationAttempt.getAppAttemptState()); 
  assertEquals(YarnApplicationAttemptState.RUNNING,
      applicationAttempt.createApplicationAttemptState());
  sendAttemptUpdateSavedEvent(applicationAttempt);
  assertEquals(RMAppAttemptState.FAILED,
      applicationAttempt.getAppAttemptState());
  assertEquals(0, applicationAttempt.getJustFinishedContainers().size());
  assertEquals(amContainer, applicationAttempt.getMasterContainer());
  assertEquals(0, application.getRanNodes().size());
  String rmAppPageUrl = pjoin(RM_WEBAPP_ADDR, "cluster", "app",
      applicationAttempt.getAppAttemptId().getApplicationId());
  assertEquals(rmAppPageUrl, applicationAttempt.getOriginalTrackingUrl());
  assertEquals(rmAppPageUrl, applicationAttempt.getTrackingUrl());
  verifyAMHostAndPortInvalidated();
  verifyApplicationAttemptFinished(RMAppAttemptState.FAILED);
}
 
Example #29
Source File: TestYarnJobValidationTool.java    From samza with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidateRunningAttemptId() throws Exception {
  ApplicationReport appReport = mock(ApplicationReport.class);
  when(client.getApplicationReport(appId)).thenReturn(appReport);
  when(appReport.getCurrentApplicationAttemptId()).thenReturn(attemptId);
  ApplicationAttemptReport attemptReport = mock(ApplicationAttemptReport.class);
  when(attemptReport.getYarnApplicationAttemptState()).thenReturn(YarnApplicationAttemptState.RUNNING);
  when(attemptReport.getApplicationAttemptId()).thenReturn(attemptId);
  when(client.getApplicationAttemptReport(attemptId)).thenReturn(attemptReport);
  assertTrue(tool.validateRunningAttemptId(appId).equals(attemptId));

  when(attemptReport.getYarnApplicationAttemptState()).thenReturn(YarnApplicationAttemptState.FAILED);
  exception.expect(SamzaException.class);
  tool.validateRunningAttemptId(appId);
}
 
Example #30
Source File: TestRMAppAttemptTransitions.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void
    testFinalSavingToFinishedWithContainerFinished() {
  Container amContainer = allocateApplicationAttempt();
  launchApplicationAttempt(amContainer);
  runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false);
  FinalApplicationStatus finalStatus = FinalApplicationStatus.SUCCEEDED;
  String trackingUrl = "mytrackingurl";
  String diagnostics = "Successful";
  applicationAttempt.handle(new RMAppAttemptUnregistrationEvent(
    applicationAttempt.getAppAttemptId(), trackingUrl, finalStatus,
    diagnostics));
  assertEquals(RMAppAttemptState.FINAL_SAVING,
    applicationAttempt.getAppAttemptState());
  assertEquals(YarnApplicationAttemptState.RUNNING,
      applicationAttempt.createApplicationAttemptState());
  // Container_finished event comes before Attempt_Saved event.
  NodeId anyNodeId = NodeId.newInstance("host", 1234);
  applicationAttempt.handle(new RMAppAttemptContainerFinishedEvent(
    applicationAttempt.getAppAttemptId(), BuilderUtils.newContainerStatus(
      amContainer.getId(), ContainerState.COMPLETE, "", 0), anyNodeId));
  assertEquals(RMAppAttemptState.FINAL_SAVING,
    applicationAttempt.getAppAttemptState());
  // send attempt_saved
  sendAttemptUpdateSavedEvent(applicationAttempt);
  testAppAttemptFinishedState(amContainer, finalStatus, trackingUrl,
    diagnostics, 0, false);
}