You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by jh...@apache.org on 2019/11/21 19:59:45 UTC

[hadoop] branch branch-2 updated: YARN-7589. TestPBImplRecords fails with NullPointerException. Contributed by Daniel Templeton

This is an automated email from the ASF dual-hosted git repository.

jhung pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/branch-2 by this push:
     new dbbe23f  YARN-7589. TestPBImplRecords fails with NullPointerException. Contributed by Daniel Templeton
dbbe23f is described below

commit dbbe23f2692dd3a7b22ba265bcb21b94edc015f2
Author: Jason Lowe <jl...@apache.org>
AuthorDate: Fri Dec 1 15:37:36 2017 -0600

    YARN-7589. TestPBImplRecords fails with NullPointerException. Contributed by Daniel Templeton
    
    (cherry picked from commit 25df5054216a6a76d09d9c49984f8075ebc6a197)
---
 .../java/org/apache/hadoop/yarn/api/records/Resource.java   |  9 ++++++---
 .../org/apache/hadoop/yarn/util/resource/ResourceUtils.java | 13 +++++++++----
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java
index 7182da5..bd6b315 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java
@@ -99,9 +99,12 @@ public abstract class Resource implements Comparable<Resource> {
   @Stable
   public static Resource newInstance(long memory, int vCores,
       Map<String, Long> others) {
-    ResourceInformation[] info = ResourceUtils.createResourceTypesArray(others);
-
-    return new LightWeightResource(memory, vCores, info);
+    if (others != null) {
+      return new LightWeightResource(memory, vCores,
+          ResourceUtils.createResourceTypesArray(others));
+    } else {
+      return newInstance(memory, vCores);
+    }
   }
 
   @InterfaceAudience.Private
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 0b909a6..d1beb1e6 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
@@ -341,15 +341,13 @@ public class ResourceUtils {
   }
 
   public static ResourceInformation[] getResourceTypesArray() {
-    initializeResourceTypesIfNeeded(null,
-        YarnConfiguration.RESOURCE_TYPES_CONFIGURATION_FILE);
+    initializeResourceTypesIfNeeded();
     return resourceTypesArray;
   }
 
   public static int getNumberOfKnownResourceTypes() {
     if (numKnownResourceTypes < 0) {
-      initializeResourceTypesIfNeeded(null,
-          YarnConfiguration.RESOURCE_TYPES_CONFIGURATION_FILE);
+      initializeResourceTypesIfNeeded();
     }
     return numKnownResourceTypes;
   }
@@ -360,6 +358,11 @@ public class ResourceUtils {
         YarnConfiguration.RESOURCE_TYPES_CONFIGURATION_FILE);
   }
 
+  private static void initializeResourceTypesIfNeeded() {
+    initializeResourceTypesIfNeeded(null,
+        YarnConfiguration.RESOURCE_TYPES_CONFIGURATION_FILE);
+  }
+
   private static void initializeResourceTypesIfNeeded(Configuration conf,
       String resourceFile) {
     if (!initializedResources) {
@@ -631,6 +634,8 @@ public class ResourceUtils {
    */
   public static ResourceInformation[] createResourceTypesArray(Map<String,
       Long> res) {
+    initializeResourceTypesIfNeeded();
+
     ResourceInformation[] info = new ResourceInformation[resourceTypes.size()];
 
     for (Entry<String, Integer> entry : RESOURCE_NAME_TO_INDEX.entrySet()) {


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org