From 5cb2a0a430846a798c6dbe5a566834bd08275a8f Mon Sep 17 00:00:00 2001 From: Ben McIlwain Date: Tue, 12 Jul 2022 16:49:16 -0400 Subject: [PATCH] Re-add database migration state commands (#1702) * Re-add database migration state commands These were removed in PR #1661, but we do still need them for the time being until we complete the ID migration as well. --- .../GetDatabaseMigrationStateCommand.java | 36 ++++ .../google/registry/tools/RegistryTool.java | 2 + .../SetDatabaseMigrationStateCommand.java | 72 +++++++ .../tools/params/TransitionListParameter.java | 9 + .../DatabaseMigrationStateScheduleTest.java | 187 ++++++++++++++++++ .../registry/testing/DatabaseHelper.java | 102 ++++++++++ .../GetDatabaseMigrationStateCommandTest.java | 66 +++++++ .../SetDatabaseMigrationStateCommandTest.java | 184 +++++++++++++++++ 8 files changed, 658 insertions(+) create mode 100644 core/src/main/java/google/registry/tools/GetDatabaseMigrationStateCommand.java create mode 100644 core/src/main/java/google/registry/tools/SetDatabaseMigrationStateCommand.java create mode 100644 core/src/test/java/google/registry/model/common/DatabaseMigrationStateScheduleTest.java create mode 100644 core/src/test/java/google/registry/tools/GetDatabaseMigrationStateCommandTest.java create mode 100644 core/src/test/java/google/registry/tools/SetDatabaseMigrationStateCommandTest.java diff --git a/core/src/main/java/google/registry/tools/GetDatabaseMigrationStateCommand.java b/core/src/main/java/google/registry/tools/GetDatabaseMigrationStateCommand.java new file mode 100644 index 000000000..8a4c680f2 --- /dev/null +++ b/core/src/main/java/google/registry/tools/GetDatabaseMigrationStateCommand.java @@ -0,0 +1,36 @@ +// Copyright 2021 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; + +import com.beust.jcommander.Parameters; +import google.registry.model.annotations.DeleteAfterMigration; +import google.registry.model.common.DatabaseMigrationStateSchedule; +import google.registry.model.common.DatabaseMigrationStateSchedule.MigrationState; +import google.registry.model.common.DatabaseMigrationStateSchedule.MigrationStateTransition; +import google.registry.model.common.TimedTransitionProperty; + +/** A command to check the current Registry 3.0 migration state of the database. */ +@DeleteAfterMigration +@Parameters(separators = " =", commandDescription = "Check current Registry 3.0 migration state") +public class GetDatabaseMigrationStateCommand implements CommandWithRemoteApi { + + @Override + public void run() throws Exception { + TimedTransitionProperty migrationSchedule = + DatabaseMigrationStateSchedule.get(); + System.out.println( + String.format("Current migration schedule: %s", migrationSchedule.toValueMap())); + } +} diff --git a/core/src/main/java/google/registry/tools/RegistryTool.java b/core/src/main/java/google/registry/tools/RegistryTool.java index 3a2d4fdab..b3f1f5092 100644 --- a/core/src/main/java/google/registry/tools/RegistryTool.java +++ b/core/src/main/java/google/registry/tools/RegistryTool.java @@ -65,6 +65,7 @@ public final class RegistryTool { .put("get_allocation_token", GetAllocationTokenCommand.class) .put("get_claims_list", GetClaimsListCommand.class) .put("get_contact", GetContactCommand.class) + .put("get_database_migration_state", GetDatabaseMigrationStateCommand.class) .put("get_domain", GetDomainCommand.class) .put("get_history_entries", GetHistoryEntriesCommand.class) .put("get_host", GetHostCommand.class) @@ -96,6 +97,7 @@ public final class RegistryTool { .put("resave_environment_entities", ResaveEnvironmentEntitiesCommand.class) .put("save_sql_credential", SaveSqlCredentialCommand.class) .put("send_escrow_report_to_icann", SendEscrowReportToIcannCommand.class) + .put("set_database_migration_state", SetDatabaseMigrationStateCommand.class) .put("set_num_instances", SetNumInstancesCommand.class) .put("setup_ote", SetupOteCommand.class) .put("uniform_rapid_suspension", UniformRapidSuspensionCommand.class) diff --git a/core/src/main/java/google/registry/tools/SetDatabaseMigrationStateCommand.java b/core/src/main/java/google/registry/tools/SetDatabaseMigrationStateCommand.java new file mode 100644 index 000000000..f880eced6 --- /dev/null +++ b/core/src/main/java/google/registry/tools/SetDatabaseMigrationStateCommand.java @@ -0,0 +1,72 @@ +// Copyright 2021 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; + +import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; + +import com.beust.jcommander.Parameter; +import com.beust.jcommander.Parameters; +import com.google.common.collect.ImmutableSortedMap; +import google.registry.model.annotations.DeleteAfterMigration; +import google.registry.model.common.DatabaseMigrationStateSchedule; +import google.registry.model.common.DatabaseMigrationStateSchedule.MigrationState; +import google.registry.tools.params.TransitionListParameter.MigrationStateTransitions; +import org.joda.time.DateTime; + +/** Command to set the Registry 3.0 database migration state schedule. */ +@DeleteAfterMigration +@Parameters( + separators = " =", + commandDescription = "Set the current database migration state schedule.") +public class SetDatabaseMigrationStateCommand extends ConfirmingCommand + implements CommandWithRemoteApi { + + private static final String WARNING_MESSAGE = + "Attempting to change the schedule with an effect that would take place within the next 10 " + + "minutes. The cache expiration duration is 5 minutes so this MAY BE DANGEROUS.\n"; + + @Parameter( + names = "--migration_schedule", + converter = MigrationStateTransitions.class, + validateWith = MigrationStateTransitions.class, + required = true, + description = + "Comma-delimited list of database transitions, of the form" + + "