From 782971ae7a0247bcf5920e10b434b7e0954dd868 Mon Sep 17 00:00:00 2001 From: Karthik Kambatla Date: Wed, 29 Oct 2014 10:24:57 -0700 Subject: [PATCH] YARN-2742. FairSchedulerConfiguration should allow extra spaces between value and unit. (Wei Yan via kasha) --- hadoop-yarn-project/CHANGES.txt | 3 +++ .../scheduler/fair/FairSchedulerConfiguration.java | 3 ++- .../scheduler/fair/TestFairSchedulerConfiguration.java | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index ce56f0d517..50b806fc9a 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -53,6 +53,9 @@ Release 2.7.0 - UNRELEASED YARN-2641. Decommission nodes on -refreshNodes instead of next NM-RM heartbeat. (Zhihai Xu via kasha) + YARN-2742. FairSchedulerConfiguration should allow extra spaces + between value and unit. (Wei Yan via kasha) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairSchedulerConfiguration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairSchedulerConfiguration.java index a96952daaa..32ef906a57 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairSchedulerConfiguration.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairSchedulerConfiguration.java @@ -241,6 +241,7 @@ public boolean getUsePortForNodeName() { public static Resource parseResourceConfigValue(String val) throws AllocationConfigurationException { try { + val = val.toLowerCase(); int memory = findResource(val, "mb"); int vcores = findResource(val, "vcores"); return BuilderUtils.newResource(memory, vcores); @@ -258,7 +259,7 @@ public long getUpdateInterval() { private static int findResource(String val, String units) throws AllocationConfigurationException { - Pattern pattern = Pattern.compile("(\\d+) ?" + units); + Pattern pattern = Pattern.compile("(\\d+)\\s*" + units); Matcher matcher = pattern.matcher(val); if (!matcher.find()) { throw new AllocationConfigurationException("Missing resource: " + units); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFairSchedulerConfiguration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFairSchedulerConfiguration.java index 3db87f6ea4..82b50a6c74 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFairSchedulerConfiguration.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFairSchedulerConfiguration.java @@ -39,6 +39,12 @@ public void testParseResourceConfigValue() throws Exception { parseResourceConfigValue("2vcores,1024mb")); assertEquals(BuilderUtils.newResource(1024, 2), parseResourceConfigValue("1024mb,2vcores")); + assertEquals(BuilderUtils.newResource(1024, 2), + parseResourceConfigValue("1024 mb, 2 vcores")); + assertEquals(BuilderUtils.newResource(1024, 2), + parseResourceConfigValue("1024 Mb, 2 vCores")); + assertEquals(BuilderUtils.newResource(1024, 2), + parseResourceConfigValue(" 1024 mb, 2 vcores ")); } @Test(expected = AllocationConfigurationException.class)