From 51d3693a9c7c4d6d2ed0daea4d1165a13fd31a84 Mon Sep 17 00:00:00 2001 From: Wangda Tan Date: Wed, 11 Oct 2017 15:25:28 -0700 Subject: [PATCH] YARN-7205. Log improvements for the ResourceUtils. (Sunil G via wangda) Change-Id: I0f5b7a7f68ec5d3e1d52211f83fdd089bc0bfd37 (cherry picked from commit 8bcc49e6771ca75f012211e27870a421b19233e7) --- .../yarn/api/records/ResourceTypeInfo.java | 7 +-- .../yarn/util/resource/ResourceUtils.java | 43 +++++++++++-------- 2 files changed, 30 insertions(+), 20 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 b6f7f147658..87753426ac3 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 abstract class ResourceTypeInfo implements Comparable { @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 703f32521ff..48e3af6542c 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 @@ -120,19 +120,21 @@ public class ResourceUtils { 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); } } @@ -346,11 +348,11 @@ public class ResourceUtils { } try { addResourcesFileToConf(resourceFile, conf); - LOG.debug("Found " + resourceFile + ", adding to configuration"); } catch (FileNotFoundException fe) { - LOG.debug("Unable to find '" + resourceFile + "'."); + if (LOG.isDebugEnabled()) { + LOG.debug("Unable to find '" + resourceFile + "'."); + } } - initializeResourcesMap(conf); } } @@ -391,7 +393,9 @@ public class ResourceUtils { 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; @@ -475,7 +479,10 @@ public class ResourceUtils { } } } catch (FileNotFoundException fe) { - LOG.info("Couldn't find node resources file"); + if (LOG.isDebugEnabled()) { + LOG.debug("Couldn't find node resources file: " + + YarnConfiguration.NODE_RESOURCES_CONFIGURATION_FILE); + } } return nodeResources; } @@ -495,8 +502,10 @@ public class ResourceUtils { 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); + } } }