YARN-8942. PriorityBasedRouterPolicy throws exception if all sub-cluster weights have negative value. Contributed by Bilwa S T.

(cherry picked from commit 108ecf992f)
This commit is contained in:
Inigo Goiri 2020-05-13 10:04:12 -07:00 committed by Brahma Reddy Battula
parent 5cb9657320
commit 97171b9b18
2 changed files with 34 additions and 0 deletions

View File

@ -24,6 +24,7 @@
import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext;
import org.apache.hadoop.yarn.exceptions.YarnException;
import org.apache.hadoop.yarn.server.federation.policies.FederationPolicyUtils;
import org.apache.hadoop.yarn.server.federation.policies.exceptions.FederationPolicyException;
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterIdInfo;
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterInfo;
@ -65,6 +66,10 @@ public SubClusterId getHomeSubcluster(
chosen = id;
}
}
if (chosen == null) {
throw new FederationPolicyException(
"No Active Subcluster with weight vector greater than zero");
}
return chosen;
}

View File

@ -16,6 +16,7 @@
*/
package org.apache.hadoop.yarn.server.federation.policies.router;
import static org.apache.hadoop.test.LambdaTestUtils.intercept;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -24,6 +25,7 @@
import org.apache.hadoop.yarn.exceptions.YarnException;
import org.apache.hadoop.yarn.server.federation.policies.dao.WeightedPolicyInfo;
import org.apache.hadoop.yarn.server.federation.policies.exceptions.FederationPolicyException;
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterIdInfo;
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterInfo;
@ -82,4 +84,31 @@ public void testPickLowestWeight() throws YarnException {
Assert.assertEquals("sc5", chosen.getId());
}
@Test
public void testZeroSubClustersWithPositiveWeight() throws Exception {
Map<SubClusterIdInfo, Float> routerWeights = new HashMap<>();
Map<SubClusterIdInfo, Float> amrmWeights = new HashMap<>();
// Set negative value to all subclusters
for (int i = 0; i < 5; i++) {
SubClusterIdInfo sc = new SubClusterIdInfo("sc" + i);
SubClusterInfo sci = mock(SubClusterInfo.class);
when(sci.getState()).thenReturn(SubClusterState.SC_RUNNING);
when(sci.getSubClusterId()).thenReturn(sc.toId());
getActiveSubclusters().put(sc.toId(), sci);
routerWeights.put(sc, 0.0f);
amrmWeights.put(sc, -1.0f);
}
getPolicyInfo().setRouterPolicyWeights(routerWeights);
getPolicyInfo().setAMRMPolicyWeights(amrmWeights);
FederationPoliciesTestUtil.initializePolicyContext(getPolicy(),
getPolicyInfo(), getActiveSubclusters());
intercept(FederationPolicyException.class,
"No Active Subcluster with weight vector greater than zero",
() -> ((FederationRouterPolicy) getPolicy())
.getHomeSubcluster(getApplicationSubmissionContext(), null));
}
}