Skip to content

Commit 2ef34e2

Browse files
ericbadgerbrumi1024
authored andcommitted
YARN-10503. Support queue capacity in terms of absolute resources with custom
resourceType. Contributed by Qi Zhu.
1 parent 01de8fd commit 2ef34e2

File tree

4 files changed

+118
-6
lines changed

4 files changed

+118
-6
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/util/resource/ResourceUtils.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,4 +766,19 @@ public static ResourceInformation[] createResourceTypesArray(Map<String,
766766

767767
return info;
768768
}
769+
770+
public static StringBuilder
771+
getCustomResourcesStrings(Resource resource) {
772+
StringBuilder res = new StringBuilder();
773+
if (ResourceUtils.getNumberOfKnownResourceTypes() > 2) {
774+
ResourceInformation[] resources =
775+
resource.getResources();
776+
for (int i = 2; i < resources.length; i++) {
777+
ResourceInformation resInfo = resources[i];
778+
res.append(","
779+
+ resInfo.getName() + "=" + resInfo.getValue());
780+
}
781+
}
782+
return res;
783+
}
769784
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerConfiguration.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,11 +2096,14 @@ private void updateMinMaxResourceToConf(String label, String queue,
20962096
}
20972097

20982098
StringBuilder resourceString = new StringBuilder();
2099+
20992100
resourceString
21002101
.append("[" + AbsoluteResourceType.MEMORY.toString().toLowerCase() + "="
21012102
+ resource.getMemorySize() + ","
21022103
+ AbsoluteResourceType.VCORES.toString().toLowerCase() + "="
2103-
+ resource.getVirtualCores() + "]");
2104+
+ resource.getVirtualCores()
2105+
+ ResourceUtils.
2106+
getCustomResourcesStrings(resource) + "]");
21042107

21052108
String prefix = getQueuePrefix(queue) + type;
21062109
if (!label.isEmpty()) {
@@ -2160,8 +2163,12 @@ private Resource internalGetLabeledResourceRequirementForQueue(String queue,
21602163
private void updateResourceValuesFromConfig(Set<String> resourceTypes,
21612164
Resource resource, String[] splits) {
21622165

2166+
String resourceName = splits[0].trim();
2167+
21632168
// If key is not a valid type, skip it.
2164-
if (!resourceTypes.contains(splits[0])) {
2169+
if (!resourceTypes.contains(resourceName)
2170+
&& !ResourceUtils.getResourceTypes().containsKey(resourceName)) {
2171+
LOG.error(resourceName + " not supported.");
21652172
return;
21662173
}
21672174

@@ -2174,9 +2181,17 @@ private void updateResourceValuesFromConfig(Set<String> resourceTypes,
21742181
resourceValue = UnitsConversionUtil.convert(units, "Mi", resourceValue);
21752182
}
21762183

2184+
// Custom resource type defined by user.
2185+
// Such as GPU FPGA etc.
2186+
if (!resourceTypes.contains(resourceName)) {
2187+
resource.setResourceInformation(resourceName, ResourceInformation
2188+
.newInstance(resourceName, units, resourceValue));
2189+
return;
2190+
}
2191+
21772192
// map it based on key.
21782193
AbsoluteResourceType resType = AbsoluteResourceType
2179-
.valueOf(StringUtils.toUpperCase(splits[0].trim()));
2194+
.valueOf(StringUtils.toUpperCase(resourceName));
21802195
switch (resType) {
21812196
case MEMORY :
21822197
resource.setMemorySize(resourceValue);
@@ -2185,8 +2200,8 @@ private void updateResourceValuesFromConfig(Set<String> resourceTypes,
21852200
resource.setVirtualCores(resourceValue.intValue());
21862201
break;
21872202
default :
2188-
resource.setResourceInformation(splits[0].trim(), ResourceInformation
2189-
.newInstance(splits[0].trim(), units, resourceValue));
2203+
resource.setResourceInformation(resourceName, ResourceInformation
2204+
.newInstance(resourceName, units, resourceValue));
21902205
break;
21912206
}
21922207
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSAllocateCustomResource.java

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity;
2020

2121
import org.apache.commons.io.FileUtils;
22+
import com.google.common.collect.Maps;
2223
import org.apache.hadoop.yarn.api.records.ContainerId;
2324
import org.apache.hadoop.yarn.api.records.Resource;
2425
import org.apache.hadoop.yarn.conf.YarnConfiguration;
@@ -48,10 +49,16 @@
4849

4950
import java.io.File;
5051
import java.io.IOException;
52+
5153
import java.util.ArrayList;
5254
import java.util.Collections;
5355
import java.util.List;
56+
import java.util.Set;
57+
import java.util.Map;
58+
import java.util.Arrays;
59+
import java.util.stream.Collectors;
5460

61+
import static org.apache.hadoop.yarn.api.records.ResourceInformation.FPGA_URI;
5562
import static org.apache.hadoop.yarn.api.records.ResourceInformation.GPU_URI;
5663
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.MAXIMUM_ALLOCATION_MB;
5764
import static org.junit.Assert.assertEquals;
@@ -238,4 +245,79 @@ public void testClusterMetricsWithGPU()
238245
metrics.getCapabilityGPUs(), 0);
239246
ClusterMetrics.destroy();
240247
}
248+
249+
/**
250+
* Test CS absolute conf with Custom resource type.
251+
* */
252+
@Test
253+
public void testCapacitySchedulerAbsoluteConfWithCustomResourceType()
254+
throws IOException {
255+
// reset resource types
256+
ResourceUtils.resetResourceTypes();
257+
String resourceTypesFileName = "resource-types-test.xml";
258+
File source = new File(
259+
conf.getClassLoader().getResource(resourceTypesFileName).getFile());
260+
resourceTypesFile = new File(source.getParent(), "resource-types.xml");
261+
FileUtils.copyFile(source, resourceTypesFile);
262+
263+
CapacitySchedulerConfiguration newConf =
264+
new CapacitySchedulerConfiguration(conf);
265+
266+
// Only memory vcores for first class.
267+
Set<String> resourceTypes = Arrays.
268+
stream(CapacitySchedulerConfiguration.
269+
AbsoluteResourceType.values()).
270+
map(value -> value.toString().toLowerCase()).
271+
collect(Collectors.toSet());
272+
273+
Map<String, Long> valuesMin = Maps.newHashMap();
274+
valuesMin.put(GPU_URI, 10L);
275+
valuesMin.put(FPGA_URI, 10L);
276+
valuesMin.put("testType", 10L);
277+
278+
Map<String, Long> valuesMax = Maps.newHashMap();
279+
valuesMax.put(GPU_URI, 100L);
280+
valuesMax.put(FPGA_URI, 100L);
281+
valuesMax.put("testType", 100L);
282+
283+
Resource aMINRES =
284+
Resource.newInstance(1000, 10, valuesMin);
285+
286+
Resource aMAXRES =
287+
Resource.newInstance(1000, 10, valuesMax);
288+
289+
// Define top-level queues
290+
newConf.setQueues(CapacitySchedulerConfiguration.ROOT,
291+
new String[] {"a", "b", "c"});
292+
newConf.setMinimumResourceRequirement("", "root.a",
293+
aMINRES);
294+
newConf.setMaximumResourceRequirement("", "root.a",
295+
aMAXRES);
296+
297+
newConf.setClass(CapacitySchedulerConfiguration.RESOURCE_CALCULATOR_CLASS,
298+
DominantResourceCalculator.class, ResourceCalculator.class);
299+
300+
//start RM
301+
MockRM rm = new MockRM(newConf);
302+
rm.start();
303+
304+
// Check the gpu resource conf is right.
305+
CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler();
306+
Assert.assertEquals(aMINRES,
307+
cs.getConfiguration().
308+
getMinimumResourceRequirement("", "root.a", resourceTypes));
309+
Assert.assertEquals(aMAXRES,
310+
cs.getConfiguration().
311+
getMaximumResourceRequirement("", "root.a", resourceTypes));
312+
313+
// Check the gpu resource of queue is right.
314+
Assert.assertEquals(aMINRES, cs.getQueue("a").
315+
getQueueResourceQuotas().getConfiguredMinResource());
316+
Assert.assertEquals(aMAXRES, cs.getQueue("a").
317+
getQueueResourceQuotas().getConfiguredMaxResource());
318+
319+
rm.close();
320+
321+
}
322+
241323
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/resources/resource-types-test.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
<configuration>
1818
<property>
1919
<name>yarn.resource-types</name>
20-
<value>yarn.io/gpu</value>
20+
<value>yarn.io/gpu,yarn.io/fpga,testType</value>
2121
</property>
2222
</configuration>

0 commit comments

Comments
 (0)