Action to delete all cross-tld entities.

Plus refactoring of the KillAllXXXActions and tests to share
common code.

This essentially completes the KillAll []s. We can now reliably
clean out everything except for:
 * Lock - harmless to leave alone or delete from the gae console
 * GaeUserIdConverter - same
 * RdeRevision - filed [] to track, but harmless if not cleaned up
 * ForeignKeyHostIndex of renamed hosts - tracked in []
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=120781975
This commit is contained in:
cgoldfeder 2016-04-25 22:09:58 -07:00 committed by Justine Tunney
parent ac2f17e10f
commit a41677aea1
9 changed files with 508 additions and 205 deletions

View file

@ -112,6 +112,12 @@
<url-pattern>/_dr/task/killAllCommitLogs</url-pattern>
</servlet-mapping>
<!-- Mapreduce to delete all cross-tld entities. -->
<servlet-mapping>
<servlet-name>tools-servlet</servlet-name>
<url-pattern>/_dr/task/killAllCrossTld</url-pattern>
</servlet-mapping>
<!-- This path serves up the App Engine results page for mapreduce runs. -->
<servlet>
<servlet-name>mapreduce</servlet-name>

View file

@ -26,6 +26,7 @@ import com.google.domain.registry.tools.server.DeleteEntityAction;
import com.google.domain.registry.tools.server.DeleteProberDataAction;
import com.google.domain.registry.tools.server.GenerateZoneFilesAction;
import com.google.domain.registry.tools.server.KillAllCommitLogsAction;
import com.google.domain.registry.tools.server.KillAllCrossTldEntitiesAction;
import com.google.domain.registry.tools.server.KillAllEppResourcesAction;
import com.google.domain.registry.tools.server.ListDomainsAction;
import com.google.domain.registry.tools.server.ListHostsAction;
@ -60,6 +61,7 @@ interface ToolsRequestComponent {
DeleteProberDataAction deleteProberDataAction();
GenerateZoneFilesAction generateZoneFilesAction();
KillAllCommitLogsAction killAllCommitLogsAction();
KillAllCrossTldEntitiesAction killAllCrossTldEntitiesAction();
KillAllEppResourcesAction killAllEppResourcesAction();
ListDomainsAction listDomainsAction();
ListHostsAction listHostsAction();

View file

@ -15,16 +15,15 @@
package com.google.domain.registry.tools.server;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.Lists.partition;
import static com.google.domain.registry.model.ofy.ObjectifyService.ofy;
import static com.google.domain.registry.request.Action.Method.POST;
import static com.google.domain.registry.util.PipelineUtils.createJobPath;
import com.google.appengine.tools.mapreduce.Input;
import com.google.appengine.tools.mapreduce.Mapper;
import com.google.appengine.tools.mapreduce.inputs.InMemoryInput;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.domain.registry.config.RegistryEnvironment;
import com.google.domain.registry.mapreduce.MapreduceAction;
import com.google.domain.registry.mapreduce.MapreduceRunner;
@ -48,27 +47,27 @@ public class KillAllCommitLogsAction implements MapreduceAction {
@Inject KillAllCommitLogsAction() {}
@Override
public void run() {
public final void run() {
checkArgument( // safety
RegistryEnvironment.get() == RegistryEnvironment.CRASH
|| RegistryEnvironment.get() == RegistryEnvironment.UNITTEST,
"DO NOT RUN ANYWHERE ELSE EXCEPT CRASH OR TESTS.");
// Create a in-memory input, assigning each bucket to its own shard for maximum parallelization,
// with one extra shard for the CommitLogCheckpointRoot.
Input<Key<?>> input = new InMemoryInput<>(
Lists.partition(
FluentIterable
.from(Arrays.<Key<?>>asList(CommitLogCheckpointRoot.getKey()))
.append(CommitLogBucket.getAllBucketKeys())
.toList(),
1));
response.sendJavaScriptRedirect(createJobPath(mrRunner
.setJobName("Delete all commit logs")
.setJobName("Delete all commit logs and checkpoints")
.setModuleName("tools")
.runMapreduce(
new KillAllCommitLogsMapper(),
new KillAllEntitiesReducer(),
ImmutableList.of(input))));
// Create a in-memory input, assigning each bucket to its own shard for maximum
// parallelization, with one extra shard for the CommitLogCheckpointRoot.
ImmutableList.of(
new InMemoryInput<>(
partition(
FluentIterable
.from(Arrays.<Key<?>>asList(CommitLogCheckpointRoot.getKey()))
.append(CommitLogBucket.getAllBucketKeys())
.toList(),
1))))));
}
/**

View file

@ -0,0 +1,105 @@
// Copyright 2016 The Domain Registry 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 com.google.domain.registry.tools.server;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.domain.registry.model.common.EntityGroupRoot.getCrossTldKey;
import static com.google.domain.registry.model.ofy.ObjectifyService.ofy;
import static com.google.domain.registry.request.Action.Method.POST;
import static com.google.domain.registry.util.PipelineUtils.createJobPath;
import com.google.appengine.tools.mapreduce.Mapper;
import com.google.common.collect.ImmutableList;
import com.google.domain.registry.config.RegistryEnvironment;
import com.google.domain.registry.mapreduce.MapreduceAction;
import com.google.domain.registry.mapreduce.MapreduceRunner;
import com.google.domain.registry.mapreduce.inputs.NullInput;
import com.google.domain.registry.model.common.EntityGroupRoot;
import com.google.domain.registry.request.Action;
import com.google.domain.registry.request.Response;
import com.googlecode.objectify.Key;
import javax.inject.Inject;
/**
* Deletes all cross tld entities in datastore.
*
* <p>This doesn't really need to be a mapreduce, but doing so makes it consistent with the other
* kill-all actions, and gives us retries, a dashboard and counters for free.
*/
@Action(path = "/_dr/task/killAllCrossTld", method = POST)
public class KillAllCrossTldEntitiesAction implements MapreduceAction {
@Inject MapreduceRunner mrRunner;
@Inject Response response;
@Inject KillAllCrossTldEntitiesAction() {}
@Override
public final void run() {
checkArgument( // safety
RegistryEnvironment.get() == RegistryEnvironment.CRASH
|| RegistryEnvironment.get() == RegistryEnvironment.UNITTEST,
"DO NOT RUN ANYWHERE ELSE EXCEPT CRASH OR TESTS.");
response.sendJavaScriptRedirect(createJobPath(mrRunner
.setJobName("Delete all cross-tld entities")
.setModuleName("tools")
.runMapreduce(
new KillAllCrossTldEntitiesMapper(),
new KillAllEntitiesReducer(),
ImmutableList.of(new NullInput<Object>()))));
}
/**
* Mapper to delete all descendants of {@link EntityGroupRoot#getCrossTldKey()}.
*
* <p>This will delete:
* <ul>
* <i>{@code ClaimsListShard}
* <i>{@code ClaimsListSingleton}
* <i>{@link EntityGroupRoot}
* <i>{@code LogsExportCursor}
* <i>{@code PremiumList}
* <i>{@code PremiumListEntry}
* <i>{@code Registrar}
* <i>{@code RegistrarBillingEntry}
* <i>{@code RegistrarContact}
* <i>{@code RegistrarCredit}
* <i>{@code RegistrarCreditBalance}
* <i>{@code Registry}
* <i>{@code RegistryCursor}
* <i>{@code ReservedList}
* <i>{@code ServerSecret}
* <i>{@code SignedMarkRevocationList}
* <i>{@code TmchCrl}
* </ul>
*/
static class KillAllCrossTldEntitiesMapper extends Mapper<Object, Key<?>, Key<?>> {
private static final long serialVersionUID = 8343696167876596542L;
@Override
public void map(Object ignored) {
// There will be exactly one input to the mapper, and we ignore it.
Key<EntityGroupRoot> crossTldKey = getCrossTldKey();
for (Key<Object> key : ofy().load().ancestor(crossTldKey).keys()) {
emit(crossTldKey, key);
getContext().incrementCounter("entities emitted");
getContext().incrementCounter(String.format("%s emitted", key.getKind()));
}
}
}
}

View file

@ -47,7 +47,7 @@ public class KillAllEppResourcesAction implements MapreduceAction {
@Inject KillAllEppResourcesAction() {}
@Override
public void run() {
public final void run() {
checkArgument( // safety
RegistryEnvironment.get() == RegistryEnvironment.CRASH
|| RegistryEnvironment.get() == RegistryEnvironment.UNITTEST,
@ -61,25 +61,26 @@ public class KillAllEppResourcesAction implements MapreduceAction {
ImmutableList.of(EppResourceInputs.createIndexInput()))));
}
/**
* Mapper to delete an {@link EppResourceIndex}, its referent, all descendants of each referent,
* and the {@link ForeignKeyIndex} or {@link DomainApplicationIndex} of the referent, as
* appropriate.
*
* <p>This will delete:
* <ul>
* <li>All {@link ForeignKeyIndex} types
* <li>{@link DomainApplicationIndex}
* <li>{@link EppResourceIndex}
* <li>All {@link EppResource} types
* <li>{@code HistoryEntry}
* <li>All {@code BillingEvent} types
* <li>All {@code PollMessage} types
* </ul>
*/
static class KillAllEppResourcesMapper extends Mapper<EppResourceIndex, Key<?>, Key<?>> {
private static final long serialVersionUID = 8205309000002507407L;
/**
* Delete an {@link EppResourceIndex}, its referent, all descendants of each referent, and the
* {@link ForeignKeyIndex} or {@link DomainApplicationIndex} of the referent, as appropriate.
*
* <p>This will delete:
* <ul>
* <li>All {@link ForeignKeyIndex} types
* <li>{@link DomainApplicationIndex}
* <li>{@link EppResourceIndex}
* <li>All {@link EppResource} types
* <li>{@code HistoryEntry}
* <li>All {@code BillingEvent} types
* <li>All {@code PollMessage} types
* </ul>
*/
@Override
public void map(final EppResourceIndex eri) {
Key<EppResourceIndex> eriKey = Key.create(eri);