From c0a7bde95e32618d5f8e1db20f4347c200be1020 Mon Sep 17 00:00:00 2001 From: jianglai Date: Wed, 30 May 2018 14:58:08 -0700 Subject: [PATCH] Remove deprecated PublishDetailReportAction ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=198624767 --- .../registry/env/common/tools/WEB-INF/web.xml | 6 - .../export/PublishDetailReportAction.java | 133 ---------- .../module/tools/ToolsRequestComponent.java | 2 - .../export/PublishDetailReportActionTest.java | 240 ------------------ .../module/tools/testdata/tools_routing.txt | 1 - 5 files changed, 382 deletions(-) delete mode 100644 java/google/registry/export/PublishDetailReportAction.java delete mode 100644 javatests/google/registry/export/PublishDetailReportActionTest.java diff --git a/java/google/registry/env/common/tools/WEB-INF/web.xml b/java/google/registry/env/common/tools/WEB-INF/web.xml index 23bf014c6..b2b4b6716 100644 --- a/java/google/registry/env/common/tools/WEB-INF/web.xml +++ b/java/google/registry/env/common/tools/WEB-INF/web.xml @@ -116,12 +116,6 @@ /_dr/task/refreshDnsForAllDomains - - - tools-servlet - /_dr/publishDetailReport - - tools-servlet /_dr/task/generateZoneFiles diff --git a/java/google/registry/export/PublishDetailReportAction.java b/java/google/registry/export/PublishDetailReportAction.java deleted file mode 100644 index 2b013e374..000000000 --- a/java/google/registry/export/PublishDetailReportAction.java +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright 2017 The Nomulus Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package google.registry.export; - -import static com.google.common.base.MoreObjects.firstNonNull; -import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; -import static google.registry.util.PreconditionsUtils.checkArgumentPresent; - -import com.google.appengine.tools.cloudstorage.GcsFilename; -import com.google.common.collect.ImmutableMap; -import com.google.common.flogger.FluentLogger; -import com.google.common.io.ByteStreams; -import com.google.common.net.MediaType; -import google.registry.gcs.GcsUtils; -import google.registry.model.registrar.Registrar; -import google.registry.request.Action; -import google.registry.request.HttpException.BadRequestException; -import google.registry.request.HttpException.InternalServerErrorException; -import google.registry.request.JsonActionRunner; -import google.registry.request.JsonActionRunner.JsonAction; -import google.registry.request.auth.Auth; -import google.registry.storage.drive.DriveConnection; -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.util.Map; -import javax.inject.Inject; - -/** - * Publish a single registrar detail report from GCS to Drive. - * - *

This is now DEPRECATED, and will be removed upon completion of the billing migration. If you - * wish to use the functionality, use {@link - * google.registry.reporting.billing.CopyDetailReportsAction} instead. - */ -@Action( - path = PublishDetailReportAction.PATH, - method = Action.Method.POST, - auth = Auth.AUTH_INTERNAL_OR_ADMIN -) -@Deprecated -public final class PublishDetailReportAction implements Runnable, JsonAction { - - private static final FluentLogger logger = FluentLogger.forEnclosingClass(); - - /** MIME type to use for deposited report files in Drive. */ - private static final MediaType REPORT_MIME_TYPE = MediaType.CSV_UTF_8; - - /** Endpoint to which JSON should be sent for this servlet. See {@code web.xml}. */ - public static final String PATH = "/_dr/publishDetailReport"; - - /** - * Name of parameter indicating the registrar client ID for which this report will be published. - */ - public static final String REGISTRAR_ID_PARAM = "registrar"; - - /** Name of parameter providing a name for the report file placed in Drive (the base name). */ - public static final String DETAIL_REPORT_NAME_PARAM = "report"; - - /** - * Name of parameter giving the prefix of the GCS object name to use as the report contents. - * Concatenating this value with the value of the "report" parameter gives the full object name. - */ - public static final String GCS_FOLDER_PREFIX_PARAM = "gcsFolder"; - - /** Name of parameter giving the GCS bucket name for the file to use as the report contents. */ - public static final String GCS_BUCKET_PARAM = "bucket"; - - @Inject DriveConnection driveConnection; - @Inject GcsUtils gcsUtils; - @Inject JsonActionRunner runner; - @Inject PublishDetailReportAction() {} - - @Override - public void run() { - runner.run(this); - } - - /** Copy a detail report from Cloud Storage to Drive. */ - @Override - public Map handleJsonRequest(Map json) { - try { - logger.atInfo().log("Publishing detail report for parameters: %s", json); - String registrarId = getParam(json, REGISTRAR_ID_PARAM); - Registrar registrar = - checkArgumentPresent( - Registrar.loadByClientId(registrarId), "Registrar %s not found", registrarId); - String driveFolderId = - checkArgumentNotNull( - registrar.getDriveFolderId(), - "No drive folder associated with registrar " + registrarId); - String gcsBucketName = getParam(json, GCS_BUCKET_PARAM); - String gcsObjectName = - getParam(json, GCS_FOLDER_PREFIX_PARAM) + getParam(json, DETAIL_REPORT_NAME_PARAM); - try (InputStream input = - gcsUtils.openInputStream(new GcsFilename(gcsBucketName, gcsObjectName))) { - String driveId = - driveConnection.createFile( - getParam(json, DETAIL_REPORT_NAME_PARAM), - REPORT_MIME_TYPE, - driveFolderId, - ByteStreams.toByteArray(input)); - logger.atInfo().log( - "Published detail report for %s to folder %s using GCS file gs://%s/%s.", - registrarId, driveFolderId, gcsBucketName, gcsObjectName); - return ImmutableMap.of("driveId", driveId); - } catch (FileNotFoundException e) { - throw new IllegalArgumentException(e.getMessage(), e); - } - } catch (Throwable e) { - String message = firstNonNull(e.getMessage(), e.toString()); - throw e instanceof IllegalArgumentException - ? new BadRequestException(message, e) : new InternalServerErrorException(message, e); - } - } - - private String getParam(Map json, String paramName) { - return (String) checkArgumentNotNull( - json.get(paramName), - "Missing required parameter: %s", paramName); - } -} diff --git a/java/google/registry/module/tools/ToolsRequestComponent.java b/java/google/registry/module/tools/ToolsRequestComponent.java index 515d3acf2..633a38709 100644 --- a/java/google/registry/module/tools/ToolsRequestComponent.java +++ b/java/google/registry/module/tools/ToolsRequestComponent.java @@ -19,7 +19,6 @@ import dagger.Subcomponent; import google.registry.backup.BackupModule; import google.registry.backup.RestoreCommitLogsAction; import google.registry.dns.DnsModule; -import google.registry.export.PublishDetailReportAction; import google.registry.flows.EppToolAction; import google.registry.flows.EppToolAction.EppToolModule; import google.registry.flows.FlowComponent; @@ -79,7 +78,6 @@ interface ToolsRequestComponent { ListTldsAction listTldsAction(); LoadTestAction loadTestAction(); PollMapreduceAction pollMapReduceAction(); - PublishDetailReportAction publishDetailReportAction(); RefreshDnsForAllDomainsAction refreshDnsForAllDomainsAction(); ResaveAllHistoryEntriesAction resaveAllHistoryEntriesAction(); RestoreCommitLogsAction restoreCommitLogsAction(); diff --git a/javatests/google/registry/export/PublishDetailReportActionTest.java b/javatests/google/registry/export/PublishDetailReportActionTest.java deleted file mode 100644 index 301039899..000000000 --- a/javatests/google/registry/export/PublishDetailReportActionTest.java +++ /dev/null @@ -1,240 +0,0 @@ -// Copyright 2017 The Nomulus Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package google.registry.export; - -import static com.google.common.truth.Truth.assertThat; -import static google.registry.export.PublishDetailReportAction.DETAIL_REPORT_NAME_PARAM; -import static google.registry.export.PublishDetailReportAction.GCS_BUCKET_PARAM; -import static google.registry.export.PublishDetailReportAction.GCS_FOLDER_PREFIX_PARAM; -import static google.registry.export.PublishDetailReportAction.REGISTRAR_ID_PARAM; -import static google.registry.testing.DatastoreHelper.loadRegistrar; -import static google.registry.testing.DatastoreHelper.persistResource; -import static google.registry.testing.JUnitBackports.assertThrows; -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import com.google.appengine.tools.cloudstorage.GcsFileOptions; -import com.google.appengine.tools.cloudstorage.GcsFilename; -import com.google.appengine.tools.cloudstorage.GcsService; -import com.google.appengine.tools.cloudstorage.GcsServiceFactory; -import com.google.common.collect.ImmutableMap; -import com.google.common.net.MediaType; -import google.registry.gcs.GcsUtils; -import google.registry.request.HttpException.BadRequestException; -import google.registry.request.HttpException.InternalServerErrorException; -import google.registry.storage.drive.DriveConnection; -import google.registry.testing.AppEngineRule; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.Map; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Unit tests for {@link PublishDetailReportAction}. */ -@RunWith(JUnit4.class) -public class PublishDetailReportActionTest { - @Rule - public final AppEngineRule appEngine = AppEngineRule.builder() - .withDatastore() - .build(); - - private final DriveConnection driveConnection = mock(DriveConnection.class); - - private final PublishDetailReportAction action = new PublishDetailReportAction(); - private final GcsService gcsService = GcsServiceFactory.createGcsService(); - private final GcsUtils gcsUtils = new GcsUtils(gcsService, 1024); - - @Before - public void setUp() throws Exception { - action.driveConnection = driveConnection; - action.gcsUtils = gcsUtils; - - when(driveConnection.createFile( - anyString(), any(MediaType.class), anyString(), any(byte[].class))) - .thenReturn("drive-id-123"); - - persistResource(loadRegistrar("TheRegistrar").asBuilder().setDriveFolderId("0B-12345").build()); - - // Persist an empty GCS file to the local GCS service so that failure tests won't fail - // prematurely on the file not existing. - gcsService.createOrReplace( - new GcsFilename("mah-buckit", "some/folder/detail_report.csv"), - GcsFileOptions.getDefaultInstance(), - ByteBuffer.allocate(0)); - } - - @Test - public void testSuccess() throws Exception { - // Create a dummy file in the local GCS service to read in the servlet. - gcsService.createOrReplace( - new GcsFilename("mah-buckit", "some/folder/detail_report.csv"), - GcsFileOptions.getDefaultInstance(), - ByteBuffer.wrap("one,two,three\n".getBytes(UTF_8))); - - Map response = - action.handleJsonRequest(ImmutableMap.of( - REGISTRAR_ID_PARAM, "TheRegistrar", - GCS_BUCKET_PARAM, "mah-buckit", - GCS_FOLDER_PREFIX_PARAM, "some/folder/", - DETAIL_REPORT_NAME_PARAM, "detail_report.csv")); - - verify(driveConnection).createFile( - "detail_report.csv", MediaType.CSV_UTF_8, "0B-12345", "one,two,three\n".getBytes(UTF_8)); - assertThat(response).containsEntry("driveId", "drive-id-123"); - } - - @Test - public void testFailure_noRegistrarParameter() throws Exception { - BadRequestException thrown = - assertThrows( - BadRequestException.class, - () -> - action.handleJsonRequest( - ImmutableMap.of( - GCS_BUCKET_PARAM, "mah-buckit", - GCS_FOLDER_PREFIX_PARAM, "some/folder/", - DETAIL_REPORT_NAME_PARAM, "detail_report.csv"))); - assertThat(thrown).hasMessageThat().contains(REGISTRAR_ID_PARAM); - } - - @Test - public void testFailure_noGcsBucketParameter() throws Exception { - BadRequestException thrown = - assertThrows( - BadRequestException.class, - () -> - action.handleJsonRequest( - ImmutableMap.of( - REGISTRAR_ID_PARAM, "TheRegistrar", - GCS_FOLDER_PREFIX_PARAM, "some/folder/", - DETAIL_REPORT_NAME_PARAM, "detail_report.csv"))); - assertThat(thrown).hasMessageThat().contains(GCS_BUCKET_PARAM); - } - - @Test - public void testFailure_noGcsFolderPrefixParameter() throws Exception { - BadRequestException thrown = - assertThrows( - BadRequestException.class, - () -> - action.handleJsonRequest( - ImmutableMap.of( - REGISTRAR_ID_PARAM, "TheRegistrar", - GCS_BUCKET_PARAM, "mah-buckit", - DETAIL_REPORT_NAME_PARAM, "detail_report.csv"))); - assertThat(thrown).hasMessageThat().contains(GCS_FOLDER_PREFIX_PARAM); - } - - @Test - public void testFailure_noReportNameParameter() throws Exception { - BadRequestException thrown = - assertThrows( - BadRequestException.class, - () -> - action.handleJsonRequest( - ImmutableMap.of( - REGISTRAR_ID_PARAM, "TheRegistrar", - GCS_BUCKET_PARAM, "mah-buckit", - GCS_FOLDER_PREFIX_PARAM, "some/folder/"))); - assertThat(thrown).hasMessageThat().contains(DETAIL_REPORT_NAME_PARAM); - } - - @Test - public void testFailure_registrarNotFound() throws Exception { - BadRequestException thrown = - assertThrows( - BadRequestException.class, - () -> - action.handleJsonRequest( - ImmutableMap.of( - REGISTRAR_ID_PARAM, "FakeRegistrar", - GCS_BUCKET_PARAM, "mah-buckit", - GCS_FOLDER_PREFIX_PARAM, "some/folder/", - DETAIL_REPORT_NAME_PARAM, "detail_report.csv"))); - assertThat(thrown).hasMessageThat().contains("FakeRegistrar"); - } - - @Test - public void testFailure_registrarHasNoDriveFolder() throws Exception { - persistResource( - loadRegistrar("TheRegistrar").asBuilder().setDriveFolderId(null).build()); - BadRequestException thrown = - assertThrows( - BadRequestException.class, - () -> - action.handleJsonRequest( - ImmutableMap.of( - REGISTRAR_ID_PARAM, "TheRegistrar", - GCS_BUCKET_PARAM, "mah-buckit", - GCS_FOLDER_PREFIX_PARAM, "some/folder/", - DETAIL_REPORT_NAME_PARAM, "detail_report.csv"))); - assertThat(thrown).hasMessageThat().contains("drive folder"); - } - - @Test - public void testFailure_gcsBucketNotFound() throws Exception { - BadRequestException thrown = - assertThrows( - BadRequestException.class, - () -> - action.handleJsonRequest( - ImmutableMap.of( - REGISTRAR_ID_PARAM, "TheRegistrar", - GCS_BUCKET_PARAM, "fake-buckit", - GCS_FOLDER_PREFIX_PARAM, "some/folder/", - DETAIL_REPORT_NAME_PARAM, "detail_report.csv"))); - assertThat(thrown).hasMessageThat().contains("fake-buckit"); - } - - @Test - public void testFailure_gcsFileNotFound() throws Exception { - BadRequestException thrown = - assertThrows( - BadRequestException.class, - () -> - action.handleJsonRequest( - ImmutableMap.of( - REGISTRAR_ID_PARAM, "TheRegistrar", - GCS_BUCKET_PARAM, "mah-buckit", - GCS_FOLDER_PREFIX_PARAM, "some/folder/", - DETAIL_REPORT_NAME_PARAM, "fake_file.csv"))); - assertThat(thrown).hasMessageThat().contains("some/folder/fake_file.csv"); - } - - @Test - public void testFailure_driveApiThrowsException() throws Exception { - when(driveConnection.createFile( - anyString(), any(MediaType.class), anyString(), any(byte[].class))) - .thenThrow(new IOException("Drive is down")); - InternalServerErrorException thrown = - assertThrows( - InternalServerErrorException.class, - () -> - action.handleJsonRequest( - ImmutableMap.of( - REGISTRAR_ID_PARAM, "TheRegistrar", - GCS_BUCKET_PARAM, "mah-buckit", - GCS_FOLDER_PREFIX_PARAM, "some/folder/", - DETAIL_REPORT_NAME_PARAM, "detail_report.csv"))); - assertThat(thrown).hasMessageThat().contains("Drive is down"); - } -} diff --git a/javatests/google/registry/module/tools/testdata/tools_routing.txt b/javatests/google/registry/module/tools/testdata/tools_routing.txt index 551c7c187..40756e6f4 100644 --- a/javatests/google/registry/module/tools/testdata/tools_routing.txt +++ b/javatests/google/registry/module/tools/testdata/tools_routing.txt @@ -12,7 +12,6 @@ PATH CLASS METHODS OK AUTH /_dr/admin/verifyOte VerifyOteAction POST n INTERNAL,API APP ADMIN /_dr/epptool EppToolAction POST n INTERNAL,API APP ADMIN /_dr/loadtest LoadTestAction POST y INTERNAL,API APP ADMIN -/_dr/publishDetailReport PublishDetailReportAction POST n INTERNAL,API APP ADMIN /_dr/task/generateZoneFiles GenerateZoneFilesAction POST n INTERNAL,API APP ADMIN /_dr/task/killAllCommitLogs KillAllCommitLogsAction POST n INTERNAL APP IGNORED /_dr/task/killAllEppResources KillAllEppResourcesAction POST n INTERNAL APP IGNORED