mirror of
https://github.com/google/nomulus.git
synced 2025-05-18 18:29:36 +02:00
Remove the ofy().load() inside of HostResource.cloneProjectedAtTime
In fact, completely eviscerate cloneProjectedAtTime (to be removed in a followup CL) in favor of doing the projection of transfers and the loading of values from the superordinate domain at call sites. This is one of the issues that blocked the memcache audit work, since the load inside of cloneProjectedAtTime could not be controlled by the caller. Note: fixed a minor bug where a subordinate host created after its superordinate domain was last transferred should have lastTransferTime==null but was previously reporting the domain's lastTransferTime. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=149769125
This commit is contained in:
parent
1f000b94e6
commit
9174855a47
67 changed files with 970 additions and 471 deletions
|
@ -14,7 +14,11 @@
|
|||
|
||||
package google.registry.rde;
|
||||
|
||||
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.eppcommon.StatusValue;
|
||||
import google.registry.model.host.HostResource;
|
||||
import google.registry.xjc.host.XjcHostAddrType;
|
||||
|
@ -25,28 +29,62 @@ import google.registry.xjc.rdehost.XjcRdeHost;
|
|||
import google.registry.xjc.rdehost.XjcRdeHostElement;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/** Utility class that turns {@link HostResource} as {@link XjcRdeHostElement}. */
|
||||
final class HostResourceToXjcConverter {
|
||||
|
||||
/** Converts {@link HostResource} to {@link XjcRdeHostElement}. */
|
||||
static XjcRdeHostElement convert(HostResource host) {
|
||||
return new XjcRdeHostElement(convertHost(host));
|
||||
/** Converts a subordinate {@link HostResource} to {@link XjcRdeHostElement}. */
|
||||
static XjcRdeHostElement convertSubordinate(
|
||||
HostResource host, DomainResource superordinateDomain) {
|
||||
checkArgument(Key.create(superordinateDomain).equals(host.getSuperordinateDomain()));
|
||||
return new XjcRdeHostElement(convertSubordinateHost(host, superordinateDomain));
|
||||
}
|
||||
|
||||
/** Converts an external {@link HostResource} to {@link XjcRdeHostElement}. */
|
||||
static XjcRdeHostElement convertExternal(HostResource host) {
|
||||
checkArgument(!host.isSubordinate());
|
||||
return new XjcRdeHostElement(convertExternalHost(host));
|
||||
}
|
||||
|
||||
/** Converts {@link HostResource} to {@link XjcRdeHost}. */
|
||||
static XjcRdeHost convertHost(HostResource model) {
|
||||
static XjcRdeHost convertSubordinateHost(HostResource model, DomainResource superordinateDomain) {
|
||||
XjcRdeHost bean = convertHostCommon(
|
||||
model,
|
||||
superordinateDomain.getCurrentSponsorClientId(),
|
||||
model.computeLastTransferTime(superordinateDomain));
|
||||
if (superordinateDomain.getStatusValues().contains(StatusValue.PENDING_TRANSFER)) {
|
||||
bean.getStatuses().add(convertStatusValue(StatusValue.PENDING_TRANSFER));
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
/** Converts {@link HostResource} to {@link XjcRdeHost}. */
|
||||
static XjcRdeHost convertExternalHost(HostResource model) {
|
||||
return convertHostCommon(
|
||||
model,
|
||||
model.getPersistedCurrentSponsorClientId(),
|
||||
model.getLastTransferTime());
|
||||
}
|
||||
|
||||
private static XjcRdeHost convertHostCommon(
|
||||
HostResource model, String clientId, DateTime lastTransferTime) {
|
||||
XjcRdeHost bean = new XjcRdeHost();
|
||||
bean.setName(model.getFullyQualifiedHostName());
|
||||
bean.setRoid(model.getRepoId());
|
||||
bean.setClID(model.getCurrentSponsorClientId());
|
||||
bean.setTrDate(model.getLastTransferTime());
|
||||
bean.setCrDate(model.getCreationTime());
|
||||
bean.setUpDate(model.getLastEppUpdateTime());
|
||||
bean.setCrRr(RdeAdapter.convertRr(model.getCreationClientId(), null));
|
||||
bean.setUpRr(RdeAdapter.convertRr(model.getLastEppUpdateClientId(), null));
|
||||
bean.setCrRr(RdeAdapter.convertRr(model.getCreationClientId(), null));
|
||||
bean.setClID(clientId);
|
||||
bean.setTrDate(lastTransferTime);
|
||||
for (StatusValue status : model.getStatusValues()) {
|
||||
// TODO(b/34844887): Remove when PENDING_TRANSFER is not persisted on host resources.
|
||||
if (status.equals(StatusValue.PENDING_TRANSFER)) {
|
||||
continue;
|
||||
}
|
||||
// TODO(cgoldfeder): Add in LINKED status if applicable.
|
||||
bean.getStatuses().add(convertStatusValue(status));
|
||||
}
|
||||
for (InetAddress addr : model.getInetAddresses()) {
|
||||
|
|
|
@ -117,9 +117,16 @@ public final class RdeMarshaller implements Serializable {
|
|||
}
|
||||
|
||||
/** Turns {@link HostResource} object into an XML fragment. */
|
||||
public DepositFragment marshalHost(HostResource host) {
|
||||
public DepositFragment marshalSubordinateHost(
|
||||
HostResource host, DomainResource superordinateDomain) {
|
||||
return marshalResource(RdeResourceType.HOST, host,
|
||||
HostResourceToXjcConverter.convert(host));
|
||||
HostResourceToXjcConverter.convertSubordinate(host, superordinateDomain));
|
||||
}
|
||||
|
||||
/** Turns {@link HostResource} object into an XML fragment. */
|
||||
public DepositFragment marshalExternalHost(HostResource host) {
|
||||
return marshalResource(RdeResourceType.HOST, host,
|
||||
HostResourceToXjcConverter.convertExternal(host));
|
||||
}
|
||||
|
||||
/** Turns {@link Registrar} object into an XML fragment. */
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package google.registry.rde;
|
||||
|
||||
import static com.google.common.base.Strings.nullToEmpty;
|
||||
import static google.registry.model.EppResourceUtils.loadAtPointInTime;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
|
||||
import com.google.appengine.tools.mapreduce.Mapper;
|
||||
|
@ -28,7 +29,6 @@ import com.google.common.collect.ImmutableSetMultimap;
|
|||
import com.google.common.collect.Maps;
|
||||
import com.googlecode.objectify.Result;
|
||||
import google.registry.model.EppResource;
|
||||
import google.registry.model.EppResourceUtils;
|
||||
import google.registry.model.contact.ContactResource;
|
||||
import google.registry.model.domain.DomainResource;
|
||||
import google.registry.model.host.HostResource;
|
||||
|
@ -77,7 +77,7 @@ public final class RdeStagingMapper extends Mapper<EppResource, PendingDeposit,
|
|||
|
||||
// Skip prober data.
|
||||
if (nullToEmpty(resource.getCreationClientId()).startsWith("prober-")
|
||||
|| nullToEmpty(resource.getCurrentSponsorClientId()).startsWith("prober-")
|
||||
|| nullToEmpty(resource.getPersistedCurrentSponsorClientId()).startsWith("prober-")
|
||||
|| nullToEmpty(resource.getLastEppUpdateClientId()).startsWith("prober-")) {
|
||||
return;
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ public final class RdeStagingMapper extends Mapper<EppResource, PendingDeposit,
|
|||
new Function<DateTime, Result<EppResource>>() {
|
||||
@Override
|
||||
public Result<EppResource> apply(DateTime input) {
|
||||
return EppResourceUtils.loadAtPointInTime(resource, input);
|
||||
return loadAtPointInTime(resource, input);
|
||||
}}));
|
||||
|
||||
// Convert resource to an XML fragment for each watermark/mode pair lazily and cache the result.
|
||||
|
@ -167,7 +167,14 @@ public final class RdeStagingMapper extends Mapper<EppResource, PendingDeposit,
|
|||
cache.put(WatermarkModePair.create(watermark, RdeMode.THIN), result);
|
||||
return result;
|
||||
} else if (resource instanceof HostResource) {
|
||||
result = Optional.of(marshaller.marshalHost((HostResource) resource));
|
||||
HostResource host = (HostResource) resource;
|
||||
result = Optional.of(host.isSubordinate()
|
||||
? marshaller.marshalSubordinateHost(
|
||||
host,
|
||||
// Note that loadAtPointInTime() does cloneProjectedAtTime(watermark) for us.
|
||||
loadAtPointInTime(
|
||||
ofy().load().key(host.getSuperordinateDomain()).now(), watermark).now())
|
||||
: marshaller.marshalExternalHost(host));
|
||||
cache.put(WatermarkModePair.create(watermark, RdeMode.FULL), result);
|
||||
cache.put(WatermarkModePair.create(watermark, RdeMode.THIN), result);
|
||||
return result;
|
||||
|
|
|
@ -98,7 +98,7 @@ final class XjcToContactResourceConverter extends XjcToEppResourceConverter {
|
|||
.setInternationalizedPostalInfo(
|
||||
getPostalInfoOfType(contact.getPostalInfos(), XjcContactPostalInfoEnumType.INT))
|
||||
.setContactId(contact.getId())
|
||||
.setCurrentSponsorClientId(contact.getClID())
|
||||
.setPersistedCurrentSponsorClientId(contact.getClID())
|
||||
.setCreationClientId(contact.getCrRr() == null ? null : contact.getCrRr().getValue())
|
||||
.setLastEppUpdateClientId(contact.getUpRr() == null ? null : contact.getUpRr().getValue())
|
||||
.setCreationTime(contact.getCrDate())
|
||||
|
|
|
@ -189,7 +189,7 @@ final class XjcToDomainResourceConverter extends XjcToEppResourceConverter {
|
|||
.setFullyQualifiedDomainName(canonicalizeDomainName(domain.getName()))
|
||||
.setRepoId(domain.getRoid())
|
||||
.setIdnTableName(domain.getIdnTableId())
|
||||
.setCurrentSponsorClientId(domain.getClID())
|
||||
.setPersistedCurrentSponsorClientId(domain.getClID())
|
||||
.setCreationClientId(domain.getCrRr().getValue())
|
||||
.setCreationTime(domain.getCrDate())
|
||||
.setAutorenewPollMessage(Key.create(autoRenewPollMessage))
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package google.registry.rde.imports;
|
||||
|
||||
import static com.google.common.base.Predicates.equalTo;
|
||||
import static com.google.common.base.Predicates.in;
|
||||
import static com.google.common.base.Predicates.not;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.rde.imports.RdeImportUtils.generateTridForImport;
|
||||
|
@ -56,6 +56,9 @@ public class XjcToHostResourceConverter extends XjcToEppResourceConverter {
|
|||
};
|
||||
|
||||
static HostResource convert(XjcRdeHost host) {
|
||||
// TODO(b/35384052): Handle subordinate hosts correctly by setting superordinateDomaina and
|
||||
// lastSuperordinateChange fields.
|
||||
|
||||
// First create and save history entry
|
||||
ofy().save().entity(
|
||||
new HistoryEntry.Builder()
|
||||
|
@ -72,7 +75,7 @@ public class XjcToHostResourceConverter extends XjcToEppResourceConverter {
|
|||
return new HostResource.Builder()
|
||||
.setFullyQualifiedHostName(canonicalizeDomainName(host.getName()))
|
||||
.setRepoId(host.getRoid())
|
||||
.setCurrentSponsorClientId(host.getClID())
|
||||
.setPersistedCurrentSponsorClientId(host.getClID())
|
||||
.setLastTransferTime(host.getTrDate())
|
||||
.setCreationTime(host.getCrDate())
|
||||
.setLastEppUpdateTime(host.getUpDate())
|
||||
|
@ -82,7 +85,8 @@ public class XjcToHostResourceConverter extends XjcToEppResourceConverter {
|
|||
FluentIterable.from(host.getStatuses())
|
||||
.transform(STATUS_VALUE_CONVERTER)
|
||||
// LINKED is implicit and should not be imported onto the new host.
|
||||
.filter(not(equalTo(StatusValue.LINKED)))
|
||||
// PENDING_TRANSFER is a property of the superordinate host.
|
||||
.filter(not(in(ImmutableSet.of(StatusValue.LINKED, StatusValue.PENDING_TRANSFER))))
|
||||
.toSet())
|
||||
.setInetAddresses(ImmutableSet.copyOf(Lists.transform(host.getAddrs(), ADDR_CONVERTER)))
|
||||
.build();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue