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" + + "