diff --git a/core/src/main/java/google/registry/model/common/DatabaseMigrationStateSchedule.java b/core/src/main/java/google/registry/model/common/DatabaseMigrationStateSchedule.java index 890ea3f8d..61e199f61 100644 --- a/core/src/main/java/google/registry/model/common/DatabaseMigrationStateSchedule.java +++ b/core/src/main/java/google/registry/model/common/DatabaseMigrationStateSchedule.java @@ -179,8 +179,9 @@ public class DatabaseMigrationStateSchedule extends CrossTldSingleton ImmutableSortedMap.of(START_OF_TIME, MigrationState.DATASTORE_ONLY), MigrationStateTransition.class); + @VisibleForTesting @Mapify(TimeMapper.class) - TimedTransitionProperty migrationTransitions = + public TimedTransitionProperty migrationTransitions = TimedTransitionProperty.forMapify( MigrationState.DATASTORE_ONLY, MigrationStateTransition.class); 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..1f858473c --- /dev/null +++ b/core/src/main/java/google/registry/tools/GetDatabaseMigrationStateCommand.java @@ -0,0 +1,34 @@ +// 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.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. */ +@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 2e2d596de..8b96ea2da 100644 --- a/core/src/main/java/google/registry/tools/RegistryTool.java +++ b/core/src/main/java/google/registry/tools/RegistryTool.java @@ -69,6 +69,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) @@ -110,6 +111,7 @@ public final class RegistryTool { .put("resave_epp_resource", ResaveEppResourceCommand.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("set_sql_replay_checkpoint", SetSqlReplayCheckpointCommand.class) .put("setup_ote", SetupOteCommand.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..5a43e8bdf --- /dev/null +++ b/core/src/main/java/google/registry/tools/SetDatabaseMigrationStateCommand.java @@ -0,0 +1,70 @@ +// 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.ofyTm; + +import com.beust.jcommander.Parameter; +import com.beust.jcommander.Parameters; +import com.google.common.collect.ImmutableSortedMap; +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. */ +@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" + + "