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 c9cc27b311..9c9c0ef897 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 @@ -342,17 +342,14 @@ private static void initializeResourceTypesIfNeeded(Configuration conf, if (!initializedResources) { synchronized (ResourceUtils.class) { if (!initializedResources) { - if (conf == null) { - conf = new YarnConfiguration(); + Configuration resConf = conf; + + if (resConf == null) { + resConf = new YarnConfiguration(); } - try { - addResourcesFileToConf(resourceFile, conf); - } catch (FileNotFoundException fe) { - if (LOG.isDebugEnabled()) { - LOG.debug("Unable to find '" + resourceFile + "'."); - } - } - initializeResourcesMap(conf); + + addResourcesFileToConf(resourceFile, resConf); + initializeResourcesMap(resConf); } } } @@ -389,7 +386,7 @@ private static InputStream getConfInputStream(String resourceFile, } private static void addResourcesFileToConf(String resourceFile, - Configuration conf) throws FileNotFoundException { + Configuration conf) { try { InputStream ris = getConfInputStream(resourceFile, conf); if (LOG.isDebugEnabled()) { @@ -397,15 +394,11 @@ private static void addResourcesFileToConf(String resourceFile, } conf.addResource(ris); } catch (FileNotFoundException fe) { - throw fe; - } catch (IOException ie) { + LOG.info("Unable to find '" + resourceFile + "'."); + } catch (IOException | YarnException ex) { LOG.fatal("Exception trying to read resource types configuration '" - + resourceFile + "'.", ie); - throw new YarnRuntimeException(ie); - } catch (YarnException ye) { - LOG.fatal("YARN Exception trying to read resource types configuration '" - + resourceFile + "'.", ye); - throw new YarnRuntimeException(ye); + + resourceFile + "'.", ex); + throw new YarnRuntimeException(ex); } } @@ -467,22 +460,19 @@ public static Map getNodeResourceInformation( private static Map initializeNodeResourceInformation( Configuration conf) { Map nodeResources = new HashMap<>(); - try { - addResourcesFileToConf( - YarnConfiguration.NODE_RESOURCES_CONFIGURATION_FILE, conf); - for (Map.Entry entry : conf) { - String key = entry.getKey(); - String value = entry.getValue(); - if (key.startsWith(YarnConfiguration.NM_RESOURCES_PREFIX)) { - addResourceInformation(key, value, nodeResources); - } - } - } catch (FileNotFoundException fe) { - if (LOG.isDebugEnabled()) { - LOG.debug("Couldn't find node resources file: " - + YarnConfiguration.NODE_RESOURCES_CONFIGURATION_FILE); + + addResourcesFileToConf(YarnConfiguration.NODE_RESOURCES_CONFIGURATION_FILE, + conf); + + for (Map.Entry entry : conf) { + String key = entry.getKey(); + String value = entry.getValue(); + + if (key.startsWith(YarnConfiguration.NM_RESOURCES_PREFIX)) { + addResourceInformation(key, value, nodeResources); } } + return nodeResources; }