Java Code Examples for org.apache.hadoop.yarn.api.records.ContainerStatus#getState()

The following examples show how to use org.apache.hadoop.yarn.api.records.ContainerStatus#getState() . 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: TestNMClient.java    From hadoop with 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 2
Source File: Hadoop21YarnNMClient.java    From twill with Apache License 2.0 6 votes vote down vote up
@Override
public void cancel() {
  LOG.info("Request to stop container {}.", container.getId());

  try {
    nmClient.stopContainer(container.getId(), container.getNodeId());
    while (true) {
      ContainerStatus status = nmClient.getContainerStatus(container.getId(), container.getNodeId());
      LOG.trace("Container status: {} {}", status, status.getDiagnostics());
      if (status.getState() == ContainerState.COMPLETE) {
        break;
      }
      Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS);
    }
    LOG.info("Container {} stopped.", container.getId());
  } catch (Exception e) {
    LOG.error("Fail to stop container {}", container.getId(), e);
    throw Throwables.propagate(e);
  }
}
 
Example 3
Source File: TestNMClient.java    From big-c with 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 4
Source File: StreamingAppMasterService.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
public void onContainerStatusReceived(ContainerId containerId, ContainerStatus containerStatus)
{
  LOG.debug("Container Status: id={}, status={}", containerId, containerStatus);
  if (containerStatus.getState() != ContainerState.RUNNING) {
    recoverContainer(containerId);
  }
}
 
Example 5
Source File: StreamingAppMasterService.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onContainerStatusReceived(ContainerId containerId, ContainerStatus containerStatus)
{
  LOG.debug("Container Status: id={}, status={}", containerId, containerStatus);
  if (containerStatus.getState() != ContainerState.RUNNING) {
    recoverContainer(containerId);
  }
}
 
Example 6
Source File: RMNodeImpl.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private void handleContainerStatus(List<ContainerStatus> containerStatuses) {
  // Filter the map to only obtain just launched containers and finished
  // containers.
  List<ContainerStatus> newlyLaunchedContainers =
      new ArrayList<ContainerStatus>();
  List<ContainerStatus> completedContainers =
      new ArrayList<ContainerStatus>();
  for (ContainerStatus remoteContainer : containerStatuses) {
    ContainerId containerId = remoteContainer.getContainerId();

    // Don't bother with containers already scheduled for cleanup, or for
    // applications already killed. The scheduler doens't need to know any
    // more about this container
    if (containersToClean.contains(containerId)) {
      LOG.info("Container " + containerId + " already scheduled for "
          + "cleanup, no further processing");
      continue;
    }
    if (finishedApplications.contains(containerId.getApplicationAttemptId()
        .getApplicationId())) {
      LOG.info("Container " + containerId
          + " belongs to an application that is already killed,"
          + " no further processing");
      continue;
    }

    // Process running containers
    if (remoteContainer.getState() == ContainerState.RUNNING) {
      if (!launchedContainers.contains(containerId)) {
        // Just launched container. RM knows about it the first time.
        launchedContainers.add(containerId);
        newlyLaunchedContainers.add(remoteContainer);
      }
    } else {
      // A finished container
      launchedContainers.remove(containerId);
      completedContainers.add(remoteContainer);
    }
  }
  if (newlyLaunchedContainers.size() != 0 || completedContainers.size() != 0) {
    nodeUpdateQueue.add(new UpdatedContainerInfo(newlyLaunchedContainers,
        completedContainers));
  }
}
 
Example 7
Source File: RMNodeImpl.java    From big-c with Apache License 2.0 4 votes vote down vote up
private void handleContainerStatus(List<ContainerStatus> containerStatuses) {
  
//LOG.info("RMNode hearbeat host"+this.getHostName());
   // Filter the map to only obtain just launched containers and finished
   // containers.
   List<ContainerStatus> newlyLaunchedContainers =
       new ArrayList<ContainerStatus>();
   List<ContainerStatus> completedContainers =
       new ArrayList<ContainerStatus>();
   for (ContainerStatus remoteContainer : containerStatuses) {
     ContainerId containerId = remoteContainer.getContainerId();

     // Don't bother with containers already scheduled for cleanup, or for
     // applications already killed. The scheduler doens't need to know any
     // more about this container
     if (containersToClean.contains(containerId)) {
       LOG.info("Container " + containerId + " already scheduled for "
           + "cleanup, no further processing");
       continue;
     }
     if (finishedApplications.contains(containerId.getApplicationAttemptId()
         .getApplicationId())) {
       LOG.info("Container " + containerId
           + " belongs to an application that is already killed,"
           + " no further processing");
       continue;
     }

     // Process running containers
     if (remoteContainer.getState() == ContainerState.RUNNING) {
       if (!launchedContainers.contains(containerId)) {
         // Just launched container. RM knows about it the first time.
         launchedContainers.add(containerId);
         newlyLaunchedContainers.add(remoteContainer);
       }
     } else {
       // A finished container
       launchedContainers.remove(containerId);
       completedContainers.add(remoteContainer);
     }
   }
   if (newlyLaunchedContainers.size() != 0 || completedContainers.size() != 0) {
     nodeUpdateQueue.add(new UpdatedContainerInfo(newlyLaunchedContainers,
         completedContainers));
   }
 }
 
Example 8
Source File: NMHeartBeatHandler.java    From incubator-myriad with Apache License 2.0 4 votes vote down vote up
private boolean containerInUse(ContainerStatus status) {
  return (status.getState() == ContainerState.NEW || status.getState() == ContainerState.RUNNING);
}