Java Code Examples for org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer

The following examples show how to use org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer. 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: hadoop   Source File: ResourceManager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void handle(ContainerPreemptEvent event) {
  ApplicationAttemptId aid = event.getAppId();
  RMContainer container = event.getContainer();
  switch (event.getType()) {
  case DROP_RESERVATION:
    scheduler.dropContainerReservation(container);
    break;
  case PREEMPT_CONTAINER:
    scheduler.preemptContainer(aid, container);
    break;
  case KILL_CONTAINER:
    scheduler.killContainer(container);
    break;
  }
}
 
Example 2
Source Project: hadoop   Source File: TestRMApplicationHistoryWriter.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(0L);
  when(container.getFinishTime()).thenReturn(1L);
  when(container.getDiagnosticsInfo()).thenReturn("test diagnostics info");
  when(container.getLogURL()).thenReturn("test log url");
  when(container.getContainerExitStatus()).thenReturn(-1);
  when(container.getContainerState()).thenReturn(ContainerState.COMPLETE);
  return container;
}
 
Example 3
Source Project: hadoop   Source File: FifoScheduler.java    License: Apache License 2.0 6 votes vote down vote up
private synchronized void removeNode(RMNode nodeInfo) {
  FiCaSchedulerNode node = getNode(nodeInfo.getNodeID());
  if (node == null) {
    return;
  }
  // Kill running containers
  for(RMContainer container : node.getRunningContainers()) {
    completedContainer(container, 
        SchedulerUtils.createAbnormalContainerStatus(
            container.getContainerId(), 
            SchedulerUtils.LOST_CONTAINER),
            RMContainerEventType.KILL);
  }
  
  //Remove the node
  this.nodes.remove(nodeInfo.getNodeID());
  updateMaximumAllocation(node, false);
  
  // Update cluster metrics
  Resources.subtractFrom(clusterResource, node.getRMNode().getTotalCapability());
}
 
Example 4
Source Project: big-c   Source File: FSAppAttempt.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Preempt a running container according to the priority
 */
@Override
public RMContainer preemptContainer() {
  if (LOG.isDebugEnabled()) {
    LOG.debug("App " + getName() + " is going to preempt a running " +
        "container");
  }

  RMContainer toBePreempted = null;
  for (RMContainer container : getLiveContainers()) {
    if (!getPreemptionContainers().contains(container) &&
        (toBePreempted == null ||
            comparator.compare(toBePreempted, container) > 0)) {
      toBePreempted = container;
    }
  }
  return toBePreempted;
}
 
Example 5
/**
 * Compare by reversed priority order first, and then reversed containerId
 * order
 * @param containers
 */
@VisibleForTesting
static void sortContainers(List<RMContainer> containers){
  Collections.sort(containers, new Comparator<RMContainer>() {
    @Override
    public int compare(RMContainer a, RMContainer b) {
      Comparator<Priority> c = new org.apache.hadoop.yarn.server
          .resourcemanager.resource.Priority.Comparator();
      int priorityComp = c.compare(b.getContainer().getPriority(),
                                   a.getContainer().getPriority());
      if (priorityComp != 0) {
        return priorityComp;
      }
      return b.getContainerId().compareTo(a.getContainerId());
    }
  });
}
 
Example 6
Source Project: hadoop   Source File: FSAppAttempt.java    License: Apache License 2.0 6 votes vote down vote up
private synchronized void unreserveInternal(
    Priority priority, FSSchedulerNode node) {
  Map<NodeId, RMContainer> reservedContainers = 
      this.reservedContainers.get(priority);
  RMContainer reservedContainer = reservedContainers.remove(node.getNodeID());
  if (reservedContainers.isEmpty()) {
    this.reservedContainers.remove(priority);
  }
  
  // Reset the re-reservation count
  resetReReservations(priority);

  Resource resource = reservedContainer.getContainer().getResource();
  this.attemptResourceUsage.decReserved(resource);

  LOG.info("Application " + getApplicationId() + " unreserved " + " on node "
      + node + ", currently has " + reservedContainers.size()
      + " at priority " + priority + "; currentReservation "
      + this.attemptResourceUsage.getReserved());
}
 
Example 7
Source Project: big-c   Source File: LeafQueue.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void attachContainer(Resource clusterResource,
    FiCaSchedulerApp application, RMContainer rmContainer) {
  if (application != null) {
    FiCaSchedulerNode node =
        scheduler.getNode(rmContainer.getContainer().getNodeId());
    allocateResource(clusterResource, application, rmContainer.getContainer()
        .getResource(), node.getLabels(),false);
    LOG.info("movedContainer" + " container=" + rmContainer.getContainer()
        + " resource=" + rmContainer.getContainer().getResource()
        + " queueMoveIn=" + this + " usedCapacity=" + getUsedCapacity()
        + " absoluteUsedCapacity=" + getAbsoluteUsedCapacity() + " used="
        + queueUsage.getUsed() + " cluster=" + clusterResource);
    // Inform the parent queue
    getParent().attachContainer(clusterResource, application, rmContainer);
  }
}
 
Example 8
Source Project: big-c   Source File: SchedulerApplicationAttempt.java    License: Apache License 2.0 6 votes vote down vote up
public synchronized void recoverContainer(RMContainer rmContainer) {
  // recover app scheduling info
  appSchedulingInfo.recoverContainer(rmContainer);

  if (rmContainer.getState().equals(RMContainerState.COMPLETED)) {
    return;
  }
  LOG.info("SchedulerAttempt " + getApplicationAttemptId()
    + " is recovering container " + rmContainer.getContainerId());
  liveContainers.put(rmContainer.getContainerId(), rmContainer);
  Resources.addTo(currentConsumption, rmContainer.getContainer()
    .getResource());
  // resourceLimit: updated when LeafQueue#recoverContainer#allocateResource
  // is called.
  // newlyAllocatedContainers.add(rmContainer);
  // schedulingOpportunities
  // lastScheduledContainer
}
 
Example 9
Source Project: hadoop   Source File: ParentQueue.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void recoverContainer(Resource clusterResource,
    SchedulerApplicationAttempt attempt, RMContainer rmContainer) {
  if (rmContainer.getState().equals(RMContainerState.COMPLETED)) {
    return;
  }
  // Careful! Locking order is important! 
  synchronized (this) {
    FiCaSchedulerNode node =
        scheduler.getNode(rmContainer.getContainer().getNodeId());
    super.allocateResource(clusterResource, rmContainer.getContainer()
        .getResource(), node.getLabels());
  }
  if (parent != null) {
    parent.recoverContainer(clusterResource, attempt, rmContainer);
  }
}
 
Example 10
Source Project: hadoop   Source File: ParentQueue.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void detachContainer(Resource clusterResource,
    FiCaSchedulerApp application, RMContainer rmContainer) {
  if (application != null) {
    FiCaSchedulerNode node =
        scheduler.getNode(rmContainer.getContainer().getNodeId());
    super.releaseResource(clusterResource,
        rmContainer.getContainer().getResource(),
        node.getLabels());
    LOG.info("movedContainer" + " queueMoveOut=" + getQueueName()
        + " usedCapacity=" + getUsedCapacity() + " absoluteUsedCapacity="
        + getAbsoluteUsedCapacity() + " used=" + queueUsage.getUsed() + " cluster="
        + clusterResource);
    // Inform the parent
    if (parent != null) {
      parent.detachContainer(clusterResource, application, rmContainer);
    }
  }
}
 
Example 11
Source Project: hadoop   Source File: SystemMetricsPublisher.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void containerCreated(RMContainer container, long createdTime) {
  if (publishSystemMetrics) {
    dispatcher.getEventHandler().handle(
        new ContainerCreatedEvent(
            container.getContainerId(),
            container.getAllocatedResource(),
            container.getAllocatedNode(),
            container.getAllocatedPriority(),
            createdTime, container.getNodeHttpAddress()));
  }
}
 
Example 12
Source Project: hadoop   Source File: SystemMetricsPublisher.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void containerFinished(RMContainer container, long finishedTime) {
  if (publishSystemMetrics) {
    dispatcher.getEventHandler().handle(
        new ContainerFinishedEvent(
            container.getContainerId(),
            container.getDiagnosticsInfo(),
            container.getContainerExitStatus(),
            container.getContainerState(),
            finishedTime));
  }
}
 
Example 13
Source Project: big-c   Source File: LeafQueue.java    License: Apache License 2.0 5 votes vote down vote up
private Container getContainer(RMContainer rmContainer, 
    FiCaSchedulerApp application, FiCaSchedulerNode node, 
    Resource capability, Priority priority) {
 //是否是reserve 的情况
  return (rmContainer != null) ? rmContainer.getContainer() :
    createContainer(application, node, capability, priority);
}
 
Example 14
Source Project: big-c   Source File: SystemMetricsPublisher.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void containerCreated(RMContainer container, long createdTime) {
  if (publishSystemMetrics) {
    dispatcher.getEventHandler().handle(
        new ContainerCreatedEvent(
            container.getContainerId(),
            container.getAllocatedResource(),
            container.getAllocatedNode(),
            container.getAllocatedPriority(),
            createdTime, container.getNodeHttpAddress()));
  }
}
 
Example 15
Source Project: big-c   Source File: AbstractYarnScheduler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 什么意思,什么叫pull the smae,我觉得这个状态是,AM已经把resource 的请求发出了,但是
 * 该container还没有真正set up起来
 * Recover resource request back from RMContainer when a container is 
 * preempted before AM pulled the same. If container is pulled by
 * AM, then RMContainer will not have resource request to recover.
 * @param rmContainer
 */
protected void recoverResourceRequestForContainer(RMContainer rmContainer) {
  List<ResourceRequest> requests = rmContainer.getResourceRequests();

  // If container state is moved to ACQUIRED, request will be empty.
  if (requests == null) {
    return;
  }
  // Add resource request back to Scheduler.
  SchedulerApplicationAttempt schedulerAttempt 
      = getCurrentAttemptForContainer(rmContainer.getContainerId());
  if (schedulerAttempt != null) {
    schedulerAttempt.recoverResourceRequests(requests);
  }
}
 
Example 16
Source Project: hadoop   Source File: LeafQueue.java    License: Apache License 2.0 5 votes vote down vote up
private void reserve(FiCaSchedulerApp application, Priority priority, 
    FiCaSchedulerNode node, RMContainer rmContainer, Container container) {
  // Update reserved metrics if this is the first reservation
  if (rmContainer == null) {
    getMetrics().reserveResource(
        application.getUser(), container.getResource());
  }

  // Inform the application 
  rmContainer = application.reserve(node, priority, rmContainer, container);
  
  // Update the node
  node.reserveResource(application, priority, rmContainer);
}
 
Example 17
Source Project: hadoop   Source File: FifoScheduler.java    License: Apache License 2.0 5 votes vote down vote up
private synchronized void doneApplicationAttempt(
    ApplicationAttemptId applicationAttemptId,
    RMAppAttemptState rmAppAttemptFinalState, boolean keepContainers)
    throws IOException {
  FiCaSchedulerApp attempt = getApplicationAttempt(applicationAttemptId);
  SchedulerApplication<FiCaSchedulerApp> application =
      applications.get(applicationAttemptId.getApplicationId());
  if (application == null || attempt == null) {
    throw new IOException("Unknown application " + applicationAttemptId + 
    " has completed!");
  }

  // Kill all 'live' containers
  for (RMContainer container : attempt.getLiveContainers()) {
    if (keepContainers
        && container.getState().equals(RMContainerState.RUNNING)) {
      // do not kill the running container in the case of work-preserving AM
      // restart.
      LOG.info("Skip killing " + container.getContainerId());
      continue;
    }
    completedContainer(container,
      SchedulerUtils.createAbnormalContainerStatus(
        container.getContainerId(), SchedulerUtils.COMPLETED_APPLICATION),
      RMContainerEventType.KILL);
  }

  // Clean up pending requests, metrics etc.
  attempt.stop(rmAppAttemptFinalState);
}
 
Example 18
Source Project: big-c   Source File: LeafQueue.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void recoverContainer(Resource clusterResource,
    SchedulerApplicationAttempt attempt, RMContainer rmContainer) {
  if (rmContainer.getState().equals(RMContainerState.COMPLETED)) {
    return;
  }
  // Careful! Locking order is important! 
  synchronized (this) {
    FiCaSchedulerNode node =
        scheduler.getNode(rmContainer.getContainer().getNodeId());
    allocateResource(clusterResource, attempt, rmContainer.getContainer()
        .getResource(), node.getLabels(),false);
  }
  getParent().recoverContainer(clusterResource, attempt, rmContainer);
}
 
Example 19
Source Project: hadoop   Source File: LeafQueue.java    License: Apache License 2.0 5 votes vote down vote up
private Resource assignOffSwitchContainers(Resource clusterResource,
    ResourceRequest offSwitchResourceRequest, FiCaSchedulerNode node,
    FiCaSchedulerApp application, Priority priority,
    RMContainer reservedContainer, MutableObject allocatedContainer,
    ResourceLimits currentResoureLimits) {
  if (canAssign(application, priority, node, NodeType.OFF_SWITCH,
      reservedContainer)) {
    return assignContainer(clusterResource, node, application, priority,
        offSwitchResourceRequest, NodeType.OFF_SWITCH, reservedContainer,
        allocatedContainer, currentResoureLimits);
  }
  
  return Resources.none();
}
 
Example 20
Source Project: hadoop   Source File: SchedulerApplicationAttempt.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get the list of reserved containers
 * @return All of the reserved containers.
 */
public synchronized List<RMContainer> getReservedContainers() {
  List<RMContainer> reservedContainers = new ArrayList<RMContainer>();
  for (Map.Entry<Priority, Map<NodeId, RMContainer>> e : 
    this.reservedContainers.entrySet()) {
    reservedContainers.addAll(e.getValue().values());
  }
  return reservedContainers;
}
 
Example 21
Source Project: hadoop   Source File: SchedulerApplicationAttempt.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Has the application reserved the given <code>node</code> at the
 * given <code>priority</code>?
 * @param node node to be checked
 * @param priority priority of reserved container
 * @return true is reserved, false if not
 */
public synchronized boolean isReserved(SchedulerNode node, Priority priority) {
  Map<NodeId, RMContainer> reservedContainers = 
      this.reservedContainers.get(priority);
  if (reservedContainers != null) {
    return reservedContainers.containsKey(node.getNodeID());
  }
  return false;
}
 
Example 22
Source Project: hadoop   Source File: SchedulerApplicationAttempt.java    License: Apache License 2.0 5 votes vote down vote up
public synchronized ContainersAndNMTokensAllocation
    pullNewlyAllocatedContainersAndNMTokens() {
  List<Container> returnContainerList =
      new ArrayList<Container>(newlyAllocatedContainers.size());
  List<NMToken> nmTokens = new ArrayList<NMToken>();
  for (Iterator<RMContainer> i = newlyAllocatedContainers.iterator(); i
    .hasNext();) {
    RMContainer rmContainer = i.next();
    Container container = rmContainer.getContainer();
    try {
      // create container token and NMToken altogether.
      container.setContainerToken(rmContext.getContainerTokenSecretManager()
        .createContainerToken(container.getId(), container.getNodeId(),
          getUser(), container.getResource(), container.getPriority(),
          rmContainer.getCreationTime(), this.logAggregationContext));
      NMToken nmToken =
          rmContext.getNMTokenSecretManager().createAndGetNMToken(getUser(),
            getApplicationAttemptId(), container);
      if (nmToken != null) {
        nmTokens.add(nmToken);
      }
    } catch (IllegalArgumentException e) {
      // DNS might be down, skip returning this container.
      LOG.error("Error trying to assign container token and NM token to" +
          " an allocated container " + container.getId(), e);
      continue;
    }
    returnContainerList.add(container);
    i.remove();
    rmContainer.handle(new RMContainerEvent(rmContainer.getContainerId(),
      RMContainerEventType.ACQUIRED));
  }
  return new ContainersAndNMTokensAllocation(returnContainerList, nmTokens);
}
 
Example 23
Source Project: big-c   Source File: SchedulerApplicationAttempt.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Has the application reserved the given <code>node</code> at the
 * given <code>priority</code>?
 * @param node node to be checked
 * @param priority priority of reserved container
 * @return true is reserved, false if not
 */
public synchronized boolean isReserved(SchedulerNode node, Priority priority) {
  Map<NodeId, RMContainer> reservedContainers = 
      this.reservedContainers.get(priority);
  if (reservedContainers != null) {
    return reservedContainers.containsKey(node.getNodeID());
  }
  return false;
}
 
Example 24
Source Project: hadoop   Source File: FSLeafQueue.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RMContainer preemptContainer() {
  RMContainer toBePreempted = null;

  // If this queue is not over its fair share, reject
  if (!preemptContainerPreCheck()) {
    return toBePreempted;
  }

  if (LOG.isDebugEnabled()) {
    LOG.debug("Queue " + getName() + " is going to preempt a container " +
        "from its applications.");
  }

  // Choose the app that is most over fair share
  Comparator<Schedulable> comparator = policy.getComparator();
  FSAppAttempt candidateSched = null;
  readLock.lock();
  try {
    for (FSAppAttempt sched : runnableApps) {
      if (candidateSched == null ||
          comparator.compare(sched, candidateSched) > 0) {
        candidateSched = sched;
      }
    }
  } finally {
    readLock.unlock();
  }

  // Preempt from the selected app
  if (candidateSched != null) {
    toBePreempted = candidateSched.preemptContainer();
  }
  return toBePreempted;
}
 
Example 25
Source Project: hadoop   Source File: FairScheduler.java    License: Apache License 2.0 5 votes vote down vote up
private synchronized void removeNode(RMNode rmNode) {
  FSSchedulerNode node = getFSSchedulerNode(rmNode.getNodeID());
  // This can occur when an UNHEALTHY node reconnects
  if (node == null) {
    return;
  }
  Resources.subtractFrom(clusterResource, rmNode.getTotalCapability());
  updateRootQueueMetrics();

  // Remove running containers
  List<RMContainer> runningContainers = node.getRunningContainers();
  for (RMContainer container : runningContainers) {
    completedContainer(container,
        SchedulerUtils.createAbnormalContainerStatus(
            container.getContainerId(),
            SchedulerUtils.LOST_CONTAINER),
        RMContainerEventType.KILL);
  }

  // Remove reservations, if any
  RMContainer reservedContainer = node.getReservedContainer();
  if (reservedContainer != null) {
    completedContainer(reservedContainer,
        SchedulerUtils.createAbnormalContainerStatus(
            reservedContainer.getContainerId(),
            SchedulerUtils.LOST_CONTAINER),
        RMContainerEventType.KILL);
  }

  nodes.remove(rmNode.getNodeID());
  queueMgr.getRootQueue().setSteadyFairShare(clusterResource);
  queueMgr.getRootQueue().recomputeSteadyShares();
  updateMaximumAllocation(node, false);
  LOG.info("Removed node " + rmNode.getNodeAddress() +
      " cluster capacity: " + clusterResource);
}
 
Example 26
Source Project: hadoop   Source File: CSAssignment.java    License: Apache License 2.0 5 votes vote down vote up
public CSAssignment(FiCaSchedulerApp application, RMContainer excessReservation) {
  this.resource = excessReservation.getContainer().getResource();
  this.type = NodeType.NODE_LOCAL;
  this.application = application;
  this.excessReservation = excessReservation;
  this.skipped = false;
}
 
Example 27
Source Project: hadoop   Source File: TestContainerAllocation.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testContainerTokenGeneratedOnPullRequest() throws Exception {
  MockRM rm1 = new MockRM(conf);
  rm1.start();
  MockNM nm1 = rm1.registerNode("127.0.0.1:1234", 8000);
  RMApp app1 = rm1.submitApp(200);
  MockAM am1 = MockRM.launchAndRegisterAM(app1, rm1, nm1);
  // request a container.
  am1.allocate("127.0.0.1", 1024, 1, new ArrayList<ContainerId>());
  ContainerId containerId2 =
      ContainerId.newContainerId(am1.getApplicationAttemptId(), 2);
  rm1.waitForState(nm1, containerId2, RMContainerState.ALLOCATED);

  RMContainer container =
      rm1.getResourceScheduler().getRMContainer(containerId2);
  // no container token is generated.
  Assert.assertEquals(containerId2, container.getContainerId());
  Assert.assertNull(container.getContainer().getContainerToken());

  // acquire the container.
  List<Container> containers =
      am1.allocate(new ArrayList<ResourceRequest>(),
        new ArrayList<ContainerId>()).getAllocatedContainers();
  Assert.assertEquals(containerId2, containers.get(0).getId());
  // container token is generated.
  Assert.assertNotNull(containers.get(0).getContainerToken());
  rm1.stop();
}
 
Example 28
Source Project: hadoop   Source File: FSAppAttempt.java    License: Apache License 2.0 5 votes vote down vote up
synchronized public void containerCompleted(RMContainer rmContainer,
    ContainerStatus containerStatus, RMContainerEventType event) {
  
  Container container = rmContainer.getContainer();
  ContainerId containerId = container.getId();
  
  // Remove from the list of newly allocated containers if found
  newlyAllocatedContainers.remove(rmContainer);
  
  // Inform the container
  rmContainer.handle(
      new RMContainerFinishedEvent(
          containerId,
          containerStatus, 
          event)
      );
  LOG.info("Completed container: " + rmContainer.getContainerId() + 
      " in state: " + rmContainer.getState() + " event:" + event);
  
  // Remove from the list of containers
  liveContainers.remove(rmContainer.getContainerId());

  RMAuditLogger.logSuccess(getUser(), 
      AuditConstants.RELEASE_CONTAINER, "SchedulerApp", 
      getApplicationId(), containerId);
  
  // Update usage metrics 
  Resource containerResource = rmContainer.getContainer().getResource();
  queue.getMetrics().releaseResources(getUser(), 1, containerResource);
  this.attemptResourceUsage.decUsed(containerResource);

  // remove from preemption map if it is completed
  preemptionMap.remove(rmContainer);

  // Clear resource utilization metrics cache.
  lastMemoryAggregateAllocationUpdateTime = -1;
}
 
Example 29
Source Project: big-c   Source File: FiCaSchedulerApp.java    License: Apache License 2.0 5 votes vote down vote up
public synchronized boolean unreserve(FiCaSchedulerNode node, Priority priority) {
  Map<NodeId, RMContainer> reservedContainers =
    this.reservedContainers.get(priority);

  if (reservedContainers != null) {
    RMContainer reservedContainer = reservedContainers.remove(node.getNodeID());

    // unreserve is now triggered in new scenarios (preemption)
    // as a consequence reservedcontainer might be null, adding NP-checks
    if (reservedContainer != null
        && reservedContainer.getContainer() != null
        && reservedContainer.getContainer().getResource() != null) {

      if (reservedContainers.isEmpty()) {
        this.reservedContainers.remove(priority);
      }
      // Reset the re-reservation count
      resetReReservations(priority);

      Resource resource = reservedContainer.getContainer().getResource();
      Resources.subtractFrom(currentReservation, resource);

      LOG.info("Application " + getApplicationId() + " unreserved "
          + " on node " + node + ", currently has " + reservedContainers.size()
          + " at priority " + priority + "; currentReservation "
          + currentReservation);
      return true;
    }
  }
  return false;
}
 
Example 30
Source Project: hadoop   Source File: MockRM.java    License: Apache License 2.0 5 votes vote down vote up
public boolean waitForState(MockNM nm, ContainerId containerId,
    RMContainerState containerState, int timeoutMillisecs) throws Exception {
  RMContainer container = getResourceScheduler().getRMContainer(containerId);
  int timeoutSecs = 0;
  while(container == null && timeoutSecs++ < timeoutMillisecs / 100) {
    nm.nodeHeartbeat(true);
    container = getResourceScheduler().getRMContainer(containerId);
    System.out.println("Waiting for container " + containerId + " to be allocated.");
    Thread.sleep(100);
    
    if (timeoutMillisecs <= timeoutSecs * 100) {
      return false;
    }
  }
  Assert.assertNotNull("Container shouldn't be null", container);
  while (!containerState.equals(container.getState())
      && timeoutSecs++ < timeoutMillisecs / 100) {
    System.out.println("Container : " + containerId + " State is : "
        + container.getState() + " Waiting for state : " + containerState);
    nm.nodeHeartbeat(true);
    Thread.sleep(100);
    
    if (timeoutMillisecs <= timeoutSecs * 100) {
      return false;
    }
  }
  
  System.out.println("Container State is : " + container.getState());
  Assert.assertEquals("Container state is not correct (timedout)",
    containerState, container.getState());
  return true;
}