diff --git a/java/google/registry/export/BUILD b/java/google/registry/export/BUILD index 33644fb92..9e4aa2c43 100644 --- a/java/google/registry/export/BUILD +++ b/java/google/registry/export/BUILD @@ -16,6 +16,7 @@ java_library( "//java/google/registry/mapreduce/inputs", "//java/google/registry/model", "//java/google/registry/request", + "//java/google/registry/request:modules", "//java/google/registry/request/auth", "//java/google/registry/storage/drive", "//java/google/registry/util", diff --git a/java/google/registry/export/DriveModule.java b/java/google/registry/export/DriveModule.java index 8ee8bf8a3..72889417a 100644 --- a/java/google/registry/export/DriveModule.java +++ b/java/google/registry/export/DriveModule.java @@ -19,11 +19,19 @@ import com.google.api.client.http.HttpTransport; import com.google.api.client.json.JsonFactory; import com.google.api.services.drive.Drive; import com.google.api.services.drive.DriveScopes; +import dagger.Component; import dagger.Module; import dagger.Provides; import google.registry.config.RegistryConfig.Config; +import google.registry.config.RegistryConfig.ConfigModule; +import google.registry.request.Modules.AppIdentityCredentialModule; +import google.registry.request.Modules.Jackson2Module; +import google.registry.request.Modules.UrlFetchTransportModule; +import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule; +import google.registry.storage.drive.DriveConnection; import java.util.Set; import java.util.function.Function; +import javax.inject.Singleton; /** Dagger module for Google {@link Drive} service connection objects. */ @Module @@ -39,4 +47,18 @@ public final class DriveModule { .setApplicationName(projectId) .build(); } + + @Singleton + @Component( + modules = { + DriveModule.class, + UrlFetchTransportModule.class, + Jackson2Module.class, + AppIdentityCredentialModule.class, + UseAppIdentityCredentialForGoogleApisModule.class, + ConfigModule.class + }) + interface DriveComponent { + DriveConnection driveConnection(); + } } diff --git a/java/google/registry/export/ExportDomainListsAction.java b/java/google/registry/export/ExportDomainListsAction.java index 74fa257f9..d0eb808f1 100644 --- a/java/google/registry/export/ExportDomainListsAction.java +++ b/java/google/registry/export/ExportDomainListsAction.java @@ -28,21 +28,25 @@ import com.google.appengine.tools.cloudstorage.RetryParams; import com.google.appengine.tools.mapreduce.Mapper; import com.google.appengine.tools.mapreduce.Reducer; import com.google.appengine.tools.mapreduce.ReducerInput; +import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import com.google.common.net.MediaType; import google.registry.config.RegistryConfig.Config; import google.registry.gcs.GcsUtils; import google.registry.mapreduce.MapreduceRunner; import google.registry.model.domain.DomainResource; +import google.registry.model.registry.Registry; import google.registry.model.registry.Registry.TldType; import google.registry.request.Action; import google.registry.request.Response; import google.registry.request.auth.Auth; +import google.registry.storage.drive.DriveConnection; import google.registry.util.FormattingLogger; +import google.registry.util.NonFinalForTesting; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.io.Writer; import javax.inject.Inject; import org.joda.time.DateTime; @@ -50,14 +54,10 @@ import org.joda.time.DateTime; /** * A mapreduce that exports the list of active domains on all real TLDs to Google Cloud Storage. * - * Each TLD's active domain names are exported as a newline-delimited flat text file with the name - * TLD.txt into the domain-lists bucket. Note that this overwrites the files in place. + *
Each TLD's active domain names are exported as a newline-delimited flat text file with the
+ * name TLD.txt into the domain-lists bucket. Note that this overwrites the files in place.
*/
-@Action(
- path = "/_dr/task/exportDomainLists",
- method = POST,
- auth = Auth.AUTH_INTERNAL_ONLY
-)
+@Action(path = "/_dr/task/exportDomainLists", method = POST, auth = Auth.AUTH_INTERNAL_ONLY)
public class ExportDomainListsAction implements Runnable {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
@@ -108,32 +108,69 @@ public class ExportDomainListsAction implements Runnable {
private static final long serialVersionUID = 7035260977259119087L;
+ @NonFinalForTesting
+ private static DriveConnection driveConnection =
+ DaggerDriveModule_DriveComponent.create().driveConnection();
+
+ static final String REGISTERED_DOMAINS_FILENAME = "registered_domains.txt";
+ static final MediaType EXPORT_MIME_TYPE = MediaType.PLAIN_TEXT_UTF_8;
+
private final String gcsBucket;
private final int gcsBufferSize;
+ static void setDriveConnectionForTesting(DriveConnection driveConnection) {
+ ExportDomainListsReducer.driveConnection = driveConnection;
+ }
+
public ExportDomainListsReducer(String gcsBucket, int gcsBufferSize) {
this.gcsBucket = gcsBucket;
this.gcsBufferSize = gcsBufferSize;
}
- @Override
- public void reduce(String tld, ReducerInput