Remove cursor migration scrap tools

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=126935942
This commit is contained in:
ctingue 2016-07-08 12:24:54 -07:00 committed by Ben McIlwain
parent 3896dfbb4a
commit 458a673601
3 changed files with 0 additions and 155 deletions

View file

@ -18,10 +18,8 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedMap;
import google.registry.tools.javascrap.DeleteOldCursorsCommand;
import google.registry.tools.javascrap.LoadAndResaveCommand; import google.registry.tools.javascrap.LoadAndResaveCommand;
import google.registry.tools.javascrap.RemoveIpAddressCommand; import google.registry.tools.javascrap.RemoveIpAddressCommand;
import google.registry.tools.javascrap.VerifyDualWrittenCursorsCommand;
/** Container class to create and run remote commands against a datastore instance. */ /** Container class to create and run remote commands against a datastore instance. */
public final class RegistryTool { public final class RegistryTool {
@ -45,7 +43,6 @@ public final class RegistryTool {
.put("delete_credit", DeleteCreditCommand.class) .put("delete_credit", DeleteCreditCommand.class)
.put("delete_entity", DeleteEntityCommand.class) .put("delete_entity", DeleteEntityCommand.class)
.put("delete_epp_resource", DeleteEppResourceCommand.class) .put("delete_epp_resource", DeleteEppResourceCommand.class)
.put("delete_old_cursors", DeleteOldCursorsCommand.class)
.put("delete_premium_list", DeletePremiumListCommand.class) .put("delete_premium_list", DeletePremiumListCommand.class)
.put("delete_reserved_list", DeleteReservedListCommand.class) .put("delete_reserved_list", DeleteReservedListCommand.class)
.put("encrypt_escrow_deposit", EncryptEscrowDepositCommand.class) .put("encrypt_escrow_deposit", EncryptEscrowDepositCommand.class)
@ -78,7 +75,6 @@ public final class RegistryTool {
.put("update_tld", UpdateTldCommand.class) .put("update_tld", UpdateTldCommand.class)
.put("upload_claims_list", UploadClaimsListCommand.class) .put("upload_claims_list", UploadClaimsListCommand.class)
.put("validate_escrow_deposit", ValidateEscrowDepositCommand.class) .put("validate_escrow_deposit", ValidateEscrowDepositCommand.class)
.put("verify_dual_written_cursors", VerifyDualWrittenCursorsCommand.class)
.build(); .build();
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View file

@ -1,38 +0,0 @@
// 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 google.registry.tools.javascrap;
import static google.registry.model.ofy.ObjectifyService.ofy;
import com.beust.jcommander.Parameters;
import google.registry.model.common.EntityGroupRoot;
import google.registry.model.registry.RegistryCursor;
import google.registry.tools.MutatingCommand;
/** Deletes old {@link RegistryCursor} entities. */
@Parameters(
separators = " =",
commandDescription = "Delete old RegistryCursor entities")
public final class DeleteOldCursorsCommand extends MutatingCommand {
@Override
protected void init() throws Exception {
for (RegistryCursor cursor :
ofy().load().type(RegistryCursor.class).ancestor(EntityGroupRoot.getCrossTldKey())) {
stageEntityChange(cursor, null);
}
}
}

View file

@ -1,113 +0,0 @@
// 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 google.registry.tools.javascrap;
import static google.registry.model.ofy.ObjectifyService.ofy;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.beust.jcommander.Parameters;
import com.googlecode.objectify.Key;
import google.registry.model.common.Cursor;
import google.registry.model.common.EntityGroupRoot;
import google.registry.model.registry.Registry;
import google.registry.model.registry.RegistryCursor;
import google.registry.tools.Command.RemoteApiCommand;
import org.joda.time.DateTime;
import java.util.HashMap;
import java.util.Map.Entry;
/**
* Scrap command that loads all legacy {@link RegistryCursor} entities and new {@link Cursor}
* entities, and reports any mismatches (after filtering out new {@code RECURRING_BILLING} cursors).
*/
@Parameters(separators = " =", commandDescription = "Verify dual-written cursors.")
public class VerifyDualWrittenCursorsCommand implements RemoteApiCommand {
@Override
public void run() throws Exception {
Iterable<Cursor> cursors =
ofy().load().type(Cursor.class).ancestor(EntityGroupRoot.getCrossTldKey());
Iterable<RegistryCursor> registryCursors =
ofy().load().type(RegistryCursor.class).ancestor(EntityGroupRoot.getCrossTldKey());
HashMap<String, Cursor> cursorMap = Maps.newHashMap();
HashMap<String, RegistryCursor> registryCursorMap = Maps.newHashMap();
// Build map of key name to new cursor.
for (Cursor c : cursors) {
String keyName = Key.create(c).getName();
if (!keyName.substring(keyName.indexOf('_') + 1).endsWith(
Cursor.CursorType.RECURRING_BILLING.toString())) {
cursorMap.put(keyName, c);
}
}
// Build map of key name to old RegistryCursor.
for (RegistryCursor rc : registryCursors) {
Key<RegistryCursor> key = Key.create(rc);
registryCursorMap.put(
String.format(
"%s_%s",
key.getParent().getString(),
key.getName()),
rc);
}
// Iterate through new cursor map, match to old RegistryCursor and check timestamp if a match
// exists, or report missing RegistryCursor otherwise.
for (Entry<String, Cursor> entry : cursorMap.entrySet()) {
String key = entry.getKey();
String registryKey = key.substring(0, key.indexOf('_'));
String cursorType = key.substring(key.indexOf('_') + 1);
Registry registry = Registry.get(Key.create(registryKey).getName());
RegistryCursor registryCursor = registryCursorMap.get(entry.getKey());
if (registryCursor == null) {
System.out.println(
String.format(
"RegistryCursor missing: TLD %s, cursorType %s",
registry.getTldStr(),
cursorType));
} else {
DateTime cursorTime = entry.getValue().getCursorTime();
DateTime matchingCursorTime =
RegistryCursor.load(registry, RegistryCursor.CursorType.valueOf(cursorType)).get();
if (!cursorTime.equals(matchingCursorTime)) {
System.out.println(
String.format(
"Mismatch for cursor for type %s and tld %s (old cursor: %s, new cursor: %s)",
cursorType,
registry.getTldStr(),
cursorTime,
matchingCursorTime));
}
}
}
// Perform set differences by matching new-style cursor names, report any discrepancies.
for (String s : Sets.difference(registryCursorMap.keySet(), cursorMap.keySet())) {
String registryKey = s.substring(0, s.indexOf('_'));
String cursorType = s.substring(s.indexOf('_') + 1);
Registry registry = Registry.get(Key.create(registryKey).getName());
System.out.println(
String.format("Cursor missing: TLD %s, cursorType %s", registry.getTldStr(), cursorType));
}
}
}