Class ResourceRequest

java.lang.Object
org.apache.hadoop.yarn.api.records.ResourceRequest
All Implemented Interfaces:
Comparable<ResourceRequest>

@Public @Stable public abstract class ResourceRequest extends Object implements Comparable<ResourceRequest>
ResourceRequest represents the request made by an application to the ResourceManager to obtain various Container allocations.

It includes:

  • Priority of the request.
  • The name of the host or rack on which the allocation is desired. A special value of * signifies that any host/rack is acceptable to the application.
  • Resource required for each request.
  • Number of containers, of above specifications, which are required by the application.
  • A boolean relaxLocality flag, defaulting to true, which tells the ResourceManager if the application wants locality to be loose (i.e. allows fall-through to rack or any) or strict (i.e. specify hard constraint on resource allocation).
See Also:
  • Field Details

    • ANY

      public static final String ANY
      The constant string representing no locality. It should be used by all references that want to pass an arbitrary host name in.
      See Also:
  • Constructor Details

    • ResourceRequest

      public ResourceRequest()
  • Method Details

    • newInstance

      @Public @Stable public static ResourceRequest newInstance(Priority priority, String hostName, Resource capability, int numContainers)
    • newInstance

      @Public @Stable public static ResourceRequest newInstance(Priority priority, String hostName, Resource capability, int numContainers, boolean relaxLocality)
    • newInstance

      @Public @Stable public static ResourceRequest newInstance(Priority priority, String hostName, Resource capability, int numContainers, boolean relaxLocality, String labelExpression)
    • newInstance

      @Public @Evolving public static ResourceRequest newInstance(Priority priority, String hostName, Resource capability, int numContainers, boolean relaxLocality, String labelExpression, ExecutionTypeRequest executionTypeRequest)
    • clone

      @Public @Evolving public static ResourceRequest clone(ResourceRequest rr)
      Clone a ResourceRequest object (shallow copy). Please keep it loaded with all (new) fields
      Parameters:
      rr - the object to copy from
      Returns:
      the copied object
    • newBuilder

      @Public @Unstable public static ResourceRequest.ResourceRequestBuilder newBuilder()
    • isAnyLocation

      @Public @Stable public static boolean isAnyLocation(String hostName)
      Check whether the given host/rack string represents an arbitrary host name.
      Parameters:
      hostName - host/rack on which the allocation is desired
      Returns:
      whether the given host/rack string represents an arbitrary host name
    • getPriority

      @Public @Stable public abstract Priority getPriority()
      Get the Priority of the request.
      Returns:
      Priority of the request
    • setPriority

      @Public @Stable public abstract void setPriority(Priority priority)
      Set the Priority of the request
      Parameters:
      priority - Priority of the request
    • getResourceName

      @Public @Stable public abstract String getResourceName()
      Get the resource (e.g. host/rack) on which the allocation is desired. A special value of * signifies that any resource (host/rack) is acceptable.
      Returns:
      resource (e.g. host/rack) on which the allocation is desired
    • setResourceName

      @Public @Stable public abstract void setResourceName(String resourceName)
      Set the resource name (e.g. host/rack) on which the allocation is desired. A special value of * signifies that any resource name (e.g. host/rack) is acceptable.
      Parameters:
      resourceName - (e.g. host/rack) on which the allocation is desired
    • getNumContainers

      @Public @Stable public abstract int getNumContainers()
      Get the number of containers required with the given specifications.
      Returns:
      number of containers required with the given specifications
    • setNumContainers

      @Public @Stable public abstract void setNumContainers(int numContainers)
      Set the number of containers required with the given specifications
      Parameters:
      numContainers - number of containers required with the given specifications
    • getRelaxLocality

      @Public @Stable public abstract boolean getRelaxLocality()
      Get whether locality relaxation is enabled with this ResourceRequest. Defaults to true.
      Returns:
      whether locality relaxation is enabled with this ResourceRequest.
    • setExecutionTypeRequest

      @Public @Evolving public void setExecutionTypeRequest(ExecutionTypeRequest execSpec)
      Set the ExecutionTypeRequest of the requested container.
      Parameters:
      execSpec - ExecutionTypeRequest of the requested container
    • getExecutionTypeRequest

      @Public @Evolving public ExecutionTypeRequest getExecutionTypeRequest()
      Get whether locality relaxation is enabled with this ResourceRequest. Defaults to true.
      Returns:
      whether locality relaxation is enabled with this ResourceRequest.
    • setRelaxLocality

      @Public @Stable public abstract void setRelaxLocality(boolean relaxLocality)

      For a request at a network hierarchy level, set whether locality can be relaxed to that level and beyond.

      If the flag is off on a rack-level ResourceRequest, containers at that request's priority will not be assigned to nodes on that request's rack unless requests specifically for those nodes have also been submitted.

      If the flag is off on an ANY-level ResourceRequest, containers at that request's priority will only be assigned on racks for which specific requests have also been submitted.

      For example, to request a container strictly on a specific node, the corresponding rack-level and any-level requests should have locality relaxation set to false. Similarly, to request a container strictly on a specific rack, the corresponding any-level request should have locality relaxation set to false.

      Parameters:
      relaxLocality - whether locality relaxation is enabled with this ResourceRequest.
    • getNodeLabelExpression

      @Public @Evolving public abstract String getNodeLabelExpression()
      Get node-label-expression for this Resource Request. If this is set, all containers allocated to satisfy this resource-request will be only on those nodes that satisfy this node-label-expression. Please note that node label expression now can only take effect when the resource request has resourceName = ANY
      Returns:
      node-label-expression
    • setNodeLabelExpression

      @Public @Evolving public abstract void setNodeLabelExpression(String nodelabelExpression)
      Set node label expression of this resource request. Now only support specifying a single node label. In the future we will support more complex node label expression specification like AND(&&), OR(||), etc. Any please note that node label expression now can only take effect when the resource request has resourceName = ANY
      Parameters:
      nodelabelExpression - node-label-expression of this ResourceRequest
    • getAllocationRequestId

      @Public @Evolving public long getAllocationRequestId()
      Get the optional ID corresponding to this allocation request. This ID is an identifier for different ResourceRequests from the same application. The allocated Container(s) received as part of the AllocateResponse response will have the ID corresponding to the original ResourceRequest for which the RM made the allocation.

      The scheduler may return multiple AllocateResponses corresponding to the same ID as and when scheduler allocates Container(s). Applications can continue to completely ignore the returned ID in the response and use the allocation for any of their outstanding requests.

      If one wishes to replace an entire ResourceRequest corresponding to a specific ID, they can simply cancel the corresponding ResourceRequest and submit a new one afresh.

      Returns:
      the ID corresponding to this allocation request.
    • setAllocationRequestId

      @Public @Evolving public void setAllocationRequestId(long allocationRequestID)
      Set the optional ID corresponding to this allocation request. This ID is an identifier for different ResourceRequests from the same application. The allocated Container(s) received as part of the AllocateResponse response will have the ID corresponding to the original ResourceRequest for which the RM made the allocation.

      The scheduler may return multiple AllocateResponses corresponding to the same ID as and when scheduler allocates Container(s). Applications can continue to completely ignore the returned ID in the response and use the allocation for any of their outstanding requests.

      If one wishes to replace an entire ResourceRequest corresponding to a specific ID, they can simply cancel the corresponding ResourceRequest and submit a new one afresh.

      If the ID is not set, scheduler will continue to work as previously and all allocated Container(s) will have the default ID, -1.

      Parameters:
      allocationRequestID - the ID corresponding to this allocation request.
    • setCapability

      @Public @Stable public abstract void setCapability(Resource capability)
      Set the Resource capability of the request.
      Parameters:
      capability - Resource capability of the request
    • getCapability

      @Public @Stable public abstract Resource getCapability()
      Get the Resource capability of the request.
      Returns:
      Resource capability of the request
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • compareTo

      public int compareTo(ResourceRequest other)
      Specified by:
      compareTo in interface Comparable<ResourceRequest>