AgentProviderService extends AbstractProviderService implements
    ProviderCore,
    AgentKeys,
    SliderKeys, AgentRestOperations { protected void addRoleRelatedTokens(Map<String, String> tokens) { for (Map.Entry<String, Map<String, ClusterNode>> entry : getRoleClusterNodeMapping().entrySet()) { String tokenName = entry.getKey().toUpperCase(Locale.ENGLISH) + "_HOST"; String hosts = StringUtils.join(",", getHostsList(entry.getValue().values(), true)); tokens.put("${" + tokenName + "}", hosts); } } AgentProviderService(); @Override String getHumanName(); @Override List<ProviderRole> getRoles(); @Override Configuration loadProviderConfigurationInformation(File confDir); @Override void validateInstanceDefinition(AggregateConf instanceDefinition); @Override void initializeApplicationConfiguration(
      AggregateConf instanceDefinition, SliderFileSystem fileSystem,
      String roleGroup); @Override void buildContainerLaunchContext(ContainerLauncher launcher,
                                          AggregateConf instanceDefinition,
                                          Container container,
                                          ProviderRole providerRole,
                                          SliderFileSystem fileSystem,
                                          Path generatedConfPath,
                                          MapOperations resourceComponent,
                                          MapOperations appComponent,
                                          Path containerTmpDirPath); @Override void rebuildContainerDetails(List<Container> liveContainers,
                                      String applicationId, Map<Integer, ProviderRole> providerRoleMap); @Override boolean isSupportedRole(String role); @Override RegistrationResponse handleRegistration(Register registration); @Override HeartBeatResponse handleHeartBeat(HeartBeat heartBeat); @Override Map<String, MonitorDetail> buildMonitorDetails(ClusterDescription clusterDesc); @Override void applyInitialRegistryDefinitions(URL amWebURI,
      URL agentOpsURI,
      URL agentStatusURI,
      ServiceRecord serviceRecord); @Override void notifyContainerCompleted(ContainerId containerId); void setInUpgradeMode(boolean inUpgradeMode); void addUpgradeContainers(Set<String> upgradeContainers); void setAppStopInitiated(boolean appStopInitiated); Map<String, String> buildProviderStatus();  }
@Test public void testRoleHostMapping() throws Exception { AgentProviderService aps = createAgentProviderService(new Configuration()); StateAccessForProviders appState = new ProviderAppState("undefined", null) { @Override public ClusterDescription getClusterStatus() { ClusterDescription cd = new ClusterDescription(); cd.status = new HashMap<String, Object>(); cd.status.put(ClusterDescriptionKeys.KEY_CLUSTER_LIVE, buildRoleMap()); return cd; } @Override public Map<String, Map<String, ClusterNode>> getRoleClusterNodeMapping() { return buildRoleMap(); } public Map<String, Map<String, ClusterNode>> buildRoleMap() { Map<String, Map<String, ClusterNode>> roleMap = new HashMap<String, Map<String, ClusterNode>>(); ClusterNode cn1 = new ClusterNode(new MockContainerId(1)); cn1.host = "FIRST_HOST"; Map<String, ClusterNode> map1 = new HashMap<String, ClusterNode>(); map1.put("FIRST_CONTAINER", cn1); ClusterNode cn2 = new ClusterNode(new MockContainerId(2)); cn2.host = "SECOND_HOST"; Map<String, ClusterNode> map2 = new HashMap<String, ClusterNode>(); map2.put("SECOND_CONTAINER", cn2); ClusterNode cn3 = new ClusterNode(new MockContainerId(3)); cn3.host = "THIRD_HOST"; map2.put("THIRD_CONTAINER", cn3); roleMap.put("FIRST_ROLE", map1); roleMap.put("SECOND_ROLE", map2); return roleMap; } @Override public boolean isApplicationLive() { return true; } @Override public ClusterDescription refreshClusterStatus() { return null; } }; aps.setAmState(appState); Map<String, String> tokens = new HashMap<String, String>(); aps.addRoleRelatedTokens(tokens); Assert.assertEquals(2, tokens.size()); Assert.assertEquals("FIRST_HOST", tokens.get("${FIRST_ROLE_HOST}")); Assert.assertEquals("THIRD_HOST,SECOND_HOST", tokens.get("${SECOND_ROLE_HOST}")); aps.close(); }