YARN-9182. Backport YARN-6445 resource profile performance improvements to branch-2
This commit is contained in:
parent
08923e324a
commit
d5963b2be9
|
@ -107,14 +107,25 @@ public abstract class Resource implements Comparable<Resource> {
|
||||||
@InterfaceStability.Unstable
|
@InterfaceStability.Unstable
|
||||||
public static Resource newInstance(Resource resource) {
|
public static Resource newInstance(Resource resource) {
|
||||||
Resource ret = Resource.newInstance(0, 0);
|
Resource ret = Resource.newInstance(0, 0);
|
||||||
for (Map.Entry<String, ResourceInformation> entry : resource.getResources()
|
Resource.copy(resource, ret);
|
||||||
.entrySet()) {
|
|
||||||
ret.setResourceInformation(entry.getKey(),
|
|
||||||
ResourceInformation.newInstance(entry.getValue()));
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@InterfaceAudience.Private
|
||||||
|
@InterfaceStability.Unstable
|
||||||
|
public static void copy(Resource source, Resource dest) {
|
||||||
|
for (Map.Entry<String, ResourceInformation> entry : source.getResources()
|
||||||
|
.entrySet()) {
|
||||||
|
try {
|
||||||
|
ResourceInformation.copy(entry.getValue(),
|
||||||
|
dest.getResourceInformation(entry.getKey()));
|
||||||
|
} catch (YarnException ye) {
|
||||||
|
dest.setResourceInformation(entry.getKey(),
|
||||||
|
ResourceInformation.newInstance(entry.getValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is DEPRECATED:
|
* This method is DEPRECATED:
|
||||||
* Use {@link Resource#getMemorySize()} instead
|
* Use {@link Resource#getMemorySize()} instead
|
||||||
|
|
|
@ -30,9 +30,9 @@ public class ResourceInformation implements Comparable<ResourceInformation> {
|
||||||
private String name;
|
private String name;
|
||||||
private String units;
|
private String units;
|
||||||
private ResourceTypes resourceType;
|
private ResourceTypes resourceType;
|
||||||
private Long value;
|
private long value;
|
||||||
private Long minimumAllocation;
|
private long minimumAllocation;
|
||||||
private Long maximumAllocation;
|
private long maximumAllocation;
|
||||||
|
|
||||||
private static final String MEMORY_URI = "memory-mb";
|
private static final String MEMORY_URI = "memory-mb";
|
||||||
private static final String VCORES_URI = "vcores";
|
private static final String VCORES_URI = "vcores";
|
||||||
|
@ -106,7 +106,7 @@ public class ResourceInformation implements Comparable<ResourceInformation> {
|
||||||
*
|
*
|
||||||
* @return the resource value
|
* @return the resource value
|
||||||
*/
|
*/
|
||||||
public Long getValue() {
|
public long getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ public class ResourceInformation implements Comparable<ResourceInformation> {
|
||||||
*
|
*
|
||||||
* @param rValue the resource value
|
* @param rValue the resource value
|
||||||
*/
|
*/
|
||||||
public void setValue(Long rValue) {
|
public void setValue(long rValue) {
|
||||||
this.value = rValue;
|
this.value = rValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ public class ResourceInformation implements Comparable<ResourceInformation> {
|
||||||
*
|
*
|
||||||
* @return the minimum allocation for the resource
|
* @return the minimum allocation for the resource
|
||||||
*/
|
*/
|
||||||
public Long getMinimumAllocation() {
|
public long getMinimumAllocation() {
|
||||||
return minimumAllocation;
|
return minimumAllocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ public class ResourceInformation implements Comparable<ResourceInformation> {
|
||||||
*
|
*
|
||||||
* @param minimumAllocation the minimum allocation for the resource
|
* @param minimumAllocation the minimum allocation for the resource
|
||||||
*/
|
*/
|
||||||
public void setMinimumAllocation(Long minimumAllocation) {
|
public void setMinimumAllocation(long minimumAllocation) {
|
||||||
this.minimumAllocation = minimumAllocation;
|
this.minimumAllocation = minimumAllocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ public class ResourceInformation implements Comparable<ResourceInformation> {
|
||||||
*
|
*
|
||||||
* @return the maximum allocation for the resource
|
* @return the maximum allocation for the resource
|
||||||
*/
|
*/
|
||||||
public Long getMaximumAllocation() {
|
public long getMaximumAllocation() {
|
||||||
return maximumAllocation;
|
return maximumAllocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ public class ResourceInformation implements Comparable<ResourceInformation> {
|
||||||
*
|
*
|
||||||
* @param maximumAllocation the maximum allocation for the resource
|
* @param maximumAllocation the maximum allocation for the resource
|
||||||
*/
|
*/
|
||||||
public void setMaximumAllocation(Long maximumAllocation) {
|
public void setMaximumAllocation(long maximumAllocation) {
|
||||||
this.maximumAllocation = maximumAllocation;
|
this.maximumAllocation = maximumAllocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,18 +163,13 @@ public class ResourceInformation implements Comparable<ResourceInformation> {
|
||||||
*/
|
*/
|
||||||
public static ResourceInformation newInstance(ResourceInformation other) {
|
public static ResourceInformation newInstance(ResourceInformation other) {
|
||||||
ResourceInformation ret = new ResourceInformation();
|
ResourceInformation ret = new ResourceInformation();
|
||||||
ret.setName(other.getName());
|
copy(other, ret);
|
||||||
ret.setResourceType(other.getResourceType());
|
|
||||||
ret.setUnits(other.getUnits());
|
|
||||||
ret.setValue(other.getValue());
|
|
||||||
ret.setMinimumAllocation(other.getMinimumAllocation());
|
|
||||||
ret.setMaximumAllocation(other.getMaximumAllocation());
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResourceInformation newInstance(String name, String units,
|
public static ResourceInformation newInstance(String name, String units,
|
||||||
Long value, ResourceTypes type, Long minimumAllocation,
|
long value, ResourceTypes type, long minimumAllocation,
|
||||||
Long maximumAllocation) {
|
long maximumAllocation) {
|
||||||
ResourceInformation ret = new ResourceInformation();
|
ResourceInformation ret = new ResourceInformation();
|
||||||
ret.setName(name);
|
ret.setName(name);
|
||||||
ret.setResourceType(type);
|
ret.setResourceType(type);
|
||||||
|
@ -186,7 +181,7 @@ public class ResourceInformation implements Comparable<ResourceInformation> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResourceInformation newInstance(String name, String units,
|
public static ResourceInformation newInstance(String name, String units,
|
||||||
Long value) {
|
long value) {
|
||||||
return ResourceInformation
|
return ResourceInformation
|
||||||
.newInstance(name, units, value, ResourceTypes.COUNTABLE, 0L,
|
.newInstance(name, units, value, ResourceTypes.COUNTABLE, 0L,
|
||||||
Long.MAX_VALUE);
|
Long.MAX_VALUE);
|
||||||
|
@ -198,7 +193,7 @@ public class ResourceInformation implements Comparable<ResourceInformation> {
|
||||||
Long.MAX_VALUE);
|
Long.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResourceInformation newInstance(String name, Long value) {
|
public static ResourceInformation newInstance(String name, long value) {
|
||||||
return ResourceInformation
|
return ResourceInformation
|
||||||
.newInstance(name, "", value, ResourceTypes.COUNTABLE, 0L,
|
.newInstance(name, "", value, ResourceTypes.COUNTABLE, 0L,
|
||||||
Long.MAX_VALUE);
|
Long.MAX_VALUE);
|
||||||
|
@ -208,6 +203,22 @@ public class ResourceInformation implements Comparable<ResourceInformation> {
|
||||||
return ResourceInformation.newInstance(name, "");
|
return ResourceInformation.newInstance(name, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the content of the source ResourceInformation object to the
|
||||||
|
* destination object, overwriting all properties of the destination object.
|
||||||
|
* @param src Source ResourceInformation object
|
||||||
|
* @param dst Destination ResourceInformation object
|
||||||
|
*/
|
||||||
|
|
||||||
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "name: " + this.name + ", units: " + this.units + ", type: "
|
return "name: " + this.name + ", units: " + this.units + ", type: "
|
||||||
|
@ -244,7 +255,7 @@ public class ResourceInformation implements Comparable<ResourceInformation> {
|
||||||
939769357 + name.hashCode(); // prime * result = 939769357 initially
|
939769357 + name.hashCode(); // prime * result = 939769357 initially
|
||||||
result = prime * result + resourceType.hashCode();
|
result = prime * result + resourceType.hashCode();
|
||||||
result = prime * result + units.hashCode();
|
result = prime * result + units.hashCode();
|
||||||
result = prime * result + value.hashCode();
|
result = prime * result + Long.valueOf(value).hashCode();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,23 +128,24 @@ public class UnitsConversionUtil {
|
||||||
* @param fromValue the value you wish to convert
|
* @param fromValue the value you wish to convert
|
||||||
* @return the value in toUnit
|
* @return the value in toUnit
|
||||||
*/
|
*/
|
||||||
public static Long convert(String fromUnit, String toUnit, Long fromValue) {
|
public static long convert(String fromUnit, String toUnit, long fromValue) {
|
||||||
if (toUnit == null || fromUnit == null || fromValue == null) {
|
if (toUnit == null || fromUnit == null) {
|
||||||
throw new IllegalArgumentException("One or more arguments are null");
|
throw new IllegalArgumentException("One or more arguments are null");
|
||||||
}
|
}
|
||||||
String overflowMsg =
|
|
||||||
"Converting " + fromValue + " from '" + fromUnit + "' to '" + toUnit
|
|
||||||
+ "' will result in an overflow of Long";
|
|
||||||
if (fromUnit.equals(toUnit)) {
|
if (fromUnit.equals(toUnit)) {
|
||||||
return fromValue;
|
return fromValue;
|
||||||
}
|
}
|
||||||
Converter fc = getConverter(fromUnit);
|
Converter fc = getConverter(fromUnit);
|
||||||
Converter tc = getConverter(toUnit);
|
Converter tc = getConverter(toUnit);
|
||||||
Long numerator = fc.numerator * tc.denominator;
|
long numerator = fc.numerator * tc.denominator;
|
||||||
Long denominator = fc.denominator * tc.numerator;
|
long denominator = fc.denominator * tc.numerator;
|
||||||
Long numeratorMultiplierLimit = Long.MAX_VALUE / numerator;
|
long numeratorMultiplierLimit = Long.MAX_VALUE / numerator;
|
||||||
if (numerator < denominator) {
|
if (numerator < denominator) {
|
||||||
if (numeratorMultiplierLimit < fromValue) {
|
if (numeratorMultiplierLimit < fromValue) {
|
||||||
|
String overflowMsg =
|
||||||
|
"Converting " + fromValue + " from '" + fromUnit + "' to '" + toUnit
|
||||||
|
+ "' will result in an overflow of Long";
|
||||||
throw new IllegalArgumentException(overflowMsg);
|
throw new IllegalArgumentException(overflowMsg);
|
||||||
}
|
}
|
||||||
return (fromValue * numerator) / denominator;
|
return (fromValue * numerator) / denominator;
|
||||||
|
@ -152,8 +153,11 @@ public class UnitsConversionUtil {
|
||||||
if (numeratorMultiplierLimit > fromValue) {
|
if (numeratorMultiplierLimit > fromValue) {
|
||||||
return (numerator * fromValue) / denominator;
|
return (numerator * fromValue) / denominator;
|
||||||
}
|
}
|
||||||
Long tmp = numerator / denominator;
|
long tmp = numerator / denominator;
|
||||||
if ((Long.MAX_VALUE / tmp) < fromValue) {
|
if ((Long.MAX_VALUE / tmp) < fromValue) {
|
||||||
|
String overflowMsg =
|
||||||
|
"Converting " + fromValue + " from '" + fromUnit + "' to '" + toUnit
|
||||||
|
+ "' will result in an overflow of Long";
|
||||||
throw new IllegalArgumentException(overflowMsg);
|
throw new IllegalArgumentException(overflowMsg);
|
||||||
}
|
}
|
||||||
return fromValue * tmp;
|
return fromValue * tmp;
|
||||||
|
@ -170,8 +174,8 @@ public class UnitsConversionUtil {
|
||||||
* @return +1, 0 or -1 depending on whether the relationship is greater than,
|
* @return +1, 0 or -1 depending on whether the relationship is greater than,
|
||||||
* equal to or lesser than
|
* equal to or lesser than
|
||||||
*/
|
*/
|
||||||
public static int compare(String unitA, Long valueA, String unitB,
|
public static int compare(String unitA, long valueA, String unitB,
|
||||||
Long valueB) {
|
long valueB) {
|
||||||
if (unitA == null || unitB == null || !KNOWN_UNITS.contains(unitA)
|
if (unitA == null || unitB == null || !KNOWN_UNITS.contains(unitA)
|
||||||
|| !KNOWN_UNITS.contains(unitB)) {
|
|| !KNOWN_UNITS.contains(unitB)) {
|
||||||
throw new IllegalArgumentException("Units cannot be null");
|
throw new IllegalArgumentException("Units cannot be null");
|
||||||
|
@ -185,19 +189,19 @@ public class UnitsConversionUtil {
|
||||||
Converter unitAC = getConverter(unitA);
|
Converter unitAC = getConverter(unitA);
|
||||||
Converter unitBC = getConverter(unitB);
|
Converter unitBC = getConverter(unitB);
|
||||||
if (unitA.equals(unitB)) {
|
if (unitA.equals(unitB)) {
|
||||||
return valueA.compareTo(valueB);
|
return Long.valueOf(valueA).compareTo(valueB);
|
||||||
}
|
}
|
||||||
int unitAPos = SORTED_UNITS.indexOf(unitA);
|
int unitAPos = SORTED_UNITS.indexOf(unitA);
|
||||||
int unitBPos = SORTED_UNITS.indexOf(unitB);
|
int unitBPos = SORTED_UNITS.indexOf(unitB);
|
||||||
try {
|
try {
|
||||||
Long tmpA = valueA;
|
long tmpA = valueA;
|
||||||
Long tmpB = valueB;
|
long tmpB = valueB;
|
||||||
if (unitAPos < unitBPos) {
|
if (unitAPos < unitBPos) {
|
||||||
tmpB = convert(unitB, unitA, valueB);
|
tmpB = convert(unitB, unitA, valueB);
|
||||||
} else {
|
} else {
|
||||||
tmpA = convert(unitA, unitB, valueA);
|
tmpA = convert(unitA, unitB, valueA);
|
||||||
}
|
}
|
||||||
return tmpA.compareTo(tmpB);
|
return Long.valueOf(tmpA).compareTo(tmpB);
|
||||||
} catch (IllegalArgumentException ie) {
|
} catch (IllegalArgumentException ie) {
|
||||||
BigInteger tmpA = BigInteger.valueOf(valueA);
|
BigInteger tmpA = BigInteger.valueOf(valueA);
|
||||||
BigInteger tmpB = BigInteger.valueOf(valueB);
|
BigInteger tmpB = BigInteger.valueOf(valueB);
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class TestResourceInformation {
|
||||||
@Test
|
@Test
|
||||||
public void testValue() {
|
public void testValue() {
|
||||||
String name = "yarn.io/test";
|
String name = "yarn.io/test";
|
||||||
Long value = 1l;
|
long value = 1L;
|
||||||
ResourceInformation ri = ResourceInformation.newInstance(name, value);
|
ResourceInformation ri = ResourceInformation.newInstance(name, value);
|
||||||
Assert.assertEquals("Resource name incorrect", name, ri.getName());
|
Assert.assertEquals("Resource name incorrect", name, ri.getName());
|
||||||
Assert.assertEquals("Resource value incorrect", value, ri.getValue());
|
Assert.assertEquals("Resource value incorrect", value, ri.getValue());
|
||||||
|
@ -59,7 +59,7 @@ public class TestResourceInformation {
|
||||||
@Test
|
@Test
|
||||||
public void testResourceInformation() {
|
public void testResourceInformation() {
|
||||||
String name = "yarn.io/test";
|
String name = "yarn.io/test";
|
||||||
Long value = 1l;
|
long value = 1L;
|
||||||
String units = "m";
|
String units = "m";
|
||||||
ResourceInformation ri =
|
ResourceInformation ri =
|
||||||
ResourceInformation.newInstance(name, units, value);
|
ResourceInformation.newInstance(name, units, value);
|
||||||
|
|
|
@ -27,62 +27,62 @@ public class TestUnitsConversionUtil {
|
||||||
public void testUnitsConversion() {
|
public void testUnitsConversion() {
|
||||||
int value = 5;
|
int value = 5;
|
||||||
String fromUnit = "";
|
String fromUnit = "";
|
||||||
Long test = Long.valueOf(value);
|
long test = value;
|
||||||
Assert.assertEquals("pico test failed",
|
Assert.assertEquals("pico test failed",
|
||||||
Long.valueOf(value * 1000l * 1000l * 1000l * 1000l),
|
value * 1000L * 1000L * 1000L * 1000L,
|
||||||
UnitsConversionUtil.convert(fromUnit, "p", test));
|
UnitsConversionUtil.convert(fromUnit, "p", test));
|
||||||
Assert.assertEquals("nano test failed",
|
Assert.assertEquals("nano test failed",
|
||||||
Long.valueOf(value * 1000l * 1000l * 1000l),
|
value * 1000L * 1000L * 1000L,
|
||||||
UnitsConversionUtil.convert(fromUnit, "n", test));
|
UnitsConversionUtil.convert(fromUnit, "n", test));
|
||||||
Assert
|
Assert
|
||||||
.assertEquals("micro test failed", Long.valueOf(value * 1000l * 1000l),
|
.assertEquals("micro test failed", value * 1000L * 1000L,
|
||||||
UnitsConversionUtil.convert(fromUnit, "u", test));
|
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));
|
UnitsConversionUtil.convert(fromUnit, "m", test));
|
||||||
|
|
||||||
test = Long.valueOf(value * 1000l * 1000l * 1000l * 1000l * 1000l);
|
test = value * 1000L * 1000L * 1000L * 1000L * 1000L;
|
||||||
fromUnit = "";
|
fromUnit = "";
|
||||||
Assert.assertEquals("kilo test failed", Long.valueOf(test / 1000l),
|
Assert.assertEquals("kilo test failed", test / 1000L,
|
||||||
UnitsConversionUtil.convert(fromUnit, "k", test));
|
UnitsConversionUtil.convert(fromUnit, "k", test));
|
||||||
|
|
||||||
Assert
|
Assert
|
||||||
.assertEquals("mega test failed", Long.valueOf(test / (1000l * 1000l)),
|
.assertEquals("mega test failed", test / (1000L * 1000L),
|
||||||
UnitsConversionUtil.convert(fromUnit, "M", test));
|
UnitsConversionUtil.convert(fromUnit, "M", test));
|
||||||
Assert.assertEquals("giga test failed",
|
Assert.assertEquals("giga test failed",
|
||||||
Long.valueOf(test / (1000l * 1000l * 1000l)),
|
test / (1000L * 1000L * 1000L),
|
||||||
UnitsConversionUtil.convert(fromUnit, "G", test));
|
UnitsConversionUtil.convert(fromUnit, "G", test));
|
||||||
Assert.assertEquals("tera test failed",
|
Assert.assertEquals("tera test failed",
|
||||||
Long.valueOf(test / (1000l * 1000l * 1000l * 1000l)),
|
test / (1000L * 1000L * 1000L * 1000L),
|
||||||
UnitsConversionUtil.convert(fromUnit, "T", test));
|
UnitsConversionUtil.convert(fromUnit, "T", test));
|
||||||
Assert.assertEquals("peta test failed",
|
Assert.assertEquals("peta test failed",
|
||||||
Long.valueOf(test / (1000l * 1000l * 1000l * 1000l * 1000l)),
|
test / (1000L * 1000L * 1000L * 1000L * 1000L),
|
||||||
UnitsConversionUtil.convert(fromUnit, "P", test));
|
UnitsConversionUtil.convert(fromUnit, "P", test));
|
||||||
|
|
||||||
Assert.assertEquals("nano to pico test failed", Long.valueOf(value * 1000l),
|
Assert.assertEquals("nano to pico test failed", value * 1000L,
|
||||||
UnitsConversionUtil.convert("n", "p", Long.valueOf(value)));
|
UnitsConversionUtil.convert("n", "p", value));
|
||||||
|
|
||||||
Assert.assertEquals("mega to giga test failed", Long.valueOf(value),
|
Assert.assertEquals("mega to giga test failed", value,
|
||||||
UnitsConversionUtil.convert("M", "G", Long.valueOf(value * 1000l)));
|
UnitsConversionUtil.convert("M", "G", value * 1000L));
|
||||||
|
|
||||||
Assert.assertEquals("Mi to Gi test failed", Long.valueOf(value),
|
Assert.assertEquals("Mi to Gi test failed", value,
|
||||||
UnitsConversionUtil.convert("Mi", "Gi", Long.valueOf(value * 1024l)));
|
UnitsConversionUtil.convert("Mi", "Gi", value * 1024L));
|
||||||
|
|
||||||
Assert.assertEquals("Mi to Ki test failed", Long.valueOf(value * 1024),
|
Assert.assertEquals("Mi to Ki test failed", value * 1024,
|
||||||
UnitsConversionUtil.convert("Mi", "Ki", Long.valueOf(value)));
|
UnitsConversionUtil.convert("Mi", "Ki", value));
|
||||||
|
|
||||||
Assert.assertEquals("Ki to base units test failed", Long.valueOf(5 * 1024),
|
Assert.assertEquals("Ki to base units test failed", 5 * 1024,
|
||||||
UnitsConversionUtil.convert("Ki", "", Long.valueOf(5)));
|
UnitsConversionUtil.convert("Ki", "", 5));
|
||||||
|
|
||||||
Assert.assertEquals("Mi to k test failed", Long.valueOf(1073741),
|
Assert.assertEquals("Mi to k test failed", 1073741,
|
||||||
UnitsConversionUtil.convert("Mi", "k", Long.valueOf(1024)));
|
UnitsConversionUtil.convert("Mi", "k", 1024));
|
||||||
|
|
||||||
Assert.assertEquals("M to Mi test failed", Long.valueOf(953),
|
Assert.assertEquals("M to Mi test failed", 953,
|
||||||
UnitsConversionUtil.convert("M", "Mi", Long.valueOf(1000)));
|
UnitsConversionUtil.convert("M", "Mi", 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOverflow() {
|
public void testOverflow() {
|
||||||
Long test = Long.valueOf(5 * 1000l * 1000l * 1000l * 1000l * 1000l);
|
long test = 5 * 1000L * 1000L * 1000L * 1000L * 1000L;
|
||||||
try {
|
try {
|
||||||
UnitsConversionUtil.convert("P", "p", test);
|
UnitsConversionUtil.convert("P", "p", test);
|
||||||
Assert.fail("this operation should result in an overflow");
|
Assert.fail("this operation should result in an overflow");
|
||||||
|
@ -100,9 +100,9 @@ public class TestUnitsConversionUtil {
|
||||||
@Test
|
@Test
|
||||||
public void testCompare() {
|
public void testCompare() {
|
||||||
String unitA = "P";
|
String unitA = "P";
|
||||||
Long valueA = Long.valueOf(1);
|
long valueA = 1;
|
||||||
String unitB = "p";
|
String unitB = "p";
|
||||||
Long valueB = Long.valueOf(2);
|
long valueB = 2;
|
||||||
Assert.assertEquals(1,
|
Assert.assertEquals(1,
|
||||||
UnitsConversionUtil.compare(unitA, valueA, unitB, valueB));
|
UnitsConversionUtil.compare(unitA, valueA, unitB, valueB));
|
||||||
Assert.assertEquals(-1,
|
Assert.assertEquals(-1,
|
||||||
|
@ -120,7 +120,7 @@ public class TestUnitsConversionUtil {
|
||||||
Assert.assertEquals(-1,
|
Assert.assertEquals(-1,
|
||||||
UnitsConversionUtil.compare(unitB, valueB, unitA, valueA));
|
UnitsConversionUtil.compare(unitB, valueB, unitA, valueA));
|
||||||
Assert.assertEquals(0,
|
Assert.assertEquals(0,
|
||||||
UnitsConversionUtil.compare(unitA, valueA, unitB, 1000l));
|
UnitsConversionUtil.compare(unitA, valueA, unitB, 1000L));
|
||||||
|
|
||||||
unitA = "p";
|
unitA = "p";
|
||||||
unitB = "n";
|
unitB = "n";
|
||||||
|
@ -129,7 +129,7 @@ public class TestUnitsConversionUtil {
|
||||||
Assert.assertEquals(1,
|
Assert.assertEquals(1,
|
||||||
UnitsConversionUtil.compare(unitB, valueB, unitA, valueA));
|
UnitsConversionUtil.compare(unitB, valueB, unitA, valueA));
|
||||||
Assert.assertEquals(0,
|
Assert.assertEquals(0,
|
||||||
UnitsConversionUtil.compare(unitA, 1000l, unitB, valueA));
|
UnitsConversionUtil.compare(unitA, 1000L, unitB, valueA));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
package org.apache.hadoop.yarn.api.records.impl.pb;
|
package org.apache.hadoop.yarn.api.records.impl.pb;
|
||||||
|
|
||||||
|
import org.apache.commons.collections.map.UnmodifiableMap;
|
||||||
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.Private;
|
import org.apache.hadoop.classification.InterfaceAudience.Private;
|
||||||
|
@ -46,6 +47,7 @@ public class ResourcePBImpl extends Resource {
|
||||||
boolean viaProto = false;
|
boolean viaProto = false;
|
||||||
|
|
||||||
private Map<String, ResourceInformation> resources;
|
private Map<String, ResourceInformation> resources;
|
||||||
|
private Map<String, ResourceInformation> readOnlyResources;
|
||||||
|
|
||||||
|
|
||||||
// call via ProtoUtils.convertToProtoFormat(Resource)
|
// call via ProtoUtils.convertToProtoFormat(Resource)
|
||||||
|
@ -68,6 +70,7 @@ public class ResourcePBImpl extends Resource {
|
||||||
public ResourcePBImpl(ResourceProto proto) {
|
public ResourcePBImpl(ResourceProto proto) {
|
||||||
this.proto = proto;
|
this.proto = proto;
|
||||||
viaProto = true;
|
viaProto = true;
|
||||||
|
this.readOnlyResources = null;
|
||||||
this.resources = null;
|
this.resources = null;
|
||||||
initResources();
|
initResources();
|
||||||
}
|
}
|
||||||
|
@ -111,10 +114,9 @@ public class ResourcePBImpl extends Resource {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMemorySize(long memory) {
|
public void setMemorySize(long memory) {
|
||||||
setResourceInformation(ResourceInformation.MEMORY_MB.getName(),
|
maybeInitBuilder();
|
||||||
ResourceInformation.newInstance(ResourceInformation.MEMORY_MB.getName(),
|
getResourceInformation(ResourceInformation.MEMORY_MB.getName())
|
||||||
ResourceInformation.MEMORY_MB.getUnits(), memory));
|
.setValue(memory);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -127,9 +129,9 @@ public class ResourcePBImpl extends Resource {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setVirtualCores(int vCores) {
|
public void setVirtualCores(int vCores) {
|
||||||
setResourceInformation(ResourceInformation.VCORES.getName(),
|
maybeInitBuilder();
|
||||||
ResourceInformation.newInstance(ResourceInformation.VCORES.getName(),
|
getResourceInformation(ResourceInformation.VCORES.getName())
|
||||||
ResourceInformation.VCORES.getUnits(), (long) vCores));
|
.setValue(vCores);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initResources() {
|
private void initResources() {
|
||||||
|
@ -143,7 +145,7 @@ public class ResourcePBImpl extends Resource {
|
||||||
entry.hasType() ? ProtoUtils.convertFromProtoFormat(entry.getType()) :
|
entry.hasType() ? ProtoUtils.convertFromProtoFormat(entry.getType()) :
|
||||||
ResourceTypes.COUNTABLE;
|
ResourceTypes.COUNTABLE;
|
||||||
String units = entry.hasUnits() ? entry.getUnits() : "";
|
String units = entry.hasUnits() ? entry.getUnits() : "";
|
||||||
Long value = entry.hasValue() ? entry.getValue() : 0L;
|
long value = entry.hasValue() ? entry.getValue() : 0L;
|
||||||
ResourceInformation ri = ResourceInformation
|
ResourceInformation ri = ResourceInformation
|
||||||
.newInstance(entry.getKey(), units, value, type, 0L, Long.MAX_VALUE);
|
.newInstance(entry.getKey(), units, value, type, 0L, Long.MAX_VALUE);
|
||||||
if (resources.containsKey(ri.getName())) {
|
if (resources.containsKey(ri.getName())) {
|
||||||
|
@ -171,7 +173,7 @@ public class ResourcePBImpl extends Resource {
|
||||||
}
|
}
|
||||||
initResources();
|
initResources();
|
||||||
if (resources.containsKey(resource)) {
|
if (resources.containsKey(resource)) {
|
||||||
resources.put(resource, resourceInformation);
|
ResourceInformation.copy(resourceInformation, resources.get(resource));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +195,7 @@ public class ResourcePBImpl extends Resource {
|
||||||
@Override
|
@Override
|
||||||
public Map<String, ResourceInformation> getResources() {
|
public Map<String, ResourceInformation> getResources() {
|
||||||
initResources();
|
initResources();
|
||||||
return Collections.unmodifiableMap(this.resources);
|
return readOnlyResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -226,6 +228,7 @@ public class ResourcePBImpl extends Resource {
|
||||||
resources.put(entry.getKey(),
|
resources.put(entry.getKey(),
|
||||||
ResourceInformation.newInstance(entry.getValue()));
|
ResourceInformation.newInstance(entry.getValue()));
|
||||||
}
|
}
|
||||||
|
readOnlyResources = Collections.unmodifiableMap(resources);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,7 +154,7 @@ public class DominantResourceCalculator extends ResourceCalculator {
|
||||||
clusterResource.getResourceInformation(rName);
|
clusterResource.getResourceInformation(rName);
|
||||||
ResourceInformation resourceInformation =
|
ResourceInformation resourceInformation =
|
||||||
resource.getResourceInformation(rName);
|
resource.getResourceInformation(rName);
|
||||||
Long resourceValue = UnitsConversionUtil
|
long resourceValue = UnitsConversionUtil
|
||||||
.convert(resourceInformation.getUnits(),
|
.convert(resourceInformation.getUnits(),
|
||||||
clusterResourceResourceInformation.getUnits(),
|
clusterResourceResourceInformation.getUnits(),
|
||||||
resourceInformation.getValue());
|
resourceInformation.getValue());
|
||||||
|
@ -180,11 +180,11 @@ public class DominantResourceCalculator extends ResourceCalculator {
|
||||||
available.getResourceInformation(resource);
|
available.getResourceInformation(resource);
|
||||||
ResourceInformation requiredResource =
|
ResourceInformation requiredResource =
|
||||||
required.getResourceInformation(resource);
|
required.getResourceInformation(resource);
|
||||||
Long requiredResourceValue = UnitsConversionUtil
|
long requiredResourceValue = UnitsConversionUtil
|
||||||
.convert(requiredResource.getUnits(), availableResource.getUnits(),
|
.convert(requiredResource.getUnits(), availableResource.getUnits(),
|
||||||
requiredResource.getValue());
|
requiredResource.getValue());
|
||||||
if (requiredResourceValue != 0) {
|
if (requiredResourceValue != 0) {
|
||||||
Long tmp = availableResource.getValue() / requiredResourceValue;
|
long tmp = availableResource.getValue() / requiredResourceValue;
|
||||||
min = min < tmp ? min : tmp;
|
min = min < tmp ? min : tmp;
|
||||||
}
|
}
|
||||||
} catch (YarnException ye) {
|
} catch (YarnException ye) {
|
||||||
|
@ -228,7 +228,7 @@ public class DominantResourceCalculator extends ResourceCalculator {
|
||||||
a.getResourceInformation(resource);
|
a.getResourceInformation(resource);
|
||||||
ResourceInformation bResourceInformation =
|
ResourceInformation bResourceInformation =
|
||||||
b.getResourceInformation(resource);
|
b.getResourceInformation(resource);
|
||||||
Long bResourceValue = UnitsConversionUtil
|
long bResourceValue = UnitsConversionUtil
|
||||||
.convert(bResourceInformation.getUnits(),
|
.convert(bResourceInformation.getUnits(),
|
||||||
aResourceInformation.getUnits(),
|
aResourceInformation.getUnits(),
|
||||||
bResourceInformation.getValue());
|
bResourceInformation.getValue());
|
||||||
|
@ -249,14 +249,13 @@ public class DominantResourceCalculator extends ResourceCalculator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Resource divideAndCeil(Resource numerator, long denominator) {
|
public Resource divideAndCeil(Resource numerator, long denominator) {
|
||||||
Resource ret = Resources.createResource(0, 0);
|
Resource ret = Resource.newInstance(numerator);
|
||||||
for (String resource : resourceNames) {
|
for (String resource : resourceNames) {
|
||||||
try {
|
try {
|
||||||
ResourceInformation resourceInformation = ResourceInformation
|
ResourceInformation resourceInformation =
|
||||||
.newInstance(numerator.getResourceInformation(resource));
|
ret.getResourceInformation(resource);
|
||||||
resourceInformation.setValue(
|
resourceInformation.setValue(
|
||||||
divideAndCeil(resourceInformation.getValue(), denominator));
|
divideAndCeil(resourceInformation.getValue(), denominator));
|
||||||
ret.setResourceInformation(resource, resourceInformation);
|
|
||||||
} catch (YarnException ye) {
|
} catch (YarnException ye) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Error getting resource information for " + resource, ye);
|
"Error getting resource information for " + resource, ye);
|
||||||
|
@ -276,7 +275,7 @@ public class DominantResourceCalculator extends ResourceCalculator {
|
||||||
@Override
|
@Override
|
||||||
public Resource normalize(Resource r, Resource minimumResource,
|
public Resource normalize(Resource r, Resource minimumResource,
|
||||||
Resource maximumResource, Resource stepFactor) {
|
Resource maximumResource, Resource stepFactor) {
|
||||||
Resource ret = Resources.createResource(0, 0);
|
Resource ret = Resource.newInstance(r);
|
||||||
for (String resource : resourceNames) {
|
for (String resource : resourceNames) {
|
||||||
try {
|
try {
|
||||||
ResourceInformation rResourceInformation =
|
ResourceInformation rResourceInformation =
|
||||||
|
@ -287,28 +286,26 @@ public class DominantResourceCalculator extends ResourceCalculator {
|
||||||
maximumResource.getResourceInformation(resource);
|
maximumResource.getResourceInformation(resource);
|
||||||
ResourceInformation stepFactorResourceInformation =
|
ResourceInformation stepFactorResourceInformation =
|
||||||
stepFactor.getResourceInformation(resource);
|
stepFactor.getResourceInformation(resource);
|
||||||
ResourceInformation tmp =
|
ResourceInformation tmp = ret.getResourceInformation(resource);
|
||||||
ResourceInformation.newInstance(rResourceInformation);
|
|
||||||
|
|
||||||
Long rValue = rResourceInformation.getValue();
|
long rValue = rResourceInformation.getValue();
|
||||||
Long minimumValue = UnitsConversionUtil
|
long minimumValue = UnitsConversionUtil
|
||||||
.convert(minimumResourceInformation.getUnits(),
|
.convert(minimumResourceInformation.getUnits(),
|
||||||
rResourceInformation.getUnits(),
|
rResourceInformation.getUnits(),
|
||||||
minimumResourceInformation.getValue());
|
minimumResourceInformation.getValue());
|
||||||
Long maximumValue = UnitsConversionUtil
|
long maximumValue = UnitsConversionUtil
|
||||||
.convert(maximumResourceInformation.getUnits(),
|
.convert(maximumResourceInformation.getUnits(),
|
||||||
rResourceInformation.getUnits(),
|
rResourceInformation.getUnits(),
|
||||||
maximumResourceInformation.getValue());
|
maximumResourceInformation.getValue());
|
||||||
Long stepFactorValue = UnitsConversionUtil
|
long stepFactorValue = UnitsConversionUtil
|
||||||
.convert(stepFactorResourceInformation.getUnits(),
|
.convert(stepFactorResourceInformation.getUnits(),
|
||||||
rResourceInformation.getUnits(),
|
rResourceInformation.getUnits(),
|
||||||
stepFactorResourceInformation.getValue());
|
stepFactorResourceInformation.getValue());
|
||||||
Long value = Math.max(rValue, minimumValue);
|
long value = Math.max(rValue, minimumValue);
|
||||||
if (stepFactorValue != 0) {
|
if (stepFactorValue != 0) {
|
||||||
value = roundUp(value, stepFactorValue);
|
value = roundUp(value, stepFactorValue);
|
||||||
}
|
}
|
||||||
tmp.setValue(Math.min(value, maximumValue));
|
tmp.setValue(Math.min(value, maximumValue));
|
||||||
ret.setResourceInformation(resource, tmp);
|
|
||||||
} catch (YarnException ye) {
|
} catch (YarnException ye) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Error getting resource information for " + resource, ye);
|
"Error getting resource information for " + resource, ye);
|
||||||
|
@ -328,28 +325,27 @@ public class DominantResourceCalculator extends ResourceCalculator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Resource rounding(Resource r, Resource stepFactor, boolean roundUp) {
|
private Resource rounding(Resource r, Resource stepFactor, boolean roundUp) {
|
||||||
Resource ret = Resources.createResource(0, 0);
|
Resource ret = Resource.newInstance(r);
|
||||||
for (String resource : resourceNames) {
|
for (String resource : resourceNames) {
|
||||||
try {
|
try {
|
||||||
ResourceInformation rResourceInformation =
|
ResourceInformation rResourceInformation =
|
||||||
r.getResourceInformation(resource);
|
r.getResourceInformation(resource);
|
||||||
ResourceInformation stepFactorResourceInformation =
|
ResourceInformation stepFactorResourceInformation =
|
||||||
stepFactor.getResourceInformation(resource);
|
stepFactor.getResourceInformation(resource);
|
||||||
ResourceInformation tmp =
|
|
||||||
ResourceInformation.newInstance(rResourceInformation);
|
|
||||||
|
|
||||||
Long rValue = rResourceInformation.getValue();
|
long rValue = rResourceInformation.getValue();
|
||||||
Long stepFactorValue = UnitsConversionUtil
|
long stepFactorValue = UnitsConversionUtil
|
||||||
.convert(stepFactorResourceInformation.getUnits(),
|
.convert(stepFactorResourceInformation.getUnits(),
|
||||||
rResourceInformation.getUnits(),
|
rResourceInformation.getUnits(),
|
||||||
stepFactorResourceInformation.getValue());
|
stepFactorResourceInformation.getValue());
|
||||||
Long value = rValue;
|
long value = rValue;
|
||||||
if (stepFactorValue != 0) {
|
if (stepFactorValue != 0) {
|
||||||
value = roundUp ? roundUp(rValue, stepFactorValue) :
|
value = roundUp ? roundUp(rValue, stepFactorValue) :
|
||||||
roundDown(rValue, stepFactorValue);
|
roundDown(rValue, stepFactorValue);
|
||||||
}
|
}
|
||||||
tmp.setValue(value);
|
ResourceInformation
|
||||||
ret.setResourceInformation(resource, tmp);
|
.copy(rResourceInformation, ret.getResourceInformation(resource));
|
||||||
|
ret.getResourceInformation(resource).setValue(value);
|
||||||
} catch (YarnException ye) {
|
} catch (YarnException ye) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Error getting resource information for " + resource, ye);
|
"Error getting resource information for " + resource, ye);
|
||||||
|
@ -372,15 +368,14 @@ public class DominantResourceCalculator extends ResourceCalculator {
|
||||||
|
|
||||||
private Resource multiplyAndNormalize(Resource r, double by,
|
private Resource multiplyAndNormalize(Resource r, double by,
|
||||||
Resource stepFactor, boolean roundUp) {
|
Resource stepFactor, boolean roundUp) {
|
||||||
Resource ret = Resources.createResource(0, 0);
|
Resource ret = Resource.newInstance(r);
|
||||||
for (String resource : resourceNames) {
|
for (String resource : resourceNames) {
|
||||||
try {
|
try {
|
||||||
ResourceInformation rResourceInformation =
|
ResourceInformation rResourceInformation =
|
||||||
r.getResourceInformation(resource);
|
r.getResourceInformation(resource);
|
||||||
ResourceInformation stepFactorResourceInformation =
|
ResourceInformation stepFactorResourceInformation =
|
||||||
stepFactor.getResourceInformation(resource);
|
stepFactor.getResourceInformation(resource);
|
||||||
ResourceInformation tmp =
|
ResourceInformation tmp = ret.getResourceInformation(resource);
|
||||||
ResourceInformation.newInstance(rResourceInformation);
|
|
||||||
|
|
||||||
Long rValue = rResourceInformation.getValue();
|
Long rValue = rResourceInformation.getValue();
|
||||||
Long stepFactorValue = UnitsConversionUtil
|
Long stepFactorValue = UnitsConversionUtil
|
||||||
|
@ -397,7 +392,6 @@ public class DominantResourceCalculator extends ResourceCalculator {
|
||||||
roundUp ? (long) Math.ceil(rValue * by) : (long) (rValue * by);
|
roundUp ? (long) Math.ceil(rValue * by) : (long) (rValue * by);
|
||||||
}
|
}
|
||||||
tmp.setValue(value);
|
tmp.setValue(value);
|
||||||
ret.setResourceInformation(resource, tmp);
|
|
||||||
} catch (YarnException ye) {
|
} catch (YarnException ye) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Error getting resource information for " + resource, ye);
|
"Error getting resource information for " + resource, ye);
|
||||||
|
@ -414,7 +408,7 @@ public class DominantResourceCalculator extends ResourceCalculator {
|
||||||
smaller.getResourceInformation(resource);
|
smaller.getResourceInformation(resource);
|
||||||
ResourceInformation bResourceInformation =
|
ResourceInformation bResourceInformation =
|
||||||
bigger.getResourceInformation(resource);
|
bigger.getResourceInformation(resource);
|
||||||
Long sResourceValue = UnitsConversionUtil
|
long sResourceValue = UnitsConversionUtil
|
||||||
.convert(sResourceInformation.getUnits(),
|
.convert(sResourceInformation.getUnits(),
|
||||||
bResourceInformation.getUnits(),
|
bResourceInformation.getUnits(),
|
||||||
sResourceInformation.getValue());
|
sResourceInformation.getValue());
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class Resources {
|
||||||
static class FixedValueResource extends Resource {
|
static class FixedValueResource extends Resource {
|
||||||
|
|
||||||
private Map<String, ResourceInformation> resources;
|
private Map<String, ResourceInformation> resources;
|
||||||
private Long resourceValue;
|
private long resourceValue;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,7 +50,7 @@ public class Resources {
|
||||||
* @param rName the name of the resource
|
* @param rName the name of the resource
|
||||||
* @param value the fixed value to be returned for all resource types
|
* @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.resourceValue = value;
|
||||||
this.name = rName;
|
this.name = rName;
|
||||||
resources = initResourceMap();
|
resources = initResourceMap();
|
||||||
|
@ -60,7 +60,7 @@ public class Resources {
|
||||||
if(this.resourceValue > Integer.MAX_VALUE) {
|
if(this.resourceValue > Integer.MAX_VALUE) {
|
||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
return this.resourceValue.intValue();
|
return Long.valueOf(this.resourceValue).intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -203,7 +203,7 @@ public class Resources {
|
||||||
try {
|
try {
|
||||||
ResourceInformation rhsValue = rhs.getResourceInformation(name);
|
ResourceInformation rhsValue = rhs.getResourceInformation(name);
|
||||||
ResourceInformation lhsValue = entry.getValue();
|
ResourceInformation lhsValue = entry.getValue();
|
||||||
Long convertedRhs = UnitsConversionUtil
|
long convertedRhs = UnitsConversionUtil
|
||||||
.convert(rhsValue.getUnits(), lhsValue.getUnits(),
|
.convert(rhsValue.getUnits(), lhsValue.getUnits(),
|
||||||
rhsValue.getValue());
|
rhsValue.getValue());
|
||||||
lhs.setResourceValue(name, lhsValue.getValue() + convertedRhs);
|
lhs.setResourceValue(name, lhsValue.getValue() + convertedRhs);
|
||||||
|
@ -225,7 +225,7 @@ public class Resources {
|
||||||
try {
|
try {
|
||||||
ResourceInformation rhsValue = rhs.getResourceInformation(name);
|
ResourceInformation rhsValue = rhs.getResourceInformation(name);
|
||||||
ResourceInformation lhsValue = entry.getValue();
|
ResourceInformation lhsValue = entry.getValue();
|
||||||
Long convertedRhs = UnitsConversionUtil
|
long convertedRhs = UnitsConversionUtil
|
||||||
.convert(rhsValue.getUnits(), lhsValue.getUnits(),
|
.convert(rhsValue.getUnits(), lhsValue.getUnits(),
|
||||||
rhsValue.getValue());
|
rhsValue.getValue());
|
||||||
lhs.setResourceValue(name, lhsValue.getValue() - convertedRhs);
|
lhs.setResourceValue(name, lhsValue.getValue() - convertedRhs);
|
||||||
|
@ -288,7 +288,7 @@ public class Resources {
|
||||||
try {
|
try {
|
||||||
ResourceInformation rhsValue = rhs.getResourceInformation(name);
|
ResourceInformation rhsValue = rhs.getResourceInformation(name);
|
||||||
ResourceInformation lhsValue = entry.getValue();
|
ResourceInformation lhsValue = entry.getValue();
|
||||||
Long convertedRhs = (long) (UnitsConversionUtil
|
long convertedRhs = (long) (UnitsConversionUtil
|
||||||
.convert(rhsValue.getUnits(), lhsValue.getUnits(),
|
.convert(rhsValue.getUnits(), lhsValue.getUnits(),
|
||||||
rhsValue.getValue()) * by);
|
rhsValue.getValue()) * by);
|
||||||
lhs.setResourceValue(name, lhsValue.getValue() + convertedRhs);
|
lhs.setResourceValue(name, lhsValue.getValue() + convertedRhs);
|
||||||
|
@ -422,7 +422,7 @@ public class Resources {
|
||||||
try {
|
try {
|
||||||
ResourceInformation rhsValue = bigger.getResourceInformation(name);
|
ResourceInformation rhsValue = bigger.getResourceInformation(name);
|
||||||
ResourceInformation lhsValue = entry.getValue();
|
ResourceInformation lhsValue = entry.getValue();
|
||||||
Long convertedRhs = UnitsConversionUtil
|
long convertedRhs = UnitsConversionUtil
|
||||||
.convert(rhsValue.getUnits(), lhsValue.getUnits(),
|
.convert(rhsValue.getUnits(), lhsValue.getUnits(),
|
||||||
rhsValue.getValue());
|
rhsValue.getValue());
|
||||||
if(lhsValue.getValue() > convertedRhs) {
|
if(lhsValue.getValue() > convertedRhs) {
|
||||||
|
@ -448,7 +448,7 @@ public class Resources {
|
||||||
try {
|
try {
|
||||||
ResourceInformation rhsValue = rhs.getResourceInformation(name);
|
ResourceInformation rhsValue = rhs.getResourceInformation(name);
|
||||||
ResourceInformation lhsValue = entry.getValue();
|
ResourceInformation lhsValue = entry.getValue();
|
||||||
Long convertedRhs = UnitsConversionUtil
|
long convertedRhs = UnitsConversionUtil
|
||||||
.convert(rhsValue.getUnits(), lhsValue.getUnits(),
|
.convert(rhsValue.getUnits(), lhsValue.getUnits(),
|
||||||
rhsValue.getValue());
|
rhsValue.getValue());
|
||||||
ResourceInformation outInfo =
|
ResourceInformation outInfo =
|
||||||
|
@ -469,7 +469,7 @@ public class Resources {
|
||||||
try {
|
try {
|
||||||
ResourceInformation rhsValue = rhs.getResourceInformation(name);
|
ResourceInformation rhsValue = rhs.getResourceInformation(name);
|
||||||
ResourceInformation lhsValue = entry.getValue();
|
ResourceInformation lhsValue = entry.getValue();
|
||||||
Long convertedRhs = UnitsConversionUtil
|
long convertedRhs = UnitsConversionUtil
|
||||||
.convert(rhsValue.getUnits(), lhsValue.getUnits(),
|
.convert(rhsValue.getUnits(), lhsValue.getUnits(),
|
||||||
rhsValue.getValue());
|
rhsValue.getValue());
|
||||||
ResourceInformation outInfo =
|
ResourceInformation outInfo =
|
||||||
|
|
|
@ -283,6 +283,7 @@ public class TestResourceUtils {
|
||||||
Map<String, ResourceInformation> actual =
|
Map<String, ResourceInformation> actual =
|
||||||
ResourceUtils.getNodeResourceInformation(conf);
|
ResourceUtils.getNodeResourceInformation(conf);
|
||||||
Assert.assertEquals(entry.getValue().getResources(), actual);
|
Assert.assertEquals(entry.getValue().getResources(), actual);
|
||||||
|
dest.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,16 @@ import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class TestResources {
|
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 static final String EXTRA_RESOURCE_TYPE = "resource2";
|
||||||
private String resourceTypesFile;
|
private String resourceTypesFile;
|
||||||
|
|
||||||
|
@ -87,7 +97,7 @@ public class TestResources {
|
||||||
@Test(timeout = 10000)
|
@Test(timeout = 10000)
|
||||||
public void testCompareToWithUnboundedResource() {
|
public void testCompareToWithUnboundedResource() {
|
||||||
unsetExtraResourceType();
|
unsetExtraResourceType();
|
||||||
Resource unboundedClone = Resources.clone(Resources.unbounded());
|
Resource unboundedClone = Resources.clone(ExtendedResources.unbounded());
|
||||||
assertTrue(unboundedClone
|
assertTrue(unboundedClone
|
||||||
.compareTo(createResource(Long.MAX_VALUE, Integer.MAX_VALUE)) == 0);
|
.compareTo(createResource(Long.MAX_VALUE, Integer.MAX_VALUE)) == 0);
|
||||||
assertTrue(unboundedClone.compareTo(createResource(Long.MAX_VALUE, 0)) > 0);
|
assertTrue(unboundedClone.compareTo(createResource(Long.MAX_VALUE, 0)) > 0);
|
||||||
|
|
|
@ -1340,15 +1340,7 @@ public abstract class AbstractYarnScheduler
|
||||||
* @return a Resource object with the minimum allocation for the scheduler
|
* @return a Resource object with the minimum allocation for the scheduler
|
||||||
*/
|
*/
|
||||||
public Resource getMinimumAllocation() {
|
public Resource getMinimumAllocation() {
|
||||||
boolean profilesEnabled = getConfig()
|
Resource ret = ResourceUtils.getResourceTypesMinimumAllocation();
|
||||||
.getBoolean(YarnConfiguration.RM_RESOURCE_PROFILES_ENABLED,
|
|
||||||
YarnConfiguration.DEFAULT_RM_RESOURCE_PROFILES_ENABLED);
|
|
||||||
Resource ret;
|
|
||||||
if (!profilesEnabled) {
|
|
||||||
ret = ResourceUtils.getResourceTypesMinimumAllocation();
|
|
||||||
} else {
|
|
||||||
ret = rmContext.getResourceProfilesManager().getMinimumProfile();
|
|
||||||
}
|
|
||||||
LOG.info("Minimum allocation = " + ret);
|
LOG.info("Minimum allocation = " + ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -1362,15 +1354,7 @@ public abstract class AbstractYarnScheduler
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public Resource getMaximumAllocation() {
|
public Resource getMaximumAllocation() {
|
||||||
boolean profilesEnabled = getConfig()
|
Resource ret = ResourceUtils.getResourceTypesMaximumAllocation();
|
||||||
.getBoolean(YarnConfiguration.RM_RESOURCE_PROFILES_ENABLED,
|
|
||||||
YarnConfiguration.DEFAULT_RM_RESOURCE_PROFILES_ENABLED);
|
|
||||||
Resource ret;
|
|
||||||
if (!profilesEnabled) {
|
|
||||||
ret = ResourceUtils.getResourceTypesMaximumAllocation();
|
|
||||||
} else {
|
|
||||||
ret = rmContext.getResourceProfilesManager().getMaximumProfile();
|
|
||||||
}
|
|
||||||
LOG.info("Maximum allocation = " + ret);
|
LOG.info("Maximum allocation = " + ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue