mirror of
https://github.com/google/nomulus.git
synced 2025-05-17 01:47:14 +02:00
Replace many Work and VoidWork usages with lambdas
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=176153460
This commit is contained in:
parent
603e0470cc
commit
cd314bdc75
36 changed files with 443 additions and 680 deletions
|
@ -35,7 +35,6 @@ import com.google.common.collect.ImmutableSet;
|
|||
import com.google.common.io.Files;
|
||||
import com.google.common.io.LineReader;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.Work;
|
||||
import google.registry.model.domain.LrpTokenEntity;
|
||||
import google.registry.tools.Command.RemoteApiCommand;
|
||||
import google.registry.tools.params.KeyValueMapParameter.StringToIntegerMap;
|
||||
|
@ -162,23 +161,14 @@ public class CreateLrpTokensCommand implements RemoteApiCommand {
|
|||
}
|
||||
final ImmutableSet<LrpTokenEntity> tokensToSave = tokensToSaveBuilder.build();
|
||||
// Wrap in a retrier to deal with transient 404 errors (thrown as RemoteApiExceptions).
|
||||
retrier.callWithRetry(
|
||||
() -> {
|
||||
saveTokens(tokensToSave);
|
||||
return null;
|
||||
},
|
||||
RemoteApiException.class);
|
||||
retrier.callWithRetry(() -> saveTokens(tokensToSave), RemoteApiException.class);
|
||||
} while (line != null);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void saveTokens(final ImmutableSet<LrpTokenEntity> tokens) {
|
||||
Collection<LrpTokenEntity> savedTokens =
|
||||
ofy().transact(new Work<Collection<LrpTokenEntity>>() {
|
||||
@Override
|
||||
public Collection<LrpTokenEntity> run() {
|
||||
return ofy().save().entities(tokens).now().values();
|
||||
}});
|
||||
ofy().transact(() -> ofy().save().entities(tokens).now().values());
|
||||
for (LrpTokenEntity token : savedTokens) {
|
||||
System.out.printf("%s,%s%n", token.getAssignee(), token.getToken());
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
|||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.beust.jcommander.internal.Sets;
|
||||
import com.googlecode.objectify.Work;
|
||||
import google.registry.model.domain.DomainApplication;
|
||||
import google.registry.model.domain.launch.ApplicationStatus;
|
||||
import google.registry.tools.Command.RemoteApiCommand;
|
||||
|
@ -70,23 +69,24 @@ final class GetAppliedLabelsCommand implements RemoteApiCommand {
|
|||
|
||||
/** Return a set of all fully-qualified domain names with open applications. */
|
||||
private static Set<String> getDomainApplicationMap(final String tld) {
|
||||
return ofy().transact(new Work<Set<String>>() {
|
||||
@Override
|
||||
public Set<String> run() {
|
||||
Set<String> labels = Sets.newHashSet();
|
||||
List<DomainApplication> domainApplications;
|
||||
domainApplications = ofy().load().type(DomainApplication.class).filter("tld", tld).list();
|
||||
for (DomainApplication domainApplication : domainApplications) {
|
||||
// Ignore deleted and rejected applications. They aren't under consideration.
|
||||
ApplicationStatus applicationStatus = domainApplication.getApplicationStatus();
|
||||
DateTime deletionTime = domainApplication.getDeletionTime();
|
||||
if (applicationStatus == REJECTED
|
||||
|| isAtOrAfter(ofy().getTransactionTime(), deletionTime)) {
|
||||
continue;
|
||||
}
|
||||
labels.add(domainApplication.getFullyQualifiedDomainName());
|
||||
}
|
||||
return labels;
|
||||
}});
|
||||
return ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
Set<String> labels = Sets.newHashSet();
|
||||
List<DomainApplication> domainApplications;
|
||||
domainApplications =
|
||||
ofy().load().type(DomainApplication.class).filter("tld", tld).list();
|
||||
for (DomainApplication domainApplication : domainApplications) {
|
||||
// Ignore deleted and rejected applications. They aren't under consideration.
|
||||
ApplicationStatus applicationStatus = domainApplication.getApplicationStatus();
|
||||
DateTime deletionTime = domainApplication.getDeletionTime();
|
||||
if (applicationStatus == REJECTED
|
||||
|| isAtOrAfter(ofy().getTransactionTime(), deletionTime)) {
|
||||
continue;
|
||||
}
|
||||
labels.add(domainApplication.getFullyQualifiedDomainName());
|
||||
}
|
||||
return labels;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
|
|||
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.model.registrar.RegistrarContact;
|
||||
import google.registry.model.registry.Registry;
|
||||
|
@ -48,11 +47,7 @@ final class ResaveEnvironmentEntitiesCommand implements RemoteApiCommand {
|
|||
System.out.printf("Re-saving %s entities.\n", clazz.getSimpleName());
|
||||
for (final Iterable<Key<T>> batch :
|
||||
partition(ofy().load().type(clazz).ancestor(getCrossTldKey()).keys().list(), BATCH_SIZE)) {
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().save().entities(ofy().load().keys(batch).values());
|
||||
}});
|
||||
ofy().transact(() -> ofy().save().entities(ofy().load().keys(batch).values()));
|
||||
System.out.printf("Re-saved entities batch: %s.\n", batch);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
|
|||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import google.registry.model.domain.DomainApplication;
|
||||
import google.registry.model.domain.launch.ApplicationStatus;
|
||||
import google.registry.model.domain.launch.LaunchInfoResponseExtension;
|
||||
|
@ -70,12 +69,7 @@ final class UpdateApplicationStatusCommand extends MutatingCommand {
|
|||
checkArgumentPresent(
|
||||
Registrar.loadByClientId(clientId), "Registrar with client ID %s not found", clientId);
|
||||
for (final String applicationId : ids) {
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
updateApplicationStatus(applicationId);
|
||||
}
|
||||
});
|
||||
ofy().transact(() -> updateApplicationStatus(applicationId));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
|
|||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.net.InternetDomainName;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import google.registry.model.domain.DomainApplication;
|
||||
import google.registry.model.domain.launch.LaunchNotice;
|
||||
import google.registry.model.domain.launch.LaunchNotice.InvalidChecksumException;
|
||||
|
@ -67,15 +66,15 @@ final class UpdateClaimsNoticeCommand implements RemoteApiCommand {
|
|||
final LaunchNotice launchNotice = LaunchNotice.create(
|
||||
tcnId, validatorId, DateTime.parse(expirationTime), DateTime.parse(acceptedTime));
|
||||
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
try {
|
||||
updateClaimsNotice(id, launchNotice);
|
||||
} catch (InvalidChecksumException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}});
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
try {
|
||||
updateClaimsNotice(id, launchNotice);
|
||||
} catch (InvalidChecksumException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateClaimsNotice(String applicationId, LaunchNotice launchNotice)
|
||||
|
|
|
@ -24,7 +24,6 @@ import com.beust.jcommander.Parameter;
|
|||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.net.InternetDomainName;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import google.registry.flows.EppException;
|
||||
import google.registry.flows.domain.DomainFlowTmchUtils;
|
||||
import google.registry.model.domain.DomainApplication;
|
||||
|
@ -67,15 +66,15 @@ final class UpdateSmdCommand implements RemoteApiCommand {
|
|||
final EncodedSignedMark encodedSignedMark =
|
||||
readEncodedSignedMark(new String(Files.readAllBytes(smdFile), US_ASCII));
|
||||
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
try {
|
||||
updateSmd(id, encodedSignedMark, reason);
|
||||
} catch (EppException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}});
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
try {
|
||||
updateSmd(id, encodedSignedMark, reason);
|
||||
} catch (EppException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateSmd(
|
||||
|
|
|
@ -20,7 +20,6 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
|
|||
import com.google.appengine.tools.mapreduce.Reducer;
|
||||
import com.google.appengine.tools.mapreduce.ReducerInput;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -37,11 +36,7 @@ public class KillAllEntitiesReducer extends Reducer<Key<?>, Key<?>, Void> {
|
|||
while (batches.hasNext()) {
|
||||
final List<Key<?>> batch = batches.next();
|
||||
// Use a transaction to get retrying for free.
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().deleteWithoutBackup().keys(batch);
|
||||
}});
|
||||
ofy().transact(() -> ofy().deleteWithoutBackup().keys(batch));
|
||||
getContext().incrementCounter("entities deleted", batch.size());
|
||||
for (Key<?> key : batch) {
|
||||
getContext().incrementCounter(String.format("%s deleted", key.getKind()));
|
||||
|
|
|
@ -20,7 +20,6 @@ import static google.registry.util.PipelineUtils.createJobPath;
|
|||
import com.google.appengine.tools.mapreduce.Mapper;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import google.registry.mapreduce.MapreduceRunner;
|
||||
import google.registry.mapreduce.inputs.EppResourceInputs;
|
||||
import google.registry.model.EppResource;
|
||||
|
@ -70,11 +69,7 @@ public class ResaveAllHistoryEntriesAction implements Runnable {
|
|||
|
||||
@Override
|
||||
public final void map(final HistoryEntry historyEntry) {
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().save().entity(ofy().load().entity(historyEntry).now()).now();
|
||||
}});
|
||||
ofy().transact(() -> ofy().save().entity(ofy().load().entity(historyEntry).now()).now());
|
||||
getContext().incrementCounter(
|
||||
String.format(
|
||||
"HistoryEntries parented under %s re-saved", historyEntry.getParent().getKind()));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue