hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xkro...@apache.org
Subject [23/32] hadoop git commit: YARN-8524. Single parameter Resource / LightWeightResource constructor looks confusing. (Szilard Nemeth via wangda)
Date Tue, 17 Jul 2018 18:35:49 GMT
YARN-8524. Single parameter Resource / LightWeightResource constructor looks confusing. (Szilard
Nemeth via wangda)

Change-Id: I4ae97548b5b8d76a6bcebb2d3d70bf8e0be3c125


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/238ffff9
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/238ffff9
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/238ffff9

Branch: refs/heads/HDFS-12943
Commit: 238ffff99907290fb2cf791a1ad28ff7f78952f4
Parents: a2e49f4
Author: Wangda Tan <wangda@apache.org>
Authored: Mon Jul 16 10:58:00 2018 -0700
Committer: Wangda Tan <wangda@apache.org>
Committed: Mon Jul 16 10:58:00 2018 -0700

----------------------------------------------------------------------
 .../hadoop/yarn/api/records/Resource.java       | 11 ------
 .../api/records/impl/LightWeightResource.java   | 16 ---------
 .../hadoop/yarn/util/resource/Resources.java    | 23 ++++++++++++-
 .../yarn/util/resource/TestResources.java       | 36 ++++++++++++++++++++
 .../scheduler/fair/ConfigurableResource.java    |  8 ++++-
 5 files changed, 65 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/238ffff9/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java
----------------------------------------------------------------------
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 173d4c9..3cac1d1 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
@@ -76,17 +76,6 @@ public abstract class Resource implements Comparable<Resource> {
   @Private
   public static final int VCORES_INDEX = 1;
 
-  /**
-   * Return a new {@link Resource} instance with all resource values
-   * initialized to {@code value}.
-   * @param value the value to use for all resources
-   * @return a new {@link Resource} instance
-   */
-  @Private
-  @Unstable
-  public static Resource newInstance(long value) {
-    return new LightWeightResource(value);
-  }
 
   @Public
   @Stable

http://git-wip-us.apache.org/repos/asf/hadoop/blob/238ffff9/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/impl/LightWeightResource.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/impl/LightWeightResource.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/impl/LightWeightResource.java
index 77f77f3..02afe50 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/impl/LightWeightResource.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/impl/LightWeightResource.java
@@ -64,22 +64,6 @@ public class LightWeightResource extends Resource {
   private ResourceInformation memoryResInfo;
   private ResourceInformation vcoresResInfo;
 
-  /**
-   * Create a new {@link LightWeightResource} instance with all resource values
-   * initialized to {@code value}.
-   * @param value the value to use for all resources
-   */
-  public LightWeightResource(long value) {
-    ResourceInformation[] types = ResourceUtils.getResourceTypesArray();
-    initResourceInformations(value, value, types.length);
-
-    for (int i = 2; i < types.length; i++) {
-      resources[i] = new ResourceInformation();
-      ResourceInformation.copy(types[i], resources[i]);
-      resources[i].setValue(value);
-    }
-  }
-
   public LightWeightResource(long memory, int vcores) {
     int numberOfKnownResourceTypes = ResourceUtils
         .getNumberOfKnownResourceTypes();

http://git-wip-us.apache.org/repos/asf/hadoop/blob/238ffff9/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java
index 7826f51..ace8b5d 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java
@@ -21,9 +21,11 @@ package org.apache.hadoop.yarn.util.resource;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceAudience.Private;
 import org.apache.hadoop.classification.InterfaceStability.Unstable;
 import org.apache.hadoop.yarn.api.records.Resource;
 import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.api.records.impl.LightWeightResource;
 import org.apache.hadoop.yarn.exceptions.ResourceNotFoundException;
 import org.apache.hadoop.yarn.util.UnitsConversionUtil;
 
@@ -39,10 +41,29 @@ public class Resources {
       LogFactory.getLog(Resources.class);
 
   /**
+   * Return a new {@link Resource} instance with all resource values
+   * initialized to {@code value}.
+   * @param value the value to use for all resources
+   * @return a new {@link Resource} instance
+   */
+  @Private
+  @Unstable
+  public static Resource createResourceWithSameValue(long value) {
+    LightWeightResource res = new LightWeightResource(value,
+            Long.valueOf(value).intValue());
+    int numberOfResources = ResourceUtils.getNumberOfKnownResourceTypes();
+    for (int i = 2; i < numberOfResources; i++) {
+      res.setResourceValue(i, value);
+    }
+
+    return res;
+  }
+
+  /**
    * Helper class to create a resource with a fixed value for all resource
    * types. For example, a NONE resource which returns 0 for any resource type.
    */
-  @InterfaceAudience.Private
+  @Private
   @Unstable
   static class FixedValueResource extends Resource {
 

http://git-wip-us.apache.org/repos/asf/hadoop/blob/238ffff9/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResources.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResources.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResources.java
index a8404fb..07b24eb 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResources.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResources.java
@@ -263,4 +263,40 @@ public class TestResources {
         multiplyAndAddTo(createResource(3, 1, 2), createResource(2, 2, 3),
             1.5));
   }
+
+  @Test
+  public void testCreateResourceWithSameLongValue() throws Exception {
+    unsetExtraResourceType();
+    setupExtraResourceType();
+
+    Resource res = Resources.createResourceWithSameValue(11L);
+    assertEquals(11L, res.getMemorySize());
+    assertEquals(11, res.getVirtualCores());
+    assertEquals(11L, res.getResourceInformation(EXTRA_RESOURCE_TYPE).getValue());
+  }
+
+  @Test
+  public void testCreateResourceWithSameIntValue() throws Exception {
+    unsetExtraResourceType();
+    setupExtraResourceType();
+
+    Resource res = Resources.createResourceWithSameValue(11);
+    assertEquals(11, res.getMemorySize());
+    assertEquals(11, res.getVirtualCores());
+    assertEquals(11, res.getResourceInformation(EXTRA_RESOURCE_TYPE).getValue());
+  }
+
+  @Test
+  public void testCreateSimpleResourceWithSameLongValue() {
+    Resource res = Resources.createResourceWithSameValue(11L);
+    assertEquals(11L, res.getMemorySize());
+    assertEquals(11, res.getVirtualCores());
+  }
+
+  @Test
+  public void testCreateSimpleResourceWithSameIntValue() {
+    Resource res = Resources.createResourceWithSameValue(11);
+    assertEquals(11, res.getMemorySize());
+    assertEquals(11, res.getVirtualCores());
+  }
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/238ffff9/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/ConfigurableResource.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/ConfigurableResource.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/ConfigurableResource.java
index 0c3b0dd..f772c4d 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/ConfigurableResource.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/ConfigurableResource.java
@@ -25,6 +25,7 @@ import org.apache.hadoop.yarn.api.records.Resource;
 import org.apache.hadoop.yarn.api.records.ResourceInformation;
 import org.apache.hadoop.yarn.exceptions.ResourceNotFoundException;
 import org.apache.hadoop.yarn.util.resource.ResourceUtils;
+import org.apache.hadoop.yarn.util.resource.Resources;
 
 /**
  * A {@code ConfigurableResource} object represents an entity that is used to
@@ -46,8 +47,13 @@ public class ConfigurableResource {
     this.resource = null;
   }
 
+  /**
+   * Creates a  {@link ConfigurableResource} instance with all resource values
+   * initialized to {@code value}.
+   * @param value the value to use for all resources
+   */
   ConfigurableResource(long value) {
-    this(Resource.newInstance(value));
+    this(Resources.createResourceWithSameValue(value));
   }
 
   public ConfigurableResource(Resource resource) {


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


Mime
View raw message