Java Code Examples for org.apache.hadoop.yarn.api.records.ResourceRequest#getCapability()

The following examples show how to use org.apache.hadoop.yarn.api.records.ResourceRequest#getCapability() . 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: FifoScheduler.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private int assignContainer(FiCaSchedulerNode node, FiCaSchedulerApp application, 
    Priority priority, int assignableContainers, 
    ResourceRequest request, NodeType type) {
  LOG.debug("assignContainers:" +
      " node=" + node.getRMNode().getNodeAddress() + 
      " application=" + application.getApplicationId().getId() + 
      " priority=" + priority.getPriority() + 
      " assignableContainers=" + assignableContainers +
      " request=" + request + " type=" + type);
  Resource capability = request.getCapability();

  int availableContainers = 
    node.getAvailableResource().getMemory() / capability.getMemory(); // TODO: A buggy
                                                                      // application
                                                                      // with this
                                                                      // zero would
                                                                      // crash the
                                                                      // scheduler.
  int assignedContainers = 
    Math.min(assignableContainers, availableContainers);

  if (assignedContainers > 0) {
    for (int i=0; i < assignedContainers; ++i) {

      NodeId nodeId = node.getRMNode().getNodeID();
      ContainerId containerId = BuilderUtils.newContainerId(application
          .getApplicationAttemptId(), application.getNewContainerId());

      // Create the container
      Container container =
          BuilderUtils.newContainer(containerId, nodeId, node.getRMNode()
            .getHttpAddress(), capability, priority, null);
      
      // Allocate!
      
      // Inform the application
      RMContainer rmContainer =
          application.allocate(type, node, priority, request, container);
      
      // Inform the node
      node.allocateContainer(rmContainer);

      // Update usage for this container
      increaseUsedResources(rmContainer);
    }

  }
  
  return assignedContainers;
}
 
Example 2
Source File: FSAppAttempt.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Assign a container to this node to facilitate {@code request}. If node does
 * not have enough memory, create a reservation. This is called once we are
 * sure the particular request should be facilitated by this node.
 *
 * @param node
 *     The node to try placing the container on.
 * @param request
 *     The ResourceRequest we're trying to satisfy.
 * @param type
 *     The locality of the assignment.
 * @param reserved
 *     Whether there's already a container reserved for this app on the node.
 * @return
 *     If an assignment was made, returns the resources allocated to the
 *     container.  If a reservation was made, returns
 *     FairScheduler.CONTAINER_RESERVED.  If no assignment or reservation was
 *     made, returns an empty resource.
 */
private Resource assignContainer(
    FSSchedulerNode node, ResourceRequest request, NodeType type,
    boolean reserved) {

  // How much does this request need?
  Resource capability = request.getCapability();

  // How much does the node have?
  Resource available = node.getAvailableResource();

  Container container = null;
  if (reserved) {
    container = node.getReservedContainer().getContainer();
  } else {
    container = createContainer(node, capability, request.getPriority());
  }

  // Can we allocate a container on this node?
  if (Resources.fitsIn(capability, available)) {
    // Inform the application of the new container for this request
    RMContainer allocatedContainer =
        allocate(type, node, request.getPriority(), request, container);
    if (allocatedContainer == null) {
      // Did the application need this resource?
      if (reserved) {
        unreserve(request.getPriority(), node);
      }
      return Resources.none();
    }

    // If we had previously made a reservation, delete it
    if (reserved) {
      unreserve(request.getPriority(), node);
    }

    // Inform the node
    node.allocateContainer(allocatedContainer);

    // If this container is used to run AM, update the leaf queue's AM usage
    if (getLiveContainers().size() == 1 && !getUnmanagedAM()) {
      getQueue().addAMResourceUsage(container.getResource());
      setAmRunning(true);
    }

    return container.getResource();
  } else {
    if (!FairScheduler.fitsInMaxShare(getQueue(), capability)) {
      return Resources.none();
    }

    // The desired container won't fit here, so reserve
    reserve(request.getPriority(), node, container, reserved);

    return FairScheduler.CONTAINER_RESERVED;
  }
}
 
Example 3
Source File: AppSchedulingInfo.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public synchronized Resource getResource(Priority priority) {
  ResourceRequest request = getResourceRequest(priority, ResourceRequest.ANY);
  return (request == null) ? null : request.getCapability();
}
 
Example 4
Source File: FifoScheduler.java    From big-c with Apache License 2.0 4 votes vote down vote up
private int assignContainer(FiCaSchedulerNode node, FiCaSchedulerApp application, 
    Priority priority, int assignableContainers, 
    ResourceRequest request, NodeType type) {
  LOG.debug("assignContainers:" +
      " node=" + node.getRMNode().getNodeAddress() + 
      " application=" + application.getApplicationId().getId() + 
      " priority=" + priority.getPriority() + 
      " assignableContainers=" + assignableContainers +
      " request=" + request + " type=" + type);
  Resource capability = request.getCapability();

  int availableContainers = 
    node.getAvailableResource().getMemory() / capability.getMemory(); // TODO: A buggy
                                                                      // application
                                                                      // with this
                                                                      // zero would
                                                                      // crash the
                                                                      // scheduler.
  int assignedContainers = 
    Math.min(assignableContainers, availableContainers);

  if (assignedContainers > 0) {
    for (int i=0; i < assignedContainers; ++i) {

      NodeId nodeId = node.getRMNode().getNodeID();
      ContainerId containerId = BuilderUtils.newContainerId(application
          .getApplicationAttemptId(), application.getNewContainerId());

      // Create the container
      Container container =
          BuilderUtils.newContainer(containerId, nodeId, node.getRMNode()
            .getHttpAddress(), capability, priority, null);
      
      // Allocate!
      
      // Inform the application
      RMContainer rmContainer =
          application.allocate(type, node, priority, request, container);
      
      // Inform the node
      node.allocateContainer(rmContainer);

      // Update usage for this container
      increaseUsedResources(rmContainer);
    }

  }
  
  return assignedContainers;
}
 
Example 5
Source File: FSAppAttempt.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Assign a container to this node to facilitate {@code request}. If node does
 * not have enough memory, create a reservation. This is called once we are
 * sure the particular request should be facilitated by this node.
 *
 * @param node
 *     The node to try placing the container on.
 * @param request
 *     The ResourceRequest we're trying to satisfy.
 * @param type
 *     The locality of the assignment.
 * @param reserved
 *     Whether there's already a container reserved for this app on the node.
 * @return
 *     If an assignment was made, returns the resources allocated to the
 *     container.  If a reservation was made, returns
 *     FairScheduler.CONTAINER_RESERVED.  If no assignment or reservation was
 *     made, returns an empty resource.
 */
private Resource assignContainer(
    FSSchedulerNode node, ResourceRequest request, NodeType type,
    boolean reserved) {

  // How much does this request need?
  Resource capability = request.getCapability();

  // How much does the node have?
  Resource available = node.getAvailableResource();

  Container container = null;
  if (reserved) {
    container = node.getReservedContainer().getContainer();
  } else {
    container = createContainer(node, capability, request.getPriority());
  }

  // Can we allocate a container on this node?
  if (Resources.fitsIn(capability, available)) {
    // Inform the application of the new container for this request
    RMContainer allocatedContainer =
        allocate(type, node, request.getPriority(), request, container);
    if (allocatedContainer == null) {
      // Did the application need this resource?
      if (reserved) {
        unreserve(request.getPriority(), node);
      }
      return Resources.none();
    }

    // If we had previously made a reservation, delete it
    if (reserved) {
      unreserve(request.getPriority(), node);
    }

    // Inform the node
    node.allocateContainer(allocatedContainer);

    // If this container is used to run AM, update the leaf queue's AM usage
    if (getLiveContainers().size() == 1 && !getUnmanagedAM()) {
      getQueue().addAMResourceUsage(container.getResource());
      setAmRunning(true);
    }

    return container.getResource();
  } else {
    if (!FairScheduler.fitsInMaxShare(getQueue(), capability)) {
      return Resources.none();
    }

    // The desired container won't fit here, so reserve
    reserve(request.getPriority(), node, container, reserved);

    return FairScheduler.CONTAINER_RESERVED;
  }
}
 
Example 6
Source File: AppSchedulingInfo.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**还没有弄明白
 * The ApplicationMaster is updating resource requirements for the
 * application, by asking for more resources and releasing resources acquired
 * by the application.
 * 如果是recover的话表明该资源被请求过,现在只不过是被抢占了,所以需要RM重新分配资源
 *
 * @param requests resources to be acquired
 * @param recoverPreemptedRequest recover Resource Request on preemption
 */
synchronized public void updateResourceRequests(
    List<ResourceRequest> requests, boolean recoverPreemptedRequest) {
  QueueMetrics metrics = queue.getMetrics();
  
  // Update resource requests
  for (ResourceRequest request : requests) {
    Priority priority = request.getPriority();
    String resourceName = request.getResourceName();
    boolean updatePendingResources = false;
    ResourceRequest lastRequest = null;

    if (resourceName.equals(ResourceRequest.ANY)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("update:" + " application=" + applicationId + " request="
            + request);
      }
      updatePendingResources = true;
      
      // Premature optimization?
      // Assumes that we won't see more than one priority request updated
      // in one call, reasonable assumption... however, it's totally safe
      // to activate same application more than once.
      // Thus we don't need another loop ala the one in decrementOutstanding()  
      // which is needed during deactivate.
      if (request.getNumContainers() > 0) {
        activeUsersManager.activateApplication(user, applicationId);
      }
    }

    Map<String, ResourceRequest> asks = this.requests.get(priority);

    if (asks == null) {                      //在该优先级还没有请求,所以新建一个请求
      asks = new ConcurrentHashMap<String, ResourceRequest>();
      this.requests.put(priority, asks);
      this.priorities.add(priority);
    }
    lastRequest = asks.get(resourceName);    //上一次的请求

    if (recoverPreemptedRequest && lastRequest != null) {
      // Increment the number of containers to 1, as it is recovering a
      // single container.
      request.setNumContainers(lastRequest.getNumContainers() + 1);
    }

    asks.put(resourceName, request);
    if (updatePendingResources) {
      
      // Similarly, deactivate application?
      if (request.getNumContainers() <= 0) {
        LOG.info("checking for deactivate of application :"
            + this.applicationId);
        checkForDeactivation();
      }
      
      int lastRequestContainers = lastRequest != null ? lastRequest
          .getNumContainers() : 0;
      Resource lastRequestCapability = lastRequest != null ? lastRequest
          .getCapability() : Resources.none();
      metrics.incrPendingResources(user, request.getNumContainers(),
          request.getCapability());
      metrics.decrPendingResources(user, lastRequestContainers,
          lastRequestCapability);
    }
  }
}
 
Example 7
Source File: AppSchedulingInfo.java    From big-c with Apache License 2.0 4 votes vote down vote up
public synchronized Resource getResource(Priority priority) {
  ResourceRequest request = getResourceRequest(priority, ResourceRequest.ANY);
  return (request == null) ? null : request.getCapability();
}