@Test public void withAdditionalRegionsDoesntAffectOtherProfiles() { ResourceRecordSet<AData> geoRRS = ResourceRecordSet.<AData>builder() .name("www.denominator.io.") .type("A") .qualifier("US-East") .ttl(3600) .add(AData.create("1.1.1.1")) .weighted(weighted) .geo(geo).build(); Map<String, Collection<String>> oregon = new LinkedHashMap<String, Collection<String>>(); oregon.put("US", Arrays.asList("US-OR")); ResourceRecordSet<?> withOregon = Geos.withAdditionalRegions(geoRRS, oregon); assertThat(withOregon) .containsRegion("US", "US-VA", "US-CA", "US-OR") .containsRegion("IM", "IM"); assertThat(withOregon.weighted()).isEqualTo(weighted); }
public static ResourceRecordSet<?> withAdditionalRegions(ResourceRecordSet<?> existing, Map<String, Collection<String>> regionsToAdd) throws IllegalArgumentException { checkArgument(!regionsToAdd.isEmpty(), "no regions specified"); checkArgument(existing.geo() != null, "rrset does not include geo configuration: %s", existing); Map<String, Collection<String>> regionsToApply = new LinkedHashMap<String, Collection<String>>(); for (Entry<String, Collection<String>> entry : existing.geo().regions().entrySet()) { regionsToApply.put(entry.getKey(), entry.getValue()); } for (Entry<String, Collection<String>> entry : regionsToAdd.entrySet()) { List<String> updates = new ArrayList<String>(); if (regionsToApply.containsKey(entry.getKey())) { updates.addAll(regionsToApply.get(entry.getKey())); } updates.addAll(entry.getValue()); regionsToApply.put(entry.getKey(), updates); } boolean noop = true; for (Entry<String, Collection<String>> entry : regionsToApply.entrySet()) { if (!existing.geo().regions().containsKey(entry.getKey())) { noop = false; break; } Collection<String> existingTerritories = existing.geo().regions().get(entry.getKey()); if (!existingTerritories.containsAll(entry.getValue())) { noop = false; break; } } if (noop) { return existing; } return ResourceRecordSet.<Map<String, Object>>builder() .name(existing.name()) .type(existing.type()) .qualifier(existing.qualifier()) .ttl(existing.ttl()) .geo(Geo.create(regionsToApply)) .weighted(existing.weighted()) .addAll(existing.records()).build(); }
Geos { public static ResourceRecordSet<?> withAdditionalRegions(ResourceRecordSet<?> existing, Map<String, Collection<String>> regionsToAdd) throws IllegalArgumentException { checkArgument(!regionsToAdd.isEmpty(), "no regions specified"); checkArgument(existing.geo() != null, "rrset does not include geo configuration: %s", existing); Map<String, Collection<String>> regionsToApply = new LinkedHashMap<String, Collection<String>>(); for (Entry<String, Collection<String>> entry : existing.geo().regions().entrySet()) { regionsToApply.put(entry.getKey(), entry.getValue()); } for (Entry<String, Collection<String>> entry : regionsToAdd.entrySet()) { List<String> updates = new ArrayList<String>(); if (regionsToApply.containsKey(entry.getKey())) { updates.addAll(regionsToApply.get(entry.getKey())); } updates.addAll(entry.getValue()); regionsToApply.put(entry.getKey(), updates); } boolean noop = true; for (Entry<String, Collection<String>> entry : regionsToApply.entrySet()) { if (!existing.geo().regions().containsKey(entry.getKey())) { noop = false; break; } Collection<String> existingTerritories = existing.geo().regions().get(entry.getKey()); if (!existingTerritories.containsAll(entry.getValue())) { noop = false; break; } } if (noop) { return existing; } return ResourceRecordSet.<Map<String, Object>>builder() .name(existing.name()) .type(existing.type()) .qualifier(existing.qualifier()) .ttl(existing.ttl()) .geo(Geo.create(regionsToApply)) .weighted(existing.weighted()) .addAll(existing.records()).build(); } }
Geos { public static ResourceRecordSet<?> withAdditionalRegions(ResourceRecordSet<?> existing, Map<String, Collection<String>> regionsToAdd) throws IllegalArgumentException { checkArgument(!regionsToAdd.isEmpty(), "no regions specified"); checkArgument(existing.geo() != null, "rrset does not include geo configuration: %s", existing); Map<String, Collection<String>> regionsToApply = new LinkedHashMap<String, Collection<String>>(); for (Entry<String, Collection<String>> entry : existing.geo().regions().entrySet()) { regionsToApply.put(entry.getKey(), entry.getValue()); } for (Entry<String, Collection<String>> entry : regionsToAdd.entrySet()) { List<String> updates = new ArrayList<String>(); if (regionsToApply.containsKey(entry.getKey())) { updates.addAll(regionsToApply.get(entry.getKey())); } updates.addAll(entry.getValue()); regionsToApply.put(entry.getKey(), updates); } boolean noop = true; for (Entry<String, Collection<String>> entry : regionsToApply.entrySet()) { if (!existing.geo().regions().containsKey(entry.getKey())) { noop = false; break; } Collection<String> existingTerritories = existing.geo().regions().get(entry.getKey()); if (!existingTerritories.containsAll(entry.getValue())) { noop = false; break; } } if (noop) { return existing; } return ResourceRecordSet.<Map<String, Object>>builder() .name(existing.name()) .type(existing.type()) .qualifier(existing.qualifier()) .ttl(existing.ttl()) .geo(Geo.create(regionsToApply)) .weighted(existing.weighted()) .addAll(existing.records()).build(); }  }
Geos { public static ResourceRecordSet<?> withAdditionalRegions(ResourceRecordSet<?> existing, Map<String, Collection<String>> regionsToAdd) throws IllegalArgumentException { checkArgument(!regionsToAdd.isEmpty(), "no regions specified"); checkArgument(existing.geo() != null, "rrset does not include geo configuration: %s", existing); Map<String, Collection<String>> regionsToApply = new LinkedHashMap<String, Collection<String>>(); for (Entry<String, Collection<String>> entry : existing.geo().regions().entrySet()) { regionsToApply.put(entry.getKey(), entry.getValue()); } for (Entry<String, Collection<String>> entry : regionsToAdd.entrySet()) { List<String> updates = new ArrayList<String>(); if (regionsToApply.containsKey(entry.getKey())) { updates.addAll(regionsToApply.get(entry.getKey())); } updates.addAll(entry.getValue()); regionsToApply.put(entry.getKey(), updates); } boolean noop = true; for (Entry<String, Collection<String>> entry : regionsToApply.entrySet()) { if (!existing.geo().regions().containsKey(entry.getKey())) { noop = false; break; } Collection<String> existingTerritories = existing.geo().regions().get(entry.getKey()); if (!existingTerritories.containsAll(entry.getValue())) { noop = false; break; } } if (noop) { return existing; } return ResourceRecordSet.<Map<String, Object>>builder() .name(existing.name()) .type(existing.type()) .qualifier(existing.qualifier()) .ttl(existing.ttl()) .geo(Geo.create(regionsToApply)) .weighted(existing.weighted()) .addAll(existing.records()).build(); }  static ResourceRecordSet<?> withAdditionalRegions(ResourceRecordSet<?> existing,
                                                           Map<String, Collection<String>> regionsToAdd); }
Geos { public static ResourceRecordSet<?> withAdditionalRegions(ResourceRecordSet<?> existing, Map<String, Collection<String>> regionsToAdd) throws IllegalArgumentException { checkArgument(!regionsToAdd.isEmpty(), "no regions specified"); checkArgument(existing.geo() != null, "rrset does not include geo configuration: %s", existing); Map<String, Collection<String>> regionsToApply = new LinkedHashMap<String, Collection<String>>(); for (Entry<String, Collection<String>> entry : existing.geo().regions().entrySet()) { regionsToApply.put(entry.getKey(), entry.getValue()); } for (Entry<String, Collection<String>> entry : regionsToAdd.entrySet()) { List<String> updates = new ArrayList<String>(); if (regionsToApply.containsKey(entry.getKey())) { updates.addAll(regionsToApply.get(entry.getKey())); } updates.addAll(entry.getValue()); regionsToApply.put(entry.getKey(), updates); } boolean noop = true; for (Entry<String, Collection<String>> entry : regionsToApply.entrySet()) { if (!existing.geo().regions().containsKey(entry.getKey())) { noop = false; break; } Collection<String> existingTerritories = existing.geo().regions().get(entry.getKey()); if (!existingTerritories.containsAll(entry.getValue())) { noop = false; break; } } if (noop) { return existing; } return ResourceRecordSet.<Map<String, Object>>builder() .name(existing.name()) .type(existing.type()) .qualifier(existing.qualifier()) .ttl(existing.ttl()) .geo(Geo.create(regionsToApply)) .weighted(existing.weighted()) .addAll(existing.records()).build(); }  static ResourceRecordSet<?> withAdditionalRegions(ResourceRecordSet<?> existing,
                                                           Map<String, Collection<String>> regionsToAdd);  }