mirror of
https://github.com/google/nomulus.git
synced 2025-07-22 18:55:58 +02:00
Convert remaining ofy() calls to auditedOfy() (#1200)
* Convert remaining ofy() calls to auditedOfy()
This commit is contained in:
parent
3f41f7f444
commit
a1b56b0521
5 changed files with 22 additions and 19 deletions
|
@ -51,7 +51,7 @@ import google.registry.model.translators.VKeyTranslatorFactory;
|
|||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* An instance of Ofy, obtained via {@code #ofy()}, should be used to access all persistable
|
||||
* An instance of Ofy, obtained via {@code #auditedOfy()}, should be used to access all persistable
|
||||
* objects. The class contains a static initializer to call factory().register(...) on all
|
||||
* persistable objects in this package.
|
||||
*/
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package google.registry.tools.javascrap;
|
||||
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
|
||||
import com.google.appengine.tools.mapreduce.Mapper;
|
||||
|
@ -111,7 +111,7 @@ public class CreateSyntheticHistoryEntriesAction implements Runnable {
|
|||
public final void map(final Key<EppResource> resourceKey) {
|
||||
tm().transact(
|
||||
() -> {
|
||||
EppResource eppResource = ofy().load().key(resourceKey).now();
|
||||
EppResource eppResource = auditedOfy().load().key(resourceKey).now();
|
||||
tm().put(
|
||||
HistoryEntry.createBuilderForResource(eppResource)
|
||||
.setClientId(registryAdminRegistrarId)
|
||||
|
|
|
@ -22,7 +22,7 @@ import static com.google.common.collect.Iterables.concat;
|
|||
import static com.google.common.collect.Lists.partition;
|
||||
import static google.registry.backup.BackupUtils.serializeEntity;
|
||||
import static google.registry.model.ofy.CommitLogBucket.getBucketKey;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static google.registry.util.DateTimeUtils.isAtOrAfter;
|
||||
|
@ -80,7 +80,7 @@ public final class CommitLogExports {
|
|||
public static CommitLogCheckpoint computeCheckpoint(Clock clock) {
|
||||
CommitLogCheckpointStrategy strategy = new CommitLogCheckpointStrategy();
|
||||
strategy.clock = clock;
|
||||
strategy.ofy = ofy();
|
||||
strategy.ofy = auditedOfy();
|
||||
|
||||
CommitLogCheckpoint checkpoint = strategy.computeCheckpoint();
|
||||
tm().transact(
|
||||
|
@ -90,7 +90,7 @@ public final class CommitLogExports {
|
|||
checkpoint.getCheckpointTime().isAfter(lastWrittenTime),
|
||||
"Newer checkpoint already written at time: %s",
|
||||
lastWrittenTime);
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.saveWithoutBackup()
|
||||
.entities(
|
||||
checkpoint, CommitLogCheckpointRoot.create(checkpoint.getCheckpointTime()));
|
||||
|
@ -135,17 +135,17 @@ public final class CommitLogExports {
|
|||
// asynchronously load the entities for the next one.
|
||||
List<List<Key<CommitLogManifest>>> keyChunks = partition(sortedKeys, EXPORT_DIFF_BATCH_SIZE);
|
||||
// Objectify's map return type is asynchronous. Calling .values() will block until it loads.
|
||||
Map<?, CommitLogManifest> nextChunkToExport = ofy().load().keys(keyChunks.get(0));
|
||||
Map<?, CommitLogManifest> nextChunkToExport = auditedOfy().load().keys(keyChunks.get(0));
|
||||
for (int i = 0; i < keyChunks.size(); i++) {
|
||||
// Force the async load to finish.
|
||||
Collection<CommitLogManifest> chunkValues = nextChunkToExport.values();
|
||||
// Since there is no hard bound on how much data this might be, take care not to let the
|
||||
// Objectify session cache fill up and potentially run out of memory. This is the only safe
|
||||
// point to do this since at this point there is no async load in progress.
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
// Kick off the next async load, which can happen in parallel to the current GCS export.
|
||||
if (i + 1 < keyChunks.size()) {
|
||||
nextChunkToExport = ofy().load().keys(keyChunks.get(i + 1));
|
||||
nextChunkToExport = auditedOfy().load().keys(keyChunks.get(i + 1));
|
||||
}
|
||||
exportChunk(commitLogStream, chunkValues);
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ public final class CommitLogExports {
|
|||
return ImmutableSet.of();
|
||||
}
|
||||
Key<CommitLogBucket> bucketKey = getBucketKey(bucketNum);
|
||||
return ofy()
|
||||
return auditedOfy()
|
||||
.load()
|
||||
.type(CommitLogManifest.class)
|
||||
.ancestor(bucketKey)
|
||||
|
@ -222,7 +222,7 @@ public final class CommitLogExports {
|
|||
new ImmutableList.Builder<>();
|
||||
for (CommitLogManifest manifest : chunk) {
|
||||
entities.add(ImmutableList.of(manifest));
|
||||
entities.add(ofy().load().type(CommitLogMutation.class).ancestor(manifest));
|
||||
entities.add(auditedOfy().load().type(CommitLogMutation.class).ancestor(manifest));
|
||||
}
|
||||
for (ImmutableObject entity : concat(entities.build())) {
|
||||
serializeEntity(entity, gcsStream);
|
||||
|
|
|
@ -16,7 +16,7 @@ package google.registry.model.index;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.config.RegistryConfig.getEppResourceIndexBucketCount;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.persistActiveContact;
|
||||
import static google.registry.testing.DatabaseHelper.persistResource;
|
||||
|
@ -44,7 +44,7 @@ class EppResourceIndexTest extends EntityTestCase {
|
|||
@Test
|
||||
void testPersistence() {
|
||||
EppResourceIndex loadedIndex = Iterables.getOnlyElement(getEppResourceIndexObjects());
|
||||
assertThat(ofy().load().key(loadedIndex.reference).now()).isEqualTo(contact);
|
||||
assertThat(auditedOfy().load().key(loadedIndex.reference).now()).isEqualTo(contact);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -56,7 +56,7 @@ class EppResourceIndexTest extends EntityTestCase {
|
|||
void testIdempotentOnUpdate() {
|
||||
contact = persistResource(contact.asBuilder().setEmailAddress("abc@def.fake").build());
|
||||
EppResourceIndex loadedIndex = Iterables.getOnlyElement(getEppResourceIndexObjects());
|
||||
assertThat(ofy().load().key(loadedIndex.reference).now()).isEqualTo(contact);
|
||||
assertThat(auditedOfy().load().key(loadedIndex.reference).now()).isEqualTo(contact);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,9 +65,11 @@ class EppResourceIndexTest extends EntityTestCase {
|
|||
private static ImmutableList<EppResourceIndex> getEppResourceIndexObjects() {
|
||||
ImmutableList.Builder<EppResourceIndex> indexEntities = new ImmutableList.Builder<>();
|
||||
for (int i = 0; i < getEppResourceIndexBucketCount(); i++) {
|
||||
indexEntities.addAll(ofy().load()
|
||||
.type(EppResourceIndex.class)
|
||||
.ancestor(Key.create(EppResourceIndexBucket.class, i + 1)));
|
||||
indexEntities.addAll(
|
||||
auditedOfy()
|
||||
.load()
|
||||
.type(EppResourceIndex.class)
|
||||
.ancestor(Key.create(EppResourceIndexBucket.class, i + 1)));
|
||||
}
|
||||
return indexEntities.build();
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ import static com.google.common.collect.Iterables.filter;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.newContactResource;
|
||||
import static google.registry.testing.DatabaseHelper.persistResource;
|
||||
|
@ -78,7 +77,9 @@ class KillAllCommitLogsActionTest extends MapreduceTestCase<KillAllCommitLogsAct
|
|||
START_OF_TIME.plusDays(1),
|
||||
ImmutableMap.of(1, bucketTime, 2, bucketTime, 3, bucketTime)));
|
||||
for (Class<?> clazz : AFFECTED_TYPES) {
|
||||
assertWithMessage("entities of type " + clazz).that(ofy().load().type(clazz)).isNotEmpty();
|
||||
assertWithMessage("entities of type " + clazz)
|
||||
.that(auditedOfy().load().type(clazz))
|
||||
.isNotEmpty();
|
||||
}
|
||||
ImmutableList<?> otherStuff =
|
||||
Streams.stream(auditedOfy().load())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue