Class PlacementConstraints

java.lang.Object
org.apache.hadoop.yarn.api.resource.PlacementConstraints

@Public @Unstable public final class PlacementConstraints extends Object
This class contains various static methods for the applications to create placement constraints (see also PlacementConstraint).
  • Field Details

  • Method Details

    • targetIn

      public static PlacementConstraint.AbstractConstraint targetIn(String scope, PlacementConstraint.TargetExpression... targetExpressions)
      Creates a constraint that requires allocations to be placed on nodes that satisfy all target expressions within the given scope (e.g., node or rack). For example, targetIn(RACK, allocationTag("hbase-m")), allows allocations on nodes that belong to a rack that has at least one tag with value "hbase-m".
      Parameters:
      scope - the scope within which the target expressions should be satisfied
      targetExpressions - the expressions that need to be satisfied within the scope
      Returns:
      the resulting placement constraint
    • targetNotIn

      public static PlacementConstraint.AbstractConstraint targetNotIn(String scope, PlacementConstraint.TargetExpression... targetExpressions)
      Creates a constraint that requires allocations to be placed on nodes that belong to a scope (e.g., node or rack) that does not satisfy any of the target expressions.
      Parameters:
      scope - the scope within which the target expressions should not be true
      targetExpressions - the expressions that need to not be true within the scope
      Returns:
      the resulting placement constraint
    • targetNodeAttribute

      public static PlacementConstraint.AbstractConstraint targetNodeAttribute(String scope, NodeAttributeOpCode opCode, PlacementConstraint.TargetExpression... targetExpressions)
      Creates a constraint that requires allocations to be placed on nodes that belong to a scope (e.g., node or rack) that satisfy any of the target expressions based on node attribute op code.
      Parameters:
      scope - the scope within which the target expressions should not be true
      opCode - Node Attribute code which could be equals, not equals.
      targetExpressions - the expressions that need to not be true within the scope
      Returns:
      the resulting placement constraint
    • cardinality

      public static PlacementConstraint.AbstractConstraint cardinality(String scope, int minCardinality, int maxCardinality, String... allocationTags)
      Creates a constraint that restricts the number of allocations within a given scope (e.g., node or rack). For example, cardinality(NODE, 3, 10, "zk") is satisfied on nodes where there are no less than 3 allocations with tag "zk" and no more than 10.
      Parameters:
      scope - the scope of the constraint
      minCardinality - determines the minimum number of allocations within the scope
      maxCardinality - determines the maximum number of allocations within the scope
      allocationTags - the constraint targets allocations with these tags
      Returns:
      the resulting placement constraint
    • cardinality

      public static PlacementConstraint.AbstractConstraint cardinality(String scope, String namespace, int minCardinality, int maxCardinality, String... allocationTags)
      Similar to cardinality(String, int, int, String...), but let you attach a namespace to the given allocation tags.
      Parameters:
      scope - the scope of the constraint
      namespace - the namespace of the allocation tags
      minCardinality - determines the minimum number of allocations within the scope
      maxCardinality - determines the maximum number of allocations within the scope
      allocationTags - allocation tags
      Returns:
      the resulting placement constraint
    • minCardinality

      public static PlacementConstraint.AbstractConstraint minCardinality(String scope, int minCardinality, String... allocationTags)
      Similar to cardinality(String, int, int, String...), but determines only the minimum cardinality (the maximum cardinality is unbound).
      Parameters:
      scope - the scope of the constraint
      minCardinality - determines the minimum number of allocations within the scope
      allocationTags - the constraint targets allocations with these tags
      Returns:
      the resulting placement constraint
    • minCardinality

      public static PlacementConstraint.AbstractConstraint minCardinality(String scope, String namespace, int minCardinality, String... allocationTags)
      Similar to minCardinality(String, int, String...), but let you attach a namespace to the allocation tags.
      Parameters:
      scope - the scope of the constraint
      namespace - the namespace of these tags
      minCardinality - determines the minimum number of allocations within the scope
      allocationTags - the constraint targets allocations with these tags
      Returns:
      the resulting placement constraint
    • maxCardinality

      public static PlacementConstraint.AbstractConstraint maxCardinality(String scope, int maxCardinality, String... allocationTags)
      Similar to cardinality(String, int, int, String...), but determines only the maximum cardinality (the minimum cardinality is 0).
      Parameters:
      scope - the scope of the constraint
      maxCardinality - determines the maximum number of allocations within the scope
      allocationTags - the constraint targets allocations with these tags
      Returns:
      the resulting placement constraint
    • maxCardinality

      public static PlacementConstraint.AbstractConstraint maxCardinality(String scope, String tagNamespace, int maxCardinality, String... allocationTags)
      Similar to maxCardinality(String, int, String...), but let you specify a namespace for the tags, see supported namespaces in AllocationTagNamespaceType.
      Parameters:
      scope - the scope of the constraint
      tagNamespace - the namespace of these tags
      maxCardinality - determines the maximum number of allocations within the scope
      allocationTags - allocation tags
      Returns:
      the resulting placement constraint
    • targetCardinality

      public static PlacementConstraint.AbstractConstraint targetCardinality(String scope, int minCardinality, int maxCardinality, PlacementConstraint.TargetExpression... targetExpressions)
      This constraint generalizes the cardinality and target constraints. Consider a set of nodes N that belongs to the scope specified in the constraint. If the target expressions are satisfied at least minCardinality times and at most maxCardinality times in the node set N, then the constraint is satisfied. For example, targetCardinality(RACK, 2, 10, allocationTag("zk")), requires an allocation to be placed within a rack that has at least 2 and at most 10 other allocations with tag "zk".
      Parameters:
      scope - the scope of the constraint
      minCardinality - the minimum number of times the target expressions have to be satisfied with the given scope
      maxCardinality - the maximum number of times the target expressions have to be satisfied with the given scope
      targetExpressions - the target expressions
      Returns:
      the resulting placement constraint
    • and

      A conjunction of constraints.
      Parameters:
      children - the children constraints that should all be satisfied
      Returns:
      the resulting placement constraint
    • or

      A disjunction of constraints.
      Parameters:
      children - the children constraints, one of which should be satisfied
      Returns:
      the resulting placement constraint
    • delayedOr

      Creates a composite constraint that includes a list of timed placement constraints. The scheduler should try to satisfy first the first timed child constraint within the specified time window. If this is not possible, it should attempt to satisfy the second, and so on.
      Parameters:
      children - the timed children constraints
      Returns:
      the resulting composite constraint
    • timedClockConstraint

      public static PlacementConstraint.TimedPlacementConstraint timedClockConstraint(PlacementConstraint.AbstractConstraint constraint, long delay, TimeUnit timeUnit)
      Creates a placement constraint that has to be satisfied within a time window.
      Parameters:
      constraint - the placement constraint
      delay - the length of the time window within which the constraint has to be satisfied
      timeUnit - the unit of time of the time window
      Returns:
      the resulting timed placement constraint
    • timedOpportunitiesConstraint

      public static PlacementConstraint.TimedPlacementConstraint timedOpportunitiesConstraint(PlacementConstraint.AbstractConstraint constraint, long delay)
      Creates a placement constraint that has to be satisfied within a number of placement opportunities (invocations of the scheduler).
      Parameters:
      constraint - the placement constraint
      delay - the number of scheduling opportunities within which the constraint has to be satisfied
      Returns:
      the resulting timed placement constraint
    • build

      public static PlacementConstraint build(PlacementConstraint.AbstractConstraint constraintExpr)
      Creates a PlacementConstraint given a constraint expression.
      Parameters:
      constraintExpr - the constraint expression
      Returns:
      the placement constraint