Remove unused and misused methods from EppResourceUtils and DomainBase.

The methods in DomainBase were the only callers for the methods in
EppResourceUtils, so I first inlined them. Then I realized that there
were no callers for loadReferencedContacts() anywhere. For loadNameservers(),
all but one invocation actually wanted to load the foreign keys, and was
repeating that work, so I replaced it with loadNameserverFullyQualifiedHostNames().
The last invocation, in the Rdap code, was incorrectly assuming this was an async
load when in fact it blocks, so I replaced it with a real async load.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=122433897
This commit is contained in:
Corey Goldfeder 2016-05-16 10:38:26 -07:00 committed by Justine Tunney
parent 9a2afc7a9b
commit d9875ea302
8 changed files with 31 additions and 60 deletions

View file

@ -16,6 +16,7 @@ package google.registry.dns.writer.dnsupdate;
import static com.google.common.base.Verify.verify;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.ofy.ObjectifyService.ofy;
import com.google.common.net.InternetDomainName;
@ -102,7 +103,8 @@ public class DnsUpdateWriter implements DnsWriter {
Update update = new Update(toAbsoluteName(findTldFromName(domainName)));
update.delete(toAbsoluteName(domainName), Type.ANY);
if (domain != null && domain.shouldPublishToDns()) {
update.add(makeNameServerSet(domainName, domain.loadNameservers()));
update.add(makeNameServerSet(
domainName, ofy().load().refs(domain.getNameservers()).values()));
update.add(makeDelegationSignerSet(domainName, domain.getDsData()));
}

View file

@ -24,7 +24,6 @@ import static google.registry.util.DateTimeUtils.isBeforeOrAt;
import static google.registry.util.DateTimeUtils.latestOf;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.Ref;
@ -138,29 +137,6 @@ public final class EppResourceUtils {
latestOf(now, resource.getUpdateAutoTimestamp().getTimestamp()));
}
/** Loads and returns the hosts specified by the given reference. */
public static ImmutableSet<HostResource> loadReferencedNameservers(
Set<Ref<HostResource>> hostRefs) {
ImmutableSet.Builder<HostResource> builder = new ImmutableSet.Builder<>();
for (Ref<HostResource> hostRef : hostRefs) {
HostResource host = hostRef.get();
if (host != null) {
builder.add(host);
}
}
return builder.build();
}
/** Loads and returns the contacts specified by the given references. */
public static ImmutableSet<ContactResource> loadReferencedContacts(
Set<Ref<ContactResource>> contactRefs) {
ImmutableSet.Builder<ContactResource> builder = new ImmutableSet.Builder<>();
for (Ref<ContactResource> contactRef : contactRefs) {
builder.add(contactRef.get());
}
return builder.build();
}
/**
* Checks multiple {@link EppResource} objects from the datastore by unique ids.
* <p>

View file

@ -19,12 +19,15 @@ import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.collect.Sets.difference;
import static com.google.common.collect.Sets.union;
import static google.registry.model.domain.DesignatedContact.Type.REGISTRANT;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.CollectionUtils.nullToEmpty;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableSortedCopy;
import static google.registry.util.CollectionUtils.union;
import static google.registry.util.DomainNameUtils.getTldFromSld;
import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
@ -37,7 +40,6 @@ import com.googlecode.objectify.annotation.OnLoad;
import com.googlecode.objectify.condition.IfNull;
import google.registry.model.EppResource;
import google.registry.model.EppResourceUtils;
import google.registry.model.contact.ContactResource;
import google.registry.model.domain.launch.LaunchNotice;
import google.registry.model.domain.secdns.DelegationSignerData;
@ -161,9 +163,16 @@ public abstract class DomainBase extends EppResource {
return builder.build();
}
/** Loads and returns all linked nameservers. */
public ImmutableSet<HostResource> loadNameservers() {
return EppResourceUtils.loadReferencedNameservers(getNameservers());
/** Loads and returns the fully qualified host names of all linked nameservers. */
public ImmutableSet<String> loadNameserverFullyQualifiedHostNames() {
return FluentIterable.from(ofy().load().refs(getNameservers()).values())
.transform(
new Function<HostResource, String>() {
@Override
public String apply(HostResource host) {
return host.getFullyQualifiedHostName();
}})
.toSet();
}
public Ref<ContactResource> getRegistrant() {
@ -192,11 +201,6 @@ public abstract class DomainBase extends EppResource {
return contactsBuilder.build();
}
/** Loads and returns all referenced contacts from this domain or application. */
public ImmutableSet<ContactResource> loadReferencedContacts() {
return EppResourceUtils.loadReferencedContacts(getReferencedContacts());
}
public String getTld() {
return tld;
}

View file

@ -397,7 +397,8 @@ public class RdapJsonFormatter {
@Nullable String linkBase,
@Nullable String whoisServer) {
// Kick off the database loads of the nameservers that we will need.
ImmutableSet<HostResource> loadedHosts = domainResource.loadNameservers();
Map<Key<HostResource>, HostResource> loadedHosts =
ofy().load().refs(domainResource.getNameservers());
// And the registrant and other contacts.
List<DesignatedContact> allContacts = new ArrayList<>();
if (domainResource.getRegistrant() != null) {
@ -427,7 +428,8 @@ public class RdapJsonFormatter {
}
// Nameservers
ImmutableList.Builder<Object> nsBuilder = new ImmutableList.Builder<>();
for (HostResource hostResource : HOST_RESOURCE_ORDERING.immutableSortedCopy(loadedHosts)) {
for (HostResource hostResource
: HOST_RESOURCE_ORDERING.immutableSortedCopy(loadedHosts.values())) {
nsBuilder.add(makeRdapJsonForHost(hostResource, false, linkBase, null));
}
ImmutableList<Object> ns = nsBuilder.build();

View file

@ -25,7 +25,6 @@ import google.registry.model.domain.DomainResource;
import google.registry.model.domain.rgp.GracePeriodStatus;
import google.registry.model.domain.secdns.DelegationSignerData;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
import google.registry.model.rde.RdeMode;
import google.registry.model.transfer.TransferData;
import google.registry.model.transfer.TransferStatus;
@ -141,11 +140,11 @@ final class DomainResourceToXjcConverter {
// it is that with host attributes, you inline the nameserver data
// on each domain; with host objects, you normalize the nameserver
// data to a separate EPP object.
ImmutableSet<HostResource> linkedNameservers = model.loadNameservers();
if (!linkedNameservers.isEmpty()) {
ImmutableSet<String> linkedNameserverHostNames = model.loadNameserverFullyQualifiedHostNames();
if (!linkedNameserverHostNames.isEmpty()) {
XjcDomainNsType nameservers = new XjcDomainNsType();
for (HostResource host : linkedNameservers) {
nameservers.getHostObjs().add(host.getFullyQualifiedHostName());
for (String hostName : linkedNameserverHostNames) {
nameservers.getHostObjs().add(hostName);
}
bean.setNs(nameservers);
}

View file

@ -48,7 +48,6 @@ import google.registry.model.domain.launch.LaunchNotice;
import google.registry.model.domain.secdns.DelegationSignerData;
import google.registry.model.eppinput.EppInput;
import google.registry.model.eppinput.EppInput.ResourceCommandWrapper;
import google.registry.model.host.HostResource;
import google.registry.model.reporting.HistoryEntry;
import google.registry.model.smd.SignedMark;
import google.registry.tools.soy.DomainAllocateSoyInfo;
@ -146,13 +145,7 @@ final class AllocateDomainCommand extends MutatingEppToolCommand {
addSoyRecord(application.getCurrentSponsorClientId(), new SoyMapData(
"name", application.getFullyQualifiedDomainName(),
"period", period.getValue(),
"nameservers", FluentIterable.from(application.loadNameservers())
.transform(new Function<HostResource, String>() {
@Override
public String apply(HostResource host) {
return host.getForeignKey();
}})
.toList(),
"nameservers", application.loadNameserverFullyQualifiedHostNames(),
"registrant", application.loadRegistrant().getForeignKey(),
"contacts", contactsMapBuilder.build(),
"authInfo", application.getAuthInfo().getPw().getValue(),

View file

@ -104,12 +104,8 @@ final class GenerateDnsReportCommand implements RemoteApiCommand, GtechCommand {
}
private void write(DomainResource domain) {
ImmutableList<String> nameservers = FluentIterable.from(domain.loadNameservers())
.transform(new Function<HostResource, String>() {
@Override
public String apply(HostResource host) {
return host.getForeignKey();
}})
ImmutableList<String> nameservers = FluentIterable
.from(domain.loadNameserverFullyQualifiedHostNames())
.toSortedList(Ordering.natural());
ImmutableList<Map<String, ?>> dsData = FluentIterable.from(domain.getDsData())
.transform(new Function<DelegationSignerData, Map<String, ?>>() {

View file

@ -34,7 +34,6 @@ import google.registry.model.domain.DesignatedContact.Type;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.GracePeriod;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
import google.registry.model.registrar.Registrar;
import google.registry.model.translators.EnumToAttributeAdapter.EppEnum;
import google.registry.util.FormattingLogger;
@ -89,11 +88,11 @@ final class DomainWhoisResponse extends WhoisResponseImpl {
.emitContact("Billing", getContactReference(Type.BILLING), preferUnicode)
.emitSet(
"Name Server",
domain.loadNameservers(),
new Function<HostResource, String>() {
domain.loadNameserverFullyQualifiedHostNames(),
new Function<String, String>() {
@Override
public String apply(HostResource host) {
return maybeFormatHostname(host.getFullyQualifiedHostName(), preferUnicode);
public String apply(String hostName) {
return maybeFormatHostname(hostName, preferUnicode);
}})
.emitField("DNSSEC", isNullOrEmpty(domain.getDsData()) ? "unsigned" : "signedDelegation")
.emitLastUpdated(getTimestamp())