From 10fc8d2a7dc975ce70de63f88a2674389314f197 Mon Sep 17 00:00:00 2001 From: Sunil G Date: Wed, 13 Dec 2017 22:00:07 +0530 Subject: [PATCH] =?UTF-8?q?YARN-7383.=20Node=20resource=20is=20not=20parse?= =?UTF-8?q?d=20correctly=20for=20resource=20names=20containing=20dot.=20Co?= =?UTF-8?q?ntributed=20by=20Gergely=20Nov=C3=A1k.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hadoop/yarn/util/resource/ResourceUtils.java | 15 ++++++--------- .../yarn/util/resource/TestResourceUtils.java | 5 ++++- .../resources/resource-types/node-resources-2.xml | 5 +++++ .../resources/resource-types/resource-types-4.xml | 7 ++++++- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/util/resource/ResourceUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/util/resource/ResourceUtils.java index 76ae0614f67..563f11ec551 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/util/resource/ResourceUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/util/resource/ResourceUtils.java @@ -464,21 +464,18 @@ public class ResourceUtils { for (Map.Entry entry : conf) { String key = entry.getKey(); String value = entry.getValue(); - - if (key.startsWith(YarnConfiguration.NM_RESOURCES_PREFIX)) { - addResourceInformation(key, value, nodeResources); - } + addResourceTypeInformation(key, value, nodeResources); } return nodeResources; } - private static void addResourceInformation(String prop, String value, + private static void addResourceTypeInformation(String prop, String value, Map nodeResources) { - String[] parts = prop.split("\\."); - LOG.info("Found resource entry " + prop); - if (parts.length == 4) { - String resourceType = parts[3]; + if (prop.startsWith(YarnConfiguration.NM_RESOURCES_PREFIX)) { + LOG.info("Found resource entry " + prop); + String resourceType = prop.substring( + YarnConfiguration.NM_RESOURCES_PREFIX.length()); if (!nodeResources.containsKey(resourceType)) { nodeResources .put(resourceType, ResourceInformation.newInstance(resourceType)); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceUtils.java index 909ad567191..1111ca6d843 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceUtils.java @@ -123,9 +123,10 @@ public class TestResourceUtils { new ResourceFileInformation("resource-types-3.xml", 3); testFile3.resourceNameUnitsMap.put("resource2", ""); ResourceFileInformation testFile4 = - new ResourceFileInformation("resource-types-4.xml", 4); + new ResourceFileInformation("resource-types-4.xml", 5); testFile4.resourceNameUnitsMap.put("resource1", "G"); testFile4.resourceNameUnitsMap.put("resource2", "m"); + testFile4.resourceNameUnitsMap.put("yarn.io/gpu", ""); ResourceFileInformation[] tests = {testFile1, testFile2, testFile3, testFile4}; @@ -291,6 +292,8 @@ public class TestResourceUtils { ResourceInformation.newInstance("resource1", "Gi", 5L)); test3Resources.setResourceInformation("resource2", ResourceInformation.newInstance("resource2", "m", 2L)); + test3Resources.setResourceInformation("yarn.io/gpu", + ResourceInformation.newInstance("yarn.io/gpu", "", 1)); testRun.put("node-resources-2.xml", test3Resources); for (Map.Entry entry : testRun.entrySet()) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/resources/resource-types/node-resources-2.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/resources/resource-types/node-resources-2.xml index 9d9b3dc65c8..382d5dd2ca2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/resources/resource-types/node-resources-2.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/resources/resource-types/node-resources-2.xml @@ -36,4 +36,9 @@ limitations under the License. See accompanying LICENSE file. 2m + + yarn.nodemanager.resource-type.yarn.io/gpu + 1 + + diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/resources/resource-types/resource-types-4.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/resources/resource-types/resource-types-4.xml index c84316a536e..ea8d2bdb8f2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/resources/resource-types/resource-types-4.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/resources/resource-types/resource-types-4.xml @@ -18,7 +18,7 @@ limitations under the License. See accompanying LICENSE file. yarn.resource-types - resource1,resource2 + resource1,resource2,yarn.io/gpu @@ -31,4 +31,9 @@ limitations under the License. See accompanying LICENSE file. m + + yarn.resource-types.yarn.io/gpu.units + + +