@Test public void testMerge() { ArrayList<ConfigUpgradePack> cups = new ArrayList<>(); for (int cupIndex = 0; cupIndex < 3; cupIndex++) { ArrayList<AffectedService> services = new ArrayList<>(); for (int serviceIndex = 0; serviceIndex < 2; serviceIndex++) { String serviceName; if (serviceIndex == 0) { serviceName = "HDFS"; } else { serviceName = String.format("SOME_SERVICE_%s", cupIndex); } ArrayList<AffectedComponent> components = new ArrayList<>(); for (int componentIndex = 0; componentIndex < 2; componentIndex++) { String componentName; if (componentIndex == 0) { componentName = "NAMENODE"; } else { componentName = "SOME_COMPONENT_" + cupIndex; } ArrayList<ConfigUpgradeChangeDefinition> changeDefinitions = new ArrayList<>(); for (int changeIndex = 0; changeIndex < 2; changeIndex++) { String change_id = String.format( "CHANGE_%s_%s_%s_%s", cupIndex, serviceIndex, componentIndex, changeIndex); ConfigUpgradeChangeDefinition changeDefinition = new ConfigUpgradeChangeDefinition(); changeDefinition.id = change_id; changeDefinitions.add(changeDefinition); } AffectedComponent component = new AffectedComponent(); component.name = componentName; component.changes = changeDefinitions; components.add(component); } AffectedService service = new AffectedService(); service.name = serviceName; service.components = components; services.add(service); } ConfigUpgradePack cupI = new ConfigUpgradePack(); cupI.services = services; cups.add(cupI); } ConfigUpgradePack result = ConfigUpgradePack.merge(cups); assertEquals(result.enumerateConfigChangesByID().entrySet().size(), 24); assertEquals(result.getServiceMap().get("HDFS").getComponentMap().get("NAMENODE").changes.get(0).id, "CHANGE_0_0_0_0"); assertEquals(result.getServiceMap().get("HDFS").getComponentMap().get("NAMENODE").changes.get(1).id, "CHANGE_0_0_0_1"); assertEquals(result.getServiceMap().get("HDFS").getComponentMap().get("NAMENODE").changes.get(2).id, "CHANGE_1_0_0_0"); assertEquals(result.getServiceMap().get("HDFS").getComponentMap().get("NAMENODE").changes.get(3).id, "CHANGE_1_0_0_1"); assertEquals(result.getServiceMap().get("HDFS").getComponentMap().get("NAMENODE").changes.get(4).id, "CHANGE_2_0_0_0"); assertEquals(result.getServiceMap().get("HDFS").getComponentMap().get("NAMENODE").changes.get(5).id, "CHANGE_2_0_0_1"); assertEquals(result.getServiceMap().get("HDFS").getComponentMap().get("SOME_COMPONENT_0").changes.get(0).id, "CHANGE_0_0_1_0"); assertEquals(result.getServiceMap().get("HDFS").getComponentMap().get("SOME_COMPONENT_0").changes.get(1).id, "CHANGE_0_0_1_1"); assertEquals(result.getServiceMap().get("HDFS").getComponentMap().get("SOME_COMPONENT_1").changes.get(0).id, "CHANGE_1_0_1_0"); assertEquals(result.getServiceMap().get("HDFS").getComponentMap().get("SOME_COMPONENT_1").changes.get(1).id, "CHANGE_1_0_1_1"); assertEquals(result.getServiceMap().get("HDFS").getComponentMap().get("SOME_COMPONENT_2").changes.get(0).id, "CHANGE_2_0_1_0"); assertEquals(result.getServiceMap().get("HDFS").getComponentMap().get("SOME_COMPONENT_2").changes.get(1).id, "CHANGE_2_0_1_1"); assertEquals(result.getServiceMap().get("SOME_SERVICE_0").getComponentMap().get("NAMENODE").changes.get(0).id, "CHANGE_0_1_0_0"); assertEquals(result.getServiceMap().get("SOME_SERVICE_0").getComponentMap().get("NAMENODE").changes.get(1).id, "CHANGE_0_1_0_1"); assertEquals(result.getServiceMap().get("SOME_SERVICE_0").getComponentMap().get("SOME_COMPONENT_0").changes.get(0).id, "CHANGE_0_1_1_0"); assertEquals(result.getServiceMap().get("SOME_SERVICE_0").getComponentMap().get("SOME_COMPONENT_0").changes.get(1).id, "CHANGE_0_1_1_1"); assertEquals(result.getServiceMap().get("SOME_SERVICE_1").getComponentMap().get("NAMENODE").changes.get(0).id, "CHANGE_1_1_0_0"); assertEquals(result.getServiceMap().get("SOME_SERVICE_1").getComponentMap().get("NAMENODE").changes.get(1).id, "CHANGE_1_1_0_1"); assertEquals(result.getServiceMap().get("SOME_SERVICE_1").getComponentMap().get("SOME_COMPONENT_1").changes.get(0).id, "CHANGE_1_1_1_0"); assertEquals(result.getServiceMap().get("SOME_SERVICE_1").getComponentMap().get("SOME_COMPONENT_1").changes.get(1).id, "CHANGE_1_1_1_1"); assertEquals(result.getServiceMap().get("SOME_SERVICE_2").getComponentMap().get("NAMENODE").changes.get(0).id, "CHANGE_2_1_0_0"); assertEquals(result.getServiceMap().get("SOME_SERVICE_2").getComponentMap().get("NAMENODE").changes.get(1).id, "CHANGE_2_1_0_1"); assertEquals(result.getServiceMap().get("SOME_SERVICE_2").getComponentMap().get("SOME_COMPONENT_2").changes.get(0).id, "CHANGE_2_1_1_0"); assertEquals(result.getServiceMap().get("SOME_SERVICE_2").getComponentMap().get("SOME_COMPONENT_2").changes.get(1).id, "CHANGE_2_1_1_1"); }
public static ConfigUpgradePack merge(ArrayList<ConfigUpgradePack> cups) { Map<String, Map<String, AffectedComponent>> mergedServiceMap = new HashMap<>(); for (ConfigUpgradePack configUpgradePack : cups) { for (AffectedService service : configUpgradePack.services) { if (! mergedServiceMap.containsKey(service.name)) { mergedServiceMap.put(service.name, new HashMap<String, AffectedComponent>()); } Map<String, AffectedComponent> mergedComponentMap = mergedServiceMap.get(service.name); for (AffectedComponent component : service.components) { if (! mergedComponentMap.containsKey(component.name)) { AffectedComponent mergedComponent = new AffectedComponent(); mergedComponent.name = component.name; mergedComponent.changes = new ArrayList<>(); mergedComponentMap.put(component.name, mergedComponent); } AffectedComponent mergedComponent = mergedComponentMap.get(component.name); mergedComponent.changes.addAll(component.changes); } } } ArrayList<AffectedService> mergedServices = new ArrayList<>(); for (String serviceName : mergedServiceMap.keySet()) { AffectedService mergedService = new AffectedService(); Map<String, AffectedComponent> mergedComponentMap = mergedServiceMap.get(serviceName); mergedService.name = serviceName; mergedService.components = new ArrayList<>(mergedComponentMap.values()); mergedServices.add(mergedService); } return new ConfigUpgradePack(mergedServices); }
ConfigUpgradePack { public static ConfigUpgradePack merge(ArrayList<ConfigUpgradePack> cups) { Map<String, Map<String, AffectedComponent>> mergedServiceMap = new HashMap<>(); for (ConfigUpgradePack configUpgradePack : cups) { for (AffectedService service : configUpgradePack.services) { if (! mergedServiceMap.containsKey(service.name)) { mergedServiceMap.put(service.name, new HashMap<String, AffectedComponent>()); } Map<String, AffectedComponent> mergedComponentMap = mergedServiceMap.get(service.name); for (AffectedComponent component : service.components) { if (! mergedComponentMap.containsKey(component.name)) { AffectedComponent mergedComponent = new AffectedComponent(); mergedComponent.name = component.name; mergedComponent.changes = new ArrayList<>(); mergedComponentMap.put(component.name, mergedComponent); } AffectedComponent mergedComponent = mergedComponentMap.get(component.name); mergedComponent.changes.addAll(component.changes); } } } ArrayList<AffectedService> mergedServices = new ArrayList<>(); for (String serviceName : mergedServiceMap.keySet()) { AffectedService mergedService = new AffectedService(); Map<String, AffectedComponent> mergedComponentMap = mergedServiceMap.get(serviceName); mergedService.name = serviceName; mergedService.components = new ArrayList<>(mergedComponentMap.values()); mergedServices.add(mergedService); } return new ConfigUpgradePack(mergedServices); } }
ConfigUpgradePack { public static ConfigUpgradePack merge(ArrayList<ConfigUpgradePack> cups) { Map<String, Map<String, AffectedComponent>> mergedServiceMap = new HashMap<>(); for (ConfigUpgradePack configUpgradePack : cups) { for (AffectedService service : configUpgradePack.services) { if (! mergedServiceMap.containsKey(service.name)) { mergedServiceMap.put(service.name, new HashMap<String, AffectedComponent>()); } Map<String, AffectedComponent> mergedComponentMap = mergedServiceMap.get(service.name); for (AffectedComponent component : service.components) { if (! mergedComponentMap.containsKey(component.name)) { AffectedComponent mergedComponent = new AffectedComponent(); mergedComponent.name = component.name; mergedComponent.changes = new ArrayList<>(); mergedComponentMap.put(component.name, mergedComponent); } AffectedComponent mergedComponent = mergedComponentMap.get(component.name); mergedComponent.changes.addAll(component.changes); } } } ArrayList<AffectedService> mergedServices = new ArrayList<>(); for (String serviceName : mergedServiceMap.keySet()) { AffectedService mergedService = new AffectedService(); Map<String, AffectedComponent> mergedComponentMap = mergedServiceMap.get(serviceName); mergedService.name = serviceName; mergedService.components = new ArrayList<>(mergedComponentMap.values()); mergedServices.add(mergedService); } return new ConfigUpgradePack(mergedServices); } ConfigUpgradePack();  ConfigUpgradePack(List<AffectedService> services); }
ConfigUpgradePack { public static ConfigUpgradePack merge(ArrayList<ConfigUpgradePack> cups) { Map<String, Map<String, AffectedComponent>> mergedServiceMap = new HashMap<>(); for (ConfigUpgradePack configUpgradePack : cups) { for (AffectedService service : configUpgradePack.services) { if (! mergedServiceMap.containsKey(service.name)) { mergedServiceMap.put(service.name, new HashMap<String, AffectedComponent>()); } Map<String, AffectedComponent> mergedComponentMap = mergedServiceMap.get(service.name); for (AffectedComponent component : service.components) { if (! mergedComponentMap.containsKey(component.name)) { AffectedComponent mergedComponent = new AffectedComponent(); mergedComponent.name = component.name; mergedComponent.changes = new ArrayList<>(); mergedComponentMap.put(component.name, mergedComponent); } AffectedComponent mergedComponent = mergedComponentMap.get(component.name); mergedComponent.changes.addAll(component.changes); } } } ArrayList<AffectedService> mergedServices = new ArrayList<>(); for (String serviceName : mergedServiceMap.keySet()) { AffectedService mergedService = new AffectedService(); Map<String, AffectedComponent> mergedComponentMap = mergedServiceMap.get(serviceName); mergedService.name = serviceName; mergedService.components = new ArrayList<>(mergedComponentMap.values()); mergedServices.add(mergedService); } return new ConfigUpgradePack(mergedServices); } ConfigUpgradePack();  ConfigUpgradePack(List<AffectedService> services); Map<String, AffectedService> getServiceMap(); Map<String, ConfigUpgradeChangeDefinition> enumerateConfigChangesByID(); static ConfigUpgradePack merge(ArrayList<ConfigUpgradePack> cups); }
ConfigUpgradePack { public static ConfigUpgradePack merge(ArrayList<ConfigUpgradePack> cups) { Map<String, Map<String, AffectedComponent>> mergedServiceMap = new HashMap<>(); for (ConfigUpgradePack configUpgradePack : cups) { for (AffectedService service : configUpgradePack.services) { if (! mergedServiceMap.containsKey(service.name)) { mergedServiceMap.put(service.name, new HashMap<String, AffectedComponent>()); } Map<String, AffectedComponent> mergedComponentMap = mergedServiceMap.get(service.name); for (AffectedComponent component : service.components) { if (! mergedComponentMap.containsKey(component.name)) { AffectedComponent mergedComponent = new AffectedComponent(); mergedComponent.name = component.name; mergedComponent.changes = new ArrayList<>(); mergedComponentMap.put(component.name, mergedComponent); } AffectedComponent mergedComponent = mergedComponentMap.get(component.name); mergedComponent.changes.addAll(component.changes); } } } ArrayList<AffectedService> mergedServices = new ArrayList<>(); for (String serviceName : mergedServiceMap.keySet()) { AffectedService mergedService = new AffectedService(); Map<String, AffectedComponent> mergedComponentMap = mergedServiceMap.get(serviceName); mergedService.name = serviceName; mergedService.components = new ArrayList<>(mergedComponentMap.values()); mergedServices.add(mergedService); } return new ConfigUpgradePack(mergedServices); } ConfigUpgradePack();  ConfigUpgradePack(List<AffectedService> services); Map<String, AffectedService> getServiceMap(); Map<String, ConfigUpgradeChangeDefinition> enumerateConfigChangesByID(); static ConfigUpgradePack merge(ArrayList<ConfigUpgradePack> cups); @XmlElementWrapper(name="services")
  @XmlElement(name="service")
  public List<AffectedService> services; }