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

@ -24,7 +24,7 @@ import com.google.common.flogger.FluentLogger;
import com.googlecode.objectify.Key;
import google.registry.model.contact.ContactResource;
import google.registry.model.domain.DesignatedContact;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.rgp.GracePeriodStatus;
import google.registry.model.domain.secdns.DelegationSignerData;
import google.registry.model.eppcommon.StatusValue;
@ -47,18 +47,18 @@ import google.registry.xjc.secdns.XjcSecdnsDsDataType;
import google.registry.xjc.secdns.XjcSecdnsDsOrKeyType;
import org.joda.time.DateTime;
/** Utility class that turns {@link DomainResource} as {@link XjcRdeDomainElement}. */
final class DomainResourceToXjcConverter {
/** Utility class that turns {@link DomainBase} as {@link XjcRdeDomainElement}. */
final class DomainBaseToXjcConverter {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
/** Converts {@link DomainResource} to {@link XjcRdeDomainElement}. */
static XjcRdeDomainElement convert(DomainResource domain, RdeMode mode) {
/** Converts {@link DomainBase} to {@link XjcRdeDomainElement}. */
static XjcRdeDomainElement convert(DomainBase domain, RdeMode mode) {
return new XjcRdeDomainElement(convertDomain(domain, mode));
}
/** Converts {@link DomainResource} to {@link XjcRdeDomain}. */
static XjcRdeDomain convertDomain(DomainResource model, RdeMode mode) {
/** Converts {@link DomainBase} to {@link XjcRdeDomain}. */
static XjcRdeDomain convertDomain(DomainBase model, RdeMode mode) {
XjcRdeDomain bean = new XjcRdeDomain();
// o A <name> element that contains the fully qualified name of the
@ -236,7 +236,7 @@ final class DomainResourceToXjcConverter {
// * An OPTIONAL <exDate> element that contains the end of the
// domain name object's validity period (expiry date) if the
// transfer caused or causes a change in the validity period.
if (model.getTransferData() != TransferData.EMPTY) {
if (!model.getTransferData().equals(TransferData.EMPTY)) {
// Temporary check to make sure that there really was a transfer. A bug caused spurious
// empty transfer records to get generated for deleted domains.
// TODO(b/33289763): remove the hasGainingAndLosingRegistrars check in February 2017
@ -254,7 +254,7 @@ final class DomainResourceToXjcConverter {
return bean;
}
private static boolean hasGainingAndLosingRegistrars(DomainResource model) {
private static boolean hasGainingAndLosingRegistrars(DomainBase model) {
return
!Strings.isNullOrEmpty(model.getTransferData().getGainingClientId())
&& !Strings.isNullOrEmpty(model.getTransferData().getLosingClientId());
@ -324,5 +324,5 @@ final class DomainResourceToXjcConverter {
return bean;
}
private DomainResourceToXjcConverter() {}
private DomainBaseToXjcConverter() {}
}

View file

@ -18,7 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.net.InetAddresses;
import com.googlecode.objectify.Key;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
import google.registry.xjc.host.XjcHostAddrType;
@ -36,7 +36,7 @@ final class HostResourceToXjcConverter {
/** Converts a subordinate {@link HostResource} to {@link XjcRdeHostElement}. */
static XjcRdeHostElement convertSubordinate(
HostResource host, DomainResource superordinateDomain) {
HostResource host, DomainBase superordinateDomain) {
checkArgument(Key.create(superordinateDomain).equals(host.getSuperordinateDomain()));
return new XjcRdeHostElement(convertSubordinateHost(host, superordinateDomain));
}
@ -48,7 +48,7 @@ final class HostResourceToXjcConverter {
}
/** Converts {@link HostResource} to {@link XjcRdeHost}. */
static XjcRdeHost convertSubordinateHost(HostResource model, DomainResource superordinateDomain) {
static XjcRdeHost convertSubordinateHost(HostResource model, DomainBase superordinateDomain) {
XjcRdeHost bean = convertHostCommon(
model,
superordinateDomain.getCurrentSponsorClientId(),

View file

@ -21,7 +21,7 @@ import com.google.common.flogger.FluentLogger;
import com.googlecode.objectify.Key;
import google.registry.model.ImmutableObject;
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.rde.RdeMode;
import google.registry.model.registrar.Registrar;
@ -123,15 +123,15 @@ public final class RdeMarshaller implements Serializable {
ContactResourceToXjcConverter.convert(contact));
}
/** Turns {@link DomainResource} object into an XML fragment. */
public DepositFragment marshalDomain(DomainResource domain, RdeMode mode) {
/** Turns {@link DomainBase} object into an XML fragment. */
public DepositFragment marshalDomain(DomainBase domain, RdeMode mode) {
return marshalResource(RdeResourceType.DOMAIN, domain,
DomainResourceToXjcConverter.convert(domain, mode));
DomainBaseToXjcConverter.convert(domain, mode));
}
/** Turns {@link HostResource} object into an XML fragment. */
public DepositFragment marshalSubordinateHost(
HostResource host, DomainResource superordinateDomain) {
HostResource host, DomainBase superordinateDomain) {
return marshalResource(RdeResourceType.HOST, host,
HostResourceToXjcConverter.convertSubordinate(host, superordinateDomain));
}

View file

@ -28,7 +28,7 @@ import com.google.common.collect.Maps;
import com.googlecode.objectify.Result;
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.rde.RdeMode;
import google.registry.model.registrar.Registrar;
@ -75,7 +75,7 @@ public final class RdeStagingMapper extends Mapper<EppResource, PendingDeposit,
// Skip polymorphic entities that share Datastore kind.
if (!(resource instanceof ContactResource
|| resource instanceof DomainResource
|| resource instanceof DomainBase
|| resource instanceof HostResource)) {
getContext().incrementCounter("polymorphic entities skipped");
return;
@ -91,16 +91,16 @@ public final class RdeStagingMapper extends Mapper<EppResource, PendingDeposit,
// The set of all TLDs to which this resource should be emitted.
ImmutableSet<String> tlds;
if (resource instanceof DomainResource) {
String tld = ((DomainResource) resource).getTld();
if (resource instanceof DomainBase) {
String tld = ((DomainBase) resource).getTld();
if (!pendings.containsKey(tld)) {
getContext().incrementCounter("DomainResource of an unneeded TLD skipped");
getContext().incrementCounter("DomainBase of an unneeded TLD skipped");
return;
}
getContext().incrementCounter("DomainResource instances");
getContext().incrementCounter("DomainBase instances");
tlds = ImmutableSet.of(tld);
} else {
getContext().incrementCounter("non-DomainResource instances");
getContext().incrementCounter("non-DomainBase instances");
// Contacts and hosts get emitted on all TLDs, even if domains don't reference them.
tlds = pendings.keySet();
}
@ -175,8 +175,8 @@ public final class RdeStagingMapper extends Mapper<EppResource, PendingDeposit,
return result;
}
resourcesFound++;
if (resource instanceof DomainResource) {
result = Optional.of(marshaller.marshalDomain((DomainResource) resource, mode));
if (resource instanceof DomainBase) {
result = Optional.of(marshaller.marshalDomain((DomainBase) resource, mode));
cache.put(WatermarkModePair.create(watermark, mode), result);
return result;
} else if (resource instanceof ContactResource) {

View file

@ -18,7 +18,7 @@ import static google.registry.flows.domain.DomainTransferUtils.createLosingTrans
import static google.registry.flows.domain.DomainTransferUtils.createPendingTransferData;
import static google.registry.flows.domain.DomainTransferUtils.createTransferServerApproveEntities;
import static google.registry.mapreduce.MapreduceRunner.PARAM_MAP_SHARDS;
import static google.registry.model.domain.DomainResource.extendRegistrationWithCap;
import static google.registry.model.domain.DomainBase.extendRegistrationWithCap;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost;
import static google.registry.rde.imports.RdeImportUtils.createAutoRenewBillingEventForDomainImport;
@ -40,7 +40,7 @@ import google.registry.dns.DnsQueue;
import google.registry.gcs.GcsUtils;
import google.registry.mapreduce.MapreduceRunner;
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.domain.rgp.GracePeriodStatus;
@ -199,8 +199,8 @@ public class RdeDomainImportAction implements Runnable {
createAutoRenewBillingEventForDomainImport(xjcDomain, historyEntry);
PollMessage.Autorenew autorenewPollMessage =
createAutoRenewPollMessageForDomainImport(xjcDomain, historyEntry);
DomainResource domain =
XjcToDomainResourceConverter.convertDomain(
DomainBase domain =
XjcToDomainBaseConverter.convertDomain(
xjcDomain, autorenewBillingEvent, autorenewPollMessage, stringGenerator);
getDnsQueue().addDomainRefreshTask(domain.getFullyQualifiedDomainName());
// Keep a list of "extra objects" that need to be saved along with the domain
@ -227,7 +227,7 @@ public class RdeDomainImportAction implements Runnable {
// the actual transfer time to avoid hitting the transfer-handling part of
// cloneProjectedAtTime(), since unlike in the DomainTransferRequestFlow case,
// this domain already has a pending transfer.
DomainResource domainAtTransferTime =
DomainBase domainAtTransferTime =
domain.cloneProjectedAtTime(automaticTransferTime.minusMillis(1));
boolean inAutorenewGraceAtTransfer =
!domainAtTransferTime.getGracePeriodsOfType(GracePeriodStatus.AUTO_RENEW).isEmpty();

View file

@ -27,7 +27,7 @@ import com.google.appengine.tools.mapreduce.InputReader;
import com.google.common.collect.ImmutableList;
import google.registry.config.RegistryConfig.ConfigModule;
import google.registry.gcs.GcsUtils;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.rde.imports.RdeParser.RdeHeader;
import google.registry.xjc.JaxbFragment;
import google.registry.xjc.rdedomain.XjcRdeDomainElement;
@ -36,7 +36,7 @@ import java.util.List;
import java.util.Optional;
/**
* A MapReduce {@link Input} that imports {@link DomainResource} objects from an escrow file.
* A MapReduce {@link Input} that imports {@link DomainBase} objects from an escrow file.
*
* <p>If a mapShards parameter has been specified, up to that many readers will be created
* so that each map shard has one reader. If a mapShards parameter has not been specified, a

View file

@ -30,7 +30,7 @@ import google.registry.config.RegistryConfig.Config;
import google.registry.flows.host.HostFlowUtils;
import google.registry.mapreduce.MapreduceRunner;
import google.registry.model.EppResource;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
import google.registry.request.Action;
@ -49,7 +49,7 @@ import org.joda.time.DateTime;
*
* <p>This mapreduce is run as the last step of the process of importing escrow files. For each host
* in the escrow file, the corresponding {@link HostResource} record in Datastore is linked to its
* superordinate {@link DomainResource} only if it is an in-zone host. This is necessary because all
* superordinate {@link DomainBase} only if it is an in-zone host. This is necessary because all
* hosts must exist before domains can be imported, due to references in host objects, and domains
* must exist before hosts can be linked to their superordinate domains.
*
@ -110,7 +110,7 @@ public class RdeHostLinkAction implements Runnable {
final InternetDomainName hostName = InternetDomainName.from(xjcHost.getName());
HostLinkResult hostLinkResult = ofy().transact(() -> {
Optional<DomainResource> superordinateDomain =
Optional<DomainBase> superordinateDomain =
lookupSuperordinateDomain(hostName, ofy().getTransactionTime());
// if suporordinateDomain is absent, this is an out of zone host and can't be linked.
// absent is only returned for out of zone hosts, and an exception is thrown for in
@ -121,7 +121,7 @@ public class RdeHostLinkAction implements Runnable {
if (superordinateDomain.get().getStatusValues().contains(StatusValue.PENDING_DELETE)) {
return HostLinkResult.SUPERORDINATE_DOMAIN_IN_PENDING_DELETE;
}
Key<DomainResource> superordinateDomainKey = Key.create(superordinateDomain.get());
Key<DomainBase> superordinateDomainKey = Key.create(superordinateDomain.get());
// link host to superordinate domain and set time of last superordinate change to
// the time of the import
HostResource host =
@ -172,7 +172,7 @@ public class RdeHostLinkAction implements Runnable {
}
/**
* Return the {@link DomainResource} this host is subordinate to, or absent for out of zone
* Return the {@link DomainBase} this host is subordinate to, or absent for out of zone
* hosts.
*
* <p>We use this instead of {@link HostFlowUtils#lookupSuperordinateDomain} because we don't
@ -181,7 +181,7 @@ public class RdeHostLinkAction implements Runnable {
*
* @throws IllegalStateException for hosts without superordinate domains
*/
private static Optional<DomainResource> lookupSuperordinateDomain(
private static Optional<DomainBase> lookupSuperordinateDomain(
InternetDomainName hostName, DateTime now) {
Optional<InternetDomainName> tld = findTldForName(hostName);
// out of zone hosts cannot be linked
@ -195,8 +195,8 @@ public class RdeHostLinkAction implements Runnable {
.stream()
.skip(hostName.parts().size() - (tld.get().parts().size() + 1))
.collect(joining("."));
Optional<DomainResource> superordinateDomain =
loadByForeignKey(DomainResource.class, domainName, now);
Optional<DomainBase> superordinateDomain =
loadByForeignKey(DomainBase.class, domainName, now);
// Hosts can't be linked if domains import hasn't been run
checkState(
superordinateDomain.isPresent(),

View file

@ -38,7 +38,7 @@ import google.registry.model.EppResource.ForeignKeyedEppResource;
import google.registry.model.billing.BillingEvent;
import google.registry.model.billing.BillingEvent.Flag;
import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.eppcommon.Trid;
import google.registry.model.index.EppResourceIndex;
import google.registry.model.index.ForeignKeyIndex;
@ -223,7 +223,7 @@ public class RdeImportUtils {
.setBySuperuser(true)
.setReason("RDE Import")
.setRequestedByRegistrar(false)
.setParent(Key.create(null, DomainResource.class, domain.getRoid()))
.setParent(Key.create(null, DomainBase.class, domain.getRoid()))
.build();
}

View file

@ -29,7 +29,7 @@ import google.registry.model.billing.BillingEvent;
import google.registry.model.contact.ContactResource;
import google.registry.model.domain.DesignatedContact;
import google.registry.model.domain.DomainAuthInfo;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.rgp.GracePeriodStatus;
import google.registry.model.domain.secdns.DelegationSignerData;
@ -55,8 +55,8 @@ import google.registry.xjc.secdns.XjcSecdnsDsDataType;
import java.util.function.Function;
import org.joda.time.DateTime;
/** Utility class that converts an {@link XjcRdeDomainElement} into a {@link DomainResource}. */
final class XjcToDomainResourceConverter extends XjcToEppResourceConverter {
/** Utility class that converts an {@link XjcRdeDomainElement} into a {@link DomainBase}. */
final class XjcToDomainBaseConverter extends XjcToEppResourceConverter {
private static final XmlToEnumMapper<TransferStatus> TRANSFER_STATUS_MAPPER =
XmlToEnumMapper.create(TransferStatus.values());
@ -131,16 +131,16 @@ final class XjcToDomainResourceConverter extends XjcToEppResourceConverter {
}
}
/** Converts {@link XjcRdeDomain} to {@link DomainResource}. */
static DomainResource convertDomain(
/** Converts {@link XjcRdeDomain} to {@link DomainBase}. */
static DomainBase convertDomain(
XjcRdeDomain domain,
BillingEvent.Recurring autoRenewBillingEvent,
PollMessage.Autorenew autoRenewPollMessage,
StringGenerator stringGenerator) {
GracePeriodConverter gracePeriodConverter =
new GracePeriodConverter(domain, Key.create(autoRenewBillingEvent));
DomainResource.Builder builder =
new DomainResource.Builder()
DomainBase.Builder builder =
new DomainBase.Builder()
.setFullyQualifiedDomainName(canonicalizeDomainName(domain.getName()))
.setRepoId(domain.getRoid())
.setIdnTableName(domain.getIdnTableId())
@ -157,7 +157,7 @@ final class XjcToDomainResourceConverter extends XjcToEppResourceConverter {
domain
.getStatuses()
.stream()
.map(XjcToDomainResourceConverter::convertStatusType)
.map(XjcToDomainBaseConverter::convertStatusType)
.collect(toImmutableSet()))
.setNameservers(convertNameservers(domain.getNs()))
.setGracePeriods(
@ -170,7 +170,7 @@ final class XjcToDomainResourceConverter extends XjcToEppResourceConverter {
domain
.getContacts()
.stream()
.map(XjcToDomainResourceConverter::convertContactType)
.map(XjcToDomainBaseConverter::convertContactType)
.collect(toImmutableSet()))
.setDsData(
domain.getSecDNS() == null
@ -179,7 +179,7 @@ final class XjcToDomainResourceConverter extends XjcToEppResourceConverter {
.getSecDNS()
.getDsDatas()
.stream()
.map(XjcToDomainResourceConverter::convertSecdnsDsDataType)
.map(XjcToDomainBaseConverter::convertSecdnsDsDataType)
.collect(toImmutableSet()))
.setTransferData(convertDomainTransferData(domain.getTrnData()))
// authInfo pw must be a token between 6 and 16 characters in length
@ -251,5 +251,5 @@ final class XjcToDomainResourceConverter extends XjcToEppResourceConverter {
return DesignatedContact.create(type, key);
}
private XjcToDomainResourceConverter() {}
private XjcToDomainBaseConverter() {}
}