Java Code Examples for org.apache.hadoop.yarn.api.records.ContainerState

The following examples show how to use org.apache.hadoop.yarn.api.records.ContainerState. 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: big-c   Source File: ContainerManagerImpl.java    License: Apache License 2.0 6 votes vote down vote up
private void waitForRecoveredContainers() throws InterruptedException {
  final int sleepMsec = 100;
  int waitIterations = 100;
  List<ContainerId> newContainers = new ArrayList<ContainerId>();
  while (--waitIterations >= 0) {
    newContainers.clear();
    for (Container container : context.getContainers().values()) {
      if (container.getContainerState() == org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerState.NEW) {
        newContainers.add(container.getContainerId());
      }
    }
    if (newContainers.isEmpty()) {
      break;
    }
    LOG.info("Waiting for containers: " + newContainers);
    Thread.sleep(sleepMsec);
  }
  if (waitIterations < 0) {
    LOG.warn("Timeout waiting for recovered containers");
  }
}
 
Example 2
Source Project: hadoop   Source File: NMClientImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void stopContainer(ContainerId containerId, NodeId nodeId)
    throws YarnException, IOException {
  StartedContainer startedContainer = getStartedContainer(containerId);

  // Only allow one request of stopping the container to move forward
  // When entering the block, check whether the precursor has already stopped
  // the container
  if (startedContainer != null) {
    synchronized (startedContainer) {
      if (startedContainer.state != ContainerState.RUNNING) {
        return;
      }
      stopContainerInternal(containerId, nodeId);
      // Only after successful
      startedContainer.state = ContainerState.COMPLETE;
      removeStartedContainer(startedContainer);
    }
  } else {
    stopContainerInternal(containerId, nodeId);
  }

}
 
Example 3
Source Project: hadoop   Source File: TestRMAppAttemptTransitions.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFinishingToFinishing() {
  Container amContainer = allocateApplicationAttempt();
  launchApplicationAttempt(amContainer);
  runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false);
  FinalApplicationStatus finalStatus = FinalApplicationStatus.SUCCEEDED;
  String trackingUrl = "mytrackingurl";
  String diagnostics = "Successful";
  unregisterApplicationAttempt(amContainer, finalStatus, trackingUrl,
      diagnostics);
  // container must be AM container to move from FINISHING to FINISHED
  NodeId anyNodeId = NodeId.newInstance("host", 1234);
  applicationAttempt.handle(
      new RMAppAttemptContainerFinishedEvent(
          applicationAttempt.getAppAttemptId(),
          BuilderUtils.newContainerStatus(
              BuilderUtils.newContainerId(
                  applicationAttempt.getAppAttemptId(), 42),
              ContainerState.COMPLETE, "", 0), anyNodeId));
  testAppAttemptFinishingState(amContainer, finalStatus, trackingUrl,
      diagnostics);
}
 
Example 4
Source Project: samza   Source File: YarnJobValidationTool.java    License: Apache License 2.0 6 votes vote down vote up
public int validateContainerCount(ApplicationAttemptId attemptId) throws Exception {
  int runningContainerCount = 0;
  for (ContainerReport containerReport : this.client.getContainers(attemptId)) {
    if (containerReport.getContainerState() == ContainerState.RUNNING) {
      ++runningContainerCount;
    }
  }
  // expected containers to be the configured job containers plus the AppMaster container
  int containerExpected = this.config.getContainerCount() + 1;

  if (runningContainerCount == containerExpected) {
    log.info("Container count matches. " + runningContainerCount + " containers are running.");
    return runningContainerCount;
  } else {
    throw new SamzaException("Container count does not match. " + runningContainerCount + " containers are running, while " + containerExpected + " is expected.");
  }
}
 
Example 5
Source Project: big-c   Source File: NodeStatusUpdaterImpl.java    License: Apache License 2.0 6 votes vote down vote up
private List<NMContainerStatus> getNMContainerStatuses() throws IOException {
  List<NMContainerStatus> containerStatuses =
      new ArrayList<NMContainerStatus>();
  for (Container container : this.context.getContainers().values()) {
    ContainerId containerId = container.getContainerId();
    ApplicationId applicationId = containerId.getApplicationAttemptId()
        .getApplicationId();
    if (!this.context.getApplications().containsKey(applicationId)) {
      context.getContainers().remove(containerId);
      continue;
    }
    NMContainerStatus status =
        container.getNMContainerStatus();
    containerStatuses.add(status);
    if (status.getContainerState() == ContainerState.COMPLETE) {
      // Adding to finished containers cache. Cache will keep it around at
      // least for #durationToTrackStoppedContainers duration. In the
      // subsequent call to stop container it will get removed from cache.
      addCompletedContainer(containerId);
    }
  }
  LOG.info("Sending out " + containerStatuses.size()
    + " NM container statuses: " + containerStatuses);
  return containerStatuses;
}
 
Example 6
Source Project: big-c   Source File: NMClientImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void stopContainer(ContainerId containerId, NodeId nodeId)
    throws YarnException, IOException {
  StartedContainer startedContainer = getStartedContainer(containerId);

  // Only allow one request of stopping the container to move forward
  // When entering the block, check whether the precursor has already stopped
  // the container
  if (startedContainer != null) {
    synchronized (startedContainer) {
      if (startedContainer.state != ContainerState.RUNNING) {
        return;
      }
      stopContainerInternal(containerId, nodeId);
      // Only after successful
      startedContainer.state = ContainerState.COMPLETE;
      removeStartedContainer(startedContainer);
    }
  } else {
    stopContainerInternal(containerId, nodeId);
  }

}
 
Example 7
Source Project: hadoop   Source File: ContainerHistoryData.java    License: Apache License 2.0 6 votes vote down vote up
@Public
@Unstable
public static ContainerHistoryData newInstance(ContainerId containerId,
    Resource allocatedResource, NodeId assignedNode, Priority priority,
    long startTime, long finishTime, String diagnosticsInfo,
    int containerExitCode, ContainerState containerState) {
  ContainerHistoryData containerHD = new ContainerHistoryData();
  containerHD.setContainerId(containerId);
  containerHD.setAllocatedResource(allocatedResource);
  containerHD.setAssignedNode(assignedNode);
  containerHD.setPriority(priority);
  containerHD.setStartTime(startTime);
  containerHD.setFinishTime(finishTime);
  containerHD.setDiagnosticsInfo(diagnosticsInfo);
  containerHD.setContainerExitStatus(containerExitCode);
  containerHD.setContainerState(containerState);
  return containerHD;
}
 
Example 8
Source Project: big-c   Source File: TestRM.java    License: Apache License 2.0 6 votes vote down vote up
@Test (timeout = 30000)
public void testAppWithNoContainers() throws Exception {
  Logger rootLogger = LogManager.getRootLogger();
  rootLogger.setLevel(Level.DEBUG);
  MockRM rm = new MockRM(conf);
  rm.start();
  MockNM nm1 = rm.registerNode("h1:1234", 5120);
  
  RMApp app = rm.submitApp(2000);

  //kick the scheduling
  nm1.nodeHeartbeat(true);

  RMAppAttempt attempt = app.getCurrentAppAttempt();
  MockAM am = rm.sendAMLaunched(attempt.getAppAttemptId());
  am.registerAppAttempt();
  am.unregisterAppAttempt();
  nm1.nodeHeartbeat(attempt.getAppAttemptId(), 1, ContainerState.COMPLETE);
  am.waitForState(RMAppAttemptState.FINISHED);
  rm.stop();
}
 
Example 9
Source Project: hadoop   Source File: TestSystemMetricsPublisher.java    License: Apache License 2.0 6 votes vote down vote up
private static RMContainer createRMContainer(ContainerId containerId) {
  RMContainer container = mock(RMContainer.class);
  when(container.getContainerId()).thenReturn(containerId);
  when(container.getAllocatedNode()).thenReturn(
      NodeId.newInstance("test host", -100));
  when(container.getAllocatedResource()).thenReturn(
      Resource.newInstance(-1, -1, -1));
  when(container.getAllocatedPriority()).thenReturn(Priority.UNDEFINED);
  when(container.getCreationTime()).thenReturn(Integer.MAX_VALUE + 1L);
  when(container.getFinishTime()).thenReturn(Integer.MAX_VALUE + 2L);
  when(container.getDiagnosticsInfo()).thenReturn("test diagnostics info");
  when(container.getContainerExitStatus()).thenReturn(-1);
  when(container.getContainerState()).thenReturn(ContainerState.COMPLETE);
  Container mockContainer = mock(Container.class);
  when(container.getContainer()).thenReturn(mockContainer);
  when(mockContainer.getNodeHttpAddress())
    .thenReturn("http://localhost:1234");
  return container;
}
 
Example 10
Source Project: hadoop   Source File: TestNMClient.java    License: Apache License 2.0 6 votes vote down vote up
private void testGetContainerStatus(Container container, int index,
    ContainerState state, String diagnostics, List<Integer> exitStatuses)
        throws YarnException, IOException {
  while (true) {
    try {
      ContainerStatus status = nmClient.getContainerStatus(
          container.getId(), container.getNodeId());
      // NodeManager may still need some time to get the stable
      // container status
      if (status.getState() == state) {
        assertEquals(container.getId(), status.getContainerId());
        assertTrue("" + index + ": " + status.getDiagnostics(),
            status.getDiagnostics().contains(diagnostics));
        
        assertTrue("Exit Statuses are supposed to be in: " + exitStatuses +
            ", but the actual exit status code is: " + status.getExitStatus(),
            exitStatuses.contains(status.getExitStatus()));
        break;
      }
      Thread.sleep(100);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
}
 
Example 11
Source Project: big-c   Source File: TestNodeManagerResync.java    License: Apache License 2.0 5 votes vote down vote up
public static NMContainerStatus createNMContainerStatus(int id,
    ContainerState containerState) {
  ApplicationId applicationId = ApplicationId.newInstance(0, 1);
  ApplicationAttemptId applicationAttemptId =
      ApplicationAttemptId.newInstance(applicationId, 1);
  ContainerId containerId = ContainerId.newContainerId(applicationAttemptId, id);
  NMContainerStatus containerReport =
      NMContainerStatus.newInstance(containerId, containerState,
        Resource.newInstance(1024, 1), "recover container", 0,
        Priority.newInstance(10), 0);
  return containerReport;
}
 
Example 12
Source Project: ambari-metrics   Source File: ContainerFinishData.java    License: Apache License 2.0 5 votes vote down vote up
@Public
@Unstable
public static ContainerFinishData newInstance(ContainerId containerId,
    long finishTime, String diagnosticsInfo, int containerExitCode,
    ContainerState containerState) {
  ContainerFinishData containerFD =
      Records.newRecord(ContainerFinishData.class);
  containerFD.setContainerId(containerId);
  containerFD.setFinishTime(finishTime);
  containerFD.setDiagnosticsInfo(diagnosticsInfo);
  containerFD.setContainerExitStatus(containerExitCode);
  containerFD.setContainerState(containerState);
  return containerFD;
}
 
Example 13
Source Project: big-c   Source File: ContainerStatusPBImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public synchronized ContainerState getState() {
  ContainerStatusProtoOrBuilder p = viaProto ? proto : builder;
  if (!p.hasState()) {
    return null;
  }
  return convertFromProtoFormat(p.getState());
}
 
Example 14
Source Project: hadoop   Source File: ContainerReportPBImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setContainerState(ContainerState containerState) {
  maybeInitBuilder();
  if (containerState == null) {
    builder.clearContainerState();
    return;
  }
  builder.setContainerState(convertToProtoFormat(containerState));
}
 
Example 15
Source Project: hadoop   Source File: TestAMRMClientAsync.java    License: Apache License 2.0 5 votes vote down vote up
@Test (timeout = 5000)
public void testCallAMRMClientAsyncStopFromCallbackHandlerWithWaitFor()
    throws YarnException, IOException, InterruptedException {
  Configuration conf = new Configuration();
  final TestCallbackHandler2 callbackHandler = new TestCallbackHandler2();
  @SuppressWarnings("unchecked")
  AMRMClient<ContainerRequest> client = mock(AMRMClientImpl.class);

  List<ContainerStatus> completed = Arrays.asList(
      ContainerStatus.newInstance(newContainerId(0, 0, 0, 0),
          ContainerState.COMPLETE, "", 0));
  final AllocateResponse response = createAllocateResponse(completed,
      new ArrayList<Container>(), null);

  when(client.allocate(anyFloat())).thenReturn(response);

  AMRMClientAsync<ContainerRequest> asyncClient =
      AMRMClientAsync.createAMRMClientAsync(client, 20, callbackHandler);
  callbackHandler.asynClient = asyncClient;
  asyncClient.init(conf);
  asyncClient.start();

  Supplier<Boolean> checker = new Supplier<Boolean>() {
    @Override
    public Boolean get() {
      return callbackHandler.notify;
    }
  };

  asyncClient.registerApplicationMaster("localhost", 1234, null);
  asyncClient.waitFor(checker);
  Assert.assertTrue(checker.get());
}
 
Example 16
Source Project: dremio-oss   Source File: YarnContainerHealthMonitor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Method to fetch the state of the container
 *
 * @param connection {@link HttpURLConnection} used to make the NodeManager REST API call
 * @return container state which can be either of the states in {@link ContainerState}
 */
@VisibleForTesting
String getContainerState(HttpURLConnection connection) throws IOException {
  if (connection.getResponseCode() == HttpStatus.SC_NOT_FOUND) {
    isHealthy = false;
    return null;
  }
  ObjectMapper mapper = new ObjectMapper();
  JsonNode containerInfoNode = mapper.readTree(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
  String containerState = containerInfoNode.get("container").get("state").asText();
  isHealthy = ContainerState.NEW.name().equals(containerState)
    || ContainerState.RUNNING.name().equals(containerState);
  return containerState;
}
 
Example 17
Source Project: hadoop   Source File: NMContainerStatus.java    License: Apache License 2.0 5 votes vote down vote up
public static NMContainerStatus newInstance(ContainerId containerId,
    ContainerState containerState, Resource allocatedResource,
    String diagnostics, int containerExitStatus, Priority priority,
    long creationTime) {
  NMContainerStatus status =
      Records.newRecord(NMContainerStatus.class);
  status.setContainerId(containerId);
  status.setContainerState(containerState);
  status.setAllocatedResource(allocatedResource);
  status.setDiagnostics(diagnostics);
  status.setContainerExitStatus(containerExitStatus);
  status.setPriority(priority);
  status.setCreationTime(creationTime);
  return status;
}
 
Example 18
Source Project: big-c   Source File: NMContainerStatusPBImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setContainerState(ContainerState containerState) {
  maybeInitBuilder();
  if (containerState == null) {
    builder.clearContainerState();
    return;
  }
  builder.setContainerState(convertToProtoFormat(containerState));
}
 
Example 19
Source Project: big-c   Source File: MockNM.java    License: Apache License 2.0 5 votes vote down vote up
public NodeHeartbeatResponse nodeHeartbeat(ApplicationAttemptId attemptId,
    long containerId, ContainerState containerState) throws Exception {
  HashMap<ApplicationId, List<ContainerStatus>> nodeUpdate =
      new HashMap<ApplicationId, List<ContainerStatus>>(1);
  ContainerStatus containerStatus = BuilderUtils.newContainerStatus(
      BuilderUtils.newContainerId(attemptId, containerId), containerState,
      "Success", 0);
  ArrayList<ContainerStatus> containerStatusList =
      new ArrayList<ContainerStatus>(1);
  containerStatusList.add(containerStatus);
  Log.info("ContainerStatus: " + containerStatus);
  nodeUpdate.put(attemptId.getApplicationId(), containerStatusList);
  return nodeHeartbeat(nodeUpdate, true);
}
 
Example 20
Source Project: big-c   Source File: TestRMWebServicesApps.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAppsQueryFinishEnd() throws JSONException, Exception {
  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  RMApp app1 = rm.submitApp(CONTAINER_MB);
  amNodeManager.nodeHeartbeat(true);
  // finish App
  MockAM am = rm
      .sendAMLaunched(app1.getCurrentAppAttempt().getAppAttemptId());
  am.registerAppAttempt();
  am.unregisterAppAttempt();
  amNodeManager.nodeHeartbeat(app1.getCurrentAppAttempt().getAppAttemptId(),
      1, ContainerState.COMPLETE);

  rm.submitApp(CONTAINER_MB);
  rm.submitApp(CONTAINER_MB);
  long end = System.currentTimeMillis();

  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("cluster")
      .path("apps").queryParam("finishedTimeEnd", String.valueOf(end))
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  assertEquals("incorrect number of elements", 1, json.length());
  JSONObject apps = json.getJSONObject("apps");
  assertEquals("incorrect number of elements", 1, apps.length());
  JSONArray array = apps.getJSONArray("app");
  assertEquals("incorrect number of elements", 3, array.length());
  rm.stop();
}
 
Example 21
Source Project: hadoop   Source File: BuilderUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static ContainerStatus newContainerStatus(ContainerId containerId,
    ContainerState containerState, String diagnostics, int exitStatus) {
  ContainerStatus containerStatus = recordFactory
    .newRecordInstance(ContainerStatus.class);
  containerStatus.setState(containerState);
  containerStatus.setContainerId(containerId);
  containerStatus.setDiagnostics(diagnostics);
  containerStatus.setExitStatus(exitStatus);
  return containerStatus;
}
 
Example 22
Source Project: big-c   Source File: ContainerFinishedEvent.java    License: Apache License 2.0 5 votes vote down vote up
public ContainerFinishedEvent(
    ContainerId containerId,
    String diagnosticsInfo,
    int containerExitStatus,
    ContainerState state,
    long finishedTime) {
  super(SystemMetricsEventType.CONTAINER_FINISHED, finishedTime);
  this.containerId = containerId;
  this.diagnosticsInfo = diagnosticsInfo;
  this.containerExitStatus = containerExitStatus;
  this.state = state;
}
 
Example 23
Source Project: hadoop   Source File: TestNodeStatusUpdater.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ConcurrentMap<ContainerId, Container> getContainers() {
  if (heartBeatID == 0) {
    return containers;
  } else if (heartBeatID == 1) {
    ContainerStatus containerStatus2 =
        createContainerStatus(2, ContainerState.RUNNING);
    putMockContainer(containerStatus2);

    ContainerStatus containerStatus3 =
        createContainerStatus(3, ContainerState.COMPLETE);
    putMockContainer(containerStatus3);
    return containers;
  } else if (heartBeatID == 2) {
    ContainerStatus containerStatus4 =
        createContainerStatus(4, ContainerState.RUNNING);
    putMockContainer(containerStatus4);

    ContainerStatus containerStatus5 =
        createContainerStatus(5, ContainerState.COMPLETE);
    putMockContainer(containerStatus5);
    return containers;
  } else if (heartBeatID == 3 || heartBeatID == 4) {
    return containers;
  } else {
    containers.clear();
    return containers;
  }
}
 
Example 24
Source Project: big-c   Source File: TestApplicationCleanup.java    License: Apache License 2.0 5 votes vote down vote up
public static NMContainerStatus createNMContainerStatus(
    ApplicationAttemptId appAttemptId, int id, ContainerState containerState,
    int memory) {
  ContainerId containerId = ContainerId.newContainerId(appAttemptId, id);
  NMContainerStatus containerReport =
      NMContainerStatus.newInstance(containerId, containerState,
          Resource.newInstance(memory, 1), "recover container", 0,
          Priority.newInstance(0), 0);
  return containerReport;
}
 
Example 25
Source Project: big-c   Source File: SchedulerUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Utility to create a {@link ContainerStatus} during exceptional
 * circumstances.
 * 
 * @param containerId {@link ContainerId} of returned/released/lost container.
 * @param diagnostics diagnostic message
 * @return <code>ContainerStatus</code> for an returned/released/lost 
 *         container
 */
private static ContainerStatus createAbnormalContainerStatus(
    ContainerId containerId, int exitStatus, String diagnostics) {
  ContainerStatus containerStatus = 
      recordFactory.newRecordInstance(ContainerStatus.class);
  containerStatus.setContainerId(containerId);
  containerStatus.setDiagnostics(diagnostics);
  containerStatus.setExitStatus(exitStatus);
  containerStatus.setState(ContainerState.COMPLETE);
  return containerStatus;
}
 
Example 26
Source Project: hadoop   Source File: TestContainerLauncher.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public StartContainersResponse startContainers(StartContainersRequest requests)
    throws IOException {

  StartContainerRequest request = requests.getStartContainerRequests().get(0);
  ContainerTokenIdentifier containerTokenIdentifier =
      MRApp.newContainerTokenIdentifier(request.getContainerToken());

  // Validate that the container is what RM is giving.
  Assert.assertEquals(MRApp.NM_HOST + ":" + MRApp.NM_PORT,
    containerTokenIdentifier.getNmHostAddress());

  StartContainersResponse response = recordFactory
      .newRecordInstance(StartContainersResponse.class);
  status = recordFactory.newRecordInstance(ContainerStatus.class);
  try {
    // make the thread sleep to look like its not going to respond
    Thread.sleep(15000);
  } catch (Exception e) {
    LOG.error(e);
    throw new UndeclaredThrowableException(e);
  }
  status.setState(ContainerState.RUNNING);
  status.setContainerId(containerTokenIdentifier.getContainerID());
  status.setExitStatus(0);
  return response;
}
 
Example 27
Source Project: hadoop   Source File: RMNodeImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void transition(RMNodeImpl rmNode, RMNodeEvent event) {
  // Inform the scheduler
  RMNodeStartedEvent startEvent = (RMNodeStartedEvent) event;
  List<NMContainerStatus> containers = null;

  String host = rmNode.nodeId.getHost();
  if (rmNode.context.getInactiveRMNodes().containsKey(host)) {
    // Old node rejoining
    RMNode previouRMNode = rmNode.context.getInactiveRMNodes().get(host);
    rmNode.context.getInactiveRMNodes().remove(host);
    rmNode.updateMetricsForRejoinedNode(previouRMNode.getState());
  } else {
    // Increment activeNodes explicitly because this is a new node.
    ClusterMetrics.getMetrics().incrNumActiveNodes();
    containers = startEvent.getNMContainerStatuses();
    if (containers != null && !containers.isEmpty()) {
      for (NMContainerStatus container : containers) {
        if (container.getContainerState() == ContainerState.RUNNING) {
          rmNode.launchedContainers.add(container.getContainerId());
        }
      }
    }
  }
  
  if (null != startEvent.getRunningApplications()) {
    for (ApplicationId appId : startEvent.getRunningApplications()) {
      handleRunningAppOnNode(rmNode, rmNode.context, appId, rmNode.nodeId);
    }
  }

  rmNode.context.getDispatcher().getEventHandler()
    .handle(new NodeAddedSchedulerEvent(rmNode, containers));
  rmNode.context.getDispatcher().getEventHandler().handle(
    new NodesListManagerEvent(
        NodesListManagerEventType.NODE_USABLE, rmNode));
}
 
Example 28
Source Project: big-c   Source File: RMContainerImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ContainerState getContainerState() {
  try {
    readLock.lock();
    if (getFinishedStatus() != null) {
      return getFinishedStatus().getState();
    } else {
      return ContainerState.RUNNING;
    }
  } finally {
    readLock.unlock();
  }
}
 
Example 29
Source Project: big-c   Source File: TestRMAppAttemptTransitions.java    License: 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);
}
 
Example 30
Source Project: hadoop   Source File: TestRMWebServicesApps.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAppsQueryFinishEnd() throws JSONException, Exception {
  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  RMApp app1 = rm.submitApp(CONTAINER_MB);
  amNodeManager.nodeHeartbeat(true);
  // finish App
  MockAM am = rm
      .sendAMLaunched(app1.getCurrentAppAttempt().getAppAttemptId());
  am.registerAppAttempt();
  am.unregisterAppAttempt();
  amNodeManager.nodeHeartbeat(app1.getCurrentAppAttempt().getAppAttemptId(),
      1, ContainerState.COMPLETE);

  rm.submitApp(CONTAINER_MB);
  rm.submitApp(CONTAINER_MB);
  long end = System.currentTimeMillis();

  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("cluster")
      .path("apps").queryParam("finishedTimeEnd", String.valueOf(end))
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  assertEquals("incorrect number of elements", 1, json.length());
  JSONObject apps = json.getJSONObject("apps");
  assertEquals("incorrect number of elements", 1, apps.length());
  JSONArray array = apps.getJSONArray("app");
  assertEquals("incorrect number of elements", 3, array.length());
  rm.stop();
}