From a2754a0eff1caea81d3e9ed6e3d949f46c85ea8a Mon Sep 17 00:00:00 2001 From: sarahcaseybot Date: Wed, 16 Jun 2021 15:13:46 -0400 Subject: [PATCH] Add new domain list fields to Registry objects (#1208) * Add domain list name fields to Registry objects * Add some comments * Added scrap command * Fix typo * capitalize TLD --- .../registry/model/registry/Registry.java | 56 +++++++++++++++++-- .../google/registry/tools/RegistryTool.java | 2 + .../tools/javascrap/ResaveAllTldsCommand.java | 30 ++++++++++ .../google/registry/model/schema.txt | 2 + 4 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 core/src/main/java/google/registry/tools/javascrap/ResaveAllTldsCommand.java diff --git a/core/src/main/java/google/registry/model/registry/Registry.java b/core/src/main/java/google/registry/model/registry/Registry.java index 42b886859..dcce46949 100644 --- a/core/src/main/java/google/registry/model/registry/Registry.java +++ b/core/src/main/java/google/registry/model/registry/Registry.java @@ -47,6 +47,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; @@ -111,6 +112,26 @@ public class Registry extends ImmutableObject implements Buildable, DatastoreAnd @PostLoad void postLoad() { tldStr = tldStrId; + // TODO(sarahbot@): Remove the rest of this method after this data migration is complete + if (premiumListName != null) { + premiumList = Key.create(getCrossTldKey(), PremiumList.class, premiumListName); + } + if (reservedListNames != null) { + reservedLists = + reservedListNames.stream() + .map(name -> Key.create(getCrossTldKey(), ReservedList.class, name)) + .collect(toImmutableSet()); + } + } + + // TODO(sarahbot@): Remove this method after this data migration is complete + @OnLoad + void onLoad() { + if (reservedLists != null) { + reservedListNames = + reservedLists.stream().map(key -> key.getName()).collect(toImmutableSet()); + } + premiumListName = premiumList == null ? null : premiumList.getName(); } /** The suffix that identifies roids as belonging to this specific tld, e.g. -HOW for .how. */ @@ -388,17 +409,37 @@ public class Registry extends ImmutableObject implements Buildable, DatastoreAnd CreateAutoTimestamp creationTime = CreateAutoTimestamp.create(null); /** The set of reserved lists that are applicable to this registry. */ - @Column(name = "reserved_list_names") - Set> reservedLists; + @Transient Set> reservedLists; - /** Retrieves an ImmutableSet of all ReservedLists associated with this tld. */ + /** The set of reserved list names that are applicable to this registry. */ + @Column(name = "reserved_list_names") + Set reservedListNames; + + /** + * Retrieves an ImmutableSet of all ReservedLists associated with this TLD. + * + *

This set contains only the names of the list and not a reference to the lists. Updates to a + * reserved list in Cloud SQL are saved as a new ReservedList entity. When using the ReservedList + * for a registry, the database should be queried for the entity with this name that has the + * largest revision ID. + */ public ImmutableSet> getReservedLists() { return nullToEmptyImmutableCopy(reservedLists); } /** The static {@link PremiumList} for this TLD, if there is one. */ + @Transient Key premiumList; + + /** + * The name of the {@link PremiumList} for this TLD, if there is one. + * + *

This is only the name of the list and not a reference to the list. Updates to the premium + * list in Cloud SQL are saved as a new PremiumList entity. When using the PremiumList for a + * registry, the database should be queried for the entity with this name that has the largest + * revision ID. + */ @Column(name = "premium_list_name", nullable = true) - Key premiumList; + String premiumListName; /** Should RDE upload a nightly escrow deposit for this TLD? */ @Column(nullable = false) @@ -879,21 +920,26 @@ public class Registry extends ImmutableObject implements Buildable, DatastoreAnd public Builder setReservedLists(Set reservedLists) { checkArgumentNotNull(reservedLists, "reservedLists must not be null"); ImmutableSet.Builder> builder = new ImmutableSet.Builder<>(); + ImmutableSet.Builder nameBuilder = new ImmutableSet.Builder<>(); for (ReservedList reservedList : reservedLists) { builder.add(Key.create(reservedList)); + nameBuilder.add(reservedList.getName()); } getInstance().reservedLists = builder.build(); + getInstance().reservedListNames = nameBuilder.build(); return this; } - public Builder setPremiumList(PremiumList premiumList) { + public Builder setPremiumList(@Nullable PremiumList premiumList) { getInstance().premiumList = (premiumList == null) ? null : Key.create(premiumList); + getInstance().premiumListName = (premiumList == null) ? null : premiumList.getName(); return this; } @VisibleForTesting public Builder setPremiumListKey(@Nullable Key premiumList) { getInstance().premiumList = premiumList; + getInstance().premiumListName = (premiumList == null) ? null : premiumList.getName(); return this; } diff --git a/core/src/main/java/google/registry/tools/RegistryTool.java b/core/src/main/java/google/registry/tools/RegistryTool.java index 8b96ea2da..99c0a8a84 100644 --- a/core/src/main/java/google/registry/tools/RegistryTool.java +++ b/core/src/main/java/google/registry/tools/RegistryTool.java @@ -20,6 +20,7 @@ import google.registry.tools.javascrap.BackfillSpec11ThreatMatchesCommand; import google.registry.tools.javascrap.DeleteContactByRoidCommand; import google.registry.tools.javascrap.PopulateNullRegistrarFieldsCommand; import google.registry.tools.javascrap.RemoveIpAddressCommand; +import google.registry.tools.javascrap.ResaveAllTldsCommand; /** Container class to create and run remote commands against a Datastore instance. */ public final class RegistryTool { @@ -106,6 +107,7 @@ public final class RegistryTool { .put("remove_ip_address", RemoveIpAddressCommand.class) .put("remove_registry_one_key", RemoveRegistryOneKeyCommand.class) .put("renew_domain", RenewDomainCommand.class) + .put("resave_all_tlds", ResaveAllTldsCommand.class) .put("resave_entities", ResaveEntitiesCommand.class) .put("resave_environment_entities", ResaveEnvironmentEntitiesCommand.class) .put("resave_epp_resource", ResaveEppResourceCommand.class) diff --git a/core/src/main/java/google/registry/tools/javascrap/ResaveAllTldsCommand.java b/core/src/main/java/google/registry/tools/javascrap/ResaveAllTldsCommand.java new file mode 100644 index 000000000..b912a453e --- /dev/null +++ b/core/src/main/java/google/registry/tools/javascrap/ResaveAllTldsCommand.java @@ -0,0 +1,30 @@ +// Copyright 2021 The Nomulus Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package google.registry.tools.javascrap; + +import static google.registry.persistence.transaction.TransactionManagerFactory.tm; + +import com.beust.jcommander.Parameters; +import google.registry.model.registry.Registry; +import google.registry.tools.CommandWithRemoteApi; + +/** Scrap command to resave all Registry entities. */ +@Parameters(commandDescription = "Resave all TLDs") +public class ResaveAllTldsCommand implements CommandWithRemoteApi { + @Override + public void run() throws Exception { + tm().transact(() -> tm().putAll(tm().loadAllOf(Registry.class))); + } +} diff --git a/core/src/test/resources/google/registry/model/schema.txt b/core/src/test/resources/google/registry/model/schema.txt index 856fe3ecb..452d80eea 100644 --- a/core/src/test/resources/google/registry/model/schema.txt +++ b/core/src/test/resources/google/registry/model/schema.txt @@ -667,6 +667,7 @@ class google.registry.model.registry.Registry { int numDnsPublishLocks; java.lang.String driveFolderId; java.lang.String lordnUsername; + java.lang.String premiumListName; java.lang.String pricingEngineClassName; java.lang.String roidSuffix; java.lang.String tldStr; @@ -675,6 +676,7 @@ class google.registry.model.registry.Registry { java.util.Set allowedFullyQualifiedHostNames; java.util.Set allowedRegistrantContactIds; java.util.Set dnsWriters; + java.util.Set reservedListNames; org.joda.money.CurrencyUnit currency; org.joda.money.Money createBillingCost; org.joda.money.Money registryLockOrUnlockBillingCost;