YARN-7205. Log improvements for the ResourceUtils. (Sunil G via wangda)

Change-Id: I0f5b7a7f68ec5d3e1d52211f83fdd089bc0bfd37
This commit is contained in:
Wangda Tan 2017-10-11 15:25:28 -07:00
parent b6c2c9058e
commit 8bcc49e677
2 changed files with 30 additions and 22 deletions

View File

@ -152,9 +152,10 @@ public static void copy(ResourceTypeInfo src, ResourceTypeInfo dst) {
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("<name=").append(this.getName()).append(" default-unit=").append( sb.append(this.getName());
this.getDefaultUnit()).append(" type=" + getResourceType()).append( if (!this.getDefaultUnit().isEmpty()) {
">"); sb.append(" (unit=").append(this.getDefaultUnit()).append(")");
}
return sb.toString(); return sb.toString();
} }

View File

@ -22,8 +22,6 @@
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; 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.conf.Configuration;
import org.apache.hadoop.yarn.api.protocolrecords.ResourceTypes; import org.apache.hadoop.yarn.api.protocolrecords.ResourceTypes;
import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.api.records.Resource;
@ -118,19 +116,21 @@ private static void addMandatoryResources(
Map<String, ResourceInformation> res) { Map<String, ResourceInformation> res) {
ResourceInformation ri; ResourceInformation ri;
if (!res.containsKey(MEMORY)) { if (!res.containsKey(MEMORY)) {
LOG.info("Adding resource type - name = " + MEMORY + ", units = " if (LOG.isDebugEnabled()) {
+ ResourceInformation.MEMORY_MB.getUnits() + ", type = " LOG.debug("Adding resource type - name = " + MEMORY + ", units = "
+ ResourceTypes.COUNTABLE); + ResourceInformation.MEMORY_MB.getUnits() + ", type = "
ri = ResourceInformation + ResourceTypes.COUNTABLE);
.newInstance(MEMORY, }
ResourceInformation.MEMORY_MB.getUnits()); ri = ResourceInformation.newInstance(MEMORY,
ResourceInformation.MEMORY_MB.getUnits());
res.put(MEMORY, ri); res.put(MEMORY, ri);
} }
if (!res.containsKey(VCORES)) { if (!res.containsKey(VCORES)) {
LOG.info("Adding resource type - name = " + VCORES + ", units = , type = " if (LOG.isDebugEnabled()) {
+ ResourceTypes.COUNTABLE); LOG.debug("Adding resource type - name = " + VCORES
ri = + ", units = , type = " + ResourceTypes.COUNTABLE);
ResourceInformation.newInstance(VCORES); }
ri = ResourceInformation.newInstance(VCORES);
res.put(VCORES, ri); res.put(VCORES, ri);
} }
} }
@ -343,11 +343,11 @@ private static void initializeResourceTypesIfNeeded(Configuration conf,
} }
try { try {
addResourcesFileToConf(resourceFile, conf); addResourcesFileToConf(resourceFile, conf);
LOG.debug("Found " + resourceFile + ", adding to configuration");
} catch (FileNotFoundException fe) { } catch (FileNotFoundException fe) {
LOG.debug("Unable to find '" + resourceFile + "'."); if (LOG.isDebugEnabled()) {
LOG.debug("Unable to find '" + resourceFile + "'.");
}
} }
initializeResourcesMap(conf); initializeResourcesMap(conf);
} }
} }
@ -388,7 +388,9 @@ private static void addResourcesFileToConf(String resourceFile,
Configuration conf) throws FileNotFoundException { Configuration conf) throws FileNotFoundException {
try { try {
InputStream ris = getConfInputStream(resourceFile, conf); 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); conf.addResource(ris);
} catch (FileNotFoundException fe) { } catch (FileNotFoundException fe) {
throw fe; throw fe;
@ -472,7 +474,10 @@ private static Map<String, ResourceInformation> initializeNodeResourceInformatio
} }
} }
} catch (FileNotFoundException fe) { } 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; return nodeResources;
} }
@ -492,8 +497,10 @@ private static void addResourceInformation(String prop, String value,
Long.valueOf(value.substring(0, value.length() - units.length())); Long.valueOf(value.substring(0, value.length() - units.length()));
nodeResources.get(resourceType).setValue(resourceValue); nodeResources.get(resourceType).setValue(resourceValue);
nodeResources.get(resourceType).setUnits(units); nodeResources.get(resourceType).setUnits(units);
LOG.debug("Setting value for resource type " + resourceType + " to " if (LOG.isDebugEnabled()) {
+ resourceValue + " with units " + units); LOG.debug("Setting value for resource type " + resourceType + " to "
+ resourceValue + " with units " + units);
}
} }
} }