Add nomulus tool setter for sunrush add grace period on TLDs

This also cleans up a few miscellaneous code quality issues encountered
while adding the new setter: using a cleaner way to conditionally set field
values, documenting the format of the add grace period parameters, and
improves some code comments and formatting.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178387731
This commit is contained in:
mcilwain 2017-12-08 09:42:21 -08:00 committed by jianglai
parent 6bd0fc58de
commit 68a26f5b6e
4 changed files with 69 additions and 73 deletions

View file

@ -327,13 +327,18 @@ public class Registry extends ImmutableObject implements Buildable {
*/
boolean domainCreateRestricted;
/** The length of the add grace period for this TLD. */
/**
* The length of the add grace period for this TLD.
*
* <p>Domain deletes are free and effective immediately so long as they take place within this
* amount of time following creation.
*/
Duration addGracePeriodLength = DEFAULT_ADD_GRACE_PERIOD;
/** The length of the add grace period for this TLD. */
/** The length of the anchor tenant add grace period for this TLD. */
Duration anchorTenantAddGracePeriodLength = DEFAULT_ANCHOR_TENANT_ADD_GRACE_PERIOD;
/** The length of the sunrush add grace period for this TLD. */
/** The length of the add grace period during sunrush for this TLD. */
Duration sunrushAddGracePeriodLength = DEFAULT_SUNRUSH_ADD_GRACE_PERIOD;
/** The length of the auto renew grace period for this TLD. */

View file

@ -73,25 +73,31 @@ abstract class CreateOrUpdateTldCommand extends MutatingCommand {
@Nullable
@Parameter(
names = "--add_grace_period",
description = "Length of the add grace period")
description = "Length of the add grace period (in ISO 8601 duration format)")
Duration addGracePeriod;
@Nullable
@Parameter(
names = "--sunrush_add_grace_period",
description = "Length of the add grace period during sunrush (in ISO 8601 duration format)")
Duration sunrushAddGracePeriod;
@Nullable
@Parameter(
names = "--redemption_grace_period",
description = "Length of the redemption grace period")
description = "Length of the redemption grace period (in ISO 8601 duration format)")
Duration redemptionGracePeriod;
@Nullable
@Parameter(
names = "--pending_delete_length",
description = "Length of the pending delete period")
description = "Length of the pending delete period (in ISO 8601 duration format)")
Duration pendingDeleteLength;
@Nullable
@Parameter(
names = "--automatic_transfer_length",
description = "Length of the automatic transfer period")
description = "Length of the automatic transfer period (in ISO 8601 duration format)")
private Duration automaticTransferLength;
@Nullable
@ -321,61 +327,23 @@ abstract class CreateOrUpdateTldCommand extends MutatingCommand {
builder.setEapFeeSchedule(eapFeeSchedule);
}
if (addGracePeriod != null) {
builder.setAddGracePeriodLength(addGracePeriod);
}
if (redemptionGracePeriod != null) {
builder.setRedemptionGracePeriodLength(redemptionGracePeriod);
}
if (pendingDeleteLength != null) {
builder.setPendingDeleteLength(pendingDeleteLength);
}
if (automaticTransferLength != null) {
builder.setAutomaticTransferLength(automaticTransferLength);
}
if (driveFolderId != null) {
builder.setDriveFolderId(driveFolderId.orElse(null));
}
if (createBillingCost != null) {
builder.setCreateBillingCost(createBillingCost);
}
if (restoreBillingCost != null) {
builder.setRestoreBillingCost(restoreBillingCost);
}
if (roidSuffix != null) {
builder.setRoidSuffix(roidSuffix);
}
if (serverStatusChangeCost != null) {
builder.setServerStatusChangeBillingCost(serverStatusChangeCost);
}
if (tldType != null) {
builder.setTldType(tldType);
}
if (premiumPriceAckRequired != null) {
builder.setPremiumPriceAckRequired(premiumPriceAckRequired);
}
if (lordnUsername != null) {
builder.setLordnUsername(lordnUsername.orElse(null));
}
if (claimsPeriodEnd != null) {
builder.setClaimsPeriodEnd(claimsPeriodEnd);
}
if (domainCreateRestricted != null) {
builder.setDomainCreateRestricted(domainCreateRestricted);
}
Optional.ofNullable(addGracePeriod).ifPresent(builder::setAddGracePeriodLength);
Optional.ofNullable(sunrushAddGracePeriod).ifPresent(builder::setSunrushAddGracePeriodLength);
Optional.ofNullable(redemptionGracePeriod).ifPresent(builder::setRedemptionGracePeriodLength);
Optional.ofNullable(pendingDeleteLength).ifPresent(builder::setPendingDeleteLength);
Optional.ofNullable(automaticTransferLength).ifPresent(builder::setAutomaticTransferLength);
Optional.ofNullable(driveFolderId).ifPresent(id -> builder.setDriveFolderId(id.orElse(null)));
Optional.ofNullable(createBillingCost).ifPresent(builder::setCreateBillingCost);
Optional.ofNullable(restoreBillingCost).ifPresent(builder::setRestoreBillingCost);
Optional.ofNullable(roidSuffix).ifPresent(builder::setRoidSuffix);
Optional.ofNullable(serverStatusChangeCost)
.ifPresent(builder::setServerStatusChangeBillingCost);
Optional.ofNullable(tldType).ifPresent(builder::setTldType);
Optional.ofNullable(premiumPriceAckRequired).ifPresent(builder::setPremiumPriceAckRequired);
Optional.ofNullable(lordnUsername).ifPresent(u -> builder.setLordnUsername(u.orElse(null)));
Optional.ofNullable(claimsPeriodEnd).ifPresent(builder::setClaimsPeriodEnd);
Optional.ofNullable(domainCreateRestricted).ifPresent(builder::setDomainCreateRestricted);
Optional.ofNullable(lrpPeriod).ifPresent(p -> builder.setLrpPeriod(p.orElse(null)));
if (premiumListName != null) {
if (premiumListName.isPresent()) {
@ -399,10 +367,6 @@ abstract class CreateOrUpdateTldCommand extends MutatingCommand {
builder.setDnsWriters(dnsWritersSet);
}
if (lrpPeriod != null) {
builder.setLrpPeriod(lrpPeriod.orElse(null));
}
ImmutableSet<String> newReservedListNames = getReservedLists(oldRegistry);
checkReservedListValidityForTld(tld, newReservedListNames);
builder.setReservedListsByName(newReservedListNames);

View file

@ -20,10 +20,12 @@ import static google.registry.model.registry.label.ReservedListTest.GET_NAME_FUN
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistPremiumList;
import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.joda.money.CurrencyUnit.JPY;
import static org.joda.money.CurrencyUnit.USD;
import static org.joda.time.DateTimeZone.UTC;
import static org.joda.time.Duration.standardDays;
import static org.joda.time.Duration.standardMinutes;
import com.beust.jcommander.ParameterException;
@ -141,6 +143,17 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
assertThat(Registry.get("xn--q9jyb4c").getAddGracePeriodLength()).isEqualTo(standardMinutes(5));
}
@Test
public void testSuccess_sunrushAddGracePeriodFlag() throws Exception {
runCommandForced(
"--sunrush_add_grace_period=P13D",
"--roid_suffix=Q9JYB4C",
"--dns_writers=VoidDnsWriter",
"xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getSunrushAddGracePeriodLength())
.isEqualTo(standardDays(13));
}
@Test
public void testSuccess_roidSuffixWorks() throws Exception {
runCommandForced("--roid_suffix=RSUFFIX", "--dns_writers=VoidDnsWriter", "tld");
@ -296,6 +309,19 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
"xn--q9jyb4c");
}
@Test
public void testFailure_invalidSunrushAddGracePeriod() throws Exception {
Exception e = expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--sunrush_add_grace_period=5d",
"--roid_suffix=Q9JYB4C",
"--dns_writers=VoidDnsWriter",
"xn--q9jyb4c"));
assertThat(e).hasMessageThat().isEqualTo("Invalid format: \"5d\"");
}
@Test
public void testFailure_invalidRedemptionGracePeriod() throws Exception {
thrown.expect(IllegalArgumentException.class, "Invalid format: \"5m\"");

View file

@ -26,6 +26,7 @@ import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.joda.money.CurrencyUnit.JPY;
import static org.joda.money.CurrencyUnit.USD;
import static org.joda.time.DateTimeZone.UTC;
import static org.joda.time.Duration.standardDays;
import static org.joda.time.Duration.standardMinutes;
import com.beust.jcommander.ParameterException;
@ -147,19 +148,22 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
public void testSuccess_addGracePeriodFlag() throws Exception {
assertThat(Registry.get("xn--q9jyb4c").getAddGracePeriodLength())
.isNotEqualTo(standardMinutes(5));
runCommandForced("--add_grace_period=PT300S", "xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getAddGracePeriodLength()).isEqualTo(standardMinutes(5));
}
@Test
public void testSuccess_sunrushAddGracePeriodFlag() throws Exception {
runCommandForced("--sunrush_add_grace_period=P13D", "xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getSunrushAddGracePeriodLength())
.isEqualTo(standardDays(13));
}
@Test
public void testSuccess_redemptionGracePeriodFlag() throws Exception {
assertThat(Registry.get("xn--q9jyb4c").getRedemptionGracePeriodLength())
.isNotEqualTo(standardMinutes(5));
runCommandForced("--redemption_grace_period=PT300S", "xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getRedemptionGracePeriodLength())
.isEqualTo(standardMinutes(5));
}
@ -168,16 +172,13 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
public void testSuccess_pendingDeleteLengthFlag() throws Exception {
assertThat(Registry.get("xn--q9jyb4c").getPendingDeleteLength())
.isNotEqualTo(standardMinutes(5));
runCommandForced("--pending_delete_length=PT300S", "xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getPendingDeleteLength()).isEqualTo(standardMinutes(5));
}
@Test
public void testSuccess_dnsWriter() throws Exception {
assertThat(Registry.get("xn--q9jyb4c").getDnsWriters()).containsExactly("VoidDnsWriter");
runCommandForced("--dns_writers=FooDnsWriter", "xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getDnsWriters()).containsExactly("FooDnsWriter");
}