Skip to content

Commit

Permalink
YARN-5587. Add support for resource profiles. (vvasudev via asuresh)
Browse files Browse the repository at this point in the history
  • Loading branch information
xslogic authored and wangdatan committed Sep 12, 2017
1 parent c2032e2 commit 6708ac3
Show file tree
Hide file tree
Showing 36 changed files with 1,102 additions and 175 deletions.
Expand Up @@ -153,6 +153,10 @@
<Class name="org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ResourceRetentionSet$LRUComparator" /> <Class name="org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ResourceRetentionSet$LRUComparator" />
<Bug pattern="SE_COMPARATOR_SHOULD_BE_SERIALIZABLE" /> <Bug pattern="SE_COMPARATOR_SHOULD_BE_SERIALIZABLE" />
</Match> </Match>
<Match>
<Class name="org.apache.hadoop.yarn.client.api.impl.AMRMClientImpl$ProfileCapabilityComparator" />
<Bug pattern="SE_COMPARATOR_SHOULD_BE_SERIALIZABLE" />
</Match>
<Match> <Match>
<Class name="org.apache.hadoop.yarn.exceptions.impl.pb.YarnRemoteExceptionPBImpl" /> <Class name="org.apache.hadoop.yarn.exceptions.impl.pb.YarnRemoteExceptionPBImpl" />
<Field name="builder" /> <Field name="builder" />
Expand Down
Expand Up @@ -204,4 +204,12 @@ public abstract void setContainersFromPreviousAttempts(
@Unstable @Unstable
public abstract void setSchedulerResourceTypes( public abstract void setSchedulerResourceTypes(
EnumSet<SchedulerResourceTypes> types); EnumSet<SchedulerResourceTypes> types);

@Public
@Unstable
public abstract Map<String, Resource> getResourceProfiles();

@Private
@Unstable
public abstract void setResourceProfiles(Map<String, Resource> profiles);
} }
Expand Up @@ -18,41 +18,93 @@


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


import com.google.common.base.Preconditions;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.yarn.util.Records; import org.apache.hadoop.yarn.util.Records;


import java.util.Map;

/** /**
* Class to capture capability requirements when using resource profiles. The * Class to capture capability requirements when using resource profiles. The
* ProfileCapability is meant to be used as part of the ResourceRequest. A * ProfileCapability is meant to be used as part of the ResourceRequest. A
* profile capability has two pieces - the resource profile name and the * profile capability has two pieces - the resource profile name and the
* overrides. The resource profile specifies the name of the resource profile * overrides. The resource profile specifies the name of the resource profile
* to be used and the capability override is the overrides desired on specific * to be used and the capability override is the overrides desired on specific
* resource types. For example, you could use the "minimum" profile and set the * resource types.
* memory in the capability override to 4096M. This implies that you wish for *
* the resources specified in the "minimum" profile but with 4096M memory. The * For example, if you have a resource profile "small" that maps to
* conversion from the ProfileCapability to the Resource class with the actual * {@literal <4096M, 2 cores, 1 gpu>} and you set the capability override to
* resource requirements will be done by the ResourceManager, which has the * {@literal <8192M, 0 cores, 0 gpu>}, then the actual resource allocation on
* actual profile to Resource mapping. * the ResourceManager will be {@literal <8192M, 2 cores, 1 gpu>}.
*
* Note that the conversion from the ProfileCapability to the Resource class
* with the actual resource requirements will be done by the ResourceManager,
* which has the actual profile to Resource mapping.
*
*/ */
@InterfaceAudience.Public @InterfaceAudience.Public
@InterfaceStability.Unstable @InterfaceStability.Unstable
public abstract class ProfileCapability { public abstract class ProfileCapability {


public static final String DEFAULT_PROFILE = "default";

public static ProfileCapability newInstance(Resource override) {
return newInstance(DEFAULT_PROFILE, override);
}

public static ProfileCapability newInstance(String profile) {
Preconditions
.checkArgument(profile != null, "The profile name cannot be null");
ProfileCapability obj = Records.newRecord(ProfileCapability.class);
obj.setProfileName(profile);
obj.setProfileCapabilityOverride(Resource.newInstance(0, 0));
return obj;
}

public static ProfileCapability newInstance(String profile, public static ProfileCapability newInstance(String profile,
Resource override) { Resource override) {
Preconditions
.checkArgument(profile != null, "The profile name cannot be null");
ProfileCapability obj = Records.newRecord(ProfileCapability.class); ProfileCapability obj = Records.newRecord(ProfileCapability.class);
obj.setProfileName(profile); obj.setProfileName(profile);
obj.setProfileCapabilityOverride(override); obj.setProfileCapabilityOverride(override);
return obj; return obj;
} }


/**
* Get the profile name.
* @return the profile name
*/
public abstract String getProfileName(); public abstract String getProfileName();


/**
* Get the profile capability override.
* @return Resource object containing the override.
*/
public abstract Resource getProfileCapabilityOverride(); public abstract Resource getProfileCapabilityOverride();


/**
* Set the resource profile name.
* @param profileName the resource profile name
*/
public abstract void setProfileName(String profileName); public abstract void setProfileName(String profileName);


/**
* Set the capability override to override specific resource types on the
* resource profile.
*
* For example, if you have a resource profile "small" that maps to
* {@literal <4096M, 2 cores, 1 gpu>} and you set the capability override to
* {@literal <8192M, 0 cores, 0 gpu>}, then the actual resource allocation on
* the ResourceManager will be {@literal <8192M, 2 cores, 1 gpu>}.
*
* Note that the conversion from the ProfileCapability to the Resource class
* with the actual resource requirements will be done by the ResourceManager,
* which has the actual profile to Resource mapping.
*
* @param r Resource object containing the capability override
*/
public abstract void setProfileCapabilityOverride(Resource r); public abstract void setProfileCapabilityOverride(Resource r);


@Override @Override
Expand Down Expand Up @@ -85,4 +137,34 @@ public String toString() {
return "{ profile: " + this.getProfileName() + ", capabilityOverride: " return "{ profile: " + this.getProfileName() + ", capabilityOverride: "
+ this.getProfileCapabilityOverride() + " }"; + this.getProfileCapabilityOverride() + " }";
} }

/**
* Get a representation of the capability as a Resource object.
* @param capability the capability we wish to convert
* @param resourceProfilesMap map of profile name to Resource object
* @return Resource object representing the capability
*/
public static Resource toResource(ProfileCapability capability,
Map<String, Resource> resourceProfilesMap) {
Preconditions
.checkArgument(capability != null, "Capability cannot be null");
Preconditions.checkArgument(resourceProfilesMap != null,
"Resource profiles map cannot be null");
Resource resource = Resource.newInstance(0, 0);

if (resourceProfilesMap.containsKey(capability.getProfileName())) {
resource = Resource
.newInstance(resourceProfilesMap.get(capability.getProfileName()));
}

if(capability.getProfileCapabilityOverride()!= null) {
for (Map.Entry<String, ResourceInformation> entry : capability
.getProfileCapabilityOverride().getResources().entrySet()) {
if (entry.getValue() != null && entry.getValue().getValue() != 0) {
resource.setResourceInformation(entry.getKey(), entry.getValue());
}
}
}
return resource;
}
} }
Expand Up @@ -19,7 +19,9 @@
package org.apache.hadoop.yarn.api.records; package org.apache.hadoop.yarn.api.records;


import org.apache.commons.lang.NotImplementedException; import org.apache.commons.lang.NotImplementedException;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceAudience.Public; import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.classification.InterfaceStability.Evolving; import org.apache.hadoop.classification.InterfaceStability.Evolving;
import org.apache.hadoop.classification.InterfaceStability.Stable; import org.apache.hadoop.classification.InterfaceStability.Stable;
import org.apache.hadoop.yarn.api.ApplicationMasterProtocol; import org.apache.hadoop.yarn.api.ApplicationMasterProtocol;
Expand Down Expand Up @@ -101,6 +103,18 @@ public static Resource newInstance(long memory, int vCores) {
return new SimpleResource(memory, vCores); return new SimpleResource(memory, vCores);
} }


@InterfaceAudience.Private
@InterfaceStability.Unstable
public static Resource newInstance(Resource resource) {
Resource ret = Resource.newInstance(0, 0);
for (Map.Entry<String, ResourceInformation> entry : resource.getResources()
.entrySet()) {
ret.setResourceInformation(entry.getKey(),
ResourceInformation.newInstance(entry.getValue()));
}
return ret;
}

/** /**
* This method is DEPRECATED: * This method is DEPRECATED:
* Use {@link Resource#getMemorySize()} instead * Use {@link Resource#getMemorySize()} instead
Expand Down
Expand Up @@ -31,6 +31,8 @@ public class ResourceInformation implements Comparable<ResourceInformation> {
private String units; private String units;
private ResourceTypes resourceType; private ResourceTypes resourceType;
private Long value; private Long value;
private Long minimumAllocation;
private Long maximumAllocation;


private static final String MEMORY_URI = "memory-mb"; private static final String MEMORY_URI = "memory-mb";
private static final String VCORES_URI = "vcores"; private static final String VCORES_URI = "vcores";
Expand Down Expand Up @@ -117,6 +119,42 @@ public void setValue(Long rValue) {
this.value = rValue; this.value = rValue;
} }


/**
* Get the minimum allocation for the resource.
*
* @return the minimum allocation for the resource
*/
public Long getMinimumAllocation() {
return minimumAllocation;
}

/**
* Set the minimum allocation for the resource.
*
* @param minimumAllocation the minimum allocation for the resource
*/
public void setMinimumAllocation(Long minimumAllocation) {
this.minimumAllocation = minimumAllocation;
}

/**
* Get the maximum allocation for the resource.
*
* @return the maximum allocation for the resource
*/
public Long getMaximumAllocation() {
return maximumAllocation;
}

/**
* Set the maximum allocation for the resource.
*
* @param maximumAllocation the maximum allocation for the resource
*/
public void setMaximumAllocation(Long maximumAllocation) {
this.maximumAllocation = maximumAllocation;
}

/** /**
* Create a new instance of ResourceInformation from another object. * Create a new instance of ResourceInformation from another object.
* *
Expand All @@ -129,33 +167,41 @@ public static ResourceInformation newInstance(ResourceInformation other) {
ret.setResourceType(other.getResourceType()); ret.setResourceType(other.getResourceType());
ret.setUnits(other.getUnits()); ret.setUnits(other.getUnits());
ret.setValue(other.getValue()); ret.setValue(other.getValue());
ret.setMinimumAllocation(other.getMinimumAllocation());
ret.setMaximumAllocation(other.getMaximumAllocation());
return ret; return ret;
} }


public static ResourceInformation newInstance(String name, String units, public static ResourceInformation newInstance(String name, String units,
Long value, ResourceTypes type) { Long value, ResourceTypes type, Long minimumAllocation,
Long maximumAllocation) {
ResourceInformation ret = new ResourceInformation(); ResourceInformation ret = new ResourceInformation();
ret.setName(name); ret.setName(name);
ret.setResourceType(type); ret.setResourceType(type);
ret.setUnits(units); ret.setUnits(units);
ret.setValue(value); ret.setValue(value);
ret.setMinimumAllocation(minimumAllocation);
ret.setMaximumAllocation(maximumAllocation);
return ret; return ret;
} }


public static ResourceInformation newInstance(String name, String units, public static ResourceInformation newInstance(String name, String units,
Long value) { Long value) {
return ResourceInformation return ResourceInformation
.newInstance(name, units, value, ResourceTypes.COUNTABLE); .newInstance(name, units, value, ResourceTypes.COUNTABLE, 0L,
Long.MAX_VALUE);
} }


public static ResourceInformation newInstance(String name, String units) { public static ResourceInformation newInstance(String name, String units) {
return ResourceInformation return ResourceInformation
.newInstance(name, units, 0L, ResourceTypes.COUNTABLE); .newInstance(name, units, 0L, ResourceTypes.COUNTABLE, 0L,
Long.MAX_VALUE);
} }


public static ResourceInformation newInstance(String name, Long value) { public static ResourceInformation newInstance(String name, Long value) {
return ResourceInformation return ResourceInformation
.newInstance(name, "", value, ResourceTypes.COUNTABLE); .newInstance(name, "", value, ResourceTypes.COUNTABLE, 0L,
Long.MAX_VALUE);
} }


public static ResourceInformation newInstance(String name) { public static ResourceInformation newInstance(String name) {
Expand All @@ -165,7 +211,8 @@ public static ResourceInformation newInstance(String name) {
@Override @Override
public String toString() { public String toString() {
return "name: " + this.name + ", units: " + this.units + ", type: " return "name: " + this.name + ", units: " + this.units + ", type: "
+ resourceType + ", value: " + value; + resourceType + ", value: " + value + ", minimum allocation: "
+ minimumAllocation + ", maximum allocation: " + maximumAllocation;
} }


public String getShorthandRepresentation() { public String getShorthandRepresentation() {
Expand Down
Expand Up @@ -98,7 +98,22 @@ public static ResourceRequest newInstance(Priority priority, String hostName,
.resourceName(hostName).capability(capability) .resourceName(hostName).capability(capability)
.numContainers(numContainers).relaxLocality(relaxLocality) .numContainers(numContainers).relaxLocality(relaxLocality)
.nodeLabelExpression(labelExpression) .nodeLabelExpression(labelExpression)
.executionTypeRequest(executionTypeRequest).build(); .executionTypeRequest(executionTypeRequest).profileCapability(null)
.build();
}

@Public
@Evolving
public static ResourceRequest newInstance(Priority priority, String hostName,
Resource capability, int numContainers, boolean relaxLocality,
String labelExpression, ExecutionTypeRequest executionTypeRequest,
ProfileCapability profile) {
return ResourceRequest.newBuilder().priority(priority)
.resourceName(hostName).capability(capability)
.numContainers(numContainers).relaxLocality(relaxLocality)
.nodeLabelExpression(labelExpression)
.executionTypeRequest(executionTypeRequest).profileCapability(profile)
.build();
} }


@Public @Public
Expand All @@ -124,6 +139,7 @@ private ResourceRequestBuilder() {
resourceRequest.setRelaxLocality(true); resourceRequest.setRelaxLocality(true);
resourceRequest.setExecutionTypeRequest( resourceRequest.setExecutionTypeRequest(
ExecutionTypeRequest.newInstance()); ExecutionTypeRequest.newInstance());
resourceRequest.setProfileCapability(null);
} }


/** /**
Expand Down Expand Up @@ -237,6 +253,21 @@ public ResourceRequestBuilder allocationRequestId(
return this; return this;
} }


/**
* Set the <code>resourceProfile</code> of the request.
* @see ResourceRequest#setProfileCapability(ProfileCapability)
* @param profileCapability
* <code>profileCapability</code> of the request
* @return {@link ResourceRequestBuilder}
*/
@Public
@Evolving
public ResourceRequestBuilder profileCapability(
ProfileCapability profileCapability) {
resourceRequest.setProfileCapability(profileCapability);
return this;
}

/** /**
* Return generated {@link ResourceRequest} object. * Return generated {@link ResourceRequest} object.
* @return {@link ResourceRequest} * @return {@link ResourceRequest}
Expand Down Expand Up @@ -454,6 +485,14 @@ public ExecutionTypeRequest getExecutionTypeRequest() {
@Evolving @Evolving
public abstract void setNodeLabelExpression(String nodelabelExpression); public abstract void setNodeLabelExpression(String nodelabelExpression);


@Public
@Evolving
public abstract ProfileCapability getProfileCapability();

@Public
@Evolving
public abstract void setProfileCapability(ProfileCapability p);

/** /**
* Get the optional <em>ID</em> corresponding to this allocation request. This * Get the optional <em>ID</em> corresponding to this allocation request. This
* ID is an identifier for different {@code ResourceRequest}s from the <b>same * ID is an identifier for different {@code ResourceRequest}s from the <b>same
Expand Down Expand Up @@ -529,12 +568,14 @@ public int hashCode() {
Resource capability = getCapability(); Resource capability = getCapability();
String hostName = getResourceName(); String hostName = getResourceName();
Priority priority = getPriority(); Priority priority = getPriority();
ProfileCapability profile = getProfileCapability();
result = result =
prime * result + ((capability == null) ? 0 : capability.hashCode()); prime * result + ((capability == null) ? 0 : capability.hashCode());
result = prime * result + ((hostName == null) ? 0 : hostName.hashCode()); result = prime * result + ((hostName == null) ? 0 : hostName.hashCode());
result = prime * result + getNumContainers(); result = prime * result + getNumContainers();
result = prime * result + ((priority == null) ? 0 : priority.hashCode()); result = prime * result + ((priority == null) ? 0 : priority.hashCode());
result = prime * result + Long.valueOf(getAllocationRequestId()).hashCode(); result = prime * result + Long.valueOf(getAllocationRequestId()).hashCode();
result = prime * result + ((profile == null) ? 0 : profile.hashCode());
return result; return result;
} }


Expand Down
1 change: 1 addition & 0 deletions hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/pom.xml
Expand Up @@ -144,6 +144,7 @@
<exclude>src/test/resources/application_1440536969523_0001.har/part-0</exclude> <exclude>src/test/resources/application_1440536969523_0001.har/part-0</exclude>
<exclude>src/test/resources/application_1440536969523_0001.har/_masterindex</exclude> <exclude>src/test/resources/application_1440536969523_0001.har/_masterindex</exclude>
<exclude>src/test/resources/application_1440536969523_0001.har/_SUCCESS</exclude> <exclude>src/test/resources/application_1440536969523_0001.har/_SUCCESS</exclude>
<exclude>src/test/resources/resource-profiles.json</exclude>
</excludes> </excludes>
</configuration> </configuration>
</plugin> </plugin>
Expand Down

0 comments on commit 6708ac3

Please sign in to comment.