Skip to content

Commit 108ecf9

Browse files
author
Inigo Goiri
committed
YARN-8942. PriorityBasedRouterPolicy throws exception if all sub-cluster weights have negative value. Contributed by Bilwa S T.
1 parent 743c2e9 commit 108ecf9

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/policies/router/PriorityRouterPolicy.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext;
2525
import org.apache.hadoop.yarn.exceptions.YarnException;
2626
import org.apache.hadoop.yarn.server.federation.policies.FederationPolicyUtils;
27+
import org.apache.hadoop.yarn.server.federation.policies.exceptions.FederationPolicyException;
2728
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
2829
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterIdInfo;
2930
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterInfo;
@@ -65,6 +66,10 @@ public SubClusterId getHomeSubcluster(
6566
chosen = id;
6667
}
6768
}
69+
if (chosen == null) {
70+
throw new FederationPolicyException(
71+
"No Active Subcluster with weight vector greater than zero");
72+
}
6873

6974
return chosen;
7075
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/policies/router/TestPriorityRouterPolicy.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.hadoop.yarn.server.federation.policies.router;
1818

19+
import static org.apache.hadoop.test.LambdaTestUtils.intercept;
1920
import static org.mockito.Mockito.mock;
2021
import static org.mockito.Mockito.when;
2122

@@ -24,6 +25,7 @@
2425

2526
import org.apache.hadoop.yarn.exceptions.YarnException;
2627
import org.apache.hadoop.yarn.server.federation.policies.dao.WeightedPolicyInfo;
28+
import org.apache.hadoop.yarn.server.federation.policies.exceptions.FederationPolicyException;
2729
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
2830
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterIdInfo;
2931
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterInfo;
@@ -82,4 +84,31 @@ public void testPickLowestWeight() throws YarnException {
8284
Assert.assertEquals("sc5", chosen.getId());
8385
}
8486

87+
@Test
88+
public void testZeroSubClustersWithPositiveWeight() throws Exception {
89+
Map<SubClusterIdInfo, Float> routerWeights = new HashMap<>();
90+
Map<SubClusterIdInfo, Float> amrmWeights = new HashMap<>();
91+
// Set negative value to all subclusters
92+
for (int i = 0; i < 5; i++) {
93+
SubClusterIdInfo sc = new SubClusterIdInfo("sc" + i);
94+
95+
SubClusterInfo sci = mock(SubClusterInfo.class);
96+
when(sci.getState()).thenReturn(SubClusterState.SC_RUNNING);
97+
when(sci.getSubClusterId()).thenReturn(sc.toId());
98+
getActiveSubclusters().put(sc.toId(), sci);
99+
routerWeights.put(sc, 0.0f);
100+
amrmWeights.put(sc, -1.0f);
101+
}
102+
getPolicyInfo().setRouterPolicyWeights(routerWeights);
103+
getPolicyInfo().setAMRMPolicyWeights(amrmWeights);
104+
FederationPoliciesTestUtil.initializePolicyContext(getPolicy(),
105+
getPolicyInfo(), getActiveSubclusters());
106+
107+
intercept(FederationPolicyException.class,
108+
"No Active Subcluster with weight vector greater than zero",
109+
() -> ((FederationRouterPolicy) getPolicy())
110+
.getHomeSubcluster(getApplicationSubmissionContext(), null));
111+
}
112+
113+
85114
}

0 commit comments

Comments
 (0)