YARN-9054. Fix FederationStateStoreFacade#buildGetSubClustersCacheRequest. Contributed by Bibin A Chundatt.

This commit is contained in:
Giovanni Matteo Fumarola 2018-11-26 10:57:38 -08:00
parent a9d96948ed
commit 0d8406135f
3 changed files with 21 additions and 3 deletions

View File

@ -463,8 +463,9 @@ private Map<SubClusterId, SubClusterInfo> buildSubClusterInfoMap(
private Object buildGetSubClustersCacheRequest(
final boolean filterInactiveSubClusters) {
final String cacheKey = buildCacheKey(getClass().getSimpleName(),
GET_SUBCLUSTERS_CACHEID, null);
final String cacheKey =
buildCacheKey(getClass().getSimpleName(), GET_SUBCLUSTERS_CACHEID,
Boolean.toString(filterInactiveSubClusters));
CacheRequest<String, Map<SubClusterId, SubClusterInfo>> cacheRequest =
new CacheRequest<String, Map<SubClusterId, SubClusterInfo>>(cacheKey,
new Func<String, Map<SubClusterId, SubClusterInfo>>() {

View File

@ -172,7 +172,7 @@ public void deregisterAllSubClusters() throws YarnException {
}
}
private void deRegisterSubCluster(SubClusterId subClusterId)
public void deRegisterSubCluster(SubClusterId subClusterId)
throws YarnException {
stateStore.deregisterSubCluster(SubClusterDeregisterRequest
.newInstance(subClusterId, SubClusterState.SC_UNREGISTERED));

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.federation.utils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
@ -135,6 +136,22 @@ public void testGetPolicyConfiguration() throws YarnException {
}
}
@Test
public void testSubClustersCache() throws YarnException {
Map<SubClusterId, SubClusterInfo> allClusters =
facade.getSubClusters(false);
Assert.assertEquals(numSubClusters, allClusters.size());
SubClusterId clusterId = new ArrayList<>(allClusters.keySet()).get(0);
// make one subcluster down unregister
stateStoreTestUtil.deRegisterSubCluster(clusterId);
Map<SubClusterId, SubClusterInfo> activeClusters =
facade.getSubClusters(true);
Assert.assertEquals(numSubClusters - 1, activeClusters.size());
// Recheck false case.
allClusters = facade.getSubClusters(false);
Assert.assertEquals(numSubClusters, allClusters.size());
}
@Test
public void testInvalidGetPolicyConfiguration() throws YarnException {
Assert.assertNull(