diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java index 103bcfd..6ab8d50 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java @@ -82,8 +82,13 @@ public static Resource newInstance(Resource resource) { Resource ret = Resource.newInstance(0, 0); for (Map.Entry entry : resource.getResources() .entrySet()) { - ret.setResourceInformation(entry.getKey(), - ResourceInformation.newInstance(entry.getValue())); + try { + ResourceInformation + .copy(entry.getValue(), ret.getResourceInformation(entry.getKey())); + } catch (YarnException ye) { + ret.setResourceInformation(entry.getKey(), + ResourceInformation.newInstance(entry.getValue())); + } } return ret; } diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ResourceInformation.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ResourceInformation.java index 7d74efc..bda7e48d 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ResourceInformation.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ResourceInformation.java @@ -30,9 +30,9 @@ private String name; private String units; private ResourceTypes resourceType; - private Long value; - private Long minimumAllocation; - private Long maximumAllocation; + private long value; + private long minimumAllocation; + private long maximumAllocation; private static final String MEMORY_URI = "memory-mb"; private static final String VCORES_URI = "vcores"; @@ -106,7 +106,7 @@ public void setResourceType(ResourceTypes type) { * * @return the resource value */ - public Long getValue() { + public long getValue() { return value; } @@ -115,7 +115,7 @@ public Long getValue() { * * @param rValue the resource value */ - public void setValue(Long rValue) { + public void setValue(long rValue) { this.value = rValue; } @@ -124,7 +124,7 @@ public void setValue(Long rValue) { * * @return the minimum allocation for the resource */ - public Long getMinimumAllocation() { + public long getMinimumAllocation() { return minimumAllocation; } @@ -133,7 +133,7 @@ public Long getMinimumAllocation() { * * @param minimumAllocation the minimum allocation for the resource */ - public void setMinimumAllocation(Long minimumAllocation) { + public void setMinimumAllocation(long minimumAllocation) { this.minimumAllocation = minimumAllocation; } @@ -142,7 +142,7 @@ public void setMinimumAllocation(Long minimumAllocation) { * * @return the maximum allocation for the resource */ - public Long getMaximumAllocation() { + public long getMaximumAllocation() { return maximumAllocation; } @@ -151,7 +151,7 @@ public Long getMaximumAllocation() { * * @param maximumAllocation the maximum allocation for the resource */ - public void setMaximumAllocation(Long maximumAllocation) { + public void setMaximumAllocation(long maximumAllocation) { this.maximumAllocation = maximumAllocation; } @@ -163,18 +163,13 @@ public void setMaximumAllocation(Long maximumAllocation) { */ public static ResourceInformation newInstance(ResourceInformation other) { ResourceInformation ret = new ResourceInformation(); - ret.setName(other.getName()); - ret.setResourceType(other.getResourceType()); - ret.setUnits(other.getUnits()); - ret.setValue(other.getValue()); - ret.setMinimumAllocation(other.getMinimumAllocation()); - ret.setMaximumAllocation(other.getMaximumAllocation()); + copy(other, ret); return ret; } public static ResourceInformation newInstance(String name, String units, - Long value, ResourceTypes type, Long minimumAllocation, - Long maximumAllocation) { + long value, ResourceTypes type, long minimumAllocation, + long maximumAllocation) { ResourceInformation ret = new ResourceInformation(); ret.setName(name); ret.setResourceType(type); @@ -186,7 +181,7 @@ public static ResourceInformation newInstance(String name, String units, } public static ResourceInformation newInstance(String name, String units, - Long value) { + long value) { return ResourceInformation .newInstance(name, units, value, ResourceTypes.COUNTABLE, 0L, Long.MAX_VALUE); @@ -198,7 +193,7 @@ public static ResourceInformation newInstance(String name, String units) { Long.MAX_VALUE); } - public static ResourceInformation newInstance(String name, Long value) { + public static ResourceInformation newInstance(String name, long value) { return ResourceInformation .newInstance(name, "", value, ResourceTypes.COUNTABLE, 0L, Long.MAX_VALUE); @@ -208,6 +203,15 @@ public static ResourceInformation newInstance(String name) { return ResourceInformation.newInstance(name, ""); } + public static void copy(ResourceInformation src, ResourceInformation dst) { + dst.setName(src.getName()); + dst.setResourceType(src.getResourceType()); + dst.setUnits(src.getUnits()); + dst.setValue(src.getValue()); + dst.setMinimumAllocation(src.getMinimumAllocation()); + dst.setMaximumAllocation(src.getMaximumAllocation()); + } + @Override public String toString() { return "name: " + this.name + ", units: " + this.units + ", type: " @@ -244,7 +248,7 @@ public int hashCode() { 939769357 + name.hashCode(); // prime * result = 939769357 initially result = prime * result + resourceType.hashCode(); result = prime * result + units.hashCode(); - result = prime * result + value.hashCode(); + result = prime * result + Long.hashCode(value); return result; } diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/util/UnitsConversionUtil.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/util/UnitsConversionUtil.java index 47bb3df..f2846d4 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/util/UnitsConversionUtil.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/util/UnitsConversionUtil.java @@ -128,8 +128,8 @@ private static Converter getConverter(String unit) { * @param fromValue the value you wish to convert * @return the value in toUnit */ - public static Long convert(String fromUnit, String toUnit, Long fromValue) { - if (toUnit == null || fromUnit == null || fromValue == null) { + public static long convert(String fromUnit, String toUnit, long fromValue) { + if (toUnit == null || fromUnit == null) { throw new IllegalArgumentException("One or more arguments are null"); } String overflowMsg = @@ -140,9 +140,9 @@ public static Long convert(String fromUnit, String toUnit, Long fromValue) { } Converter fc = getConverter(fromUnit); Converter tc = getConverter(toUnit); - Long numerator = fc.numerator * tc.denominator; - Long denominator = fc.denominator * tc.numerator; - Long numeratorMultiplierLimit = Long.MAX_VALUE / numerator; + long numerator = fc.numerator * tc.denominator; + long denominator = fc.denominator * tc.numerator; + long numeratorMultiplierLimit = Long.MAX_VALUE / numerator; if (numerator < denominator) { if (numeratorMultiplierLimit < fromValue) { throw new IllegalArgumentException(overflowMsg); @@ -152,7 +152,7 @@ public static Long convert(String fromUnit, String toUnit, Long fromValue) { if (numeratorMultiplierLimit > fromValue) { return (numerator * fromValue) / denominator; } - Long tmp = numerator / denominator; + long tmp = numerator / denominator; if ((Long.MAX_VALUE / tmp) < fromValue) { throw new IllegalArgumentException(overflowMsg); } @@ -170,8 +170,8 @@ public static Long convert(String fromUnit, String toUnit, Long fromValue) { * @return +1, 0 or -1 depending on whether the relationship is greater than, * equal to or lesser than */ - public static int compare(String unitA, Long valueA, String unitB, - Long valueB) { + public static int compare(String unitA, long valueA, String unitB, + long valueB) { if (unitA == null || unitB == null || !KNOWN_UNITS.contains(unitA) || !KNOWN_UNITS.contains(unitB)) { throw new IllegalArgumentException("Units cannot be null"); @@ -185,19 +185,19 @@ public static int compare(String unitA, Long valueA, String unitB, Converter unitAC = getConverter(unitA); Converter unitBC = getConverter(unitB); if (unitA.equals(unitB)) { - return valueA.compareTo(valueB); + return Long.valueOf(valueA).compareTo(valueB); } int unitAPos = SORTED_UNITS.indexOf(unitA); int unitBPos = SORTED_UNITS.indexOf(unitB); try { - Long tmpA = valueA; - Long tmpB = valueB; + long tmpA = valueA; + long tmpB = valueB; if (unitAPos < unitBPos) { tmpB = convert(unitB, unitA, valueB); } else { tmpA = convert(unitA, unitB, valueA); } - return tmpA.compareTo(tmpB); + return Long.valueOf(tmpA).compareTo(tmpB); } catch (IllegalArgumentException ie) { BigInteger tmpA = BigInteger.valueOf(valueA); BigInteger tmpB = BigInteger.valueOf(valueB); diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/conf/TestResourceInformation.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/conf/TestResourceInformation.java index 28f69c9..adbaa9f 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/conf/TestResourceInformation.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/conf/TestResourceInformation.java @@ -50,7 +50,7 @@ public void testUnits() { @Test public void testValue() { String name = "yarn.io/test"; - Long value = 1l; + long value = 1l; ResourceInformation ri = ResourceInformation.newInstance(name, value); Assert.assertEquals("Resource name incorrect", name, ri.getName()); Assert.assertEquals("Resource value incorrect", value, ri.getValue()); @@ -59,7 +59,7 @@ public void testValue() { @Test public void testResourceInformation() { String name = "yarn.io/test"; - Long value = 1l; + long value = 1l; String units = "m"; ResourceInformation ri = ResourceInformation.newInstance(name, units, value); diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/util/TestUnitsConversionUtil.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/util/TestUnitsConversionUtil.java index 0f999e8..0b512a5 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/util/TestUnitsConversionUtil.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/test/java/org/apache/hadoop/yarn/util/TestUnitsConversionUtil.java @@ -27,62 +27,62 @@ public void testUnitsConversion() { int value = 5; String fromUnit = ""; - Long test = Long.valueOf(value); + long test = value; Assert.assertEquals("pico test failed", - Long.valueOf(value * 1000l * 1000l * 1000l * 1000l), + value * 1000L * 1000L * 1000L * 1000L, UnitsConversionUtil.convert(fromUnit, "p", test)); Assert.assertEquals("nano test failed", - Long.valueOf(value * 1000l * 1000l * 1000l), + value * 1000L * 1000L * 1000L, UnitsConversionUtil.convert(fromUnit, "n", test)); Assert - .assertEquals("micro test failed", Long.valueOf(value * 1000l * 1000l), + .assertEquals("micro test failed", value * 1000L * 1000L, UnitsConversionUtil.convert(fromUnit, "u", test)); - Assert.assertEquals("milli test failed", Long.valueOf(value * 1000l), + Assert.assertEquals("milli test failed", value * 1000L, UnitsConversionUtil.convert(fromUnit, "m", test)); - test = Long.valueOf(value * 1000l * 1000l * 1000l * 1000l * 1000l); + test = value * 1000L * 1000L * 1000L * 1000L * 1000L; fromUnit = ""; - Assert.assertEquals("kilo test failed", Long.valueOf(test / 1000l), + Assert.assertEquals("kilo test failed", test / 1000L, UnitsConversionUtil.convert(fromUnit, "k", test)); Assert - .assertEquals("mega test failed", Long.valueOf(test / (1000l * 1000l)), + .assertEquals("mega test failed", test / (1000L * 1000L), UnitsConversionUtil.convert(fromUnit, "M", test)); Assert.assertEquals("giga test failed", - Long.valueOf(test / (1000l * 1000l * 1000l)), + test / (1000L * 1000L * 1000L), UnitsConversionUtil.convert(fromUnit, "G", test)); Assert.assertEquals("tera test failed", - Long.valueOf(test / (1000l * 1000l * 1000l * 1000l)), + test / (1000L * 1000L * 1000L * 1000L), UnitsConversionUtil.convert(fromUnit, "T", test)); Assert.assertEquals("peta test failed", - Long.valueOf(test / (1000l * 1000l * 1000l * 1000l * 1000l)), + test / (1000L * 1000L * 1000L * 1000L * 1000L), UnitsConversionUtil.convert(fromUnit, "P", test)); - Assert.assertEquals("nano to pico test failed", Long.valueOf(value * 1000l), - UnitsConversionUtil.convert("n", "p", Long.valueOf(value))); + Assert.assertEquals("nano to pico test failed", value * 1000L, + UnitsConversionUtil.convert("n", "p", value)); - Assert.assertEquals("mega to giga test failed", Long.valueOf(value), - UnitsConversionUtil.convert("M", "G", Long.valueOf(value * 1000l))); + Assert.assertEquals("mega to giga test failed", value, + UnitsConversionUtil.convert("M", "G", value * 1000L)); - Assert.assertEquals("Mi to Gi test failed", Long.valueOf(value), - UnitsConversionUtil.convert("Mi", "Gi", Long.valueOf(value * 1024l))); + Assert.assertEquals("Mi to Gi test failed", value, + UnitsConversionUtil.convert("Mi", "Gi", value * 1024L)); - Assert.assertEquals("Mi to Ki test failed", Long.valueOf(value * 1024), - UnitsConversionUtil.convert("Mi", "Ki", Long.valueOf(value))); + Assert.assertEquals("Mi to Ki test failed", value * 1024, + UnitsConversionUtil.convert("Mi", "Ki", value)); - Assert.assertEquals("Ki to base units test failed", Long.valueOf(5 * 1024), - UnitsConversionUtil.convert("Ki", "", Long.valueOf(5))); + Assert.assertEquals("Ki to base units test failed", 5 * 1024, + UnitsConversionUtil.convert("Ki", "", 5)); - Assert.assertEquals("Mi to k test failed", Long.valueOf(1073741), - UnitsConversionUtil.convert("Mi", "k", Long.valueOf(1024))); + Assert.assertEquals("Mi to k test failed", 1073741, + UnitsConversionUtil.convert("Mi", "k", 1024)); - Assert.assertEquals("M to Mi test failed", Long.valueOf(953), - UnitsConversionUtil.convert("M", "Mi", Long.valueOf(1000))); + Assert.assertEquals("M to Mi test failed", 953, + UnitsConversionUtil.convert("M", "Mi", 1000)); } @Test public void testOverflow() { - Long test = Long.valueOf(5 * 1000l * 1000l * 1000l * 1000l * 1000l); + long test = 5 * 1000L * 1000L * 1000L * 1000L * 1000L; try { UnitsConversionUtil.convert("P", "p", test); Assert.fail("this operation should result in an overflow"); @@ -100,9 +100,9 @@ public void testOverflow() { @Test public void testCompare() { String unitA = "P"; - Long valueA = Long.valueOf(1); + long valueA = 1; String unitB = "p"; - Long valueB = Long.valueOf(2); + long valueB = 2; Assert.assertEquals(1, UnitsConversionUtil.compare(unitA, valueA, unitB, valueB)); Assert.assertEquals(-1, @@ -120,7 +120,7 @@ public void testCompare() { Assert.assertEquals(-1, UnitsConversionUtil.compare(unitB, valueB, unitA, valueA)); Assert.assertEquals(0, - UnitsConversionUtil.compare(unitA, valueA, unitB, 1000l)); + UnitsConversionUtil.compare(unitA, valueA, unitB, 1000L)); unitA = "p"; unitB = "n"; @@ -129,7 +129,7 @@ public void testCompare() { Assert.assertEquals(1, UnitsConversionUtil.compare(unitB, valueB, unitA, valueA)); Assert.assertEquals(0, - UnitsConversionUtil.compare(unitA, 1000l, unitB, valueA)); + UnitsConversionUtil.compare(unitA, 1000L, unitB, valueA)); } } diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ResourcePBImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ResourcePBImpl.java index da07539..ecb6adb 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ResourcePBImpl.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ResourcePBImpl.java @@ -97,10 +97,8 @@ public void setMemory(int memory) { @Override public void setMemorySize(long memory) { - setResourceInformation(ResourceInformation.MEMORY_MB.getName(), - ResourceInformation.newInstance(ResourceInformation.MEMORY_MB.getName(), - ResourceInformation.MEMORY_MB.getUnits(), memory)); - + maybeInitBuilder(); + getResourceInformation(ResourceInformation.MEMORY_MB.getName()).setValue(memory); } @Override @@ -113,9 +111,8 @@ public int getVirtualCores() { @Override public void setVirtualCores(int vCores) { - setResourceInformation(ResourceInformation.VCORES.getName(), - ResourceInformation.newInstance(ResourceInformation.VCORES.getName(), - ResourceInformation.VCORES.getUnits(), (long) vCores)); + maybeInitBuilder(); + getResourceInformation(ResourceInformation.VCORES.getName()).setValue(vCores); } private void initResources() { @@ -129,7 +126,7 @@ private void initResources() { entry.hasType() ? ProtoUtils.convertFromProtoFormat(entry.getType()) : ResourceTypes.COUNTABLE; String units = entry.hasUnits() ? entry.getUnits() : ""; - Long value = entry.hasValue() ? entry.getValue() : 0L; + long value = entry.hasValue() ? entry.getValue() : 0L; ResourceInformation ri = ResourceInformation .newInstance(entry.getKey(), units, value, type, 0L, Long.MAX_VALUE); if (resources.containsKey(ri.getName())) { @@ -157,7 +154,7 @@ public void setResourceInformation(String resource, } initResources(); if (resources.containsKey(resource)) { - resources.put(resource, resourceInformation); + ResourceInformation.copy(resourceInformation, resources.get(resource)); } } @@ -179,7 +176,7 @@ public void setResourceValue(String resource, Long value) @Override public Map getResources() { initResources(); - return Collections.unmodifiableMap(this.resources); + return resources; } @Override diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/DominantResourceCalculator.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/DominantResourceCalculator.java index b265575..6e61a14 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/DominantResourceCalculator.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/DominantResourceCalculator.java @@ -154,7 +154,7 @@ protected float getResourceAsValue(Resource clusterResource, clusterResource.getResourceInformation(rName); ResourceInformation resourceInformation = resource.getResourceInformation(rName); - Long resourceValue = UnitsConversionUtil + long resourceValue = UnitsConversionUtil .convert(resourceInformation.getUnits(), clusterResourceResourceInformation.getUnits(), resourceInformation.getValue()); @@ -180,11 +180,11 @@ public long computeAvailableContainers(Resource available, Resource required) { available.getResourceInformation(resource); ResourceInformation requiredResource = required.getResourceInformation(resource); - Long requiredResourceValue = UnitsConversionUtil + long requiredResourceValue = UnitsConversionUtil .convert(requiredResource.getUnits(), availableResource.getUnits(), requiredResource.getValue()); if (requiredResourceValue != 0) { - Long tmp = availableResource.getValue() / requiredResourceValue; + long tmp = availableResource.getValue() / requiredResourceValue; min = min < tmp ? min : tmp; } } catch (YarnException ye) { @@ -228,7 +228,7 @@ public float ratio(Resource a, Resource b) { a.getResourceInformation(resource); ResourceInformation bResourceInformation = b.getResourceInformation(resource); - Long bResourceValue = UnitsConversionUtil + long bResourceValue = UnitsConversionUtil .convert(bResourceInformation.getUnits(), aResourceInformation.getUnits(), bResourceInformation.getValue()); @@ -252,11 +252,12 @@ public Resource divideAndCeil(Resource numerator, long denominator) { Resource ret = Resources.createResource(0, 0); for (String resource : resourceNames) { try { - ResourceInformation resourceInformation = ResourceInformation - .newInstance(numerator.getResourceInformation(resource)); + ResourceInformation resourceInformation = ret.getResourceInformation(resource); + ResourceInformation.copy(numerator.getResourceInformation(resource), resourceInformation); + // ResourceInformation resourceInformation = ResourceInformation + // .newInstance(numerator.getResourceInformation(resource)); resourceInformation.setValue( divideAndCeil(resourceInformation.getValue(), denominator)); - ret.setResourceInformation(resource, resourceInformation); } catch (YarnException ye) { throw new IllegalArgumentException( "Error getting resource information for " + resource, ye); @@ -279,28 +280,27 @@ public Resource normalize(Resource r, Resource minimumResource, maximumResource.getResourceInformation(resource); ResourceInformation stepFactorResourceInformation = stepFactor.getResourceInformation(resource); - ResourceInformation tmp = - ResourceInformation.newInstance(rResourceInformation); + ResourceInformation tmp = ret.getResourceInformation(resource); + ResourceInformation.copy(rResourceInformation, tmp); - Long rValue = rResourceInformation.getValue(); - Long minimumValue = UnitsConversionUtil + long rValue = rResourceInformation.getValue(); + long minimumValue = UnitsConversionUtil .convert(minimumResourceInformation.getUnits(), rResourceInformation.getUnits(), minimumResourceInformation.getValue()); - Long maximumValue = UnitsConversionUtil + long maximumValue = UnitsConversionUtil .convert(maximumResourceInformation.getUnits(), rResourceInformation.getUnits(), maximumResourceInformation.getValue()); - Long stepFactorValue = UnitsConversionUtil + long stepFactorValue = UnitsConversionUtil .convert(stepFactorResourceInformation.getUnits(), rResourceInformation.getUnits(), stepFactorResourceInformation.getValue()); - Long value = Math.max(rValue, minimumValue); + long value = Math.max(rValue, minimumValue); if (stepFactorValue != 0) { value = roundUp(value, stepFactorValue); } tmp.setValue(Math.min(value, maximumValue)); - ret.setResourceInformation(resource, tmp); } catch (YarnException ye) { throw new IllegalArgumentException( "Error getting resource information for " + resource, ye); @@ -327,21 +327,23 @@ private Resource rounding(Resource r, Resource stepFactor, boolean roundUp) { r.getResourceInformation(resource); ResourceInformation stepFactorResourceInformation = stepFactor.getResourceInformation(resource); - ResourceInformation tmp = - ResourceInformation.newInstance(rResourceInformation); + // ResourceInformation tmp = + // ResourceInformation.newInstance(rResourceInformation); - Long rValue = rResourceInformation.getValue(); - Long stepFactorValue = UnitsConversionUtil + long rValue = rResourceInformation.getValue(); + long stepFactorValue = UnitsConversionUtil .convert(stepFactorResourceInformation.getUnits(), rResourceInformation.getUnits(), stepFactorResourceInformation.getValue()); - Long value = rValue; + long value = rValue; if (stepFactorValue != 0) { value = roundUp ? roundUp(rValue, stepFactorValue) : roundDown(rValue, stepFactorValue); } - tmp.setValue(value); - ret.setResourceInformation(resource, tmp); + // tmp.setValue(value); + ResourceInformation.copy(rResourceInformation, ret.getResourceInformation(resource)); + ret.getResourceInformation(resource).setValue(value); + // ret.setResourceInformation(resource, tmp); } catch (YarnException ye) { throw new IllegalArgumentException( "Error getting resource information for " + resource, ye); @@ -371,8 +373,8 @@ private Resource multiplyAndNormalize(Resource r, double by, r.getResourceInformation(resource); ResourceInformation stepFactorResourceInformation = stepFactor.getResourceInformation(resource); - ResourceInformation tmp = - ResourceInformation.newInstance(rResourceInformation); + ResourceInformation tmp = ret.getResourceInformation(resource); + ResourceInformation.copy(rResourceInformation, tmp); Long rValue = rResourceInformation.getValue(); Long stepFactorValue = UnitsConversionUtil @@ -389,7 +391,6 @@ private Resource multiplyAndNormalize(Resource r, double by, roundUp ? (long) Math.ceil(rValue * by) : (long) (rValue * by); } tmp.setValue(value); - ret.setResourceInformation(resource, tmp); } catch (YarnException ye) { throw new IllegalArgumentException( "Error getting resource information for " + resource, ye); @@ -406,7 +407,7 @@ public boolean fitsIn(Resource cluster, Resource smaller, Resource bigger) { smaller.getResourceInformation(resource); ResourceInformation bResourceInformation = bigger.getResourceInformation(resource); - Long sResourceValue = UnitsConversionUtil + long sResourceValue = UnitsConversionUtil .convert(sResourceInformation.getUnits(), bResourceInformation.getUnits(), sResourceInformation.getValue()); diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java index 9a1a13c..8128cb1 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java @@ -42,7 +42,7 @@ static class FixedValueResource extends Resource { private Map resources; - private Long resourceValue; + private long resourceValue; private String name; /** @@ -50,7 +50,7 @@ * @param rName the name of the resource * @param value the fixed value to be returned for all resource types */ - FixedValueResource(String rName, Long value) { + FixedValueResource(String rName, long value) { this.resourceValue = value; this.name = rName; resources = initResourceMap(); @@ -60,7 +60,7 @@ private int resourceValueToInt() { if(this.resourceValue > Integer.MAX_VALUE) { return Integer.MAX_VALUE; } - return this.resourceValue.intValue(); + return Long.valueOf(this.resourceValue).intValue(); } @Override @@ -209,7 +209,7 @@ public static Resource addTo(Resource lhs, Resource rhs) { try { ResourceInformation rhsValue = rhs.getResourceInformation(name); ResourceInformation lhsValue = entry.getValue(); - Long convertedRhs = UnitsConversionUtil + long convertedRhs = UnitsConversionUtil .convert(rhsValue.getUnits(), lhsValue.getUnits(), rhsValue.getValue()); lhs.setResourceValue(name, lhsValue.getValue() + convertedRhs); @@ -231,7 +231,7 @@ public static Resource subtractFrom(Resource lhs, Resource rhs) { try { ResourceInformation rhsValue = rhs.getResourceInformation(name); ResourceInformation lhsValue = entry.getValue(); - Long convertedRhs = UnitsConversionUtil + long convertedRhs = UnitsConversionUtil .convert(rhsValue.getUnits(), lhsValue.getUnits(), rhsValue.getValue()); lhs.setResourceValue(name, lhsValue.getValue() - convertedRhs); @@ -294,7 +294,7 @@ public static Resource multiplyAndAddTo( try { ResourceInformation rhsValue = rhs.getResourceInformation(name); ResourceInformation lhsValue = entry.getValue(); - Long convertedRhs = (long) (UnitsConversionUtil + long convertedRhs = (long) (UnitsConversionUtil .convert(rhsValue.getUnits(), lhsValue.getUnits(), rhsValue.getValue()) * by); lhs.setResourceValue(name, lhsValue.getValue() + convertedRhs); @@ -416,7 +416,7 @@ public static boolean fitsIn(Resource smaller, Resource bigger) { try { ResourceInformation rhsValue = bigger.getResourceInformation(name); ResourceInformation lhsValue = entry.getValue(); - Long convertedRhs = UnitsConversionUtil + long convertedRhs = UnitsConversionUtil .convert(rhsValue.getUnits(), lhsValue.getUnits(), rhsValue.getValue()); if(lhsValue.getValue() > convertedRhs) { @@ -442,7 +442,7 @@ public static Resource componentwiseMin(Resource lhs, Resource rhs) { try { ResourceInformation rhsValue = rhs.getResourceInformation(name); ResourceInformation lhsValue = entry.getValue(); - Long convertedRhs = UnitsConversionUtil + long convertedRhs = UnitsConversionUtil .convert(rhsValue.getUnits(), lhsValue.getUnits(), rhsValue.getValue()); ResourceInformation outInfo = @@ -463,7 +463,7 @@ public static Resource componentwiseMax(Resource lhs, Resource rhs) { try { ResourceInformation rhsValue = rhs.getResourceInformation(name); ResourceInformation lhsValue = entry.getValue(); - Long convertedRhs = UnitsConversionUtil + long convertedRhs = UnitsConversionUtil .convert(rhsValue.getUnits(), lhsValue.getUnits(), rhsValue.getValue()); ResourceInformation outInfo = diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceUtils.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceUtils.java index 6f17659..38554b6 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceUtils.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResourceUtils.java @@ -283,6 +283,7 @@ public void testGetResourceInformation() throws Exception { Map actual = ResourceUtils.getNodeResourceInformation(conf); Assert.assertEquals(entry.getValue().getResources(), actual); + dest.delete(); } } diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResources.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResources.java index 75827f6..1bf04c8 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResources.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/resource/TestResources.java @@ -42,6 +42,16 @@ public class TestResources { + static class ExtendedResources extends Resources { + public static Resource unbounded() { + return new FixedValueResource("UNBOUNDED", Long.MAX_VALUE); + } + + public static Resource none() { + return new FixedValueResource("NONE", 0L); + } + } + private static final String EXTRA_RESOURCE_TYPE = "resource2"; private String resourceTypesFile; @@ -87,7 +97,7 @@ public Resource createResource(long memory, int vCores, long resource2) { @Test(timeout = 1000) public void testCompareToWithUnboundedResource() { unsetExtraResourceType(); - Resource unboundedClone = Resources.clone(Resources.unbounded()); + Resource unboundedClone = Resources.clone(ExtendedResources.unbounded()); assertTrue(unboundedClone .compareTo(createResource(Long.MAX_VALUE, Integer.MAX_VALUE)) == 0); assertTrue(unboundedClone.compareTo(createResource(Long.MAX_VALUE, 0)) > 0); diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/ResourceProfilesManagerImpl.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/ResourceProfilesManagerImpl.java index 8839bf9..7987ded 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/ResourceProfilesManagerImpl.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/ResourceProfilesManagerImpl.java @@ -131,7 +131,8 @@ private Resource parseResource(String key, Map value) throws IOException { continue; } if (resourceName.equals(VCORES)) { - resource.setVirtualCores(resourceValue.getValue().intValue()); + resource + .setVirtualCores(Long.valueOf(resourceValue.getValue()).intValue()); continue; } if (resourceTypes.containsKey(resourceName)) {