mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 16:37:13 +02:00
Fix RDE import pending transfer handling
Mostly based on the original PR, but with some tweaking by nfelt@, in particular to add some support for autorenew grace period subsumption. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=169922894
This commit is contained in:
parent
2814561e92
commit
3ad21e3834
7 changed files with 495 additions and 89 deletions
|
@ -18,6 +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.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost;
|
||||
import static google.registry.rde.imports.RdeImportUtils.createAutoRenewBillingEventForDomainImport;
|
||||
|
@ -44,6 +45,7 @@ import google.registry.model.billing.BillingEvent;
|
|||
import google.registry.model.domain.DomainResource;
|
||||
import google.registry.model.domain.Period;
|
||||
import google.registry.model.domain.Period.Unit;
|
||||
import google.registry.model.domain.rgp.GracePeriodStatus;
|
||||
import google.registry.model.poll.PollMessage;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.model.transfer.TransferData;
|
||||
|
@ -60,6 +62,7 @@ import google.registry.xjc.rdedomain.XjcRdeDomain;
|
|||
import google.registry.xjc.rdedomain.XjcRdeDomainElement;
|
||||
import javax.inject.Inject;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* A mapreduce that imports domains from an escrow file.
|
||||
|
@ -171,69 +174,118 @@ public class RdeDomainImportAction implements Runnable {
|
|||
getContext().incrementCounter("domain imports attempted");
|
||||
|
||||
logger.infofmt("Saving domain %s", xjcDomain.getName());
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
HistoryEntry historyEntry = createHistoryEntryForDomainImport(xjcDomain);
|
||||
BillingEvent.Recurring autorenewBillingEvent =
|
||||
createAutoRenewBillingEventForDomainImport(xjcDomain, historyEntry);
|
||||
PollMessage.Autorenew autorenewPollMessage =
|
||||
createAutoRenewPollMessageForDomainImport(xjcDomain, historyEntry);
|
||||
DomainResource domain = XjcToDomainResourceConverter.convertDomain(
|
||||
xjcDomain, autorenewBillingEvent, autorenewPollMessage);
|
||||
getDnsQueue().addDomainRefreshTask(domain.getFullyQualifiedDomainName());
|
||||
// Keep a list of "extra objects" that need to be saved along with the domain
|
||||
// and add to it if necessary.
|
||||
ImmutableSet<Object> extraEntitiesToSave =
|
||||
getImportUtils().createIndexesForEppResource(domain);
|
||||
// Create speculative server approval entities for pending transfers
|
||||
if (domain.getTransferData().getTransferStatus() == TransferStatus.PENDING) {
|
||||
TransferData transferData = domain.getTransferData();
|
||||
checkArgumentNotNull(transferData,
|
||||
"Domain %s is in pending transfer but has no transfer data",
|
||||
domain.getFullyQualifiedDomainName());
|
||||
Money transferCost = getDomainRenewCost(
|
||||
domain.getFullyQualifiedDomainName(),
|
||||
transferData.getPendingTransferExpirationTime(),
|
||||
1);
|
||||
// Create speculative entities in anticipation of an automatic server approval.
|
||||
ImmutableSet<TransferServerApproveEntity> serverApproveEntities =
|
||||
createTransferServerApproveEntities(
|
||||
transferData.getPendingTransferExpirationTime(),
|
||||
domain.getRegistrationExpirationTime().plusYears(1),
|
||||
historyEntry,
|
||||
domain,
|
||||
historyEntry.getTrid(),
|
||||
transferData.getGainingClientId(),
|
||||
Optional.of(transferCost),
|
||||
transferData.getTransferRequestTime());
|
||||
transferData =
|
||||
createPendingTransferData(
|
||||
transferData.asBuilder(),
|
||||
serverApproveEntities,
|
||||
Period.create(1, Unit.YEARS));
|
||||
// Create a poll message to notify the losing registrar that a transfer was requested.
|
||||
PollMessage requestPollMessage = createLosingTransferPollMessage(domain.getRepoId(),
|
||||
transferData, transferData.getPendingTransferExpirationTime(), historyEntry)
|
||||
.asBuilder().setEventTime(transferData.getTransferRequestTime()).build();
|
||||
domain = domain.asBuilder().setTransferData(transferData).build();
|
||||
autorenewBillingEvent = autorenewBillingEvent.asBuilder()
|
||||
.setRecurrenceEndTime(transferData.getPendingTransferExpirationTime()).build();
|
||||
autorenewPollMessage = autorenewPollMessage.asBuilder()
|
||||
.setAutorenewEndTime(transferData.getPendingTransferExpirationTime()).build();
|
||||
extraEntitiesToSave = new ImmutableSet.Builder<>()
|
||||
.add(requestPollMessage)
|
||||
.addAll(extraEntitiesToSave)
|
||||
.addAll(serverApproveEntities).build();
|
||||
} // End pending transfer check
|
||||
ofy().save()
|
||||
.entities(new ImmutableSet.Builder<>()
|
||||
.add(domain, historyEntry, autorenewBillingEvent, autorenewPollMessage)
|
||||
.addAll(extraEntitiesToSave)
|
||||
.build())
|
||||
.now();
|
||||
}
|
||||
});
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
HistoryEntry historyEntry = createHistoryEntryForDomainImport(xjcDomain);
|
||||
BillingEvent.Recurring autorenewBillingEvent =
|
||||
createAutoRenewBillingEventForDomainImport(xjcDomain, historyEntry);
|
||||
PollMessage.Autorenew autorenewPollMessage =
|
||||
createAutoRenewPollMessageForDomainImport(xjcDomain, historyEntry);
|
||||
DomainResource domain =
|
||||
XjcToDomainResourceConverter.convertDomain(
|
||||
xjcDomain, autorenewBillingEvent, autorenewPollMessage);
|
||||
getDnsQueue().addDomainRefreshTask(domain.getFullyQualifiedDomainName());
|
||||
// Keep a list of "extra objects" that need to be saved along with the domain
|
||||
// and add to it if necessary.
|
||||
ImmutableSet<Object> extraEntitiesToSave =
|
||||
getImportUtils().createIndexesForEppResource(domain);
|
||||
// Create speculative server approval entities for pending transfers
|
||||
if (domain.getTransferData().getTransferStatus() == TransferStatus.PENDING) {
|
||||
TransferData transferData = domain.getTransferData();
|
||||
checkArgumentNotNull(
|
||||
transferData,
|
||||
"Domain %s is in pending transfer but has no transfer data",
|
||||
domain.getFullyQualifiedDomainName());
|
||||
Money transferCost =
|
||||
getDomainRenewCost(
|
||||
domain.getFullyQualifiedDomainName(),
|
||||
transferData.getPendingTransferExpirationTime(),
|
||||
1);
|
||||
DateTime automaticTransferTime =
|
||||
transferData.getPendingTransferExpirationTime();
|
||||
// If the transfer will occur within the autorenew grace period, it should
|
||||
// subsume the autorenew, so we don't add the normal extra year. See the
|
||||
// original logic in DomainTransferRequestFlow (which is very similar) for
|
||||
// more information. That said, note that here we stop 1 millisecond before
|
||||
// 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 =
|
||||
domain.cloneProjectedAtTime(automaticTransferTime.minusMillis(1));
|
||||
boolean inAutorenewGraceAtTransfer =
|
||||
!domainAtTransferTime
|
||||
.getGracePeriodsOfType(GracePeriodStatus.AUTO_RENEW)
|
||||
.isEmpty();
|
||||
int extraYears = inAutorenewGraceAtTransfer ? 0 : 1;
|
||||
// Construct the capped new expiration time.
|
||||
DateTime serverApproveNewExpirationTime =
|
||||
extendRegistrationWithCap(
|
||||
automaticTransferTime,
|
||||
domainAtTransferTime.getRegistrationExpirationTime(),
|
||||
extraYears);
|
||||
// Create speculative entities in anticipation of an automatic server
|
||||
// approval.
|
||||
ImmutableSet<TransferServerApproveEntity> serverApproveEntities =
|
||||
createTransferServerApproveEntities(
|
||||
automaticTransferTime,
|
||||
serverApproveNewExpirationTime,
|
||||
historyEntry,
|
||||
domain,
|
||||
historyEntry.getTrid(),
|
||||
transferData.getGainingClientId(),
|
||||
Optional.of(transferCost),
|
||||
transferData.getTransferRequestTime());
|
||||
transferData =
|
||||
createPendingTransferData(
|
||||
transferData.asBuilder(),
|
||||
serverApproveEntities,
|
||||
Period.create(1, Unit.YEARS));
|
||||
// Create a poll message to notify the losing registrar that a transfer was
|
||||
// requested.
|
||||
PollMessage requestPollMessage =
|
||||
createLosingTransferPollMessage(
|
||||
domain.getRepoId(),
|
||||
transferData,
|
||||
serverApproveNewExpirationTime,
|
||||
historyEntry)
|
||||
.asBuilder()
|
||||
.setEventTime(transferData.getTransferRequestTime())
|
||||
.build();
|
||||
domain = domain.asBuilder().setTransferData(transferData).build();
|
||||
autorenewBillingEvent =
|
||||
autorenewBillingEvent
|
||||
.asBuilder()
|
||||
.setRecurrenceEndTime(transferData.getPendingTransferExpirationTime())
|
||||
.build();
|
||||
autorenewPollMessage =
|
||||
autorenewPollMessage
|
||||
.asBuilder()
|
||||
.setAutorenewEndTime(transferData.getPendingTransferExpirationTime())
|
||||
.build();
|
||||
extraEntitiesToSave =
|
||||
new ImmutableSet.Builder<>()
|
||||
.add(requestPollMessage)
|
||||
.addAll(extraEntitiesToSave)
|
||||
.addAll(serverApproveEntities)
|
||||
.build();
|
||||
} // End pending transfer check
|
||||
ofy()
|
||||
.save()
|
||||
.entities(
|
||||
new ImmutableSet.Builder<>()
|
||||
.add(
|
||||
domain,
|
||||
historyEntry,
|
||||
autorenewBillingEvent,
|
||||
autorenewPollMessage)
|
||||
.addAll(extraEntitiesToSave)
|
||||
.build())
|
||||
.now();
|
||||
}
|
||||
});
|
||||
// Record the number of domains imported
|
||||
getContext().incrementCounter("domains saved");
|
||||
logger.infofmt("Domain %s was imported successfully", xjcDomain.getName());
|
||||
|
|
|
@ -16,12 +16,12 @@ package google.registry.rde.imports;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
|
||||
import static java.nio.charset.StandardCharsets.US_ASCII;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.google.appengine.tools.cloudstorage.GcsFilename;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -61,7 +61,6 @@ import java.util.UUID;
|
|||
import javax.inject.Inject;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* Utility functions for escrow file import.
|
||||
|
@ -89,14 +88,9 @@ public class RdeImportUtils {
|
|||
public <T extends EppResource & ForeignKeyedEppResource> ImmutableSet<Object>
|
||||
createIndexesForEppResource(T resource) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<T> resourceClass = (Class<T>) resource.getClass();
|
||||
Object existing = ofy.load().key(Key.create(resource)).now();
|
||||
if (existing != null) {
|
||||
// This will roll back the transaction and prevent duplicate history entries from being saved.
|
||||
throw new ResourceExistsException();
|
||||
}
|
||||
ForeignKeyIndex<T> existingForeignKeyIndex =
|
||||
ForeignKeyIndex.load(resourceClass, resource.getForeignKey(), START_OF_TIME);
|
||||
ForeignKeyIndex.load(
|
||||
(Class<T>) resource.getClass(), resource.getForeignKey(), START_OF_TIME);
|
||||
// ForeignKeyIndex should never have existed, since existing resource was not found.
|
||||
checkState(
|
||||
existingForeignKeyIndex == null,
|
||||
|
@ -111,20 +105,27 @@ public class RdeImportUtils {
|
|||
/**
|
||||
* Imports a resource from an escrow file.
|
||||
*
|
||||
* <p>The host will only be imported if it has not been previously imported.
|
||||
* <p>The resource will only be imported if it has not been previously imported.
|
||||
*
|
||||
* <p>If the host is imported, {@link ForeignKeyIndex} and {@link EppResourceIndex} are also
|
||||
* <p>If the resource is imported, {@link ForeignKeyIndex} and {@link EppResourceIndex} are also
|
||||
* created.
|
||||
*/
|
||||
public <T extends EppResource & ForeignKeyedEppResource> void
|
||||
importEppResource(final T resource) {
|
||||
Object existing = ofy.load().key(Key.create(resource)).now();
|
||||
if (existing != null) {
|
||||
// This will roll back the transaction and prevent duplicate history entries from being saved.
|
||||
throw new ResourceExistsException();
|
||||
}
|
||||
ofy.save().entities(new ImmutableSet.Builder<>()
|
||||
.add(resource)
|
||||
.addAll(createIndexesForEppResource(resource))
|
||||
.build());
|
||||
logger.infofmt(
|
||||
"Imported %s resource - ROID=%s, id=%s",
|
||||
resource.getClass().getCanonicalName(), resource.getRepoId(), resource.getForeignKey());
|
||||
resource.getClass().getSimpleName(),
|
||||
resource.getRepoId(),
|
||||
resource.getForeignKey());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -221,7 +222,7 @@ public class RdeImportUtils {
|
|||
.setType(HistoryEntry.Type.RDE_IMPORT)
|
||||
.setClientId(domain.getClID())
|
||||
.setTrid(generateTridForImport())
|
||||
.setModificationTime(DateTime.now(UTC))
|
||||
.setModificationTime(ofy().getTransactionTime())
|
||||
.setXmlBytes(getObjectXml(element))
|
||||
.setBySuperuser(true)
|
||||
.setReason("RDE Import")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue