Examples of AllocateResponse


Examples of org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse

    }
  }

  @Test
  public void testAllocateResponseWithoutIncDecContainers() {
    AllocateResponse r =
        AllocateResponse.newInstance(3, new ArrayList<ContainerStatus>(),
            new ArrayList<Container>(), new ArrayList<NodeReport>(), null,
            AMCommand.AM_RESYNC, 3, null, new ArrayList<NMToken>(), null, null);

    // serde
    AllocateResponseProto p = ((AllocateResponsePBImpl) r).getProto();
    r = new AllocateResponsePBImpl(p);

    // check value
    Assert.assertEquals(0, r.getIncreasedContainers().size());
    Assert.assertEquals(0, r.getDecreasedContainers().size());
  }
View Full Code Here

Examples of org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse

    // create app and launch the AM
    RMApp app0 = rm1.submitApp(200);
    MockAM am0 = launchAM(app0, rm1, nm1);

    // alloc another container on nm2
    AllocateResponse allocResponse =
        am0.allocate(Arrays.asList(ResourceRequest.newInstance(
            Priority.newInstance(1), "*", Resource.newInstance(1024, 0), 1)),
            null);
    while (null == allocResponse.getAllocatedContainers()
        || allocResponse.getAllocatedContainers().isEmpty()) {
      nm2.nodeHeartbeat(true);
      allocResponse = am0.allocate(null, null);
      Thread.sleep(1000);
    }

View Full Code Here

Examples of org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse

      int containers) throws Exception {
    requests.addAll(createReq(hosts, memory, priority, containers));
  }

  public AllocateResponse schedule() throws Exception {
    AllocateResponse response = allocate(requests, releases);
    requests.clear();
    releases.clear();
    return response;
  }
View Full Code Here

Examples of org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse

            new ArrayList<String>(blacklistRemovals));
    AllocateRequest allocateRequest =
        AllocateRequest.newInstance(lastResponseID,
          super.getApplicationProgress(), new ArrayList<ResourceRequest>(ask),
          new ArrayList<ContainerId>(release), blacklistRequest);
    AllocateResponse allocateResponse;
    try {
      allocateResponse = scheduler.allocate(allocateRequest);
    } catch (YarnException e) {
      throw new IOException(e);
    }
    lastResponseID = allocateResponse.getResponseId();
    availableResources = allocateResponse.getAvailableResources();
    lastClusterNmCount = clusterNmCount;
    clusterNmCount = allocateResponse.getNumClusterNodes();

    if (ask.size() > 0 || release.size() > 0) {
      LOG.info("getResources() for " + applicationId + ":" + " ask="
          + ask.size() + " release= " + release.size() + " newContainers="
          + allocateResponse.getAllocatedContainers().size()
          + " finishedContainers="
          + allocateResponse.getCompletedContainersStatuses().size()
          + " resourcelimit=" + availableResources + " knownNMs="
          + clusterNmCount);
    }

    ask.clear();
View Full Code Here

Examples of org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse

 
  @SuppressWarnings("unchecked")
  private List<Container> getResources() throws Exception {
    int headRoom = getAvailableResources() != null
        ? getAvailableResources().getMemory() : 0;//first time it would be null
    AllocateResponse response;
    /*
     * If contact with RM is lost, the AM will wait MR_AM_TO_RM_WAIT_INTERVAL_MS
     * milliseconds before aborting. During this interval, AM will still try
     * to contact the RM.
     */
    try {
      response = makeRemoteRequest();
      // Reset retry count if no exception occurred.
      retrystartTime = System.currentTimeMillis();
    } catch (Exception e) {
      // This can happen when the connection to the RM has gone down. Keep
      // re-trying until the retryInterval has expired.
      if (System.currentTimeMillis() - retrystartTime >= retryInterval) {
        LOG.error("Could not contact RM after " + retryInterval + " milliseconds.");
        eventHandler.handle(new JobEvent(this.getJob().getID(),
                                         JobEventType.INTERNAL_ERROR));
        throw new YarnRuntimeException("Could not contact RM after " +
                                retryInterval + " milliseconds.");
      }
      // Throw this up to the caller, which may decide to ignore it and
      // continue to attempt to contact the RM.
      throw e;
    }
    if (response.getAMCommand() != null) {
      switch(response.getAMCommand()) {
      case AM_RESYNC:
      case AM_SHUTDOWN:
        // This can happen if the RM has been restarted. If it is in that state,
        // this application must clean itself up.
        eventHandler.handle(new JobEvent(this.getJob().getID(),
                                         JobEventType.JOB_AM_REBOOT));
        throw new YarnRuntimeException("Resource Manager doesn't recognize AttemptId: " +
                                 this.getContext().getApplicationID());
      default:
        String msg =
              "Unhandled value of AMCommand: " + response.getAMCommand();
        LOG.error(msg);
        throw new YarnRuntimeException(msg);
      }
    }
    int newHeadRoom = getAvailableResources() != null ? getAvailableResources().getMemory() : 0;
    List<Container> newContainers = response.getAllocatedContainers();
    // Setting NMTokens
    if (response.getNMTokens() != null) {
      for (NMToken nmToken : response.getNMTokens()) {
        NMTokenCache.setNMToken(nmToken.getNodeId().toString(),
            nmToken.getToken());
      }
    }
   
    List<ContainerStatus> finishedContainers = response.getCompletedContainersStatuses();
    if (newContainers.size() + finishedContainers.size() > 0 || headRoom != newHeadRoom) {
      //something changed
      recalculateReduceSchedule = true;
      if (LOG.isDebugEnabled() && headRoom != newHeadRoom) {
        LOG.debug("headroom=" + newHeadRoom);
View Full Code Here

Examples of org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse

    MockAM am1 = rm.sendAMLaunched(attempt1.getAppAttemptId());
    am1.registerAppAttempt();

    LOG.info("sending container requests ");
    am1.addRequests(new String[] {"*"}, 3 * GB, 1, 1);
    AllocateResponse alloc1Response = am1.schedule(); // send the request

    // kick the scheduler
    nm1.nodeHeartbeat(true);
    int waitCounter = 20;
    LOG.info("heartbeating nm1");
    while (alloc1Response.getAllocatedContainers().size() < 1
        && waitCounter-- > 0) {
      LOG.info("Waiting for containers to be created for app 1...");
      Thread.sleep(500);
      alloc1Response = am1.schedule();
    }
    LOG.info("received container : "
        + alloc1Response.getAllocatedContainers().size());

    // No container should be allocated.
    // Internally it should not been reserved.
    Assert.assertTrue(alloc1Response.getAllocatedContainers().size() == 0);

    LOG.info("heartbeating nm2");
    waitCounter = 20;
    nm2.nodeHeartbeat(true);
    while (alloc1Response.getAllocatedContainers().size() < 1
        && waitCounter-- > 0) {
      LOG.info("Waiting for containers to be created for app 1...");
      Thread.sleep(500);
      alloc1Response = am1.schedule();
    }
    LOG.info("received container : "
        + alloc1Response.getAllocatedContainers().size());
    Assert.assertTrue(alloc1Response.getAllocatedContainers().size() == 1);

    rm.stop();
  }
View Full Code Here

Examples of org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse

        log.debug("ApplicationAttemptId not set, delaying poll requests.");
      }
      return result;
    }

    AllocateResponse response = doContainerRequest();

    // for now just stash tokens into hadoops NMTokenCache
    if (!response.getNMTokens().isEmpty()) {
      populateNmTokenCache(response);
    }

    List<Container> allocatedContainers = preProcessAllocatedContainers(response.getAllocatedContainers());
    if(allocatedContainers != null && allocatedContainers.size() > 0) {
      if (log.isDebugEnabled()){
        log.debug("response has " + allocatedContainers.size() + " new containers");
        for (Container c : allocatedContainers) {
          log.debug("new container: " + c.getId());
        }
      }
      handleAllocatedContainers(allocatedContainers);
      if(getYarnEventPublisher() != null) {
        for(Container container : allocatedContainers) {
          getYarnEventPublisher().publishContainerAllocated(this, container);
        }
      }
      result = true;
    }

    List<ContainerStatus> containerStatuses = response.getCompletedContainersStatuses();
    if(containerStatuses != null && containerStatuses.size() > 0) {
      if (log.isDebugEnabled()) {
        log.debug("response has " + containerStatuses.size() + " completed containers");
        for (ContainerStatus cs : containerStatuses) {
          log.debug("completed container: " + cs.getContainerId() + " with status=" + cs);
View Full Code Here

Examples of org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse

        request.setAskList(requestedContainers);
        request.setReleaseList(release);
        request.setProgress(applicationProgress);

        // do request and return response
        AllocateResponse allocate = getRmTemplate().allocate(request);
        requestId.set(allocate.getResponseId());
        return allocate;
    }
View Full Code Here

Examples of org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse

    }
    for (ContainerId id : releasedContainers) {
      LOG.info("Released container, id=" + id.getId());
    }

    AllocateResponse resp = resourceManager.allocate(req);
    return resp.getAMResponse();
  }
View Full Code Here

Examples of org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse

  public AMResponse allocate(
      List<ResourceRequest> resourceRequest, List<ContainerId> releases)
      throws Exception {
    AllocateRequest req = BuilderUtils.newAllocateRequest(attemptId,
        ++responseId, 0F, resourceRequest, releases);
    AllocateResponse resp = amRMProtocol.allocate(req);
    return resp.getAMResponse();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.