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

The following examples show how to use org.apache.hadoop.yarn.api.records.ContainerStatus#getContainerId() . 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: AbstractYarnScheduler.java    From big-c with Apache License 2.0 6 votes vote down vote up
protected synchronized void containerLaunchedOnNode(
     ContainerStatus containerStatus, SchedulerNode node) {
   // Get the application for the finished container
ContainerId containerId = containerStatus.getContainerId();
   SchedulerApplicationAttempt application = getCurrentAttemptForContainer
       (containerId);
   if (application == null) {
     LOG.info("Unknown application "
         + containerId.getApplicationAttemptId().getApplicationId()
         + " launched container " + containerId + " on node: " + node);
     this.rmContext.getDispatcher().getEventHandler()
       .handle(new RMNodeCleanContainerEvent(node.getNodeID(), containerId));
     return;
   }

   Set<Integer> cpuCores = containerStatus.getCpuCores();
   node.registerCoresToContainer(containerId, cpuCores);
   application.containerLaunchedOnNode(containerId, node.getNodeID());
 }
 
Example 2
Source File: FairScheduler.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Process a heartbeat update from a node.
 */
private synchronized void nodeUpdate(RMNode nm) {
  long start = getClock().getTime();
  if (LOG.isDebugEnabled()) {
    LOG.debug("nodeUpdate: " + nm + " cluster capacity: " + clusterResource);
  }
  eventLog.log("HEARTBEAT", nm.getHostName());
  FSSchedulerNode node = getFSSchedulerNode(nm.getNodeID());
  
  List<UpdatedContainerInfo> containerInfoList = nm.pullContainerUpdates();
  List<ContainerStatus> newlyLaunchedContainers = new ArrayList<ContainerStatus>();
  List<ContainerStatus> completedContainers = new ArrayList<ContainerStatus>();
  for(UpdatedContainerInfo containerInfo : containerInfoList) {
    newlyLaunchedContainers.addAll(containerInfo.getNewlyLaunchedContainers());
    completedContainers.addAll(containerInfo.getCompletedContainers());
  } 
  // Processing the newly launched containers
  for (ContainerStatus launchedContainer : newlyLaunchedContainers) {
    containerLaunchedOnNode(launchedContainer.getContainerId(), node);
  }

  // Process completed containers
  for (ContainerStatus completedContainer : completedContainers) {
    ContainerId containerId = completedContainer.getContainerId();
    LOG.debug("Container FINISHED: " + containerId);
    completedContainer(getRMContainer(containerId),
        completedContainer, RMContainerEventType.FINISHED);
  }

  if (continuousSchedulingEnabled) {
    if (!completedContainers.isEmpty()) {
      attemptScheduling(node);
    }
  } else {
    attemptScheduling(node);
  }

  long duration = getClock().getTime() - start;
  fsOpDurations.addNodeUpdateDuration(duration);
}
 
Example 3
Source File: CapacityScheduler.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private synchronized void nodeUpdate(RMNode nm) {
  if (LOG.isDebugEnabled()) {
    LOG.debug("nodeUpdate: " + nm + " clusterResources: " + clusterResource);
  }

  FiCaSchedulerNode node = getNode(nm.getNodeID());
  
  List<UpdatedContainerInfo> containerInfoList = nm.pullContainerUpdates();
  List<ContainerStatus> newlyLaunchedContainers = new ArrayList<ContainerStatus>();
  List<ContainerStatus> completedContainers = new ArrayList<ContainerStatus>();
  for(UpdatedContainerInfo containerInfo : containerInfoList) {
    newlyLaunchedContainers.addAll(containerInfo.getNewlyLaunchedContainers());
    completedContainers.addAll(containerInfo.getCompletedContainers());
  }
  
  // Processing the newly launched containers
  for (ContainerStatus launchedContainer : newlyLaunchedContainers) {
    containerLaunchedOnNode(launchedContainer.getContainerId(), node);
  }

  // Process completed containers
  for (ContainerStatus completedContainer : completedContainers) {
    ContainerId containerId = completedContainer.getContainerId();
    LOG.debug("Container FINISHED: " + containerId);
    completedContainer(getRMContainer(containerId), 
        completedContainer, RMContainerEventType.FINISHED);
  }

  // Now node data structures are upto date and ready for scheduling.
  if(LOG.isDebugEnabled()) {
    LOG.debug("Node being looked for scheduling " + nm
      + " availableResource: " + node.getAvailableResource());
  }
}
 
Example 4
Source File: FairScheduler.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Process a heartbeat update from a node.
 */
private synchronized void nodeUpdate(RMNode nm) {
  long start = getClock().getTime();
  if (LOG.isDebugEnabled()) {
    LOG.debug("nodeUpdate: " + nm + " cluster capacity: " + clusterResource);
  }
  eventLog.log("HEARTBEAT", nm.getHostName());
  FSSchedulerNode node = getFSSchedulerNode(nm.getNodeID());
  
  List<UpdatedContainerInfo> containerInfoList = nm.pullContainerUpdates();
  List<ContainerStatus> newlyLaunchedContainers = new ArrayList<ContainerStatus>();
  List<ContainerStatus> completedContainers = new ArrayList<ContainerStatus>();
  for(UpdatedContainerInfo containerInfo : containerInfoList) {
    newlyLaunchedContainers.addAll(containerInfo.getNewlyLaunchedContainers());
    completedContainers.addAll(containerInfo.getCompletedContainers());
  } 
  // Processing the newly launched containers
  for (ContainerStatus launchedContainer : newlyLaunchedContainers) {
    containerLaunchedOnNode(launchedContainer, node);
  }

  // Process completed containers
  for (ContainerStatus completedContainer : completedContainers) {
    ContainerId containerId = completedContainer.getContainerId();
    LOG.debug("Container FINISHED: " + containerId);
    completedContainer(getRMContainer(containerId),
        completedContainer, RMContainerEventType.FINISHED);
  }

  if (continuousSchedulingEnabled) {
    if (!completedContainers.isEmpty()) {
      attemptScheduling(node);
    }
  } else {
    attemptScheduling(node);
  }

  long duration = getClock().getTime() - start;
  fsOpDurations.addNodeUpdateDuration(duration);
}
 
Example 5
Source File: CapacityScheduler.java    From big-c with Apache License 2.0 5 votes vote down vote up
private synchronized void nodeUpdate(RMNode nm) {
  if (LOG.isDebugEnabled()) {
    LOG.debug("nodeUpdate: " + nm + " clusterResources: " + clusterResource);
  }

  FiCaSchedulerNode node = getNode(nm.getNodeID());
  
  List<UpdatedContainerInfo> containerInfoList = nm.pullContainerUpdates();
  List<ContainerStatus> newlyLaunchedContainers = new ArrayList<ContainerStatus>();
  List<ContainerStatus> completedContainers = new ArrayList<ContainerStatus>();
  for(UpdatedContainerInfo containerInfo : containerInfoList) {
    newlyLaunchedContainers.addAll(containerInfo.getNewlyLaunchedContainers());
    completedContainers.addAll(containerInfo.getCompletedContainers());
  }
  
  // Processing the newly launched containers
  for (ContainerStatus launchedContainer : newlyLaunchedContainers) {
    containerLaunchedOnNode(launchedContainer, node);
    LOG.info("Container LAUNCHED:"+launchedContainer.getContainerId());
  }

  // Process completed containers
  for (ContainerStatus completedContainer : completedContainers) {
    ContainerId containerId = completedContainer.getContainerId();
    LOG.info("Container FINISHED: " + containerId);
    completedContainer(getRMContainer(containerId), 
        completedContainer, RMContainerEventType.FINISHED);
  }
  
  // Now node data structures are up to date and ready for scheduling.
  if(LOG.isDebugEnabled()) 
  {
    LOG.info("Node being looked for scheduling " + nm
      + " availableResource: " + node.getAvailableResource());
  }
}
 
Example 6
Source File: DagAwareYarnTaskScheduler.java    From tez with Apache License 2.0 5 votes vote down vote up
@Override
public void onContainersCompleted(List<ContainerStatus> statuses) {
  if (stopRequested) {
    return;
  }

  List<TaskStatus> taskStatusList = new ArrayList<>(statuses.size());
  synchronized (this) {
    for (ContainerStatus status : statuses) {
      ContainerId cid = status.getContainerId();
      LOG.info("Container {} completed with status {}", cid, status);
      Object task = releasedContainers.remove(cid);
      if (task == null) {
        HeldContainer hc = heldContainers.get(cid);
        if (hc != null) {
          task = containerCompleted(hc);
        }
      }
      if (task != null) {
        taskStatusList.add(new TaskStatus(task, status));
      }
    }
  }

  // perform app callback outside of locks
  for (TaskStatus taskStatus : taskStatusList) {
    getContext().containerCompleted(taskStatus.task, taskStatus.status);
  }
}
 
Example 7
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 8
Source File: FifoScheduler.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private synchronized void nodeUpdate(RMNode rmNode) {
  FiCaSchedulerNode node = getNode(rmNode.getNodeID());
  
  List<UpdatedContainerInfo> containerInfoList = rmNode.pullContainerUpdates();
  List<ContainerStatus> newlyLaunchedContainers = new ArrayList<ContainerStatus>();
  List<ContainerStatus> completedContainers = new ArrayList<ContainerStatus>();
  for(UpdatedContainerInfo containerInfo : containerInfoList) {
    newlyLaunchedContainers.addAll(containerInfo.getNewlyLaunchedContainers());
    completedContainers.addAll(containerInfo.getCompletedContainers());
  }
  // Processing the newly launched containers
  for (ContainerStatus launchedContainer : newlyLaunchedContainers) {
    containerLaunchedOnNode(launchedContainer.getContainerId(), node);
  }

  // Process completed containers
  for (ContainerStatus completedContainer : completedContainers) {
    ContainerId containerId = completedContainer.getContainerId();
    LOG.debug("Container FINISHED: " + containerId);
    completedContainer(getRMContainer(containerId), 
        completedContainer, RMContainerEventType.FINISHED);
  }


  if (rmContext.isWorkPreservingRecoveryEnabled()
      && !rmContext.isSchedulerReadyForAllocatingContainers()) {
    return;
  }

  if (Resources.greaterThanOrEqual(resourceCalculator, clusterResource,
          node.getAvailableResource(),minimumAllocation)) {
    LOG.debug("Node heartbeat " + rmNode.getNodeID() + 
        " available resource = " + node.getAvailableResource());

    assignContainers(node);

    LOG.debug("Node after allocation " + rmNode.getNodeID() + " resource = "
        + node.getAvailableResource());
  }

  updateAvailableResourcesMetrics();
}
 
Example 9
Source File: ResourceSchedulerWrapper.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private void updateQueueWithNodeUpdate(
        NodeUpdateSchedulerEventWrapper eventWrapper) {
  RMNodeWrapper node = (RMNodeWrapper) eventWrapper.getRMNode();
  List<UpdatedContainerInfo> containerList = node.getContainerUpdates();
  for (UpdatedContainerInfo info : containerList) {
    for (ContainerStatus status : info.getCompletedContainers()) {
      ContainerId containerId = status.getContainerId();
      SchedulerAppReport app = scheduler.getSchedulerAppInfo(
              containerId.getApplicationAttemptId());

      if (app == null) {
        // this happens for the AM container
        // The app have already removed when the NM sends the release
        // information.
        continue;
      }

      String queue =
          appQueueMap.get(containerId.getApplicationAttemptId()
            .getApplicationId());
      int releasedMemory = 0, releasedVCores = 0;
      if (status.getExitStatus() == ContainerExitStatus.SUCCESS) {
        for (RMContainer rmc : app.getLiveContainers()) {
          if (rmc.getContainerId() == containerId) {
            releasedMemory += rmc.getContainer().getResource().getMemory();
            releasedVCores += rmc.getContainer()
                    .getResource().getVirtualCores();
            break;
          }
        }
      } else if (status.getExitStatus() == ContainerExitStatus.ABORTED) {
        if (preemptionContainerMap.containsKey(containerId)) {
          Resource preResource = preemptionContainerMap.get(containerId);
          releasedMemory += preResource.getMemory();
          releasedVCores += preResource.getVirtualCores();
          preemptionContainerMap.remove(containerId);
        }
      }
      // update queue counters
      updateQueueMetrics(queue, releasedMemory, releasedVCores);
    }
  }
}
 
Example 10
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 11
Source File: FifoScheduler.java    From big-c with Apache License 2.0 4 votes vote down vote up
private synchronized void nodeUpdate(RMNode rmNode) {
  FiCaSchedulerNode node = getNode(rmNode.getNodeID());
  
  List<UpdatedContainerInfo> containerInfoList = rmNode.pullContainerUpdates();
  List<ContainerStatus> newlyLaunchedContainers = new ArrayList<ContainerStatus>();
  List<ContainerStatus> completedContainers = new ArrayList<ContainerStatus>();
  for(UpdatedContainerInfo containerInfo : containerInfoList) {
    newlyLaunchedContainers.addAll(containerInfo.getNewlyLaunchedContainers());
    completedContainers.addAll(containerInfo.getCompletedContainers());
  }
  // Processing the newly launched containers
  for (ContainerStatus launchedContainer : newlyLaunchedContainers) {
    containerLaunchedOnNode(launchedContainer, node);
  }

  // Process completed containers
  for (ContainerStatus completedContainer : completedContainers) {
    ContainerId containerId = completedContainer.getContainerId();
    LOG.info("Container FINISHED by FifoScheduler by nodeUpdate: " + containerId);
    completedContainer(getRMContainer(containerId), 
        completedContainer, RMContainerEventType.FINISHED);
  }


  if (rmContext.isWorkPreservingRecoveryEnabled()
      && !rmContext.isSchedulerReadyForAllocatingContainers()) {
    return;
  }

  if (Resources.greaterThanOrEqual(resourceCalculator, clusterResource,
          node.getAvailableResource(),minimumAllocation)) {
    LOG.debug("Node heartbeat " + rmNode.getNodeID() + 
        " available resource = " + node.getAvailableResource());

    assignContainers(node);

    LOG.debug("Node after allocation " + rmNode.getNodeID() + " resource = "
        + node.getAvailableResource());
  }

  updateAvailableResourcesMetrics();
}
 
Example 12
Source File: ResourceSchedulerWrapper.java    From big-c with Apache License 2.0 4 votes vote down vote up
private void updateQueueWithNodeUpdate(
        NodeUpdateSchedulerEventWrapper eventWrapper) {
  RMNodeWrapper node = (RMNodeWrapper) eventWrapper.getRMNode();
  List<UpdatedContainerInfo> containerList = node.getContainerUpdates();
  for (UpdatedContainerInfo info : containerList) {
    for (ContainerStatus status : info.getCompletedContainers()) {
      ContainerId containerId = status.getContainerId();
      SchedulerAppReport app = scheduler.getSchedulerAppInfo(
              containerId.getApplicationAttemptId());

      if (app == null) {
        // this happens for the AM container
        // The app have already removed when the NM sends the release
        // information.
        continue;
      }

      String queue =
          appQueueMap.get(containerId.getApplicationAttemptId()
            .getApplicationId());
      int releasedMemory = 0, releasedVCores = 0;
      if (status.getExitStatus() == ContainerExitStatus.SUCCESS) {
        for (RMContainer rmc : app.getLiveContainers()) {
          if (rmc.getContainerId() == containerId) {
            releasedMemory += rmc.getContainer().getResource().getMemory();
            releasedVCores += rmc.getContainer()
                    .getResource().getVirtualCores();
            break;
          }
        }
      } else if (status.getExitStatus() == ContainerExitStatus.ABORTED) {
        if (preemptionContainerMap.containsKey(containerId)) {
          Resource preResource = preemptionContainerMap.get(containerId);
          releasedMemory += preResource.getMemory();
          releasedVCores += preResource.getVirtualCores();
          preemptionContainerMap.remove(containerId);
        }
      }
      // update queue counters
      updateQueueMetrics(queue, releasedMemory, releasedVCores);
    }
  }
}
 
Example 13
Source File: YarnTaskSchedulerService.java    From incubator-tez with Apache License 2.0 4 votes vote down vote up
@Override
public void onContainersCompleted(List<ContainerStatus> statuses) {
  if (isStopped.get()) {
    return;
  }
  Map<Object, ContainerStatus> appContainerStatus =
                      new HashMap<Object, ContainerStatus>(statuses.size());
  synchronized (this) {
    for(ContainerStatus containerStatus : statuses) {
      ContainerId completedId = containerStatus.getContainerId();
      HeldContainer delayedContainer = heldContainers.get(completedId);

      Object task = releasedContainers.remove(completedId);
      if(task != null){
        if (delayedContainer != null) {
          LOG.warn("Held container should be null since releasedContainer is not");
        }
        // TODO later we may want to check if exit code matched expectation
        // e.g. successful container should not come back fail exit code after
        // being released
        // completion of a container we had released earlier
        // an allocated container completed. notify app
        LOG.info("Released container completed:" + completedId +
                 " last allocated to task: " + task);
        appContainerStatus.put(task, containerStatus);
        continue;
      }

      // not found in released containers. check currently allocated containers
      // no need to release this container as the RM has already completed it
      task = unAssignContainer(completedId, false);
      if (delayedContainer != null) {
        heldContainers.remove(completedId);
        Resources.subtract(allocatedResources, delayedContainer.getContainer().getResource());
      } else {
        LOG.warn("Held container expected to be not null for a non-AM-released container");
      }
      if(task != null) {
        // completion of a container we have allocated currently
        // an allocated container completed. notify app
        LOG.info("Allocated container completed:" + completedId +
                 " last allocated to task: " + task);
        appContainerStatus.put(task, containerStatus);
        continue;
      }

      // container neither allocated nor released
      LOG.info("Ignoring unknown container: " + containerStatus.getContainerId());
    }
  }

  // upcall to app must be outside locks
  for (Entry<Object, ContainerStatus> entry : appContainerStatus.entrySet()) {
    appClientDelegate.containerCompleted(entry.getKey(), entry.getValue());
  }
}
 
Example 14
Source File: YarnTaskSchedulerService.java    From tez with Apache License 2.0 4 votes vote down vote up
@Override
public void onContainersCompleted(List<ContainerStatus> statuses) {
  if (isStopStarted.get()) {
    if (LOG.isDebugEnabled()) {
      for (ContainerStatus status : statuses) {
        LOG.debug("Container " + status.getContainerId() + " is completed with ContainerStatus=" +
            status);
      }
    }
    return;
  }
  Map<Object, ContainerStatus> appContainerStatus =
                      new HashMap<Object, ContainerStatus>(statuses.size());
  synchronized (this) {
    for(ContainerStatus containerStatus : statuses) {
      ContainerId completedId = containerStatus.getContainerId();
      HeldContainer delayedContainer = heldContainers.get(completedId);

      Object task = releasedContainers.remove(completedId);
      if(task != null){
        if (delayedContainer != null) {
          LOG.warn("Held container should be null since releasedContainer is not");
        }
        // TODO later we may want to check if exit code matched expectation
        // e.g. successful container should not come back fail exit code after
        // being released
        // completion of a container we had released earlier
        // an allocated container completed. notify app
        if (LOG.isDebugEnabled()) {
          LOG.debug("Released container completed:" + completedId +
              " last allocated to task: " + task);
        }
        appContainerStatus.put(task, containerStatus);
        continue;
      }

      // not found in released containers. check currently allocated containers
      // no need to release this container as the RM has already completed it
      task = unAssignContainer(completedId, false);
      if (delayedContainer != null) {
        heldContainers.remove(completedId);
        Resources.subtract(allocatedResources, delayedContainer.getContainer().getResource());
      } else {
        LOG.warn("Held container expected to be not null for a non-AM-released container");
      }
      if(task != null) {
        // completion of a container we have allocated currently
        // an allocated container completed. notify app. This will cause attempt to get killed
        LOG.info(
            "Allocated container completed:" + completedId + " last allocated to task: " + task);
        appContainerStatus.put(task, containerStatus);
        continue;
      }

      // container neither allocated nor released
      if (delayedContainer != null) {
        LOG.info("Delayed container {} completed", containerStatus.getContainerId());
        maybeRescheduleContainerAtPriority(delayedContainer.getContainer().getPriority());
      } else {
        LOG.info("Ignoring unknown container: " + containerStatus.getContainerId());
      }
    }
  }

  // upcall to app must be outside locks
  for (Entry<Object, ContainerStatus> entry : appContainerStatus.entrySet()) {
    getContext().containerCompleted(entry.getKey(), entry.getValue());
  }
}