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
This commit is contained in:
sarahcaseybot 2021-06-16 15:13:46 -04:00 committed by GitHub
parent a8fea440d9
commit 8771222d9f
4 changed files with 85 additions and 5 deletions

View file

@ -47,6 +47,7 @@ import com.googlecode.objectify.annotation.Embed;
import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id; import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Mapify; import com.googlecode.objectify.annotation.Mapify;
import com.googlecode.objectify.annotation.OnLoad;
import com.googlecode.objectify.annotation.OnSave; import com.googlecode.objectify.annotation.OnSave;
import com.googlecode.objectify.annotation.Parent; import com.googlecode.objectify.annotation.Parent;
import google.registry.model.Buildable; import google.registry.model.Buildable;
@ -111,6 +112,26 @@ public class Registry extends ImmutableObject implements Buildable, DatastoreAnd
@PostLoad @PostLoad
void postLoad() { void postLoad() {
tldStr = tldStrId; 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. */ /** 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); CreateAutoTimestamp creationTime = CreateAutoTimestamp.create(null);
/** The set of reserved lists that are applicable to this registry. */ /** The set of reserved lists that are applicable to this registry. */
@Column(name = "reserved_list_names") @Transient Set<Key<ReservedList>> reservedLists;
Set<Key<ReservedList>> 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<String> reservedListNames;
/**
* Retrieves an ImmutableSet of all ReservedLists associated with this TLD.
*
* <p>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<Key<ReservedList>> getReservedLists() { public ImmutableSet<Key<ReservedList>> getReservedLists() {
return nullToEmptyImmutableCopy(reservedLists); return nullToEmptyImmutableCopy(reservedLists);
} }
/** The static {@link PremiumList} for this TLD, if there is one. */ /** The static {@link PremiumList} for this TLD, if there is one. */
@Transient Key<PremiumList> premiumList;
/**
* The name of the {@link PremiumList} for this TLD, if there is one.
*
* <p>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) @Column(name = "premium_list_name", nullable = true)
Key<PremiumList> premiumList; String premiumListName;
/** Should RDE upload a nightly escrow deposit for this TLD? */ /** Should RDE upload a nightly escrow deposit for this TLD? */
@Column(nullable = false) @Column(nullable = false)
@ -879,21 +920,26 @@ public class Registry extends ImmutableObject implements Buildable, DatastoreAnd
public Builder setReservedLists(Set<ReservedList> reservedLists) { public Builder setReservedLists(Set<ReservedList> reservedLists) {
checkArgumentNotNull(reservedLists, "reservedLists must not be null"); checkArgumentNotNull(reservedLists, "reservedLists must not be null");
ImmutableSet.Builder<Key<ReservedList>> builder = new ImmutableSet.Builder<>(); ImmutableSet.Builder<Key<ReservedList>> builder = new ImmutableSet.Builder<>();
ImmutableSet.Builder<String> nameBuilder = new ImmutableSet.Builder<>();
for (ReservedList reservedList : reservedLists) { for (ReservedList reservedList : reservedLists) {
builder.add(Key.create(reservedList)); builder.add(Key.create(reservedList));
nameBuilder.add(reservedList.getName());
} }
getInstance().reservedLists = builder.build(); getInstance().reservedLists = builder.build();
getInstance().reservedListNames = nameBuilder.build();
return this; return this;
} }
public Builder setPremiumList(PremiumList premiumList) { public Builder setPremiumList(@Nullable PremiumList premiumList) {
getInstance().premiumList = (premiumList == null) ? null : Key.create(premiumList); getInstance().premiumList = (premiumList == null) ? null : Key.create(premiumList);
getInstance().premiumListName = (premiumList == null) ? null : premiumList.getName();
return this; return this;
} }
@VisibleForTesting @VisibleForTesting
public Builder setPremiumListKey(@Nullable Key<PremiumList> premiumList) { public Builder setPremiumListKey(@Nullable Key<PremiumList> premiumList) {
getInstance().premiumList = premiumList; getInstance().premiumList = premiumList;
getInstance().premiumListName = (premiumList == null) ? null : premiumList.getName();
return this; return this;
} }

View file

@ -20,6 +20,7 @@ import google.registry.tools.javascrap.BackfillSpec11ThreatMatchesCommand;
import google.registry.tools.javascrap.DeleteContactByRoidCommand; import google.registry.tools.javascrap.DeleteContactByRoidCommand;
import google.registry.tools.javascrap.PopulateNullRegistrarFieldsCommand; import google.registry.tools.javascrap.PopulateNullRegistrarFieldsCommand;
import google.registry.tools.javascrap.RemoveIpAddressCommand; import google.registry.tools.javascrap.RemoveIpAddressCommand;
import google.registry.tools.javascrap.ResaveAllTldsCommand;
/** Container class to create and run remote commands against a Datastore instance. */ /** Container class to create and run remote commands against a Datastore instance. */
public final class RegistryTool { public final class RegistryTool {
@ -106,6 +107,7 @@ public final class RegistryTool {
.put("remove_ip_address", RemoveIpAddressCommand.class) .put("remove_ip_address", RemoveIpAddressCommand.class)
.put("remove_registry_one_key", RemoveRegistryOneKeyCommand.class) .put("remove_registry_one_key", RemoveRegistryOneKeyCommand.class)
.put("renew_domain", RenewDomainCommand.class) .put("renew_domain", RenewDomainCommand.class)
.put("resave_all_tlds", ResaveAllTldsCommand.class)
.put("resave_entities", ResaveEntitiesCommand.class) .put("resave_entities", ResaveEntitiesCommand.class)
.put("resave_environment_entities", ResaveEnvironmentEntitiesCommand.class) .put("resave_environment_entities", ResaveEnvironmentEntitiesCommand.class)
.put("resave_epp_resource", ResaveEppResourceCommand.class) .put("resave_epp_resource", ResaveEppResourceCommand.class)

View file

@ -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)));
}
}

View file

@ -667,6 +667,7 @@ class google.registry.model.registry.Registry {
int numDnsPublishLocks; int numDnsPublishLocks;
java.lang.String driveFolderId; java.lang.String driveFolderId;
java.lang.String lordnUsername; java.lang.String lordnUsername;
java.lang.String premiumListName;
java.lang.String pricingEngineClassName; java.lang.String pricingEngineClassName;
java.lang.String roidSuffix; java.lang.String roidSuffix;
java.lang.String tldStr; java.lang.String tldStr;
@ -675,6 +676,7 @@ class google.registry.model.registry.Registry {
java.util.Set<java.lang.String> allowedFullyQualifiedHostNames; java.util.Set<java.lang.String> allowedFullyQualifiedHostNames;
java.util.Set<java.lang.String> allowedRegistrantContactIds; java.util.Set<java.lang.String> allowedRegistrantContactIds;
java.util.Set<java.lang.String> dnsWriters; java.util.Set<java.lang.String> dnsWriters;
java.util.Set<java.lang.String> reservedListNames;
org.joda.money.CurrencyUnit currency; org.joda.money.CurrencyUnit currency;
org.joda.money.Money createBillingCost; org.joda.money.Money createBillingCost;
org.joda.money.Money registryLockOrUnlockBillingCost; org.joda.money.Money registryLockOrUnlockBillingCost;