Skip to content

Commit

Permalink
YARN-8002. Support NOT_SELF and ALL namespace types for allocation ta…
Browse files Browse the repository at this point in the history
…g. (Weiwei Yang via wangda)

Change-Id: I63b4e4192a95bf7ded98c54e46a2871c72869700
  • Loading branch information
wangdatan committed Mar 19, 2018
1 parent d67a5e2 commit a08921c
Show file tree
Hide file tree
Showing 20 changed files with 1,031 additions and 372 deletions.
Expand Up @@ -18,12 +18,6 @@

package org.apache.hadoop.yarn.api.records;

import org.apache.hadoop.yarn.exceptions.InvalidAllocationTagException;

import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;

/**
* Class to describe all supported forms of namespaces for an allocation tag.
*/
Expand All @@ -44,29 +38,6 @@ public String getTypeKeyword() {
return this.typeKeyword;
}

/**
* Parses the namespace type from a given string.
* @param prefix namespace prefix.
* @return namespace type.
* @throws InvalidAllocationTagException
*/
public static AllocationTagNamespaceType fromString(String prefix) throws
InvalidAllocationTagException {
for (AllocationTagNamespaceType type :
AllocationTagNamespaceType.values()) {
if(type.getTypeKeyword().equals(prefix)) {
return type;
}
}

Set<String> values = Arrays.stream(AllocationTagNamespaceType.values())
.map(AllocationTagNamespaceType::toString)
.collect(Collectors.toSet());
throw new InvalidAllocationTagException(
"Invalid namespace prefix: " + prefix
+ ", valid values are: " + String.join(",", values));
}

@Override
public String toString() {
return this.getTypeKeyword();
Expand Down

This file was deleted.

Expand Up @@ -22,7 +22,7 @@

import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.classification.InterfaceStability.Unstable;
import org.apache.hadoop.yarn.api.records.AllocationTagNamespace;
import org.apache.hadoop.yarn.api.records.AllocationTagNamespaceType;
import org.apache.hadoop.yarn.api.resource.PlacementConstraint.AbstractConstraint;
import org.apache.hadoop.yarn.api.resource.PlacementConstraint.And;
import org.apache.hadoop.yarn.api.resource.PlacementConstraint.DelayedOr;
Expand Down Expand Up @@ -107,6 +107,25 @@ public static AbstractConstraint cardinality(String scope, int minCardinality,
PlacementTargets.allocationTag(allocationTags));
}

/**
* Similar to {@link #cardinality(String, int, int, String...)}, but let you
* attach a namespace to the given allocation tags.
*
* @param scope the scope of the constraint
* @param namespace the namespace of the allocation tags
* @param minCardinality determines the minimum number of allocations within
* the scope
* @param maxCardinality determines the maximum number of allocations within
* the scope
* @param allocationTags allocation tags
* @return the resulting placement constraint
*/
public static AbstractConstraint cardinality(String scope, String namespace,
int minCardinality, int maxCardinality, String... allocationTags) {
return new SingleConstraint(scope, minCardinality, maxCardinality,
PlacementTargets.allocationTagWithNamespace(namespace, allocationTags));
}

/**
* Similar to {@link #cardinality(String, int, int, String...)}, but
* determines only the minimum cardinality (the maximum cardinality is
Expand All @@ -124,6 +143,23 @@ public static AbstractConstraint minCardinality(String scope,
allocationTags);
}

/**
* Similar to {@link #minCardinality(String, int, String...)}, but let you
* attach a namespace to the allocation tags.
*
* @param scope the scope of the constraint
* @param namespace the namespace of these tags
* @param minCardinality determines the minimum number of allocations within
* the scope
* @param allocationTags the constraint targets allocations with these tags
* @return the resulting placement constraint
*/
public static AbstractConstraint minCardinality(String scope,
String namespace, int minCardinality, String... allocationTags) {
return cardinality(scope, namespace, minCardinality, Integer.MAX_VALUE,
allocationTags);
}

/**
* Similar to {@link #cardinality(String, int, int, String...)}, but
* determines only the maximum cardinality (the minimum cardinality is 0).
Expand All @@ -139,6 +175,23 @@ public static AbstractConstraint maxCardinality(String scope,
return cardinality(scope, 0, maxCardinality, allocationTags);
}

/**
* Similar to {@link #maxCardinality(String, int, String...)}, but let you
* specify a namespace for the tags, see supported namespaces in
* {@link AllocationTagNamespaceType}.
*
* @param scope the scope of the constraint
* @param tagNamespace the namespace of these tags
* @param maxCardinality determines the maximum number of allocations within
* the scope
* @param allocationTags allocation tags
* @return the resulting placement constraint
*/
public static AbstractConstraint maxCardinality(String scope,
String tagNamespace, int maxCardinality, String... allocationTags) {
return cardinality(scope, tagNamespace, 0, maxCardinality, allocationTags);
}

/**
* This constraint generalizes the cardinality and target constraints.
*
Expand Down Expand Up @@ -242,9 +295,8 @@ public static TargetExpression allocationTagWithNamespace(String namespace,
*/
public static TargetExpression allocationTagToIntraApp(
String... allocationTags) {
AllocationTagNamespace selfNs = new AllocationTagNamespace.Self();
return new TargetExpression(TargetType.ALLOCATION_TAG,
selfNs.toString(), allocationTags);
AllocationTagNamespaceType.SELF.toString(), allocationTags);
}
}

Expand Down

This file was deleted.

0 comments on commit a08921c

Please sign in to comment.