Skip to content

Commit

Permalink
CDPD-39756. YARN-10950. Code cleanup in QueueCapacities (apache#3454)
Browse files Browse the repository at this point in the history
(cherry picked from commit a9b2469)
Change-Id: Ife0d60af3022a4653c2c297865bb703699c70e36
(cherry picked from commit 9011b874bfe827a40afcebdf6d2b313da7ee2b4b)
  • Loading branch information
adamantal authored and zmolnar-inf committed May 10, 2022
1 parent b692189 commit 0714657
Showing 1 changed file with 18 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@
public class QueueCapacities {
private static final String NL = CommonNodeLabelsManager.NO_LABEL;
private static final float LABEL_DOESNT_EXIST_CAP = 0f;
private Map<String, Capacities> capacitiesMap;
private ReadLock readLock;
private WriteLock writeLock;
private final Map<String, Capacities> capacitiesMap;
private final ReadLock readLock;
private final WriteLock writeLock;
private final boolean isRoot;

public QueueCapacities(boolean isRoot) {
ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
readLock = lock.readLock();
writeLock = lock.writeLock();

capacitiesMap = new HashMap<String, Capacities>();
capacitiesMap = new HashMap<>();
this.isRoot = isRoot;
}

Expand All @@ -52,15 +51,15 @@ private enum CapacityType {
USED_CAP(0), ABS_USED_CAP(1), MAX_CAP(2), ABS_MAX_CAP(3), CAP(4), ABS_CAP(5),
MAX_AM_PERC(6), RESERVED_CAP(7), ABS_RESERVED_CAP(8), WEIGHT(9), NORMALIZED_WEIGHT(10);

private int idx;
private final int idx;

private CapacityType(int idx) {
CapacityType(int idx) {
this.idx = idx;
}
}

private static class Capacities {
private float[] capacitiesArr;
private final float[] capacitiesArr;

public Capacities() {
capacitiesArr = new float[CapacityType.values().length];
Expand All @@ -71,19 +70,17 @@ public Capacities() {

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{used=" + capacitiesArr[0] + "%, ");
sb.append("abs_used=" + capacitiesArr[1] + "%, ");
sb.append("max_cap=" + capacitiesArr[2] + "%, ");
sb.append("abs_max_cap=" + capacitiesArr[3] + "%, ");
sb.append("cap=" + capacitiesArr[4] + "%, ");
sb.append("abs_cap=" + capacitiesArr[5] + "%}");
sb.append("max_am_perc=" + capacitiesArr[6] + "%}");
sb.append("reserved_cap=" + capacitiesArr[7] + "%}");
sb.append("abs_reserved_cap=" + capacitiesArr[8] + "%}");
sb.append("weight=" + capacitiesArr[9] + "w, ");
sb.append("normalized_weight=" + capacitiesArr[10] + "w}");
return sb.toString();
return "{used=" + capacitiesArr[0] + "%, " +
"abs_used=" + capacitiesArr[1] + "%, " +
"max_cap=" + capacitiesArr[2] + "%, " +
"abs_max_cap=" + capacitiesArr[3] + "%, " +
"cap=" + capacitiesArr[4] + "%, " +
"abs_cap=" + capacitiesArr[5] + "%, " +
"max_am_perc=" + capacitiesArr[6] + "%, " +
"reserved_cap=" + capacitiesArr[7] + "%, " +
"abs_reserved_cap=" + capacitiesArr[8] + "%, " +
"weight=" + capacitiesArr[9] + "w, " +
"normalized_weight=" + capacitiesArr[10] + "w}";
}
}

Expand Down Expand Up @@ -118,7 +115,6 @@ private void _set(String label, CapacityType type, float value) {
}
}

/* Used Capacity Getter and Setter */
public float getUsedCapacity() {
return _get(NL, CapacityType.USED_CAP);
}
Expand All @@ -135,7 +131,6 @@ public void setUsedCapacity(String label, float value) {
_set(label, CapacityType.USED_CAP, value);
}

/* Absolute Used Capacity Getter and Setter */
public float getAbsoluteUsedCapacity() {
return _get(NL, CapacityType.ABS_USED_CAP);
}
Expand All @@ -152,7 +147,6 @@ public void setAbsoluteUsedCapacity(String label, float value) {
_set(label, CapacityType.ABS_USED_CAP, value);
}

/* Capacity Getter and Setter */
public float getCapacity() {
return _get(NL, CapacityType.CAP);
}
Expand All @@ -173,7 +167,6 @@ public void setCapacity(String label, float value) {
_set(label, CapacityType.CAP, value);
}

/* Absolute Capacity Getter and Setter */
public float getAbsoluteCapacity() {
return _get(NL, CapacityType.ABS_CAP);
}
Expand All @@ -193,7 +186,6 @@ public void setAbsoluteCapacity(String label, float value) {
_set(label, CapacityType.ABS_CAP, value);
}

/* Maximum Capacity Getter and Setter */
public float getMaximumCapacity() {
return _get(NL, CapacityType.MAX_CAP);
}
Expand All @@ -210,7 +202,6 @@ public void setMaximumCapacity(String label, float value) {
_set(label, CapacityType.MAX_CAP, value);
}

/* Absolute Maximum Capacity Getter and Setter */
public float getAbsoluteMaximumCapacity() {
return _get(NL, CapacityType.ABS_MAX_CAP);
}
Expand All @@ -227,8 +218,6 @@ public void setAbsoluteMaximumCapacity(String label, float value) {
_set(label, CapacityType.ABS_MAX_CAP, value);
}

/* Absolute Maximum AM resource percentage Getter and Setter */

public float getMaxAMResourcePercentage() {
return _get(NL, CapacityType.MAX_AM_PERC);
}
Expand All @@ -245,7 +234,6 @@ public void setMaxAMResourcePercentage(float value) {
_set(NL, CapacityType.MAX_AM_PERC, value);
}

/* Reserved Capacity Getter and Setter */
public float getReservedCapacity() {
return _get(NL, CapacityType.RESERVED_CAP);
}
Expand All @@ -262,7 +250,6 @@ public void setReservedCapacity(String label, float value) {
_set(label, CapacityType.RESERVED_CAP, value);
}

/* Absolute Reserved Capacity Getter and Setter */
public float getAbsoluteReservedCapacity() {
return _get(NL, CapacityType.ABS_RESERVED_CAP);
}
Expand All @@ -279,7 +266,6 @@ public void setAbsoluteReservedCapacity(String label, float value) {
_set(label, CapacityType.ABS_RESERVED_CAP, value);
}

/* Weight Getter and Setter */
public float getWeight() {
return _get(NL, CapacityType.WEIGHT);
}
Expand All @@ -296,7 +282,6 @@ public void setWeight(String label, float value) {
_set(label, CapacityType.WEIGHT, value);
}

/* Weight Getter and Setter */
public float getNormalizedWeight() {
return _get(NL, CapacityType.NORMALIZED_WEIGHT);
}
Expand Down

0 comments on commit 0714657

Please sign in to comment.