From 477617eec99ec6eeaea6b755aa8de3b460da9455 Mon Sep 17 00:00:00 2001 From: larryruili Date: Tue, 8 Aug 2017 15:46:59 -0700 Subject: [PATCH] Add activity report generation code This adds Bigquery API client code to generate the activity reports from our now standardSQL queries. The naming mirrors that of RDE (Staging generates the reports and uploads them to GCS). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=164656344 --- .../registry/bigquery/BigqueryConnection.java | 23 ++- .../env/common/backend/WEB-INF/web.xml | 11 ++ .../backend/BackendRequestComponent.java | 2 + .../ActivityReportingQueryBuilder.java | 84 +++++--- java/google/registry/reporting/BUILD | 4 + .../reporting/IcannReportingModule.java | 36 ++++ .../IcannReportingStagingAction.java | 185 ++++++++++++++++++ .../reporting/IcannReportingUploadAction.java | 27 +-- .../sql/activity_report_aggregation.sql | 59 +++--- .../registry/reporting/sql/dns_counts.sql | 1 + .../registry/reporting/sql/epp_metrics.sql | 1 + .../registry/reporting/sql/monthly_logs.sql | 1 + .../sql/registrar_operating_status.sql | 1 + .../registry/reporting/sql/whois_counts.sql | 1 + .../backend/testdata/backend_routing.txt | 1 + .../ActivityReportingQueryBuilderTest.java | 38 ++-- javatests/google/registry/reporting/BUILD | 2 + .../IcannReportingStagingActionTest.java | 149 ++++++++++++++ .../IcannReportingUploadActionTest.java | 35 +++- .../activity_report_aggregation_test.sql | 59 +++--- .../reporting/testdata/dns_counts_test.sql | 1 + .../reporting/testdata/epp_metrics_test.sql | 3 +- .../reporting/testdata/monthly_logs_test.sql | 1 + .../registrar_operating_status_test.sql | 1 + .../reporting/testdata/whois_counts_test.sql | 3 +- 25 files changed, 612 insertions(+), 117 deletions(-) create mode 100644 java/google/registry/reporting/IcannReportingStagingAction.java create mode 100644 javatests/google/registry/reporting/IcannReportingStagingActionTest.java diff --git a/java/google/registry/bigquery/BigqueryConnection.java b/java/google/registry/bigquery/BigqueryConnection.java index e19b1829d..38ef5e9ef 100644 --- a/java/google/registry/bigquery/BigqueryConnection.java +++ b/java/google/registry/bigquery/BigqueryConnection.java @@ -466,6 +466,25 @@ public class BigqueryConnection implements AutoCloseable { directExecutor()); } + /** + * Returns the result of calling queryToLocalTable, but synchronously to avoid spawning new + * background threads, which App Engine doesn't support. + * + * @see + * App Engine Runtime + * + *

Returns the results of the query in an ImmutableTable on success. + */ + public ImmutableTable queryToLocalTableSync(String querySql) + throws Exception { + Job job = new Job() + .setConfiguration(new JobConfiguration() + .setQuery(new JobConfigurationQuery() + .setQuery(querySql) + .setDefaultDataset(getDataset()))); + return getQueryResults(runJob(job)); + } + /** * Returns the query results for the given job as an ImmutableTable, row-keyed by row number * (indexed from 1), column-keyed by the TableFieldSchema for that field, and with the value @@ -590,7 +609,7 @@ public class BigqueryConnection implements AutoCloseable { } /** - * Lanuch a job, wait for it to complete, but do not check for errors. + * Launch a job, wait for it to complete, but do not check for errors. * * @throws BigqueryJobFailureException */ @@ -599,7 +618,7 @@ public class BigqueryConnection implements AutoCloseable { } /** - * Lanuch a job, but do not wait for it to complete. + * Launch a job, but do not wait for it to complete. * * @throws BigqueryJobFailureException */ diff --git a/java/google/registry/env/common/backend/WEB-INF/web.xml b/java/google/registry/env/common/backend/WEB-INF/web.xml index 716ab146c..d976425d5 100644 --- a/java/google/registry/env/common/backend/WEB-INF/web.xml +++ b/java/google/registry/env/common/backend/WEB-INF/web.xml @@ -57,6 +57,17 @@ /_dr/task/brdaCopy + + + backend-servlet + /_dr/task/icannReportingStaging + +