|
39 | 39 | import org.apache.hadoop.yarn.api.records.NodeId; |
40 | 40 | import org.apache.hadoop.yarn.api.records.Priority; |
41 | 41 | import org.apache.hadoop.yarn.api.records.Resource; |
| 42 | +import org.apache.hadoop.yarn.api.records.ResourceInformation; |
42 | 43 | import org.apache.hadoop.yarn.api.records.ResourceRequest; |
43 | 44 | import org.apache.hadoop.yarn.conf.YarnConfiguration; |
44 | 45 | import org.apache.hadoop.yarn.factories.RecordFactory; |
|
49 | 50 | import org.apache.hadoop.yarn.server.resourcemanager.RMContext; |
50 | 51 | import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.NullRMNodeLabelsManager; |
51 | 52 | import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager; |
| 53 | +import org.apache.hadoop.yarn.server.resourcemanager.resource.TestResourceProfiles; |
52 | 54 | import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp; |
53 | 55 | import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt; |
54 | 56 | import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceLimits; |
|
59 | 61 | import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp; |
60 | 62 | import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerNode; |
61 | 63 | import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; |
| 64 | +import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator; |
62 | 65 | import org.apache.hadoop.yarn.util.resource.ResourceCalculator; |
| 66 | +import org.apache.hadoop.yarn.util.resource.ResourceUtils; |
63 | 67 | import org.apache.hadoop.yarn.util.resource.Resources; |
64 | 68 | import org.junit.Assert; |
65 | 69 | import org.junit.Before; |
@@ -750,4 +754,85 @@ public void testHeadroom() throws Exception { |
750 | 754 |
|
751 | 755 |
|
752 | 756 | } |
| 757 | + |
| 758 | + /** |
| 759 | + * {@link LeafQueue#activateApplications()} should validate values of all |
| 760 | + * resourceTypes before activating application. |
| 761 | + * |
| 762 | + * @throws Exception |
| 763 | + */ |
| 764 | + @Test |
| 765 | + public void testAMLimitByAllResources() throws Exception { |
| 766 | + CapacitySchedulerConfiguration csconf = |
| 767 | + new CapacitySchedulerConfiguration(); |
| 768 | + csconf.setResourceComparator(DominantResourceCalculator.class); |
| 769 | + String queueName = "a1"; |
| 770 | + csconf.setQueues(CapacitySchedulerConfiguration.ROOT, |
| 771 | + new String[] {queueName}); |
| 772 | + csconf.setCapacity("root." + queueName, 100); |
| 773 | + |
| 774 | + ResourceInformation res0 = ResourceInformation.newInstance("memory-mb", |
| 775 | + ResourceInformation.MEMORY_MB.getUnits(), GB, Long.MAX_VALUE); |
| 776 | + ResourceInformation res1 = ResourceInformation.newInstance("vcores", |
| 777 | + ResourceInformation.VCORES.getUnits(), 1, Integer.MAX_VALUE); |
| 778 | + ResourceInformation res2 = ResourceInformation.newInstance("gpu", |
| 779 | + ResourceInformation.GPUS.getUnits(), 0, Integer.MAX_VALUE); |
| 780 | + Map<String, ResourceInformation> riMap = new HashMap<>(); |
| 781 | + riMap.put(ResourceInformation.MEMORY_URI, res0); |
| 782 | + riMap.put(ResourceInformation.VCORES_URI, res1); |
| 783 | + riMap.put(ResourceInformation.GPU_URI, res2); |
| 784 | + ResourceUtils.initializeResourcesFromResourceInformationMap(riMap); |
| 785 | + |
| 786 | + YarnConfiguration config = new YarnConfiguration(csconf); |
| 787 | + config.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, |
| 788 | + ResourceScheduler.class); |
| 789 | + config.setBoolean(TestResourceProfiles.TEST_CONF_RESET_RESOURCE_TYPES, |
| 790 | + false); |
| 791 | + |
| 792 | + MockRM rm = new MockRM(config); |
| 793 | + rm.start(); |
| 794 | + |
| 795 | + Map<String, Long> res = new HashMap<>(); |
| 796 | + res.put("gpu", 0L); |
| 797 | + |
| 798 | + Resource clusterResource = Resource.newInstance(16 * GB, 64, res); |
| 799 | + |
| 800 | + // Cluster Resource - 16GB, 64vcores |
| 801 | + // AMLimit 16384 x .1 mb , 64 x .1 vcore |
| 802 | + // Effective AM limit after normalized to minimum resource 2048,7 |
| 803 | + |
| 804 | + rm.registerNode("127.0.0.1:1234", clusterResource); |
| 805 | + |
| 806 | + String userName = "user_0"; |
| 807 | + ResourceScheduler scheduler = rm.getRMContext().getScheduler(); |
| 808 | + LeafQueue queueA = (LeafQueue) ((CapacityScheduler) scheduler) |
| 809 | + .getQueue(queueName); |
| 810 | + |
| 811 | + Resource amResource = Resource.newInstance(GB, 1); |
| 812 | + |
| 813 | + rm.submitApp(amResource, "app-1", userName, null, queueName); |
| 814 | + rm.submitApp(amResource, "app-2", userName, null, queueName); |
| 815 | + |
| 816 | + // app-3 should not be activated as amLimit will be reached |
| 817 | + // for memory |
| 818 | + rm.submitApp(amResource, "app-3", userName, null, queueName); |
| 819 | + |
| 820 | + Assert.assertEquals("PendingApplications should be 1", 1, |
| 821 | + queueA.getNumPendingApplications()); |
| 822 | + Assert.assertEquals("Active applications should be 2", 2, |
| 823 | + queueA.getNumActiveApplications()); |
| 824 | + // AMLimit is 2048,7 |
| 825 | + Assert.assertEquals(2048, |
| 826 | + queueA.getQueueResourceUsage().getAMLimit().getMemorySize()); |
| 827 | + Assert.assertEquals(7, |
| 828 | + queueA.getQueueResourceUsage().getAMLimit().getVirtualCores()); |
| 829 | + // Used AM Resource is 2048,2 |
| 830 | + Assert.assertEquals(2048, |
| 831 | + queueA.getQueueResourceUsage().getAMUsed().getMemorySize()); |
| 832 | + Assert.assertEquals(2, |
| 833 | + queueA.getQueueResourceUsage().getAMUsed().getVirtualCores()); |
| 834 | + |
| 835 | + rm.close(); |
| 836 | + |
| 837 | + } |
753 | 838 | } |
0 commit comments