AgentProviderService extends AbstractProviderService implements
    ProviderCore,
    AgentKeys,
    SliderKeys, AgentRestOperations { protected void dereferenceAllConfigs(Map<String, Map<String, String>> configurations) { Map<String, String> allConfigs = new HashMap<String, String>(); String lookupFormat = "${@ for (String configType : configurations.keySet()) { Map<String, String> configBucket = configurations.get(configType); for (String configName : configBucket.keySet()) { allConfigs.put(String.format(lookupFormat, configType, configName), configBucket.get(configName)); } } boolean finished = false; while (!finished) { finished = true; for (Map.Entry<String, String> entry : allConfigs.entrySet()) { String configValue = entry.getValue(); for (Map.Entry<String, String> lookUpEntry : allConfigs.entrySet()) { String lookUpValue = lookUpEntry.getValue(); if (lookUpValue.contains("${@ continue; } String lookUpKey = lookUpEntry.getKey(); if (configValue != null && configValue.contains(lookUpKey)) { configValue = configValue.replace(lookUpKey, lookUpValue); } } if (!configValue.equals(entry.getValue())) { finished = false; allConfigs.put(entry.getKey(), configValue); } } } for (String configType : configurations.keySet()) { Map<String, String> configBucket = configurations.get(configType); for (Map.Entry<String, String> entry: configBucket.entrySet()) { String configName = entry.getKey(); String configValue = entry.getValue(); for (Map.Entry<String, String> lookUpEntry : allConfigs.entrySet()) { String lookUpValue = lookUpEntry.getValue(); if (lookUpValue.contains("${@ continue; } String lookUpKey = lookUpEntry.getKey(); if (configValue != null && configValue.contains(lookUpKey)) { configValue = configValue.replace(lookUpKey, lookUpValue); } } configBucket.put(configName, configValue); } } } 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 testDereferenceAllConfig() throws IOException { AgentProviderService aps = createAgentProviderService(new Configuration()); Map<String, Map<String, String>> allConfigs = new HashMap<String, Map<String, String>>(); Map<String, String> cfg1 = new HashMap<String, String>(); cfg1.put("a1", "0${@ cfg1.put("b1", "22"); cfg1.put("c1", "33"); cfg1.put("d1", "${@ Map<String, String> cfg2 = new HashMap<String, String>(); cfg2.put("A1", "11${@ cfg2.put("B1", "${@ cfg2.put("C1", "DD${@ cfg2.put("D1", "${14}"); allConfigs.put("cfg1", cfg1); allConfigs.put("cfg-2", cfg2); aps.dereferenceAllConfigs(allConfigs); Assert.assertEquals("01122", cfg1.get("a1")); Assert.assertEquals("22", cfg1.get("b1")); Assert.assertEquals("33", cfg1.get("c1")); Assert.assertEquals("33AA", cfg1.get("d1")); Assert.assertEquals("1122", cfg2.get("A1")); Assert.assertEquals("1122,1122,AA,33", cfg2.get("B1")); Assert.assertEquals("DD33", cfg2.get("C1")); Assert.assertEquals("${14}", cfg2.get("D1")); }
@Test public void testDereferenceAllConfigLoop() throws IOException { AgentProviderService aps = createAgentProviderService(new Configuration()); Map<String, Map<String, String>> allConfigs = new HashMap<String, Map<String, String>>(); Map<String, String> cfg1 = new HashMap<String, String>(); cfg1.put("a1", "0${@ Map<String, String> cfg2 = new HashMap<String, String>(); cfg2.put("A1", "11${@ allConfigs.put("cfg1", cfg1); allConfigs.put("cfg-2", cfg2); aps.dereferenceAllConfigs(allConfigs); Assert.assertEquals("0${@ Assert.assertEquals("11${@ }