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

@ -22,7 +22,7 @@ import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.collect.ImmutableMap;
import google.registry.flows.EppException;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.rdap.RdapJsonFormatter.OutputDataType;
import google.registry.rdap.RdapMetrics.EndpointType;
import google.registry.request.Action;
@ -75,14 +75,14 @@ public class RdapDomainAction extends RdapActionBase {
pathSearchString, getHumanReadableObjectTypeName(), e.getMessage()));
}
// The query string is not used; the RDAP syntax is /rdap/domain/mydomain.com.
Optional<DomainResource> domainResource =
Optional<DomainBase> domainBase =
loadByForeignKey(
DomainResource.class, pathSearchString, shouldIncludeDeleted() ? START_OF_TIME : now);
if (!shouldBeVisible(domainResource, now)) {
DomainBase.class, pathSearchString, shouldIncludeDeleted() ? START_OF_TIME : now);
if (!shouldBeVisible(domainBase, now)) {
throw new NotFoundException(pathSearchString + " not found");
}
return rdapJsonFormatter.makeRdapJsonForDomain(
domainResource.get(),
domainBase.get(),
true,
fullServletPath,
rdapWhoisServer,

View file

@ -31,7 +31,7 @@ import com.google.common.net.InetAddresses;
import com.google.common.primitives.Booleans;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.cmd.Query;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.host.HostResource;
import google.registry.rdap.RdapJsonFormatter.BoilerplateType;
import google.registry.rdap.RdapJsonFormatter.OutputDataType;
@ -216,11 +216,11 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
*/
private RdapSearchResults searchByDomainNameWithoutWildcard(
final RdapSearchPattern partialStringQuery, final DateTime now) {
Optional<DomainResource> domainResource =
loadByForeignKey(DomainResource.class, partialStringQuery.getInitialString(), now);
Optional<DomainBase> domainBase =
loadByForeignKey(DomainBase.class, partialStringQuery.getInitialString(), now);
return makeSearchResults(
shouldBeVisible(domainResource, now)
? ImmutableList.of(domainResource.get())
shouldBeVisible(domainBase, now)
? ImmutableList.of(domainBase.get())
: ImmutableList.of(),
now);
}
@ -238,10 +238,10 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
// domains directly, rather than the foreign keys, because then we have an index on TLD if we
// need it.
int querySizeLimit = RESULT_SET_SIZE_SCALING_FACTOR * rdapResultSetMaxSize;
Query<DomainResource> query =
Query<DomainBase> query =
ofy()
.load()
.type(DomainResource.class)
.type(DomainBase.class)
.filter("fullyQualifiedDomainName <", partialStringQuery.getNextInitialString())
.filter("fullyQualifiedDomainName >=", partialStringQuery.getInitialString());
if (cursorString.isPresent()) {
@ -262,10 +262,10 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
// searchByDomainNameWithInitialString, unable to perform an inequality query on deletion time.
// Don't use queryItems, because it doesn't handle pending deletes.
int querySizeLimit = RESULT_SET_SIZE_SCALING_FACTOR * rdapResultSetMaxSize;
Query<DomainResource> query =
Query<DomainBase> query =
ofy()
.load()
.type(DomainResource.class)
.type(DomainBase.class)
.filter("tld", tld);
if (cursorString.isPresent()) {
query = query.filter("fullyQualifiedDomainName >", cursorString.get());
@ -368,9 +368,9 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
// The suffix must be a domain that we manage. That way, we can look up the domain and search
// through the subordinate hosts. This is more efficient, and lets us permit wildcard searches
// with no initial string.
DomainResource domainResource =
DomainBase domainBase =
loadByForeignKey(
DomainResource.class,
DomainBase.class,
partialStringQuery.getSuffix(),
shouldIncludeDeleted() ? START_OF_TIME : now)
.orElseThrow(
@ -380,7 +380,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
+ "must be a domain defined in the system"));
Optional<String> desiredRegistrar = getDesiredRegistrar();
ImmutableList.Builder<Key<HostResource>> builder = new ImmutableList.Builder<>();
for (String fqhn : ImmutableSortedSet.copyOf(domainResource.getSubordinateHosts())) {
for (String fqhn : ImmutableSortedSet.copyOf(domainBase.getSubordinateHosts())) {
// We can't just check that the host name starts with the initial query string, because
// then the query ns.exam*.example.com would match against nameserver ns.example.com.
if (partialStringQuery.matches(fqhn)) {
@ -451,17 +451,17 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
// We must break the query up into chunks, because the in operator is limited to 30 subqueries.
// Since it is possible for the same domain to show up more than once in our result list (if
// we do a wildcard nameserver search that returns multiple nameservers used by the same
// domain), we must create a set of resulting {@link DomainResource} objects. Use a sorted set,
// domain), we must create a set of resulting {@link DomainBase} objects. Use a sorted set,
// and fetch all domains, to make sure that we can return the first domains in alphabetical
// order.
ImmutableSortedSet.Builder<DomainResource> domainSetBuilder =
ImmutableSortedSet.Builder<DomainBase> domainSetBuilder =
ImmutableSortedSet.orderedBy(
Comparator.comparing(DomainResource::getFullyQualifiedDomainName));
Comparator.comparing(DomainBase::getFullyQualifiedDomainName));
int numHostKeysSearched = 0;
for (List<Key<HostResource>> chunk : Iterables.partition(hostKeys, 30)) {
numHostKeysSearched += chunk.size();
Query<DomainResource> query = ofy().load()
.type(DomainResource.class)
Query<DomainBase> query = ofy().load()
.type(DomainBase.class)
.filter("nsHosts in", chunk);
if (!shouldIncludeDeleted()) {
query = query.filter("deletionTime >", now);
@ -470,7 +470,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
} else if (cursorString.isPresent()) {
query = query.filter("fullyQualifiedDomainName >", cursorString.get());
}
Stream<DomainResource> stream =
Stream<DomainBase> stream =
Streams.stream(query).filter(domain -> isAuthorized(domain, now));
if (cursorString.isPresent()) {
stream =
@ -479,7 +479,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
}
stream.forEach(domainSetBuilder::add);
}
List<DomainResource> domains = domainSetBuilder.build().asList();
List<DomainBase> domains = domainSetBuilder.build().asList();
metricInformationBuilder.setNumHostsRetrieved(numHostKeysSearched);
if (domains.size() > rdapResultSetMaxSize) {
return makeSearchResults(
@ -502,14 +502,14 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
}
/** Output JSON for a list of domains, with no incompleteness warnings. */
private RdapSearchResults makeSearchResults(List<DomainResource> domains, DateTime now) {
private RdapSearchResults makeSearchResults(List<DomainBase> domains, DateTime now) {
return makeSearchResults(
domains, IncompletenessWarningType.COMPLETE, Optional.of((long) domains.size()), now);
}
/** Output JSON from data in an {@link RdapResultSet} object. */
private RdapSearchResults makeSearchResults(
RdapResultSet<DomainResource> resultSet, DateTime now) {
RdapResultSet<DomainBase> resultSet, DateTime now) {
return makeSearchResults(
resultSet.resources(),
resultSet.incompletenessWarningType(),
@ -525,7 +525,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
* maximum number of nameservers in the first stage query.
*/
private RdapSearchResults makeSearchResults(
List<DomainResource> domains,
List<DomainBase> domains,
IncompletenessWarningType incompletenessWarningType,
Optional<Long> numDomainsRetrieved,
DateTime now) {
@ -535,7 +535,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
RdapAuthorization authorization = getAuthorization();
List<ImmutableMap<String, Object>> jsonList = new ArrayList<>();
Optional<String> newCursor = Optional.empty();
for (DomainResource domain : domains) {
for (DomainBase domain : domains) {
newCursor = Optional.of(domain.getFullyQualifiedDomainName());
jsonList.add(
rdapJsonFormatter.makeRdapJsonForDomain(

View file

@ -39,7 +39,7 @@ import google.registry.model.contact.ContactResource;
import google.registry.model.contact.PostalInfo;
import google.registry.model.domain.DesignatedContact;
import google.registry.model.domain.DesignatedContact.Type;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.eppcommon.Address;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
@ -455,9 +455,9 @@ public class RdapJsonFormatter {
}
/**
* Creates a JSON object for a {@link DomainResource}.
* Creates a JSON object for a {@link DomainBase}.
*
* @param domainResource the domain resource object from which the JSON object should be created
* @param domainBase the domain resource object from which the JSON object should be created
* @param isTopLevel if true, the top-level boilerplate will be added
* @param linkBase the URL base to be used when creating links
* @param whoisServer the fully-qualified domain name of the WHOIS server to be listed in the
@ -468,7 +468,7 @@ public class RdapJsonFormatter {
* registrar owning the domain, no contact information is included
*/
ImmutableMap<String, Object> makeRdapJsonForDomain(
DomainResource domainResource,
DomainBase domainBase,
boolean isTopLevel,
@Nullable String linkBase,
@Nullable String whoisServer,
@ -478,22 +478,22 @@ public class RdapJsonFormatter {
// Start with the domain-level information.
ImmutableMap.Builder<String, Object> jsonBuilder = new ImmutableMap.Builder<>();
jsonBuilder.put("objectClassName", "domain");
jsonBuilder.put("handle", domainResource.getRepoId());
jsonBuilder.put("ldhName", domainResource.getFullyQualifiedDomainName());
jsonBuilder.put("handle", domainBase.getRepoId());
jsonBuilder.put("ldhName", domainBase.getFullyQualifiedDomainName());
// Only include the unicodeName field if there are unicode characters.
if (hasUnicodeComponents(domainResource.getFullyQualifiedDomainName())) {
jsonBuilder.put("unicodeName", Idn.toUnicode(domainResource.getFullyQualifiedDomainName()));
if (hasUnicodeComponents(domainBase.getFullyQualifiedDomainName())) {
jsonBuilder.put("unicodeName", Idn.toUnicode(domainBase.getFullyQualifiedDomainName()));
}
jsonBuilder.put(
"status",
makeStatusValueList(
domainResource.getStatusValues(),
domainBase.getStatusValues(),
false, // isRedacted
domainResource.getDeletionTime().isBefore(now)));
domainBase.getDeletionTime().isBefore(now)));
jsonBuilder.put("links", ImmutableList.of(
makeLink("domain", domainResource.getFullyQualifiedDomainName(), linkBase)));
makeLink("domain", domainBase.getFullyQualifiedDomainName(), linkBase)));
boolean displayContacts =
authorization.isAuthorizedForClientId(domainResource.getCurrentSponsorClientId());
authorization.isAuthorizedForClientId(domainBase.getCurrentSponsorClientId());
// If we are outputting all data (not just summary data), also add information about hosts,
// contacts and events (history entries). If we are outputting summary data, instead add a
// remark indicating that fact.
@ -504,26 +504,26 @@ public class RdapJsonFormatter {
remarks = displayContacts
? ImmutableList.of()
: ImmutableList.of(RdapIcannStandardInformation.DOMAIN_CONTACTS_HIDDEN_DATA_REMARK);
ImmutableList<Object> events = makeEvents(domainResource, now);
ImmutableList<Object> events = makeEvents(domainBase, now);
if (!events.isEmpty()) {
jsonBuilder.put("events", events);
}
// Kick off the database loads of the nameservers that we will need, so it can load
// asynchronously while we load and process the contacts.
Map<Key<HostResource>, HostResource> loadedHosts =
ofy().load().keys(domainResource.getNameservers());
ofy().load().keys(domainBase.getNameservers());
// Load the registrant and other contacts and add them to the data.
ImmutableList<ImmutableMap<String, Object>> entities;
if (!displayContacts) {
entities = ImmutableList.of();
} else {
Map<Key<ContactResource>, ContactResource> loadedContacts =
ofy().load().keys(domainResource.getReferencedContacts());
ofy().load().keys(domainBase.getReferencedContacts());
entities =
Streams.concat(
domainResource.getContacts().stream(),
domainBase.getContacts().stream(),
Stream.of(
DesignatedContact.create(Type.REGISTRANT, domainResource.getRegistrant())))
DesignatedContact.create(Type.REGISTRANT, domainBase.getRegistrant())))
.sorted(DESIGNATED_CONTACT_ORDERING)
.map(
designatedContact ->
@ -540,7 +540,7 @@ public class RdapJsonFormatter {
}
entities =
addRegistrarEntity(
entities, domainResource.getCurrentSponsorClientId(), linkBase, whoisServer, now);
entities, domainBase.getCurrentSponsorClientId(), linkBase, whoisServer, now);
if (!entities.isEmpty()) {
jsonBuilder.put("entities", entities);
}
@ -1022,8 +1022,8 @@ public class RdapJsonFormatter {
eventsBuilder.add(makeEvent(
eventAction, historyEntry.getClientId(), historyEntry.getModificationTime()));
}
if (resource instanceof DomainResource) {
DateTime expirationTime = ((DomainResource) resource).getRegistrationExpirationTime();
if (resource instanceof DomainBase) {
DateTime expirationTime = ((DomainBase) resource).getRegistrationExpirationTime();
if (expirationTime != null) {
eventsBuilder.add(makeEvent(RdapEventAction.EXPIRATION, null, expirationTime));
}

View file

@ -25,7 +25,7 @@ import com.google.common.collect.Iterables;
import com.google.common.net.InetAddresses;
import com.google.common.primitives.Booleans;
import com.googlecode.objectify.cmd.Query;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.host.HostResource;
import google.registry.rdap.RdapJsonFormatter.BoilerplateType;
import google.registry.rdap.RdapJsonFormatter.OutputDataType;
@ -204,9 +204,9 @@ public class RdapNameserverSearchAction extends RdapSearchActionBase {
/** Searches for nameservers by name using the superordinate domain as a suffix. */
private RdapSearchResults searchByNameUsingSuperordinateDomain(
final RdapSearchPattern partialStringQuery, final DateTime now) {
Optional<DomainResource> domainResource =
loadByForeignKey(DomainResource.class, partialStringQuery.getSuffix(), now);
if (!domainResource.isPresent()) {
Optional<DomainBase> domainBase =
loadByForeignKey(DomainBase.class, partialStringQuery.getSuffix(), now);
if (!domainBase.isPresent()) {
// Don't allow wildcards with suffixes which are not domains we manage. That would risk a
// table scan in many easily foreseeable cases. The user might ask for ns*.zombo.com,
// forcing us to query for all hosts beginning with ns, then filter for those ending in
@ -216,7 +216,7 @@ public class RdapNameserverSearchAction extends RdapSearchActionBase {
"A suffix after a wildcard in a nameserver lookup must be an in-bailiwick domain");
}
List<HostResource> hostList = new ArrayList<>();
for (String fqhn : ImmutableSortedSet.copyOf(domainResource.get().getSubordinateHosts())) {
for (String fqhn : ImmutableSortedSet.copyOf(domainBase.get().getSubordinateHosts())) {
if (cursorString.isPresent() && (fqhn.compareTo(cursorString.get()) <= 0)) {
continue;
}
@ -235,7 +235,7 @@ public class RdapNameserverSearchAction extends RdapSearchActionBase {
return makeSearchResults(
hostList,
IncompletenessWarningType.COMPLETE,
domainResource.get().getSubordinateHosts().size(),
domainBase.get().getSubordinateHosts().size(),
CursorType.NAME,
now);
}