mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 00:17:20 +02:00
Switch from Guava Optionals to Java 8 Optionals
This was a surprisingly involved change. Some of the difficulties included java.util.Optional purposely not being Serializable (so I had to move a few Optionals in mapreduce classes to @Nullable) and having to add the Truth Java8 extension library for assertion support. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=171863777
This commit is contained in:
parent
184b2b56ac
commit
c0f8da0c6e
581 changed files with 1325 additions and 932 deletions
|
@ -20,10 +20,10 @@ import static google.registry.mapreduce.MapreduceRunner.PARAM_REDUCE_SHARDS;
|
|||
import static google.registry.request.RequestParameters.extractBooleanParameter;
|
||||
import static google.registry.request.RequestParameters.extractOptionalIntParameter;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import google.registry.request.Parameter;
|
||||
import java.util.Optional;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/** Dagger module for the mapreduce package. */
|
||||
|
|
|
@ -33,12 +33,12 @@ import com.google.appengine.tools.mapreduce.outputs.NoOutput;
|
|||
import com.google.appengine.tools.pipeline.Job0;
|
||||
import com.google.appengine.tools.pipeline.JobSetting;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Optional;
|
||||
import google.registry.mapreduce.inputs.ConcatenatingInput;
|
||||
import google.registry.request.Parameter;
|
||||
import google.registry.util.FormattingLogger;
|
||||
import google.registry.util.PipelineUtils;
|
||||
import java.io.Serializable;
|
||||
import java.util.Optional;
|
||||
import javax.inject.Inject;
|
||||
import org.joda.time.Duration;
|
||||
|
||||
|
@ -143,7 +143,7 @@ public class MapreduceRunner {
|
|||
return new MapJob<>(
|
||||
new MapSpecification.Builder<I, O, R>()
|
||||
.setJobName(jobName)
|
||||
.setInput(new ConcatenatingInput<>(inputs, httpParamMapShards.or(defaultMapShards)))
|
||||
.setInput(new ConcatenatingInput<>(inputs, httpParamMapShards.orElse(defaultMapShards)))
|
||||
.setMapper(mapper)
|
||||
.setOutput(output)
|
||||
.build(),
|
||||
|
@ -199,13 +199,13 @@ public class MapreduceRunner {
|
|||
return new MapReduceJob<>(
|
||||
new MapReduceSpecification.Builder<I, K, V, O, R>()
|
||||
.setJobName(jobName)
|
||||
.setInput(new ConcatenatingInput<>(inputs, httpParamMapShards.or(defaultMapShards)))
|
||||
.setInput(new ConcatenatingInput<>(inputs, httpParamMapShards.orElse(defaultMapShards)))
|
||||
.setMapper(mapper)
|
||||
.setReducer(reducer)
|
||||
.setOutput(output)
|
||||
.setKeyMarshaller(Marshallers.<K>getSerializationMarshaller())
|
||||
.setValueMarshaller(Marshallers.<V>getSerializationMarshaller())
|
||||
.setNumReducers(httpParamReduceShards.or(defaultReduceShards))
|
||||
.setNumReducers(httpParamReduceShards.orElse(defaultReduceShards))
|
||||
.build(),
|
||||
new MapReduceSettings.Builder()
|
||||
.setWorkerQueueName(QUEUE_NAME)
|
||||
|
|
|
@ -14,6 +14,7 @@ java_library(
|
|||
"@com_google_appengine_api_1_0_sdk",
|
||||
"@com_google_appengine_tools_appengine_mapreduce",
|
||||
"@com_google_appengine_tools_appengine_pipeline",
|
||||
"@com_google_code_findbugs_jsr305",
|
||||
"@com_google_dagger",
|
||||
"@com_google_guava",
|
||||
"@javax_servlet_api",
|
||||
|
|
|
@ -16,27 +16,33 @@ package google.registry.mapreduce.inputs;
|
|||
|
||||
import com.google.appengine.tools.mapreduce.Input;
|
||||
import com.google.appengine.tools.mapreduce.InputReader;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.model.ofy.CommitLogBucket;
|
||||
import google.registry.model.ofy.CommitLogManifest;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/** Base class for {@link Input} classes that map over {@link CommitLogManifest}. */
|
||||
public class CommitLogManifestInput extends Input<Key<CommitLogManifest>> {
|
||||
|
||||
private static final long serialVersionUID = 2043552272352286428L;
|
||||
private static final long serialVersionUID = 6744322799131602384L;
|
||||
|
||||
/**
|
||||
* Cutoff date for result.
|
||||
*
|
||||
* If present, all resulting CommitLogManifest will be dated prior to this date.
|
||||
* <p>If present, all resulting CommitLogManifest will be dated prior to this date. This can't be
|
||||
* of type {@code Optional<DateTime>} because Optional purposely isn't Serializable.
|
||||
*/
|
||||
private final Optional<DateTime> olderThan;
|
||||
@Nullable
|
||||
private final DateTime olderThan;
|
||||
|
||||
public CommitLogManifestInput(Optional<DateTime> olderThan) {
|
||||
public CommitLogManifestInput() {
|
||||
this.olderThan = null;
|
||||
}
|
||||
|
||||
public CommitLogManifestInput(@Nullable DateTime olderThan) {
|
||||
this.olderThan = olderThan;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ import com.google.appengine.api.datastore.Cursor;
|
|||
import com.google.appengine.api.datastore.DatastoreTimeoutException;
|
||||
import com.google.appengine.api.datastore.QueryResultIterator;
|
||||
import com.google.appengine.tools.mapreduce.InputReader;
|
||||
import com.google.common.base.Optional;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.cmd.Query;
|
||||
import google.registry.model.ofy.CommitLogBucket;
|
||||
|
@ -30,13 +29,12 @@ import google.registry.util.FormattingLogger;
|
|||
import google.registry.util.Retrier;
|
||||
import google.registry.util.SystemSleeper;
|
||||
import java.util.NoSuchElementException;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/** {@link InputReader} that maps over {@link CommitLogManifest}. */
|
||||
class CommitLogManifestReader extends InputReader<Key<CommitLogManifest>> {
|
||||
|
||||
private static final long serialVersionUID = 5117046535590539778L;
|
||||
|
||||
static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
|
||||
|
||||
/**
|
||||
|
@ -48,6 +46,7 @@ class CommitLogManifestReader extends InputReader<Key<CommitLogManifest>> {
|
|||
private static final long MEMORY_ESTIMATE = 100 * 1024;
|
||||
|
||||
private static final Retrier retrier = new Retrier(new SystemSleeper(), 3);
|
||||
private static final long serialVersionUID = 2553537421598284748L;
|
||||
|
||||
private final Key<CommitLogBucket> bucketKey;
|
||||
|
||||
|
@ -56,7 +55,8 @@ class CommitLogManifestReader extends InputReader<Key<CommitLogManifest>> {
|
|||
*
|
||||
* If present, all resulting CommitLogManifest will be dated prior to this date.
|
||||
*/
|
||||
private final Optional<DateTime> olderThan;
|
||||
@Nullable
|
||||
private final DateTime olderThan;
|
||||
|
||||
private Cursor cursor;
|
||||
private int total;
|
||||
|
@ -64,7 +64,7 @@ class CommitLogManifestReader extends InputReader<Key<CommitLogManifest>> {
|
|||
|
||||
private transient QueryResultIterator<Key<CommitLogManifest>> queryIterator;
|
||||
|
||||
CommitLogManifestReader(Key<CommitLogBucket> bucketKey, Optional<DateTime> olderThan) {
|
||||
CommitLogManifestReader(Key<CommitLogBucket> bucketKey, @Nullable DateTime olderThan) {
|
||||
this.bucketKey = bucketKey;
|
||||
this.olderThan = olderThan;
|
||||
}
|
||||
|
@ -112,10 +112,10 @@ class CommitLogManifestReader extends InputReader<Key<CommitLogManifest>> {
|
|||
/** Query for children of this bucket. */
|
||||
Query<CommitLogManifest> query() {
|
||||
Query<CommitLogManifest> query = ofy().load().type(CommitLogManifest.class).ancestor(bucketKey);
|
||||
if (olderThan.isPresent()) {
|
||||
if (olderThan != null) {
|
||||
query = query.filterKey(
|
||||
"<",
|
||||
Key.create(bucketKey, CommitLogManifest.class, olderThan.get().getMillis()));
|
||||
Key.create(bucketKey, CommitLogManifest.class, olderThan.getMillis()));
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue