From 4d5b6845b7504c4f21629b70e6f77a0a452a693e Mon Sep 17 00:00:00 2001 From: mcilwain Date: Fri, 7 Jul 2017 15:24:24 -0700 Subject: [PATCH] Add plural DNS writers field to Registry entity This is the first step in a multi-step data migration to allow multiple DNS writers per TLD. The overall process looks like this: 1. Add a plural DNS writers field with backfill (this commit). 2. Deploy it. 3. Run the ResaveEnvironmentEntitiesCommand to populate this new field on all entities. 4. Update the code to use the new field everywhere. 5. Deploy it. 6. Delete the now-unreferenced, old deprecated singular value field. This process is rollback-safe. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=161253436 --- .../registry/model/registry/Registry.java | 33 +++++++++++++++++++ javatests/google/registry/model/schema.txt | 1 + .../registry/tools/SetupOteCommandTest.java | 1 + .../registry/tools/UpdateTldCommandTest.java | 3 ++ 4 files changed, 38 insertions(+) diff --git a/java/google/registry/model/registry/Registry.java b/java/google/registry/model/registry/Registry.java index f572c65ec..f93ba9cc2 100644 --- a/java/google/registry/model/registry/Registry.java +++ b/java/google/registry/model/registry/Registry.java @@ -21,6 +21,7 @@ import static com.google.common.base.Predicates.not; import static google.registry.config.RegistryConfig.getSingletonCacheRefreshDuration; import static google.registry.model.common.EntityGroupRoot.getCrossTldKey; import static google.registry.model.ofy.ObjectifyService.ofy; +import static google.registry.util.CollectionUtils.isNullOrEmpty; import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy; import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME; @@ -49,6 +50,7 @@ import com.googlecode.objectify.annotation.Embed; import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Id; import com.googlecode.objectify.annotation.Mapify; +import com.googlecode.objectify.annotation.OnLoad; import com.googlecode.objectify.annotation.OnSave; import com.googlecode.objectify.annotation.Parent; import google.registry.model.Buildable; @@ -269,9 +271,30 @@ public class Registry extends ImmutableObject implements Buildable { * *

This must be a valid key for the map of DnsWriters injected by * @Inject Map + * + * @deprecated by dnsWriters */ + // TODO(b/63385623): Delete this field when the data migration is complete. + @Deprecated String dnsWriter; + /** + * The set of name(s) of the {@code DnsWriter} implementations that this TLD uses. + * + *

There must be at least one entry in this set. + * + *

All entries of this list must be valid keys for the map of {@code DnsWriter}s injected by + * @Inject Map + */ + Set dnsWriters; + + @OnLoad + public void migrateDnsWriters() { + if (isNullOrEmpty(dnsWriters)) { + dnsWriters = ImmutableSet.of(dnsWriter); + } + } + /** * The unicode-aware representation of the TLD associated with this {@link Registry}. * @@ -588,10 +611,15 @@ public class Registry extends ImmutableObject implements Buildable { return pricingEngineClassName; } + @Deprecated public String getDnsWriter() { return dnsWriter; } + public ImmutableSet getDnsWriters() { + return ImmutableSet.copyOf(dnsWriters); + } + public ImmutableSet getAllowedRegistrantContactIds() { return nullToEmptyImmutableCopy(allowedRegistrantContactIds); } @@ -676,6 +704,7 @@ public class Registry extends ImmutableObject implements Buildable { public Builder setDnsWriter(String dnsWriter) { getInstance().dnsWriter = checkArgumentNotNull(dnsWriter); + getInstance().dnsWriters = ImmutableSet.of(dnsWriter); return this; } @@ -946,6 +975,10 @@ public class Registry extends ImmutableObject implements Buildable { checkArgumentNotNull( instance.dnsWriter, "A DNS writer must be specified. VoidDnsWriter can be used if DNS writing isn't wanted"); + checkArgument( + instance.dnsWriters != null && !instance.dnsWriters.isEmpty(), + "At least one DNS writer must be specified." + + " VoidDnsWriter can be used if DNS writing isn't desired"); instance.tldStrId = tldName; instance.tldUnicode = Idn.toUnicode(tldName); return super.build(); diff --git a/javatests/google/registry/model/schema.txt b/javatests/google/registry/model/schema.txt index 4ec26a6e9..2b8eb8109 100644 --- a/javatests/google/registry/model/schema.txt +++ b/javatests/google/registry/model/schema.txt @@ -700,6 +700,7 @@ class google.registry.model.registry.Registry { java.util.Set> reservedLists; java.util.Set allowedFullyQualifiedHostNames; java.util.Set allowedRegistrantContactIds; + java.util.Set dnsWriters; org.joda.money.CurrencyUnit currency; org.joda.money.Money createBillingCost; org.joda.money.Money restoreBillingCost; diff --git a/javatests/google/registry/tools/SetupOteCommandTest.java b/javatests/google/registry/tools/SetupOteCommandTest.java index 36584727d..c1d80c282 100644 --- a/javatests/google/registry/tools/SetupOteCommandTest.java +++ b/javatests/google/registry/tools/SetupOteCommandTest.java @@ -68,6 +68,7 @@ public class SetupOteCommandTest extends CommandTestCase { assertThat(registry.getRoidSuffix()).isEqualTo(roidSuffix); assertThat(registry.getTldState(DateTime.now(UTC))).isEqualTo(tldState); assertThat(registry.getDnsWriter()).isEqualTo(dnsWriter); + assertThat(registry.getDnsWriters()).containsExactly(dnsWriter); assertThat(registry.getPremiumList()).isNotNull(); assertThat(registry.getPremiumList().getName()).isEqualTo(premiumList); assertThat(registry.getAddGracePeriodLength()).isEqualTo(addGracePeriodLength); diff --git a/javatests/google/registry/tools/UpdateTldCommandTest.java b/javatests/google/registry/tools/UpdateTldCommandTest.java index 59911798f..fd02ff6f3 100644 --- a/javatests/google/registry/tools/UpdateTldCommandTest.java +++ b/javatests/google/registry/tools/UpdateTldCommandTest.java @@ -177,8 +177,11 @@ public class UpdateTldCommandTest extends CommandTestCase { @Test public void testSuccess_dnsWriter() throws Exception { assertThat(Registry.get("xn--q9jyb4c").getDnsWriter()).isEqualTo("VoidDnsWriter"); + assertThat(Registry.get("xn--q9jyb4c").getDnsWriters()).containsExactly("VoidDnsWriter"); + runCommandForced("--dns_writer=FooDnsWriter", "xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getDnsWriter()).isEqualTo("FooDnsWriter"); + assertThat(Registry.get("xn--q9jyb4c").getDnsWriters()).containsExactly("FooDnsWriter"); } @Test