From 78bf82610a30745a83bc16e8d340c0c2fec5ca1e Mon Sep 17 00:00:00 2001 From: Sunil G Date: Sun, 1 Oct 2017 13:02:23 +0530 Subject: [PATCH] YARN-7205 --- .../hadoop/yarn/api/records/ResourceTypeInfo.java | 7 +-- .../hadoop/yarn/util/resource/ResourceUtils.java | 63 ++++++++++++++-------- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ResourceTypeInfo.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ResourceTypeInfo.java index b6f7f14..8775342 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ResourceTypeInfo.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ResourceTypeInfo.java @@ -152,9 +152,10 @@ public static void copy(ResourceTypeInfo src, ResourceTypeInfo dst) { @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append(""); + sb.append(this.getName()); + if (!this.getDefaultUnit().isEmpty()) { + sb.append(" (unit=").append(this.getDefaultUnit()).append(")"); + } return sb.toString(); } 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 0564d74..ad7ff97 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 @@ -22,8 +22,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.classification.InterfaceAudience; -import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.yarn.api.protocolrecords.ResourceTypes; import org.apache.hadoop.yarn.api.records.Resource; @@ -117,19 +115,21 @@ private static void addMandatoryResources( Map res) { ResourceInformation ri; if (!res.containsKey(MEMORY)) { - LOG.info("Adding resource type - name = " + MEMORY + ", units = " - + ResourceInformation.MEMORY_MB.getUnits() + ", type = " - + ResourceTypes.COUNTABLE); - ri = ResourceInformation - .newInstance(MEMORY, - ResourceInformation.MEMORY_MB.getUnits()); + if (LOG.isDebugEnabled()) { + LOG.debug("Adding resource type - name = " + MEMORY + ", units = " + + ResourceInformation.MEMORY_MB.getUnits() + ", type = " + + ResourceTypes.COUNTABLE); + } + ri = ResourceInformation.newInstance(MEMORY, + ResourceInformation.MEMORY_MB.getUnits()); res.put(MEMORY, ri); } if (!res.containsKey(VCORES)) { - LOG.info("Adding resource type - name = " + VCORES + ", units = , type = " - + ResourceTypes.COUNTABLE); - ri = - ResourceInformation.newInstance(VCORES); + if (LOG.isDebugEnabled()) { + LOG.debug("Adding resource type - name = " + VCORES + + ", units = , type = " + ResourceTypes.COUNTABLE); + } + ri = ResourceInformation.newInstance(VCORES); res.put(VCORES, ri); } } @@ -340,13 +340,25 @@ private static void initializeResourceTypesIfNeeded(Configuration conf, if (conf == null) { conf = new YarnConfiguration(); } - try { - addResourcesFileToConf(resourceFile, conf); - LOG.debug("Found " + resourceFile + ", adding to configuration"); - } catch (FileNotFoundException fe) { - LOG.debug("Unable to find '" + resourceFile + "'."); + boolean profileEnabled = conf.getBoolean( + YarnConfiguration.RM_RESOURCE_PROFILES_ENABLED, + YarnConfiguration.DEFAULT_RM_RESOURCE_PROFILES_ENABLED); + + // Let's load new resource profile xml file only is profile + // capability is enabled in YARN. + if (profileEnabled) { + try { + addResourcesFileToConf(resourceFile, conf); + if (LOG.isDebugEnabled()) { + LOG.debug( + "Found " + resourceFile + ", adding to configuration"); + } + } catch (FileNotFoundException fe) { + if (LOG.isDebugEnabled()) { + LOG.debug("Unable to find '" + resourceFile + "'."); + } + } } - initializeResourcesMap(conf); } } @@ -387,7 +399,9 @@ private static void addResourcesFileToConf(String resourceFile, Configuration conf) throws FileNotFoundException { try { InputStream ris = getConfInputStream(resourceFile, conf); - LOG.debug("Found " + resourceFile + ", adding to configuration"); + if (LOG.isDebugEnabled()) { + LOG.debug("Found " + resourceFile + ", adding to configuration"); + } conf.addResource(ris); } catch (FileNotFoundException fe) { throw fe; @@ -471,7 +485,10 @@ public static String getUnits(String resourceValue) { } } } catch (FileNotFoundException fe) { - LOG.info("Couldn't find node resources file"); + if (LOG.isDebugEnabled()) { + LOG.debug("Couldn't find node resources file named:" + + YarnConfiguration.NODE_RESOURCES_CONFIGURATION_FILE); + } } return nodeResources; } @@ -491,8 +508,10 @@ private static void addResourceInformation(String prop, String value, Long.valueOf(value.substring(0, value.length() - units.length())); nodeResources.get(resourceType).setValue(resourceValue); nodeResources.get(resourceType).setUnits(units); - LOG.debug("Setting value for resource type " + resourceType + " to " - + resourceValue + " with units " + units); + if (LOG.isDebugEnabled()) { + LOG.debug("Setting value for resource type " + resourceType + " to " + + resourceValue + " with units " + units); + } } } -- 2.10.1 (Apple Git-78)