HomeAMRMProxyPolicy extends AbstractAMRMProxyPolicy { @Override public Map<SubClusterId, List<ResourceRequest>> splitResourceRequests( List<ResourceRequest> resourceRequests, Set<SubClusterId> timedOutSubClusters) throws YarnException { if (homeSubcluster == null) { throw new FederationPolicyException("No home subcluster available"); } Map<SubClusterId, SubClusterInfo> active = getActiveSubclusters(); if (!active.containsKey(homeSubcluster)) { throw new FederationPolicyException( "The local subcluster " + homeSubcluster + " is not active"); } List<ResourceRequest> resourceRequestsCopy = new ArrayList<>(resourceRequests); return Collections.singletonMap(homeSubcluster, resourceRequestsCopy); }  @Override void reinitialize(
      FederationPolicyInitializationContext policyContext); @Override Map<SubClusterId, List<ResourceRequest>> splitResourceRequests(
      List<ResourceRequest> resourceRequests,
      Set<SubClusterId> timedOutSubClusters);  }
@Test public void testSplitAllocateRequest() throws YarnException { String[] hosts = new String[] {"host0", "host1", "host2", "host3"}; List<ResourceRequest> resourceRequests = createResourceRequests( hosts, 2 * 1024, 2, 1, 3, null, false); HomeAMRMProxyPolicy federationPolicy = (HomeAMRMProxyPolicy) getPolicy(); Map<SubClusterId, List<ResourceRequest>> response = federationPolicy .splitResourceRequests(resourceRequests, new HashSet<SubClusterId>()); assertEquals(1, response.size()); assertNotNull(response.get(HOME_SC_ID)); assertEquals(9, response.get(HOME_SC_ID).size()); }
@Test public void testHomeSubclusterNotActive() throws YarnException { initializePolicyContext(getPolicy(), mock(WeightedPolicyInfo.class), getActiveSubclusters(), "badsc"); try { String[] hosts = new String[] {"host0", "host1", "host2", "host3"}; List<ResourceRequest> resourceRequests = createResourceRequests( hosts, 2 * 1024, 2, 1, 3, null, false); HomeAMRMProxyPolicy federationPolicy = (HomeAMRMProxyPolicy)getPolicy(); federationPolicy.splitResourceRequests(resourceRequests, new HashSet<SubClusterId>()); fail("It should fail when the home subcluster is not active"); } catch(FederationPolicyException e) { GenericTestUtils.assertExceptionContains("is not active", e); } }