mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Migrate away from VoidWorks
This is one last hanging piece of work left over from last year's Java 8 migration. There's no functionality changes in this CL, just refactoring. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=201947600
This commit is contained in:
parent
7d3cb3d426
commit
d3364b0387
18 changed files with 349 additions and 502 deletions
|
@ -309,6 +309,14 @@ public class Ofy {
|
|||
throw new AssertionError(); // How on earth did we get here?
|
||||
}
|
||||
|
||||
public void transactNewReadOnly(Runnable work) {
|
||||
transactNewReadOnly(
|
||||
() -> {
|
||||
work.run();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/** Execute some work in a transactionless context. */
|
||||
public <R> R doTransactionless(Work<R> work) {
|
||||
try {
|
||||
|
|
|
@ -26,7 +26,6 @@ import com.google.common.collect.ImmutableSet;
|
|||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
import com.googlecode.objectify.annotation.Index;
|
||||
|
@ -156,22 +155,15 @@ public class RegistrarContact extends ImmutableObject implements Jsonifiable {
|
|||
final Registrar registrar, final Set<RegistrarContact> contacts) {
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
() -> {
|
||||
ofy()
|
||||
.delete()
|
||||
.keys(
|
||||
difference(
|
||||
ImmutableSet.copyOf(
|
||||
ofy()
|
||||
.load()
|
||||
.type(RegistrarContact.class)
|
||||
.ancestor(registrar)
|
||||
.keys()),
|
||||
ofy().load().type(RegistrarContact.class).ancestor(registrar).keys()),
|
||||
contacts.stream().map(Key::create).collect(toImmutableSet())));
|
||||
ofy().save().entities(contacts);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@ import com.google.common.collect.ImmutableMap;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.model.registry.label.DomainLabelMetrics.PremiumListCheckOutcome;
|
||||
import google.registry.model.registry.label.PremiumList.PremiumListEntry;
|
||||
|
@ -196,11 +195,7 @@ public final class PremiumListUtils {
|
|||
|
||||
/** Deletes the PremiumList and all of its child entities. */
|
||||
public static void deletePremiumList(final PremiumList premiumList) {
|
||||
ofy().transactNew(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().delete().entity(premiumList);
|
||||
}});
|
||||
ofy().transactNew(() -> ofy().delete().entity(premiumList));
|
||||
deleteRevisionAndEntriesOfPremiumList(premiumList);
|
||||
cachePremiumLists.invalidate(premiumList.getName());
|
||||
}
|
||||
|
@ -209,20 +204,13 @@ public final class PremiumListUtils {
|
|||
if (premiumList.getRevisionKey() == null) {
|
||||
return;
|
||||
}
|
||||
for (final List<Key<PremiumListEntry>> batch : partition(
|
||||
for (final List<Key<PremiumListEntry>> batch :
|
||||
partition(
|
||||
ofy().load().type(PremiumListEntry.class).ancestor(premiumList.revisionKey).keys(),
|
||||
TRANSACTION_BATCH_SIZE)) {
|
||||
ofy().transactNew(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().delete().keys(batch);
|
||||
}});
|
||||
ofy().transactNew(() -> ofy().delete().keys(batch));
|
||||
}
|
||||
ofy().transactNew(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().delete().key(premiumList.getRevisionKey());
|
||||
}});
|
||||
ofy().transactNew(() -> ofy().delete().key(premiumList.getRevisionKey()));
|
||||
}
|
||||
|
||||
/** Returns whether a PremiumList of the given name exists, bypassing the cache. */
|
||||
|
|
|
@ -22,7 +22,6 @@ import com.google.auto.value.AutoValue;
|
|||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
import google.registry.model.ImmutableObject;
|
||||
|
@ -216,9 +215,7 @@ public class Lock extends ImmutableObject {
|
|||
// Just use the default clock because we aren't actually doing anything that will use the clock.
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
() -> {
|
||||
// To release a lock, check that no one else has already obtained it and if not
|
||||
// delete it. If the lock in Datastore was different then this lock is gone already;
|
||||
// this can happen if release() is called around the expiration time and the lock
|
||||
|
@ -240,7 +237,6 @@ public class Lock extends ImmutableObject {
|
|||
logger.atInfo().log(
|
||||
"Not deleting lock: %s - someone else has it: %s", lockId, loadedLock);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import com.google.appengine.tools.cloudstorage.RetryParams;
|
|||
import com.google.appengine.tools.mapreduce.Mapper;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.config.RegistryConfig.ConfigModule;
|
||||
import google.registry.gcs.GcsUtils;
|
||||
|
@ -139,13 +138,12 @@ public class RdeContactImportAction implements Runnable {
|
|||
// Record number of attempted map operations
|
||||
getContext().incrementCounter("contact imports attempted");
|
||||
logger.atInfo().log("Saving contact %s", xjcContact.getId());
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
ContactResource contact =
|
||||
XjcToContactResourceConverter.convertContact(xjcContact);
|
||||
getImportUtils().importEppResource(contact);
|
||||
}
|
||||
});
|
||||
// Record number of contacts imported
|
||||
getContext().incrementCounter("contacts saved");
|
||||
|
|
|
@ -35,7 +35,6 @@ import com.google.appengine.tools.mapreduce.Mapper;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.config.RegistryConfig.ConfigModule;
|
||||
import google.registry.dns.DnsQueue;
|
||||
|
@ -171,13 +170,25 @@ public class RdeDomainImportAction implements Runnable {
|
|||
try {
|
||||
// Record number of attempted map operations
|
||||
getContext().incrementCounter("domain imports attempted");
|
||||
|
||||
logger.atInfo().log("Saving domain %s", xjcDomain.getName());
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
|
||||
ofy().transact(() -> saveDomain(xjcDomain));
|
||||
|
||||
// Record the number of domains imported
|
||||
getContext().incrementCounter("domains saved");
|
||||
logger.atInfo().log("Domain %s was imported successfully", xjcDomain.getName());
|
||||
} catch (ResourceExistsException e) {
|
||||
// Record the number of domains already in the registry
|
||||
getContext().incrementCounter("existing domains skipped");
|
||||
logger.atInfo().log("Domain %s already exists", xjcDomain.getName());
|
||||
} catch (Exception e) {
|
||||
getContext().incrementCounter("domain import errors");
|
||||
logger.atSevere().withCause(e).log(
|
||||
"Error processing domain %s; xml=%s", xjcDomain.getName(), xjcDomain);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveDomain(XjcRdeDomain xjcDomain) {
|
||||
HistoryEntry historyEntry = createHistoryEntryForDomainImport(xjcDomain);
|
||||
BillingEvent.Recurring autorenewBillingEvent =
|
||||
createAutoRenewBillingEventForDomainImport(xjcDomain, historyEntry);
|
||||
|
@ -203,8 +214,7 @@ public class RdeDomainImportAction implements Runnable {
|
|||
domain.getFullyQualifiedDomainName(),
|
||||
transferData.getPendingTransferExpirationTime(),
|
||||
1);
|
||||
DateTime automaticTransferTime =
|
||||
transferData.getPendingTransferExpirationTime();
|
||||
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
|
||||
|
@ -215,9 +225,7 @@ public class RdeDomainImportAction implements Runnable {
|
|||
DomainResource domainAtTransferTime =
|
||||
domain.cloneProjectedAtTime(automaticTransferTime.minusMillis(1));
|
||||
boolean inAutorenewGraceAtTransfer =
|
||||
!domainAtTransferTime
|
||||
.getGracePeriodsOfType(GracePeriodStatus.AUTO_RENEW)
|
||||
.isEmpty();
|
||||
!domainAtTransferTime.getGracePeriodsOfType(GracePeriodStatus.AUTO_RENEW).isEmpty();
|
||||
int extraYears = inAutorenewGraceAtTransfer ? 0 : 1;
|
||||
// Construct the capped new expiration time.
|
||||
DateTime serverApproveNewExpirationTime =
|
||||
|
@ -239,17 +247,12 @@ public class RdeDomainImportAction implements Runnable {
|
|||
transferData.getTransferRequestTime());
|
||||
transferData =
|
||||
createPendingTransferData(
|
||||
transferData.asBuilder(),
|
||||
serverApproveEntities,
|
||||
Period.create(1, Unit.YEARS));
|
||||
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)
|
||||
domain.getRepoId(), transferData, serverApproveNewExpirationTime, historyEntry)
|
||||
.asBuilder()
|
||||
.setEventTime(transferData.getTransferRequestTime())
|
||||
.build();
|
||||
|
@ -275,28 +278,10 @@ public class RdeDomainImportAction implements Runnable {
|
|||
.save()
|
||||
.entities(
|
||||
new ImmutableSet.Builder<>()
|
||||
.add(
|
||||
domain,
|
||||
historyEntry,
|
||||
autorenewBillingEvent,
|
||||
autorenewPollMessage)
|
||||
.add(domain, historyEntry, autorenewBillingEvent, autorenewPollMessage)
|
||||
.addAll(extraEntitiesToSave)
|
||||
.build())
|
||||
.now();
|
||||
}
|
||||
});
|
||||
// Record the number of domains imported
|
||||
getContext().incrementCounter("domains saved");
|
||||
logger.atInfo().log("Domain %s was imported successfully", xjcDomain.getName());
|
||||
} catch (ResourceExistsException e) {
|
||||
// Record the number of domains already in the registry
|
||||
getContext().incrementCounter("existing domains skipped");
|
||||
logger.atInfo().log("Domain %s already exists", xjcDomain.getName());
|
||||
} catch (Exception e) {
|
||||
getContext().incrementCounter("domain import errors");
|
||||
logger.atSevere().withCause(e).log(
|
||||
"Error processing domain %s; xml=%s", xjcDomain.getName(), xjcDomain);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import com.google.appengine.tools.cloudstorage.RetryParams;
|
|||
import com.google.appengine.tools.mapreduce.Mapper;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.config.RegistryConfig.ConfigModule;
|
||||
import google.registry.gcs.GcsUtils;
|
||||
|
@ -124,13 +123,11 @@ public class RdeHostImportAction implements Runnable {
|
|||
// Record number of attempted map operations
|
||||
getContext().incrementCounter("host imports attempted");
|
||||
logger.atInfo().log("Saving host %s", xjcHost.getName());
|
||||
ofy().transact(new VoidWork() {
|
||||
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
HostResource host = XjcToHostResourceConverter.convert(xjcHost);
|
||||
getImportUtils().importEppResource(host);
|
||||
}
|
||||
});
|
||||
// Record number of hosts imported
|
||||
getContext().incrementCounter("hosts saved");
|
||||
|
|
|
@ -30,10 +30,10 @@ import com.beust.jcommander.Parameter;
|
|||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.base.Ascii;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.template.soy.data.SoyMapData;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import google.registry.flows.EppException;
|
||||
import google.registry.model.domain.DesignatedContact;
|
||||
import google.registry.model.domain.DomainApplication;
|
||||
|
@ -99,11 +99,10 @@ final class AllocateDomainCommand extends MutatingEppToolCommand {
|
|||
protected void initMutatingEppToolCommand() {
|
||||
checkArgument(superuser, "This command MUST be run as --superuser.");
|
||||
setSoyTemplate(DomainAllocateSoyInfo.getInstance(), DomainAllocateSoyInfo.CREATE);
|
||||
ofy()
|
||||
.transactNewReadOnly(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().transactNewReadOnly(this::initAllocateDomainCommand);
|
||||
}
|
||||
|
||||
private void initAllocateDomainCommand() {
|
||||
Iterable<Key<DomainApplication>> keys =
|
||||
transform(
|
||||
Splitter.on(',').split(ids),
|
||||
|
@ -111,8 +110,7 @@ final class AllocateDomainCommand extends MutatingEppToolCommand {
|
|||
for (DomainApplication application : ofy().load().keys(keys).values()) {
|
||||
// If the application is already allocated print a warning but do not fail.
|
||||
if (application.getApplicationStatus() == ApplicationStatus.ALLOCATED) {
|
||||
System.err.printf(
|
||||
"Application %s has already been allocated\n", application.getRepoId());
|
||||
System.err.printf("Application %s has already been allocated\n", application.getRepoId());
|
||||
continue;
|
||||
}
|
||||
// Ensure domain doesn't already have a final status which it shouldn't be updated
|
||||
|
@ -137,42 +135,26 @@ final class AllocateDomainCommand extends MutatingEppToolCommand {
|
|||
emptyToNull(history.getTrid().getClientTransactionId().orElse(null));
|
||||
Period period = checkNotNull(extractPeriodFromXml(history.getXmlBytes()));
|
||||
checkArgument(period.getUnit() == Period.Unit.YEARS);
|
||||
ImmutableMap.Builder<String, String> contactsMapBuilder =
|
||||
new ImmutableMap.Builder<>();
|
||||
ImmutableMap.Builder<String, String> contactsMapBuilder = new ImmutableMap.Builder<>();
|
||||
for (DesignatedContact contact : application.getContacts()) {
|
||||
contactsMapBuilder.put(
|
||||
Ascii.toLowerCase(contact.getType().toString()),
|
||||
ofy().load().key(contact.getContactKey()).now().getForeignKey());
|
||||
}
|
||||
LaunchNotice launchNotice = application.getLaunchNotice();
|
||||
addSoyRecord(
|
||||
application.getCurrentSponsorClientId(),
|
||||
new SoyMapData(
|
||||
"name", application.getFullyQualifiedDomainName(),
|
||||
"period", period.getValue(),
|
||||
"nameservers", application.loadNameserverFullyQualifiedHostNames(),
|
||||
"registrant",
|
||||
ofy().load().key(application.getRegistrant()).now().getForeignKey(),
|
||||
"contacts", contactsMapBuilder.build(),
|
||||
"authInfo", application.getAuthInfo().getPw().getValue(),
|
||||
"smdId",
|
||||
String smdId =
|
||||
application.getEncodedSignedMarks().isEmpty()
|
||||
? null
|
||||
: unmarshal(
|
||||
SignedMark.class,
|
||||
application.getEncodedSignedMarks().get(0).getBytes())
|
||||
.getId(),
|
||||
"applicationRoid", application.getRepoId(),
|
||||
"applicationTime", application.getCreationTime().toString(),
|
||||
"launchNotice",
|
||||
launchNotice == null
|
||||
: unmarshal(SignedMark.class, application.getEncodedSignedMarks().get(0).getBytes())
|
||||
.getId();
|
||||
ImmutableMap<String, String> launchNoticeMap =
|
||||
(launchNotice == null)
|
||||
? null
|
||||
: ImmutableMap.of(
|
||||
"noticeId", launchNotice.getNoticeId().getTcnId(),
|
||||
"expirationTime",
|
||||
launchNotice.getExpirationTime().toString(),
|
||||
"acceptedTime", launchNotice.getAcceptedTime().toString()),
|
||||
"dsRecords",
|
||||
"expirationTime", launchNotice.getExpirationTime().toString(),
|
||||
"acceptedTime", launchNotice.getAcceptedTime().toString());
|
||||
ImmutableList<ImmutableMap<String, ?>> dsRecords =
|
||||
application
|
||||
.getDsData()
|
||||
.stream()
|
||||
|
@ -183,7 +165,21 @@ final class AllocateDomainCommand extends MutatingEppToolCommand {
|
|||
"algorithm", dsData.getAlgorithm(),
|
||||
"digestType", dsData.getDigestType(),
|
||||
"digest", base16().encode(dsData.getDigest())))
|
||||
.collect(toImmutableList()),
|
||||
.collect(toImmutableList());
|
||||
addSoyRecord(
|
||||
application.getCurrentSponsorClientId(),
|
||||
new SoyMapData(
|
||||
"name", application.getFullyQualifiedDomainName(),
|
||||
"period", period.getValue(),
|
||||
"nameservers", application.loadNameserverFullyQualifiedHostNames(),
|
||||
"registrant", ofy().load().key(application.getRegistrant()).now().getForeignKey(),
|
||||
"contacts", contactsMapBuilder.build(),
|
||||
"authInfo", application.getAuthInfo().getPw().getValue(),
|
||||
"smdId", smdId,
|
||||
"applicationRoid", application.getRepoId(),
|
||||
"applicationTime", application.getCreationTime().toString(),
|
||||
"launchNotice", launchNoticeMap,
|
||||
"dsRecords", dsRecords,
|
||||
"clTrid", clientTransactionId));
|
||||
applicationKeys.add(Key.create(application));
|
||||
} catch (EppException e) {
|
||||
|
@ -191,6 +187,4 @@ final class AllocateDomainCommand extends MutatingEppToolCommand {
|
|||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
|
|||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import google.registry.model.domain.DomainResource;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.model.registry.Registry;
|
||||
|
@ -78,11 +77,7 @@ final class DeleteTldCommand extends ConfirmingCommand implements RemoteApiComma
|
|||
|
||||
@Override
|
||||
protected String execute() {
|
||||
ofy().transactNew(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().delete().entity(registry).now();
|
||||
}});
|
||||
ofy().transactNew(() -> ofy().delete().entity(registry).now());
|
||||
registry.invalidateInCache();
|
||||
return String.format("Deleted TLD '%s'.\n", tld);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import com.google.common.collect.ImmutableList;
|
|||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.tools.Command.RemoteApiCommand;
|
||||
import java.util.ArrayList;
|
||||
|
@ -142,10 +141,12 @@ public abstract class MutatingCommand extends ConfirmingCommand implements Remot
|
|||
@Override
|
||||
protected String execute() throws Exception {
|
||||
for (final List<EntityChange> batch : getCollatedEntityChangeBatches()) {
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
for (EntityChange change : batch) {
|
||||
ofy().transact(() -> batch.forEach(this::executeChange));
|
||||
}
|
||||
return String.format("Updated %d entities.\n", changedEntitiesMap.size());
|
||||
}
|
||||
|
||||
private void executeChange(EntityChange change) {
|
||||
// Load the key of the entity to mutate and double-check that it hasn't been
|
||||
// modified from the version that existed when the change was prepared.
|
||||
ImmutableObject existingEntity = ofy().load().key(change.key).now();
|
||||
|
@ -153,26 +154,18 @@ public abstract class MutatingCommand extends ConfirmingCommand implements Remot
|
|||
Objects.equals(change.oldEntity, existingEntity),
|
||||
"Entity changed since init() was called.\n%s",
|
||||
prettyPrintEntityDeepDiff(
|
||||
change.oldEntity == null ? ImmutableMap.of()
|
||||
: change.oldEntity.toDiffableFieldMap(),
|
||||
existingEntity == null ? ImmutableMap.of()
|
||||
: existingEntity.toDiffableFieldMap()));
|
||||
(change.oldEntity == null) ? ImmutableMap.of() : change.oldEntity.toDiffableFieldMap(),
|
||||
(existingEntity == null) ? ImmutableMap.of() : existingEntity.toDiffableFieldMap()));
|
||||
switch (change.type) {
|
||||
case CREATE: // Fall through.
|
||||
case UPDATE:
|
||||
ofy().save().entity(change.newEntity).now();
|
||||
break;
|
||||
return;
|
||||
case DELETE:
|
||||
ofy().delete().key(change.key).now();
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException(
|
||||
"Unknown entity change type: " + change.type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}});
|
||||
}
|
||||
return String.format("Updated %d entities.\n", changedEntitiesMap.size());
|
||||
throw new UnsupportedOperationException("Unknown entity change type: " + change.type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,7 +25,6 @@ import com.google.appengine.api.datastore.KeyFactory;
|
|||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import com.googlecode.objectify.impl.EntityMetadata;
|
||||
import google.registry.request.Action;
|
||||
import google.registry.request.HttpException.BadRequestException;
|
||||
|
@ -90,11 +89,7 @@ public class DeleteEntityAction implements Runnable {
|
|||
getDatastoreService().delete(rawDeletions);
|
||||
// Delete ofy entities.
|
||||
final ImmutableList<Object> ofyDeletions = ofyDeletionsBuilder.build();
|
||||
ofy().transactNew(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().delete().entities(ofyDeletions).now();
|
||||
}});
|
||||
ofy().transactNew(() -> ofy().delete().entities(ofyDeletions).now());
|
||||
String message = String.format(
|
||||
"Deleted %d raw entities and %d registered entities",
|
||||
rawDeletions.size(),
|
||||
|
|
|
@ -17,7 +17,6 @@ package google.registry.model.common;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
|
@ -47,11 +46,10 @@ public class GaeUserIdConverterTest {
|
|||
|
||||
@Test
|
||||
public void testSuccess_inTransaction() {
|
||||
ofy().transactNew(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy()
|
||||
.transactNew(
|
||||
() ->
|
||||
assertThat(GaeUserIdConverter.convertEmailAddressToGaeUserId("example@example.com"))
|
||||
.matches("[0-9]+");
|
||||
}});
|
||||
.matches("[0-9]+"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,13 +83,13 @@ public class OfyTest {
|
|||
// This can't be initialized earlier because namespaces need the AppEngineRule to work.
|
||||
}
|
||||
|
||||
private void doBackupGroupRootTimestampInversionTest(VoidWork work) {
|
||||
private void doBackupGroupRootTimestampInversionTest(Runnable runnable) {
|
||||
DateTime groupTimestamp = ofy().load().key(someObject.getParent()).now()
|
||||
.getUpdateAutoTimestamp().getTimestamp();
|
||||
// Set the clock in Ofy to the same time as the backup group root's save time.
|
||||
Ofy ofy = new Ofy(new FakeClock(groupTimestamp));
|
||||
TimestampInversionException thrown =
|
||||
assertThrows(TimestampInversionException.class, () -> ofy.transact(work));
|
||||
assertThrows(TimestampInversionException.class, () -> ofy.transact(runnable));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains(
|
||||
|
@ -101,20 +101,12 @@ public class OfyTest {
|
|||
|
||||
@Test
|
||||
public void testBackupGroupRootTimestampsMustIncreaseOnSave() {
|
||||
doBackupGroupRootTimestampInversionTest(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().save().entity(someObject);
|
||||
}});
|
||||
doBackupGroupRootTimestampInversionTest(() -> ofy().save().entity(someObject));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBackupGroupRootTimestampsMustIncreaseOnDelete() {
|
||||
doBackupGroupRootTimestampInversionTest(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().delete().entity(someObject);
|
||||
}});
|
||||
doBackupGroupRootTimestampInversionTest(() -> ofy().delete().entity(someObject));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -125,12 +117,9 @@ public class OfyTest {
|
|||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
() -> {
|
||||
ofy().save().entity(someObject);
|
||||
ofy().save().entity(someObject);
|
||||
}
|
||||
}));
|
||||
assertThat(thrown).hasMessageThat().contains("Multiple entries with same key");
|
||||
}
|
||||
|
@ -143,12 +132,9 @@ public class OfyTest {
|
|||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
() -> {
|
||||
ofy().delete().entity(someObject);
|
||||
ofy().delete().entity(someObject);
|
||||
}
|
||||
}));
|
||||
assertThat(thrown).hasMessageThat().contains("Multiple entries with same key");
|
||||
}
|
||||
|
@ -161,12 +147,9 @@ public class OfyTest {
|
|||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
() -> {
|
||||
ofy().save().entity(someObject);
|
||||
ofy().delete().entity(someObject);
|
||||
}
|
||||
}));
|
||||
assertThat(thrown).hasMessageThat().contains("Multiple entries with same key");
|
||||
}
|
||||
|
@ -179,12 +162,9 @@ public class OfyTest {
|
|||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
() -> {
|
||||
ofy().delete().entity(someObject);
|
||||
ofy().save().entity(someObject);
|
||||
}
|
||||
}));
|
||||
assertThat(thrown).hasMessageThat().contains("Multiple entries with same key");
|
||||
}
|
||||
|
@ -193,15 +173,7 @@ public class OfyTest {
|
|||
public void testSavingKeyTwiceInOneCall() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().save().entities(someObject, someObject);
|
||||
}
|
||||
}));
|
||||
() -> ofy().transact(() -> ofy().save().entities(someObject, someObject)));
|
||||
}
|
||||
|
||||
/** Simple entity class with lifecycle callbacks. */
|
||||
|
@ -241,11 +213,7 @@ public class OfyTest {
|
|||
public void testLifecycleCallbacks_loadFromDatastore() {
|
||||
ofy().factory().register(LifecycleObject.class);
|
||||
final LifecycleObject object = new LifecycleObject();
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().save().entity(object).now();
|
||||
}});
|
||||
ofy().transact(() -> ofy().save().entity(object).now());
|
||||
assertThat(object.onSaveCalled).isTrue();
|
||||
ofy().clearSessionCache();
|
||||
assertThat(ofy().load().entity(object).now().onLoadCalled).isTrue();
|
||||
|
|
|
@ -22,7 +22,6 @@ import static google.registry.model.rde.RdeRevision.saveRevision;
|
|||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
|
||||
import com.google.common.base.VerifyException;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Rule;
|
||||
|
@ -51,17 +50,12 @@ public class RdeRevisionTest {
|
|||
|
||||
@Test
|
||||
public void testSaveRevision_objectDoesntExist_newRevisionIsZero_nextRevIsOne() {
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
saveRevision("despondency", DateTime.parse("1984-12-18TZ"), FULL, 0);
|
||||
}});
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().transact(() -> saveRevision("despondency", DateTime.parse("1984-12-18TZ"), FULL, 0));
|
||||
ofy()
|
||||
.transact(
|
||||
() ->
|
||||
assertThat(getNextRevision("despondency", DateTime.parse("1984-12-18TZ"), FULL))
|
||||
.isEqualTo(1);
|
||||
}});
|
||||
.isEqualTo(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -72,12 +66,8 @@ public class RdeRevisionTest {
|
|||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
saveRevision("despondency", DateTime.parse("1984-12-18TZ"), FULL, 1);
|
||||
}
|
||||
}));
|
||||
() ->
|
||||
saveRevision("despondency", DateTime.parse("1984-12-18TZ"), FULL, 1)));
|
||||
assertThat(thrown).hasMessageThat().contains("object missing");
|
||||
}
|
||||
|
||||
|
@ -90,29 +80,19 @@ public class RdeRevisionTest {
|
|||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
saveRevision("melancholy", DateTime.parse("1984-12-18TZ"), FULL, 0);
|
||||
}
|
||||
}));
|
||||
() -> saveRevision("melancholy", DateTime.parse("1984-12-18TZ"), FULL, 0)));
|
||||
assertThat(thrown).hasMessageThat().contains("object already created");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveRevision_objectExistsAtZero_newRevisionIsOne_nextRevIsTwo() {
|
||||
save("melancholy", DateTime.parse("1984-12-18TZ"), FULL, 0);
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
saveRevision("melancholy", DateTime.parse("1984-12-18TZ"), FULL, 1);
|
||||
}});
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().transact(() -> saveRevision("melancholy", DateTime.parse("1984-12-18TZ"), FULL, 1));
|
||||
ofy()
|
||||
.transact(
|
||||
() ->
|
||||
assertThat(getNextRevision("melancholy", DateTime.parse("1984-12-18TZ"), FULL))
|
||||
.isEqualTo(2);
|
||||
}});
|
||||
.isEqualTo(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -124,12 +104,7 @@ public class RdeRevisionTest {
|
|||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
saveRevision("melancholy", DateTime.parse("1984-12-18TZ"), FULL, 2);
|
||||
}
|
||||
}));
|
||||
() -> saveRevision("melancholy", DateTime.parse("1984-12-18TZ"), FULL, 2)));
|
||||
assertThat(thrown).hasMessageThat().contains("should be at 1 ");
|
||||
}
|
||||
|
||||
|
@ -141,12 +116,8 @@ public class RdeRevisionTest {
|
|||
() ->
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
saveRevision("melancholy", DateTime.parse("1984-12-18TZ"), FULL, -1);
|
||||
}
|
||||
}));
|
||||
() ->
|
||||
saveRevision("melancholy", DateTime.parse("1984-12-18TZ"), FULL, -1)));
|
||||
assertThat(thrown).hasMessageThat().contains("Negative revision");
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ import com.google.common.collect.ImmutableMap;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import google.registry.model.EntityTestCase;
|
||||
import google.registry.model.common.EntityGroupRoot;
|
||||
import google.registry.model.registrar.Registrar.State;
|
||||
|
@ -418,15 +417,16 @@ public class RegistrarTest extends EntityTestCase {
|
|||
|
||||
@Test
|
||||
public void testLoadByClientIdCached_isTransactionless() {
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
assertThat(Registrar.loadByClientIdCached("registrar")).isPresent();
|
||||
// Load something as a control to make sure we are seeing loaded keys in the session cache.
|
||||
// Load something as a control to make sure we are seeing loaded keys in the session
|
||||
// cache.
|
||||
ofy().load().entity(abuseAdminContact).now();
|
||||
assertThat(ofy().getSessionKeys()).contains(Key.create(abuseAdminContact));
|
||||
assertThat(ofy().getSessionKeys()).doesNotContain(Key.create(registrar));
|
||||
}});
|
||||
});
|
||||
ofy().clearSessionCache();
|
||||
// Conversely, loads outside of a transaction should end up in the session cache.
|
||||
assertThat(Registrar.loadByClientIdCached("registrar")).isPresent();
|
||||
|
|
|
@ -41,7 +41,6 @@ import com.google.common.collect.ImmutableList;
|
|||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import google.registry.dns.writer.VoidDnsWriter;
|
||||
import google.registry.model.pricing.StaticPremiumListPricingEngine;
|
||||
import google.registry.model.registry.Registry;
|
||||
|
@ -193,18 +192,14 @@ public class PremiumListUtilsTest {
|
|||
// Remove one of the premium list entries from behind the Bloom filter's back.
|
||||
ofy()
|
||||
.transactNew(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
() ->
|
||||
ofy()
|
||||
.delete()
|
||||
.keys(
|
||||
Key.create(
|
||||
PremiumList.getCached("tld").get().getRevisionKey(),
|
||||
PremiumListEntry.class,
|
||||
"rich"));
|
||||
}
|
||||
});
|
||||
"rich")));
|
||||
ofy().clearSessionCache();
|
||||
|
||||
assertThat(getPremiumPrice("rich", Registry.get("tld"))).isEmpty();
|
||||
|
|
|
@ -53,7 +53,6 @@ import com.google.common.collect.Iterables;
|
|||
import com.google.common.collect.Streams;
|
||||
import com.google.common.net.InetAddresses;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import com.googlecode.objectify.cmd.Saver;
|
||||
import google.registry.dns.writer.VoidDnsWriter;
|
||||
import google.registry.model.Buildable;
|
||||
|
@ -366,11 +365,7 @@ public class DatastoreHelper {
|
|||
final DomainResource persistedDomain = persistResource(domain);
|
||||
// Calls {@link LordnTask#enqueueDomainResourceTask} wrapped in an ofy transaction so that the
|
||||
// transaction time is set correctly.
|
||||
ofy().transactNew(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
LordnTask.enqueueDomainResourceTask(persistedDomain);
|
||||
}});
|
||||
ofy().transactNew(() -> LordnTask.enqueueDomainResourceTask(persistedDomain));
|
||||
return persistedDomain;
|
||||
}
|
||||
|
||||
|
@ -947,11 +942,7 @@ public class DatastoreHelper {
|
|||
assertWithMessage("Attempting to persist a Builder is almost certainly an error in test code")
|
||||
.that(resource)
|
||||
.isNotInstanceOf(Buildable.Builder.class);
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
saveResource(resource, wantBackup);
|
||||
}});
|
||||
ofy().transact(() -> saveResource(resource, wantBackup));
|
||||
// Force the session cache to be cleared so that when we read the resource back, we read from
|
||||
// Datastore and not from the session cache. This is needed to trigger Objectify's load process
|
||||
// (unmarshalling entity protos to POJOs, nulling out empty collections, calling @OnLoad
|
||||
|
@ -964,13 +955,13 @@ public class DatastoreHelper {
|
|||
public static <R extends EppResource> R persistEppResourceInFirstBucket(final R resource) {
|
||||
final EppResourceIndex eppResourceIndex =
|
||||
EppResourceIndex.create(Key.create(EppResourceIndexBucket.class, 1), Key.create(resource));
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
Saver saver = ofy().save();
|
||||
saver.entity(resource);
|
||||
persistEppResourceExtras(resource, eppResourceIndex, saver);
|
||||
}});
|
||||
});
|
||||
ofy().clearSessionCache();
|
||||
return ofy().load().entity(resource).now();
|
||||
}
|
||||
|
@ -987,13 +978,7 @@ public class DatastoreHelper {
|
|||
}
|
||||
// Persist domains ten at a time, to avoid exceeding the entity group limit.
|
||||
for (final List<R> chunk : Iterables.partition(resources, 10)) {
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
for (R resource : chunk) {
|
||||
saveResource(resource, wantBackup);
|
||||
}
|
||||
}});
|
||||
ofy().transact(() -> chunk.forEach(resource -> saveResource(resource, wantBackup)));
|
||||
}
|
||||
// Force the session to be cleared so that when we read it back, we read from Datastore
|
||||
// and not from the transaction's session cache.
|
||||
|
@ -1015,10 +1000,12 @@ public class DatastoreHelper {
|
|||
*/
|
||||
public static <R extends EppResource> R persistEppResource(final R resource) {
|
||||
checkState(!ofy().inTransaction());
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().save().<ImmutableObject>entities(
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
ofy()
|
||||
.save()
|
||||
.<ImmutableObject>entities(
|
||||
resource,
|
||||
new HistoryEntry.Builder()
|
||||
.setParent(resource)
|
||||
|
@ -1026,7 +1013,7 @@ public class DatastoreHelper {
|
|||
.setModificationTime(ofy().getTransactionTime())
|
||||
.build());
|
||||
ofy().save().entity(ForeignKeyIndex.create(resource, resource.getDeletionTime()));
|
||||
}});
|
||||
});
|
||||
ofy().clearSessionCache();
|
||||
return ofy().load().entity(resource).safe();
|
||||
}
|
||||
|
@ -1099,11 +1086,7 @@ public class DatastoreHelper {
|
|||
* ForeignKeyedEppResources.
|
||||
*/
|
||||
public static <R> ImmutableList<R> persistSimpleResources(final Iterable<R> resources) {
|
||||
ofy().transact(new VoidWork(){
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().saveWithoutBackup().entities(resources);
|
||||
}});
|
||||
ofy().transact(() -> ofy().saveWithoutBackup().entities(resources));
|
||||
// Force the session to be cleared so that when we read it back, we read from Datastore
|
||||
// and not from the transaction's session cache.
|
||||
ofy().clearSessionCache();
|
||||
|
|
|
@ -35,7 +35,6 @@ import com.google.appengine.api.taskqueue.TransientFailureException;
|
|||
import com.google.apphosting.api.DeadlineExceededException;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import google.registry.model.domain.DomainResource;
|
||||
import google.registry.model.domain.launch.LaunchNotice;
|
||||
import google.registry.model.ofy.Ofy;
|
||||
|
@ -174,15 +173,7 @@ public class LordnTaskTest {
|
|||
public void test_enqueueDomainResourceTask_throwsNpeOnNullDomain() {
|
||||
assertThrows(
|
||||
NullPointerException.class,
|
||||
() ->
|
||||
ofy()
|
||||
.transactNew(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
LordnTask.enqueueDomainResourceTask(null);
|
||||
}
|
||||
}));
|
||||
() -> ofy().transactNew(() -> LordnTask.enqueueDomainResourceTask(null)));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue