mirror of
https://github.com/google/nomulus.git
synced 2025-07-09 04:33:28 +02:00
Always save reserved lists to Cloud SQL (#471)
* Always save reserved lists to Cloud SQL Otherwise it's too easy to forget to run this additional option, and then things will fall out of sync and start throwing errors.
This commit is contained in:
parent
9ea06ebf35
commit
b148102716
5 changed files with 24 additions and 43 deletions
|
@ -62,12 +62,6 @@ public abstract class CreateOrUpdateReservedListCommand extends MutatingCommand
|
|||
arity = 1)
|
||||
Boolean shouldPublish;
|
||||
|
||||
@Parameter(
|
||||
names = {"--also_cloud_sql"},
|
||||
description =
|
||||
"Persist reserved list to Cloud SQL in addition to Datastore; defaults to false.")
|
||||
boolean alsoCloudSql;
|
||||
|
||||
google.registry.schema.tld.ReservedList cloudSqlReservedList;
|
||||
|
||||
abstract void saveToCloudSql();
|
||||
|
@ -78,23 +72,18 @@ public abstract class CreateOrUpdateReservedListCommand extends MutatingCommand
|
|||
String output = super.execute();
|
||||
logger.atInfo().log(output);
|
||||
|
||||
String cloudSqlMessage;
|
||||
if (alsoCloudSql) {
|
||||
String cloudSqlMessage =
|
||||
String.format(
|
||||
"Saved reserved list %s with %d entries",
|
||||
name, cloudSqlReservedList.getLabelsToReservations().size());
|
||||
try {
|
||||
logger.atInfo().log("Saving reserved list to Cloud SQL for TLD %s", name);
|
||||
saveToCloudSql();
|
||||
logger.atInfo().log(cloudSqlMessage);
|
||||
} catch (Throwable e) {
|
||||
cloudSqlMessage =
|
||||
String.format(
|
||||
"Saved reserved list %s with %d entries",
|
||||
name, cloudSqlReservedList.getLabelsToReservations().size());
|
||||
try {
|
||||
logger.atInfo().log("Saving reserved list to Cloud SQL for TLD %s", name);
|
||||
saveToCloudSql();
|
||||
logger.atInfo().log(cloudSqlMessage);
|
||||
} catch (Throwable e) {
|
||||
cloudSqlMessage =
|
||||
"Unexpected error saving reserved list to Cloud SQL from nomulus tool command";
|
||||
logger.atSevere().withCause(e).log(cloudSqlMessage);
|
||||
}
|
||||
} else {
|
||||
cloudSqlMessage = "Persisting reserved list to Cloud SQL is not enabled";
|
||||
"Unexpected error saving reserved list to Cloud SQL from nomulus tool command";
|
||||
logger.atSevere().withCause(e).log(cloudSqlMessage);
|
||||
}
|
||||
return cloudSqlMessage;
|
||||
}
|
||||
|
|
|
@ -67,11 +67,9 @@ final class CreateReservedListCommand extends CreateOrUpdateReservedListCommand
|
|||
.setLastUpdateTime(now)
|
||||
.build();
|
||||
stageEntityChange(null, reservedList);
|
||||
if (alsoCloudSql) {
|
||||
cloudSqlReservedList =
|
||||
google.registry.schema.tld.ReservedList.create(
|
||||
name, shouldPublish, parseToReservationsByLabels(allLines));
|
||||
}
|
||||
cloudSqlReservedList =
|
||||
google.registry.schema.tld.ReservedList.create(
|
||||
name, shouldPublish, parseToReservationsByLabels(allLines));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -50,11 +50,9 @@ final class UpdateReservedListCommand extends CreateOrUpdateReservedListCommand
|
|||
.setLastUpdateTime(new SystemClock().nowUtc())
|
||||
.setShouldPublish(shouldPublish);
|
||||
stageEntityChange(existing.get(), updated.build());
|
||||
if (alsoCloudSql) {
|
||||
cloudSqlReservedList =
|
||||
google.registry.schema.tld.ReservedList.create(
|
||||
name, shouldPublish, parseToReservationsByLabels(allLines));
|
||||
}
|
||||
cloudSqlReservedList =
|
||||
google.registry.schema.tld.ReservedList.create(
|
||||
name, shouldPublish, parseToReservationsByLabels(allLines));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -178,8 +178,7 @@ public class CreateReservedListCommandTest extends
|
|||
|
||||
@Test
|
||||
public void testSaveToCloudSql_succeeds() throws Exception {
|
||||
runCommandForced(
|
||||
"--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath, "--also_cloud_sql");
|
||||
runCommandForced("--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath);
|
||||
verifyXnq9jyb4cInDatastore();
|
||||
verifyXnq9jyb4cInCloudSql();
|
||||
}
|
||||
|
@ -193,8 +192,7 @@ public class CreateReservedListCommandTest extends
|
|||
"xn--q9jyb4c_common-reserved",
|
||||
true,
|
||||
ImmutableMap.of("testdomain", ReservedEntry.create(FULLY_BLOCKED, ""))));
|
||||
runCommandForced(
|
||||
"--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath, "--also_cloud_sql");
|
||||
runCommandForced("--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath);
|
||||
verifyXnq9jyb4cInDatastore();
|
||||
}
|
||||
|
||||
|
|
|
@ -116,20 +116,18 @@ public class UpdateReservedListCommandTest extends
|
|||
public void testSaveToCloudSql_succeeds() throws Exception {
|
||||
populateInitialReservedListInDatastore(true);
|
||||
populateInitialReservedListInCloudSql(true);
|
||||
runCommandForced(
|
||||
"--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath, "--also_cloud_sql");
|
||||
runCommandForced("--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath);
|
||||
verifyXnq9jyb4cInDatastore();
|
||||
verifyXnq9jyb4cInCloudSql();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveToCloudSql_succeedsEvenPreviousListNotExist() throws Exception {
|
||||
// Note that, during the dual-write phase, we just always save the revered list to
|
||||
// Cloud SQL (if --also_cloud_sql is set) without checking if there is a list with
|
||||
// same name. This is to backfill the existing list in Datastore when we update it.
|
||||
// Note that, during the dual-write phase, we always save the reserved list to Cloud SQL without
|
||||
// checking if there is a list with same name. This is to backfill the existing list in Cloud
|
||||
// Datastore when we update it.
|
||||
populateInitialReservedListInDatastore(true);
|
||||
runCommandForced(
|
||||
"--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath, "--also_cloud_sql");
|
||||
runCommandForced("--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath);
|
||||
verifyXnq9jyb4cInDatastore();
|
||||
assertThat(ReservedListDao.checkExists("xn--q9jyb4c_common-reserved")).isTrue();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue