|
@@ -19,6 +19,7 @@
|
|
|
package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity;
|
|
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.hadoop.thirdparty.com.google.common.collect.Maps;
|
|
|
import org.apache.hadoop.yarn.api.records.ContainerId;
|
|
|
import org.apache.hadoop.yarn.api.records.Resource;
|
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
@@ -50,10 +51,16 @@ import org.junit.Test;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
+import static org.apache.hadoop.yarn.api.records.ResourceInformation.FPGA_URI;
|
|
|
import static org.apache.hadoop.yarn.api.records.ResourceInformation.GPU_URI;
|
|
|
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.MAXIMUM_ALLOCATION_MB;
|
|
|
import static org.junit.Assert.assertEquals;
|
|
@@ -248,4 +255,79 @@ public class TestCSAllocateCustomResource {
|
|
|
.get(GPU_URI)).longValue(), 0);
|
|
|
ClusterMetrics.destroy();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test CS absolute conf with Custom resource type.
|
|
|
+ * */
|
|
|
+ @Test
|
|
|
+ public void testCapacitySchedulerAbsoluteConfWithCustomResourceType()
|
|
|
+ throws IOException {
|
|
|
+ // reset resource types
|
|
|
+ ResourceUtils.resetResourceTypes();
|
|
|
+ String resourceTypesFileName = "resource-types-test.xml";
|
|
|
+ File source = new File(
|
|
|
+ conf.getClassLoader().getResource(resourceTypesFileName).getFile());
|
|
|
+ resourceTypesFile = new File(source.getParent(), "resource-types.xml");
|
|
|
+ FileUtils.copyFile(source, resourceTypesFile);
|
|
|
+
|
|
|
+ CapacitySchedulerConfiguration newConf =
|
|
|
+ new CapacitySchedulerConfiguration(conf);
|
|
|
+
|
|
|
+ // Only memory vcores for first class.
|
|
|
+ Set<String> resourceTypes = Arrays.
|
|
|
+ stream(CapacitySchedulerConfiguration.
|
|
|
+ AbsoluteResourceType.values()).
|
|
|
+ map(value -> value.toString().toLowerCase()).
|
|
|
+ collect(Collectors.toSet());
|
|
|
+
|
|
|
+ Map<String, Long> valuesMin = Maps.newHashMap();
|
|
|
+ valuesMin.put(GPU_URI, 10L);
|
|
|
+ valuesMin.put(FPGA_URI, 10L);
|
|
|
+ valuesMin.put("testType", 10L);
|
|
|
+
|
|
|
+ Map<String, Long> valuesMax = Maps.newHashMap();
|
|
|
+ valuesMax.put(GPU_URI, 100L);
|
|
|
+ valuesMax.put(FPGA_URI, 100L);
|
|
|
+ valuesMax.put("testType", 100L);
|
|
|
+
|
|
|
+ Resource aMINRES =
|
|
|
+ Resource.newInstance(1000, 10, valuesMin);
|
|
|
+
|
|
|
+ Resource aMAXRES =
|
|
|
+ Resource.newInstance(1000, 10, valuesMax);
|
|
|
+
|
|
|
+ // Define top-level queues
|
|
|
+ newConf.setQueues(CapacitySchedulerConfiguration.ROOT,
|
|
|
+ new String[] {"a", "b", "c"});
|
|
|
+ newConf.setMinimumResourceRequirement("", "root.a",
|
|
|
+ aMINRES);
|
|
|
+ newConf.setMaximumResourceRequirement("", "root.a",
|
|
|
+ aMAXRES);
|
|
|
+
|
|
|
+ newConf.setClass(CapacitySchedulerConfiguration.RESOURCE_CALCULATOR_CLASS,
|
|
|
+ DominantResourceCalculator.class, ResourceCalculator.class);
|
|
|
+
|
|
|
+ //start RM
|
|
|
+ MockRM rm = new MockRM(newConf);
|
|
|
+ rm.start();
|
|
|
+
|
|
|
+ // Check the gpu resource conf is right.
|
|
|
+ CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler();
|
|
|
+ Assert.assertEquals(aMINRES,
|
|
|
+ cs.getConfiguration().
|
|
|
+ getMinimumResourceRequirement("", "root.a", resourceTypes));
|
|
|
+ Assert.assertEquals(aMAXRES,
|
|
|
+ cs.getConfiguration().
|
|
|
+ getMaximumResourceRequirement("", "root.a", resourceTypes));
|
|
|
+
|
|
|
+ // Check the gpu resource of queue is right.
|
|
|
+ Assert.assertEquals(aMINRES, cs.getQueue("root.a").
|
|
|
+ getQueueResourceQuotas().getConfiguredMinResource());
|
|
|
+ Assert.assertEquals(aMAXRES, cs.getQueue("root.a").
|
|
|
+ getQueueResourceQuotas().getConfiguredMaxResource());
|
|
|
+
|
|
|
+ rm.close();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|