Merge DomainResource into DomainBase

This eliminates the use of Objectify polymorphism for EPP resources entirely
(yay!), which makes the Registry 3.0 database migration easier.

It is unfortunate that the naming parallelism of EppResources is lost between
ContactResource, HostResource, and DomainResource, but the actual type as far as
Datastore was concerned was DomainBase all along, and it would be a much more
substantial data migration to allow us to continue using the class name
DomainResource now that we're no longer using Objectify polymorphism. This
simply isn't worth it.

This also removes the polymorphic Datastore indexes (which will no longer
function as of this change). The non-polymorphic replacement indexes were added
in []

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=230930546
This commit is contained in:
mcilwain 2019-01-25 10:53:10 -08:00 committed by Ben McIlwain
parent 97c2049669
commit e2528875b2
166 changed files with 1525 additions and 1666 deletions

View file

@ -21,7 +21,7 @@ import com.google.common.base.Strings;
import com.googlecode.objectify.Key;
import google.registry.model.EppResource;
import google.registry.model.contact.ContactResource;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.host.HostResource;
import google.registry.model.index.ForeignKeyIndex;
import org.joda.time.DateTime;
@ -33,7 +33,7 @@ class CommandUtilities {
public enum ResourceType {
CONTACT(ContactResource.class),
HOST(HostResource.class),
DOMAIN(DomainResource.class);
DOMAIN(DomainBase.class);
private Class<? extends EppResource> clazz;

View file

@ -20,7 +20,7 @@ import static google.registry.model.registry.Registries.assertTldsExist;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.google.common.collect.Iterators;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.util.Clock;
import java.util.List;
import javax.inject.Inject;
@ -46,7 +46,7 @@ final class CountDomainsCommand implements CommandWithRemoteApi {
return Iterators.size(
ofy()
.load()
.type(DomainResource.class)
.type(DomainBase.class)
.filter("tld", tld)
.filter("deletionTime >", now)
.chunkAll()

View file

@ -19,7 +19,7 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.registrar.Registrar;
import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldType;
@ -62,7 +62,7 @@ final class DeleteTldCommand extends ConfirmingCommand implements CommandWithRem
}
int count = ofy().load()
.type(DomainResource.class)
.type(DomainBase.class)
.filter("tld", tld)
.limit(1)
.count();

View file

@ -25,7 +25,7 @@ import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.host.HostResource;
import google.registry.tools.params.PathParameter;
import google.registry.util.Clock;
@ -71,8 +71,8 @@ final class GenerateDnsReportCommand implements CommandWithRemoteApi {
String generate() {
result.append("[\n");
Iterable<DomainResource> domains = ofy().load().type(DomainResource.class).filter("tld", tld);
for (DomainResource domain : domains) {
Iterable<DomainBase> domains = ofy().load().type(DomainBase.class).filter("tld", tld);
for (DomainBase domain : domains) {
// Skip deleted domains and domains that don't get published to DNS.
if (isBeforeOrAt(domain.getDeletionTime(), now) || !domain.shouldPublishToDns()) {
continue;
@ -93,7 +93,7 @@ final class GenerateDnsReportCommand implements CommandWithRemoteApi {
return result.append("\n]\n").toString();
}
private void write(DomainResource domain) {
private void write(DomainBase domain) {
ImmutableList<String> nameservers =
ImmutableList.sortedCopyOf(domain.loadNameserverFullyQualifiedHostNames());
ImmutableList<Map<String, ?>> dsData =

View file

@ -21,7 +21,7 @@ import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.google.common.collect.ImmutableList;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.tmch.LordnTaskUtils;
import google.registry.tools.params.PathParameter;
import java.io.IOException;
@ -58,7 +58,7 @@ final class GenerateLordnCommand implements CommandWithRemoteApi {
DateTime now = DateTime.now(UTC);
ImmutableList.Builder<String> claimsCsv = new ImmutableList.Builder<>();
ImmutableList.Builder<String> sunriseCsv = new ImmutableList.Builder<>();
for (DomainResource domain : ofy().load().type(DomainResource.class).filter("tld", tld)) {
for (DomainBase domain : ofy().load().type(DomainBase.class).filter("tld", tld)) {
String status = " ";
if (domain.getLaunchNotice() == null && domain.getSmdId() != null) {
sunriseCsv.add(LordnTaskUtils.getCsvLineForSunriseDomain(domain, domain.getCreationTime()));

View file

@ -18,7 +18,7 @@ import static google.registry.model.EppResourceUtils.loadByForeignKey;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import java.util.List;
/** Command to show a domain resource. */
@ -34,7 +34,7 @@ final class GetDomainCommand extends GetEppResourceCommand {
public void runAndPrint() {
for (String domainName : mainParameters) {
printResource(
"Domain", domainName, loadByForeignKey(DomainResource.class, domainName, readTimestamp));
"Domain", domainName, loadByForeignKey(DomainBase.class, domainName, readTimestamp));
}
}
}

View file

@ -25,7 +25,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.common.flogger.FluentLogger;
import com.google.template.soy.data.SoyMapData;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.eppcommon.StatusValue;
import google.registry.tools.soy.DomainUpdateSoyInfo;
import java.util.Optional;
@ -46,10 +46,10 @@ public class LockDomainCommand extends LockOrUnlockDomainCommand {
// Project all domains as of the same time so that argument order doesn't affect behavior.
DateTime now = DateTime.now(UTC);
for (String domain : getDomains()) {
Optional<DomainResource> domainResource = loadByForeignKey(DomainResource.class, domain, now);
checkArgumentPresent(domainResource, "Domain '%s' does not exist or is deleted", domain);
Optional<DomainBase> domainBase = loadByForeignKey(DomainBase.class, domain, now);
checkArgumentPresent(domainBase, "Domain '%s' does not exist or is deleted", domain);
ImmutableSet<StatusValue> statusesToAdd =
Sets.difference(REGISTRY_LOCK_STATUSES, domainResource.get().getStatusValues())
Sets.difference(REGISTRY_LOCK_STATUSES, domainBase.get().getStatusValues())
.immutableCopy();
if (statusesToAdd.isEmpty()) {
logger.atInfo().log("Domain '%s' is already locked and needs no updates.", domain);

View file

@ -23,7 +23,7 @@ import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.google.common.base.Joiner;
import com.google.template.soy.data.SoyMapData;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.tools.soy.RenewDomainSoyInfo;
import google.registry.util.Clock;
import java.util.List;
@ -57,11 +57,11 @@ final class RenewDomainCommand extends MutatingEppToolCommand {
checkArgument(period < 10, "Cannot renew domains for 10 or more years");
DateTime now = clock.nowUtc();
for (String domainName : mainParameters) {
Optional<DomainResource> domainOptional =
loadByForeignKey(DomainResource.class, domainName, now);
Optional<DomainBase> domainOptional =
loadByForeignKey(DomainBase.class, domainName, now);
checkArgumentPresent(domainOptional, "Domain '%s' does not exist or is deleted", domainName);
setSoyTemplate(RenewDomainSoyInfo.getInstance(), RenewDomainSoyInfo.RENEWDOMAIN);
DomainResource domain = domainOptional.get();
DomainBase domain = domainOptional.get();
addSoyRecord(
domain.getCurrentSponsorClientId(),
new SoyMapData(

View file

@ -30,7 +30,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.google.template.soy.data.SoyMapData;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.secdns.DelegationSignerData;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
@ -121,7 +121,7 @@ final class UniformRapidSuspensionCommand extends MutatingEppToolCommand {
} catch (ClassCastException | ParseException e) {
throw new IllegalArgumentException("Invalid --dsdata JSON", e);
}
Optional<DomainResource> domain = loadByForeignKey(DomainResource.class, domainName, now);
Optional<DomainBase> domain = loadByForeignKey(DomainBase.class, domainName, now);
checkArgumentPresent(domain, "Domain '%s' does not exist or is deleted", domainName);
Set<String> missingHosts =
difference(newHostsSet, checkResourcesExist(HostResource.class, newHosts, now));
@ -146,7 +146,7 @@ final class UniformRapidSuspensionCommand extends MutatingEppToolCommand {
"reason", (undo ? "Undo " : "") + "Uniform Rapid Suspension"));
}
private ImmutableSortedSet<String> getExistingNameservers(DomainResource domain) {
private ImmutableSortedSet<String> getExistingNameservers(DomainBase domain) {
ImmutableSortedSet.Builder<String> nameservers = ImmutableSortedSet.naturalOrder();
for (HostResource host : ofy().load().keys(domain.getNameservers()).values()) {
nameservers.add(host.getForeignKey());
@ -154,7 +154,7 @@ final class UniformRapidSuspensionCommand extends MutatingEppToolCommand {
return nameservers.build();
}
private ImmutableSortedSet<String> getExistingLocks(DomainResource domain) {
private ImmutableSortedSet<String> getExistingLocks(DomainBase domain) {
ImmutableSortedSet.Builder<String> locks = ImmutableSortedSet.naturalOrder();
for (StatusValue lock : domain.getStatusValues()) {
if (URS_LOCKS.contains(lock.getXmlName())) {
@ -164,7 +164,7 @@ final class UniformRapidSuspensionCommand extends MutatingEppToolCommand {
return locks.build();
}
private ImmutableSortedSet<String> getExistingDsData(DomainResource domain) {
private ImmutableSortedSet<String> getExistingDsData(DomainBase domain) {
ImmutableSortedSet.Builder<String> dsDataJsons = ImmutableSortedSet.naturalOrder();
HexBinaryAdapter hexBinaryAdapter = new HexBinaryAdapter();
for (DelegationSignerData dsData : domain.getDsData()) {

View file

@ -25,7 +25,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.common.flogger.FluentLogger;
import com.google.template.soy.data.SoyMapData;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.eppcommon.StatusValue;
import google.registry.tools.soy.DomainUpdateSoyInfo;
import java.util.Optional;
@ -46,10 +46,10 @@ public class UnlockDomainCommand extends LockOrUnlockDomainCommand {
// Project all domains as of the same time so that argument order doesn't affect behavior.
DateTime now = DateTime.now(UTC);
for (String domain : getDomains()) {
Optional<DomainResource> domainResource = loadByForeignKey(DomainResource.class, domain, now);
checkArgumentPresent(domainResource, "Domain '%s' does not exist or is deleted", domain);
Optional<DomainBase> domainBase = loadByForeignKey(DomainBase.class, domain, now);
checkArgumentPresent(domainBase, "Domain '%s' does not exist or is deleted", domain);
ImmutableSet<StatusValue> statusesToRemove =
Sets.intersection(domainResource.get().getStatusValues(), REGISTRY_LOCK_STATUSES)
Sets.intersection(domainBase.get().getStatusValues(), REGISTRY_LOCK_STATUSES)
.immutableCopy();
if (statusesToRemove.isEmpty()) {
logger.atInfo().log("Domain '%s' is already unlocked and needs no updates.", domain);

View file

@ -32,7 +32,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.googlecode.objectify.Key;
import google.registry.model.billing.BillingEvent;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.Period;
import google.registry.model.domain.Period.Unit;
import google.registry.model.eppcommon.StatusValue;
@ -91,7 +91,7 @@ class UnrenewDomainCommand extends ConfirmingCommand implements CommandWithRemot
domainsNonexistentBuilder.add(domainName);
continue;
}
Optional<DomainResource> domain = loadByForeignKey(DomainResource.class, domainName, now);
Optional<DomainBase> domain = loadByForeignKey(DomainBase.class, domainName, now);
if (!domain.isPresent()
|| domain.get().getStatusValues().contains(StatusValue.PENDING_DELETE)) {
domainsDeletingBuilder.add(domainName);
@ -151,8 +151,8 @@ class UnrenewDomainCommand extends ConfirmingCommand implements CommandWithRemot
private void unrenewDomain(String domainName) {
ofy().assertInTransaction();
DateTime now = ofy().getTransactionTime();
Optional<DomainResource> domainOptional =
loadByForeignKey(DomainResource.class, domainName, now);
Optional<DomainBase> domainOptional =
loadByForeignKey(DomainBase.class, domainName, now);
// Transactional sanity checks on the off chance that something changed between init() running
// and here.
checkState(
@ -160,7 +160,7 @@ class UnrenewDomainCommand extends ConfirmingCommand implements CommandWithRemot
&& !domainOptional.get().getStatusValues().contains(StatusValue.PENDING_DELETE),
"Domain %s was deleted or is pending deletion",
domainName);
DomainResource domain = domainOptional.get();
DomainBase domain = domainOptional.get();
checkState(
Sets.intersection(domain.getStatusValues(), DISALLOWED_STATUSES).isEmpty(),
"Domain %s has prohibited status values",
@ -206,7 +206,7 @@ class UnrenewDomainCommand extends ConfirmingCommand implements CommandWithRemot
.build();
// End the old autorenew billing event and poll message now.
updateAutorenewRecurrenceEndTime(domain, now);
DomainResource newDomain =
DomainBase newDomain =
domain
.asBuilder()
.setRegistrationExpirationTime(newExpirationTime)

View file

@ -30,7 +30,7 @@ import com.google.common.collect.Sets;
import com.google.common.flogger.FluentLogger;
import com.google.template.soy.data.SoyMapData;
import google.registry.model.domain.DesignatedContact;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.eppcommon.StatusValue;
import google.registry.tools.params.NameserversParameter;
import google.registry.tools.soy.DomainUpdateSoyInfo;
@ -173,18 +173,18 @@ final class UpdateDomainCommand extends CreateOrUpdateDomainCommand {
if (!nameservers.isEmpty() || !admins.isEmpty() || !techs.isEmpty() || !statuses.isEmpty()) {
DateTime now = DateTime.now(UTC);
Optional<DomainResource> domainOptional =
loadByForeignKey(DomainResource.class, domain, now);
Optional<DomainBase> domainOptional =
loadByForeignKey(DomainBase.class, domain, now);
checkArgumentPresent(domainOptional, "Domain '%s' does not exist or is deleted", domain);
DomainResource domainResource = domainOptional.get();
DomainBase domainBase = domainOptional.get();
checkArgument(
!domainResource.getStatusValues().contains(SERVER_UPDATE_PROHIBITED),
!domainBase.getStatusValues().contains(SERVER_UPDATE_PROHIBITED),
"The domain '%s' has status SERVER_UPDATE_PROHIBITED. Verify that you are allowed "
+ "to make updates, and if so, use the domain_unlock command to enable updates.",
domain);
if (!nameservers.isEmpty()) {
ImmutableSortedSet<String> existingNameservers =
domainResource.loadNameserverFullyQualifiedHostNames();
domainBase.loadNameserverFullyQualifiedHostNames();
populateAddRemoveLists(
ImmutableSet.copyOf(nameservers),
existingNameservers,
@ -201,9 +201,9 @@ final class UpdateDomainCommand extends CreateOrUpdateDomainCommand {
}
if (!admins.isEmpty() || !techs.isEmpty()) {
ImmutableSet<String> existingAdmins =
getContactsOfType(domainResource, DesignatedContact.Type.ADMIN);
getContactsOfType(domainBase, DesignatedContact.Type.ADMIN);
ImmutableSet<String> existingTechs =
getContactsOfType(domainResource, DesignatedContact.Type.TECH);
getContactsOfType(domainBase, DesignatedContact.Type.TECH);
if (!admins.isEmpty()) {
populateAddRemoveLists(
@ -222,7 +222,7 @@ final class UpdateDomainCommand extends CreateOrUpdateDomainCommand {
}
if (!statuses.isEmpty()) {
Set<String> currentStatusValues = new HashSet<>();
for (StatusValue statusValue : domainResource.getStatusValues()) {
for (StatusValue statusValue : domainBase.getStatusValues()) {
currentStatusValues.add(statusValue.getXmlName());
}
populateAddRemoveLists(
@ -290,8 +290,8 @@ final class UpdateDomainCommand extends CreateOrUpdateDomainCommand {
}
ImmutableSet<String> getContactsOfType(
DomainResource domainResource, final DesignatedContact.Type contactType) {
return domainResource
DomainBase domainBase, final DesignatedContact.Type contactType) {
return domainBase
.getContacts()
.stream()
.filter(contact -> contact.getType().equals(contactType))

View file

@ -38,7 +38,7 @@ import google.registry.gcs.GcsUtils;
import google.registry.mapreduce.MapreduceRunner;
import google.registry.mapreduce.inputs.NullInput;
import google.registry.model.EppResource;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.secdns.DelegationSignerData;
import google.registry.model.host.HostResource;
import google.registry.request.Action;
@ -140,7 +140,7 @@ public class GenerateZoneFilesAction implements Runnable, JsonActionRunner.JsonA
new GenerateBindFileMapper(
tlds, exportTime, dnsDefaultATtl, dnsDefaultNsTtl, dnsDefaultDsTtl),
new GenerateBindFileReducer(bucket, exportTime, gcsBufferSize),
ImmutableList.of(new NullInput<>(), createEntityInput(DomainResource.class)))
ImmutableList.of(new NullInput<>(), createEntityInput(DomainBase.class)))
.getLinkToMapreduceConsole();
ImmutableList<String> filenames =
tlds.stream()
@ -185,7 +185,7 @@ public class GenerateZoneFilesAction implements Runnable, JsonActionRunner.JsonA
emit(tld, null);
}
} else {
mapDomain((DomainResource) resource);
mapDomain((DomainBase) resource);
}
}
@ -194,7 +194,7 @@ public class GenerateZoneFilesAction implements Runnable, JsonActionRunner.JsonA
// be emitted in the final file, which is incorrect. Rather, to match the actual DNS glue
// records, we only want to emit host information for in-bailiwick hosts in the specified
// TLD(s), meaning those that act as nameservers for their respective superordinate domains.
private void mapDomain(DomainResource domain) {
private void mapDomain(DomainBase domain) {
// Domains never change their tld, so we can check if it's from the wrong tld right away.
if (tlds.contains(domain.getTld())) {
domain = loadAtPointInTime(domain, exportTime).now();
@ -210,7 +210,7 @@ public class GenerateZoneFilesAction implements Runnable, JsonActionRunner.JsonA
}
}
private void emitForSubordinateHosts(DomainResource domain) {
private void emitForSubordinateHosts(DomainBase domain) {
ImmutableSet<String> subordinateHosts = domain.getSubordinateHosts();
if (!subordinateHosts.isEmpty()) {
for (HostResource unprojectedHost : ofy().load().keys(domain.getNameservers()).values()) {
@ -276,7 +276,7 @@ public class GenerateZoneFilesAction implements Runnable, JsonActionRunner.JsonA
* }
*/
private static String domainStanza(
DomainResource domain,
DomainBase domain,
DateTime exportTime,
Duration dnsDefaultNsTtl,
Duration dnsDefaultDsTtl) {

View file

@ -29,7 +29,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import google.registry.model.EppResource;
import google.registry.model.EppResourceUtils;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.request.Action;
import google.registry.request.Parameter;
import google.registry.request.auth.Auth;
@ -45,7 +45,7 @@ import org.joda.time.DateTime;
path = ListDomainsAction.PATH,
method = {GET, POST},
auth = Auth.AUTH_INTERNAL_OR_ADMIN)
public final class ListDomainsAction extends ListObjectsAction<DomainResource> {
public final class ListDomainsAction extends ListObjectsAction<DomainBase> {
/** An App Engine limitation on how many subqueries can be used in a single query. */
@VisibleForTesting @NonFinalForTesting static int maxNumSubqueries = 30;
@ -71,16 +71,16 @@ public final class ListDomainsAction extends ListObjectsAction<DomainResource> {
}
@Override
public ImmutableSet<DomainResource> loadObjects() {
public ImmutableSet<DomainBase> loadObjects() {
checkArgument(!tlds.isEmpty(), "Must specify TLDs to query");
assertTldsExist(tlds);
DateTime now = clock.nowUtc();
ImmutableList.Builder<DomainResource> domainsBuilder = new ImmutableList.Builder<>();
ImmutableList.Builder<DomainBase> domainsBuilder = new ImmutableList.Builder<>();
for (List<String> tldsBatch : Lists.partition(tlds.asList(), maxNumSubqueries)) {
domainsBuilder.addAll(
ofy()
.load()
.type(DomainResource.class)
.type(DomainBase.class)
.filter("tld in", tldsBatch)
// Get the N most recently created domains (requires ordering in descending order).
.order("-creationTime")

View file

@ -26,7 +26,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.flogger.FluentLogger;
import google.registry.dns.DnsQueue;
import google.registry.mapreduce.MapreduceRunner;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.request.Action;
import google.registry.request.Parameter;
import google.registry.request.Response;
@ -69,13 +69,13 @@ public class RefreshDnsForAllDomainsAction implements Runnable {
.setDefaultMapShards(10)
.runMapOnly(
new RefreshDnsForAllDomainsActionMapper(tlds),
ImmutableList.of(createEntityInput(DomainResource.class)))
ImmutableList.of(createEntityInput(DomainBase.class)))
.sendLinkToMapreduceConsole(response);
}
/** Mapper to refresh DNS for all active domain resources. */
public static class RefreshDnsForAllDomainsActionMapper
extends Mapper<DomainResource, Void, Void> {
extends Mapper<DomainBase, Void, Void> {
private static final long serialVersionUID = 1455544013508953083L;
@ -88,7 +88,7 @@ public class RefreshDnsForAllDomainsAction implements Runnable {
}
@Override
public void map(final DomainResource domain) {
public void map(final DomainBase domain) {
String domainName = domain.getFullyQualifiedDomainName();
if (tlds.contains(domain.getTld())) {
if (isActive(domain, DateTime.now(DateTimeZone.UTC))) {