FairSchedulerConfiguration extends Configuration { public static ConfigurableResource parseResourceConfigValue(String value) throws AllocationConfigurationException { return parseResourceConfigValue(value, Long.MAX_VALUE); } FairSchedulerConfiguration();  FairSchedulerConfiguration(Configuration conf); Resource getMinimumAllocation(); Resource getMaximumAllocation(); Resource getIncrementAllocation(); float getReservationThresholdIncrementMultiple(); float getLocalityThresholdNode(); float getLocalityThresholdRack(); @Deprecated boolean isContinuousSchedulingEnabled(); @Deprecated int getContinuousSchedulingSleepMs(); @Deprecated long getLocalityDelayNodeMs(); @Deprecated long getLocalityDelayRackMs(); boolean getPreemptionEnabled(); float getPreemptionUtilizationThreshold(); boolean getAssignMultiple(); boolean isMaxAssignDynamic(); int getMaxAssign(); boolean getSizeBasedWeight(); long getWaitTimeBeforeNextStarvationCheck(); int getWaitTimeBeforeKill(); boolean getUsePortForNodeName(); float getReservableNodes(); static ConfigurableResource parseResourceConfigValue(String value); static ConfigurableResource parseResourceConfigValue(String value,
      long missing); long getUpdateInterval(); static final Log LOG; @Deprecated
  static final String RM_SCHEDULER_INCREMENT_ALLOCATION_MB; @Deprecated
  static final int DEFAULT_RM_SCHEDULER_INCREMENT_ALLOCATION_MB; @Deprecated
  static final String RM_SCHEDULER_INCREMENT_ALLOCATION_VCORES; @Deprecated
  static final int DEFAULT_RM_SCHEDULER_INCREMENT_ALLOCATION_VCORES; static final String RM_SCHEDULER_RESERVATION_THRESHOLD_INCREMENT_MULTIPLE; static final float DEFAULT_RM_SCHEDULER_RESERVATION_THRESHOLD_INCREMENT_MULTIPLE; static final String ALLOCATION_FILE; static final String ASSIGN_MULTIPLE; static final String DYNAMIC_MAX_ASSIGN; static final String UPDATE_INTERVAL_MS; static final int DEFAULT_UPDATE_INTERVAL_MS; static final String RESERVABLE_NODES; static final float RESERVABLE_NODES_DEFAULT; }
@Test public void testParseResourceConfigValue() throws Exception { Resource expected = BuilderUtils.newResource(5 * 1024, 2); Resource clusterResource = BuilderUtils.newResource(10 * 1024, 4); assertEquals(expected, parseResourceConfigValue("2 vcores, 5120 mb").getResource()); assertEquals(expected, parseResourceConfigValue("5120 mb, 2 vcores").getResource()); assertEquals(expected, parseResourceConfigValue("2vcores,5120mb").getResource()); assertEquals(expected, parseResourceConfigValue("5120mb,2vcores").getResource()); assertEquals(expected, parseResourceConfigValue("5120mb mb, 2 vcores").getResource()); assertEquals(expected, parseResourceConfigValue("5120 Mb, 2 vCores").getResource()); assertEquals(expected, parseResourceConfigValue(" 5120 mb, 2 vcores ").getResource()); assertEquals(expected, parseResourceConfigValue(" 5120.3 mb, 2.35 vcores ").getResource()); assertEquals(expected, parseResourceConfigValue(" 5120. mb, 2. vcores ").getResource()); assertEquals(expected, parseResourceConfigValue("50% memory, 50% cpu"). getResource(clusterResource)); assertEquals(expected, parseResourceConfigValue("50% Memory, 50% CpU"). getResource(clusterResource)); assertEquals(BuilderUtils.newResource(5 * 1024, 4), parseResourceConfigValue("50% memory, 100% cpu"). getResource(clusterResource)); assertEquals(BuilderUtils.newResource(5 * 1024, 4), parseResourceConfigValue(" 100% cpu, 50% memory"). getResource(clusterResource)); assertEquals(BuilderUtils.newResource(5 * 1024, 0), parseResourceConfigValue("50% memory, 0% cpu"). getResource(clusterResource)); assertEquals(expected, parseResourceConfigValue("50 % memory, 50 % cpu"). getResource(clusterResource)); assertEquals(expected, parseResourceConfigValue("50%memory,50%cpu"). getResource(clusterResource)); assertEquals(expected, parseResourceConfigValue(" 50 % memory, 50 % cpu "). getResource(clusterResource)); assertEquals(expected, parseResourceConfigValue("50.% memory, 50.% cpu"). getResource(clusterResource)); assertEquals(BuilderUtils.newResource((int)(1024 * 10 * 0.109), 2), parseResourceConfigValue("10.9% memory, 50.6% cpu"). getResource(clusterResource)); assertEquals(expected, parseResourceConfigValue("50%").getResource(clusterResource)); Configuration conf = new Configuration(); conf.set(YarnConfiguration.RESOURCE_TYPES, "test1"); ResourceUtils.resetResourceTypes(conf); clusterResource = BuilderUtils.newResource(10 * 1024, 4); expected = BuilderUtils.newResource(5 * 1024, 2); expected.setResourceValue("test1", Long.MAX_VALUE); assertEquals(expected, parseResourceConfigValue("vcores=2, memory-mb=5120").getResource()); assertEquals(expected, parseResourceConfigValue("memory-mb=5120, vcores=2").getResource()); assertEquals(expected, parseResourceConfigValue("vcores=2,memory-mb=5120").getResource()); assertEquals(expected, parseResourceConfigValue(" vcores = 2 , " + "memory-mb = 5120 ").getResource()); expected.setResourceValue("test1", 0L); assertEquals(expected, parseResourceConfigValue("vcores=2, memory-mb=5120", 0L).getResource()); assertEquals(expected, parseResourceConfigValue("memory-mb=5120, vcores=2", 0L).getResource()); assertEquals(expected, parseResourceConfigValue("vcores=2,memory-mb=5120", 0L).getResource()); assertEquals(expected, parseResourceConfigValue(" vcores = 2 , memory-mb = 5120 ", 0L).getResource()); clusterResource.setResourceValue("test1", 8L); expected.setResourceValue("test1", 4L); assertEquals(expected, parseResourceConfigValue("50%").getResource(clusterResource)); assertEquals(expected, parseResourceConfigValue("vcores=2, memory-mb=5120, " + "test1=4").getResource()); assertEquals(expected, parseResourceConfigValue("test1=4, vcores=2, " + "memory-mb=5120").getResource()); assertEquals(expected, parseResourceConfigValue("memory-mb=5120, test1=4, " + "vcores=2").getResource()); assertEquals(expected, parseResourceConfigValue("vcores=2,memory-mb=5120," + "test1=4").getResource()); assertEquals(expected, parseResourceConfigValue(" vcores = 2 , memory-mb = 5120 , " + "test1 = 4 ").getResource()); expected = BuilderUtils.newResource(4 * 1024, 3); expected.setResourceValue("test1", 8L); assertEquals(expected, parseResourceConfigValue("vcores=75%, " + "memory-mb=40%").getResource(clusterResource)); assertEquals(expected, parseResourceConfigValue("memory-mb=40%, " + "vcores=75%").getResource(clusterResource)); assertEquals(expected, parseResourceConfigValue("vcores=75%," + "memory-mb=40%").getResource(clusterResource)); assertEquals(expected, parseResourceConfigValue(" vcores = 75 % , " + "memory-mb = 40 % ").getResource(clusterResource)); expected.setResourceValue("test1", 4L); assertEquals(expected, parseResourceConfigValue("vcores=75%, memory-mb=40%, " + "test1=50%").getResource(clusterResource)); assertEquals(expected, parseResourceConfigValue("test1=50%, vcores=75%, " + "memory-mb=40%").getResource(clusterResource)); assertEquals(expected, parseResourceConfigValue("memory-mb=40%, test1=50%, " + "vcores=75%").getResource(clusterResource)); assertEquals(expected, parseResourceConfigValue("vcores=75%,memory-mb=40%," + "test1=50%").getResource(clusterResource)); assertEquals(expected, parseResourceConfigValue(" vcores = 75 % , memory-mb = 40 % , " + "test1 = 50 % ").getResource(clusterResource)); }
@Test(expected = AllocationConfigurationException.class) public void testNoUnits() throws Exception { parseResourceConfigValue("1024"); }
@Test(expected = AllocationConfigurationException.class) public void testOnlyMemory() throws Exception { parseResourceConfigValue("1024mb"); }
@Test(expected = AllocationConfigurationException.class) public void testOnlyCPU() throws Exception { parseResourceConfigValue("1024vcores"); }
@Test(expected = AllocationConfigurationException.class) public void testGibberish() throws Exception { parseResourceConfigValue("1o24vc0res"); }
@Test(expected = AllocationConfigurationException.class) public void testNoUnitsPercentage() throws Exception { parseResourceConfigValue("95%, 50% memory"); }
@Test(expected = AllocationConfigurationException.class) public void testInvalidNumPercentage() throws Exception { parseResourceConfigValue("95A% cpu, 50% memory"); }
@Test(expected = AllocationConfigurationException.class) public void testCpuPercentageMemoryAbsolute() throws Exception { parseResourceConfigValue("50% cpu, 1024 mb"); }
@Test(expected = AllocationConfigurationException.class) public void testMemoryPercentageCpuAbsolute() throws Exception { parseResourceConfigValue("50% memory, 2 vcores"); }