mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 16:07:15 +02:00
Clean up billing MR work
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=136196221
This commit is contained in:
parent
afcd04f190
commit
3c36b6b928
7 changed files with 4 additions and 190 deletions
|
@ -67,6 +67,8 @@ import org.joda.time.DateTime;
|
||||||
* {@code cursorTime}) represents the inclusive lower bound on the range of billing times that will
|
* {@code cursorTime}) represents the inclusive lower bound on the range of billing times that will
|
||||||
* be expanded as a result of the job (the exclusive upper bound being the execution time of the
|
* be expanded as a result of the job (the exclusive upper bound being the execution time of the
|
||||||
* job).
|
* job).
|
||||||
|
*
|
||||||
|
* <p>NOTE: This is not yet production ready and not configured to run.
|
||||||
*/
|
*/
|
||||||
@Action(path = "/_dr/task/expandRecurringBillingEvents")
|
@Action(path = "/_dr/task/expandRecurringBillingEvents")
|
||||||
public class ExpandRecurringBillingEventsAction implements Runnable {
|
public class ExpandRecurringBillingEventsAction implements Runnable {
|
||||||
|
|
|
@ -72,17 +72,6 @@
|
||||||
<url-pattern>/_dr/task/resaveAllEppResources</url-pattern>
|
<url-pattern>/_dr/task/resaveAllEppResources</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
<!-- Mapreduce to count recurring billing events (to test the child entity reader). -->
|
|
||||||
<servlet-mapping>
|
|
||||||
<servlet-name>tools-servlet</servlet-name>
|
|
||||||
<url-pattern>/_dr/task/countRecurringBillingEvents</url-pattern>
|
|
||||||
</servlet-mapping>
|
|
||||||
|
|
||||||
<!-- Mapreduce to backfill new autorenew flag on recurring billing events. -->
|
|
||||||
<servlet-mapping>
|
|
||||||
<servlet-name>tools-servlet</servlet-name>
|
|
||||||
<url-pattern>/_dr/task/backfillAutorenewBillingFlag</url-pattern>
|
|
||||||
</servlet-mapping>
|
|
||||||
|
|
||||||
<!-- Mapreduce to delete EppResources, children, and indices. -->
|
<!-- Mapreduce to delete EppResources, children, and indices. -->
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
|
|
|
@ -42,8 +42,6 @@ import google.registry.tools.server.ResaveAllEppResourcesAction;
|
||||||
import google.registry.tools.server.ToolsServerModule;
|
import google.registry.tools.server.ToolsServerModule;
|
||||||
import google.registry.tools.server.UpdatePremiumListAction;
|
import google.registry.tools.server.UpdatePremiumListAction;
|
||||||
import google.registry.tools.server.VerifyOteAction;
|
import google.registry.tools.server.VerifyOteAction;
|
||||||
import google.registry.tools.server.javascrap.BackfillAutorenewBillingFlagAction;
|
|
||||||
import google.registry.tools.server.javascrap.CountRecurringBillingEventsAction;
|
|
||||||
import google.registry.tools.server.javascrap.RefreshAllDomainsAction;
|
import google.registry.tools.server.javascrap.RefreshAllDomainsAction;
|
||||||
|
|
||||||
/** Dagger component with per-request lifetime for "tools" App Engine module. */
|
/** Dagger component with per-request lifetime for "tools" App Engine module. */
|
||||||
|
@ -59,8 +57,6 @@ import google.registry.tools.server.javascrap.RefreshAllDomainsAction;
|
||||||
WhiteboxModule.class,
|
WhiteboxModule.class,
|
||||||
})
|
})
|
||||||
interface ToolsRequestComponent {
|
interface ToolsRequestComponent {
|
||||||
BackfillAutorenewBillingFlagAction backfillAutorenewBillingFlagAction();
|
|
||||||
CountRecurringBillingEventsAction countRecurringBillingEventsAction();
|
|
||||||
CreateGroupsAction createGroupsAction();
|
CreateGroupsAction createGroupsAction();
|
||||||
CreatePremiumListAction createPremiumListAction();
|
CreatePremiumListAction createPremiumListAction();
|
||||||
DeleteEntityAction deleteEntityAction();
|
DeleteEntityAction deleteEntityAction();
|
||||||
|
|
|
@ -9,6 +9,7 @@ java_library(
|
||||||
name = "javascrap",
|
name = "javascrap",
|
||||||
srcs = glob(["*.java"]),
|
srcs = glob(["*.java"]),
|
||||||
deps = [
|
deps = [
|
||||||
|
"//java/com/google/common/annotations",
|
||||||
"//java/com/google/common/base",
|
"//java/com/google/common/base",
|
||||||
"//java/com/google/common/collect",
|
"//java/com/google/common/collect",
|
||||||
"//third_party/java/appengine:appengine-api",
|
"//third_party/java/appengine:appengine-api",
|
||||||
|
|
|
@ -1,97 +0,0 @@
|
||||||
// Copyright 2016 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.tools.server.javascrap;
|
|
||||||
|
|
||||||
import static google.registry.mapreduce.MapreduceRunner.PARAM_DRY_RUN;
|
|
||||||
import static google.registry.mapreduce.inputs.EppResourceInputs.createChildEntityInput;
|
|
||||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
|
||||||
import static google.registry.util.PipelineUtils.createJobPath;
|
|
||||||
|
|
||||||
import com.google.appengine.tools.mapreduce.Input;
|
|
||||||
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.model.billing.BillingEvent.Flag;
|
|
||||||
import google.registry.model.billing.BillingEvent.Recurring;
|
|
||||||
import google.registry.model.domain.DomainResource;
|
|
||||||
import google.registry.request.Action;
|
|
||||||
import google.registry.request.Parameter;
|
|
||||||
import google.registry.request.Response;
|
|
||||||
import google.registry.util.FormattingLogger;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
/** A mapreduce that backfills new {@link Flag#AUTO_RENEW} flag on recurring billing events. */
|
|
||||||
@Action(path = "/_dr/task/backfillAutorenewBillingFlag")
|
|
||||||
public class BackfillAutorenewBillingFlagAction implements Runnable {
|
|
||||||
|
|
||||||
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
|
|
||||||
|
|
||||||
@Inject MapreduceRunner mrRunner;
|
|
||||||
@Inject @Parameter(PARAM_DRY_RUN) boolean isDryRun;
|
|
||||||
@Inject Response response;
|
|
||||||
@Inject BackfillAutorenewBillingFlagAction() {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
response.sendJavaScriptRedirect(createJobPath(mrRunner
|
|
||||||
.setJobName("Backfill AUTO_RENEW flag on Recurring billing events")
|
|
||||||
.setModuleName("tools")
|
|
||||||
.runMapOnly(
|
|
||||||
new BackfillAutorenewBillingFlagMapper(isDryRun),
|
|
||||||
ImmutableList.of(createRecurringInput()))));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Input<? extends Recurring> createRecurringInput() {
|
|
||||||
return createChildEntityInput(
|
|
||||||
ImmutableSet.<Class<? extends DomainResource>>of(DomainResource.class),
|
|
||||||
ImmutableSet.<Class<? extends Recurring>>of(Recurring.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Mapper to count BillingEvent.Recurring resources. */
|
|
||||||
public static class BackfillAutorenewBillingFlagMapper extends Mapper<Recurring, Void, Void> {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -6576637759905280988L;
|
|
||||||
|
|
||||||
private final boolean isDryRun;
|
|
||||||
|
|
||||||
public BackfillAutorenewBillingFlagMapper(boolean isDryRun) {
|
|
||||||
this.isDryRun = isDryRun;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void map(final Recurring recurring) {
|
|
||||||
try {
|
|
||||||
// A note on how this works: Since OnLoad makes the backfill change for us, all we need to
|
|
||||||
// do is check that this condition exists on the loaded entity, and just re-save to persist
|
|
||||||
// the new data to datastore.
|
|
||||||
if (!isDryRun) {
|
|
||||||
ofy().transactNew(new VoidWork() {
|
|
||||||
@Override
|
|
||||||
public void vrun() {
|
|
||||||
ofy().save().entity(ofy().load().entity(recurring).now());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
getContext().incrementCounter("Saved Recurring billing events");
|
|
||||||
}
|
|
||||||
getContext().incrementCounter("Recurring billing events encountered");
|
|
||||||
} catch (Throwable t) {
|
|
||||||
logger.severe(t, "Error while backfilling AUTO_RENEW flags.");
|
|
||||||
getContext().incrementCounter("error: " + t.getClass().getSimpleName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,73 +0,0 @@
|
||||||
// Copyright 2016 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.tools.server.javascrap;
|
|
||||||
|
|
||||||
import static google.registry.mapreduce.inputs.EppResourceInputs.createChildEntityInput;
|
|
||||||
import static google.registry.util.PipelineUtils.createJobPath;
|
|
||||||
|
|
||||||
import com.google.appengine.tools.mapreduce.Input;
|
|
||||||
import com.google.appengine.tools.mapreduce.Mapper;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import google.registry.mapreduce.MapreduceRunner;
|
|
||||||
import google.registry.model.EppResource;
|
|
||||||
import google.registry.model.billing.BillingEvent.Recurring;
|
|
||||||
import google.registry.request.Action;
|
|
||||||
import google.registry.request.Response;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A mapreduce that counts all BillingEvent.Recurring entities.
|
|
||||||
*
|
|
||||||
* <p>This is a test of the ChildEntityInput/ChildEntityReader classes.
|
|
||||||
*/
|
|
||||||
@Action(path = "/_dr/task/countRecurringBillingEvents")
|
|
||||||
public class CountRecurringBillingEventsAction implements Runnable {
|
|
||||||
|
|
||||||
// TODO(b/27562876): Delete this mapreduce once tested in production.
|
|
||||||
|
|
||||||
@Inject MapreduceRunner mrRunner;
|
|
||||||
@Inject Response response;
|
|
||||||
@Inject CountRecurringBillingEventsAction() {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
response.sendJavaScriptRedirect(createJobPath(mrRunner
|
|
||||||
.setJobName("Count recurring billing events")
|
|
||||||
.setModuleName("tools")
|
|
||||||
.runMapOnly(
|
|
||||||
new CountRecurringBillingEventsMapper(),
|
|
||||||
ImmutableList.of(createRecurringInput()))));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Input<? extends Recurring> createRecurringInput() {
|
|
||||||
return createChildEntityInput(
|
|
||||||
ImmutableSet.<Class<? extends EppResource>>of(EppResource.class),
|
|
||||||
ImmutableSet.<Class<? extends Recurring>>of(Recurring.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Mapper to count BillingEvent.Recurring resources. */
|
|
||||||
public static class CountRecurringBillingEventsMapper extends Mapper<Recurring, Void, Void> {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -8547238315947793512L;
|
|
||||||
|
|
||||||
public CountRecurringBillingEventsMapper() {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void map(final Recurring recurring) {
|
|
||||||
getContext().incrementCounter("recurring billing events");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -12,6 +12,7 @@ java_library(
|
||||||
name = "batch",
|
name = "batch",
|
||||||
srcs = glob(["*.java"]),
|
srcs = glob(["*.java"]),
|
||||||
deps = [
|
deps = [
|
||||||
|
"//java/com/google/common/annotations",
|
||||||
"//java/com/google/common/base",
|
"//java/com/google/common/base",
|
||||||
"//java/com/google/common/collect",
|
"//java/com/google/common/collect",
|
||||||
"//java/com/google/common/io",
|
"//java/com/google/common/io",
|
||||||
|
@ -30,12 +31,7 @@ java_library(
|
||||||
"//third_party/java/servlet/servlet_api",
|
"//third_party/java/servlet/servlet_api",
|
||||||
"//third_party/java/truth",
|
"//third_party/java/truth",
|
||||||
"//java/google/registry/batch",
|
"//java/google/registry/batch",
|
||||||
"//java/google/registry/config",
|
|
||||||
"//java/google/registry/gcs",
|
|
||||||
"//java/google/registry/groups",
|
|
||||||
"//java/google/registry/mapreduce",
|
|
||||||
"//java/google/registry/model",
|
"//java/google/registry/model",
|
||||||
"//java/google/registry/request",
|
|
||||||
"//java/google/registry/util",
|
"//java/google/registry/util",
|
||||||
"//javatests/google/registry/testing",
|
"//javatests/google/registry/testing",
|
||||||
"//javatests/google/registry/testing/mapreduce",
|
"//javatests/google/registry/testing/mapreduce",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue