diff --git a/java/google/registry/model/registry/Registry.java b/java/google/registry/model/registry/Registry.java index d8e1de28a..76e20f39c 100644 --- a/java/google/registry/model/registry/Registry.java +++ b/java/google/registry/model/registry/Registry.java @@ -398,6 +398,9 @@ public class Registry extends ImmutableObject implements Buildable { /** A whitelist of hosts allowed to be used on domains on this TLD (ignored if empty). */ Set allowedFullyQualifiedHostNames; + /** The set of {@link TldState}s for which LRP applications are accepted (ignored if empty). */ + Set lrpTldStates; + public String getTldStr() { return tldStr; } @@ -575,6 +578,10 @@ public class Registry extends ImmutableObject implements Buildable { return nullToEmptyImmutableCopy(allowedFullyQualifiedHostNames); } + public ImmutableSet getLrpTldStates() { + return nullToEmptyImmutableCopy(lrpTldStates); + } + @Override public Builder asBuilder() { return new Builder(clone(this)); @@ -831,6 +838,11 @@ public class Registry extends ImmutableObject implements Buildable { return this; } + public Builder setLrpTldStates(ImmutableSet lrpTldStates) { + getInstance().lrpTldStates = lrpTldStates; + return this; + } + @Override public Registry build() { final Registry instance = getInstance(); @@ -848,6 +860,10 @@ public class Registry extends ImmutableObject implements Buildable { // cloned it into a new builder, to block re-building a Registry in an invalid state. instance.tldStateTransitions.checkValidity(); instance.renewBillingCostTransitions.checkValidity(); + checkArgument( + instance.tldStateTransitions.toValueMap().values() + .containsAll(instance.getLrpTldStates()), + "Cannot specify an LRP TLD state that is not part of the TLD state transitions."); instance.eapFeeSchedule.checkValidity(); // All costs must be in the expected currency. // TODO(b/21854155): When we move PremiumList into datastore, verify its currency too. diff --git a/java/google/registry/tools/CreateOrUpdateTldCommand.java b/java/google/registry/tools/CreateOrUpdateTldCommand.java index 0d44a2303..a00acd266 100644 --- a/java/google/registry/tools/CreateOrUpdateTldCommand.java +++ b/java/google/registry/tools/CreateOrUpdateTldCommand.java @@ -35,6 +35,7 @@ import google.registry.model.registry.Registry.TldState; import google.registry.model.registry.Registry.TldType; import google.registry.model.registry.label.PremiumList; import google.registry.tools.params.OptionalStringParameter; +import google.registry.tools.params.TldStateParameter; import google.registry.tools.params.TransitionListParameter.BillingCostTransitions; import google.registry.tools.params.TransitionListParameter.TldStateTransitions; import java.util.List; @@ -215,10 +216,16 @@ abstract class CreateOrUpdateTldCommand extends MutatingCommand { names = "--dns_writer", description = "The name of the DnsWriter implementation to use", converter = OptionalStringParameter.class, - validateWith = OptionalStringParameter.class - ) + validateWith = OptionalStringParameter.class) Optional dnsWriter; + @Nullable + @Parameter( + names = "--lrp_tld_states", + converter = TldStateParameter.class, + description = "A comma-separated list of TLD states for which LRP is available") + List lrpTldStates; + /** Returns the existing registry (for update) or null (for creates). */ @Nullable abstract Registry getOldRegistry(String tld); @@ -385,6 +392,10 @@ abstract class CreateOrUpdateTldCommand extends MutatingCommand { } } + if (lrpTldStates != null) { + builder.setLrpTldStates(ImmutableSet.copyOf(lrpTldStates)); + } + ImmutableSet newReservedListNames = getReservedLists(oldRegistry); checkReservedListValidityForTld(tld, newReservedListNames); builder.setReservedListsByName(newReservedListNames); diff --git a/java/google/registry/tools/params/EnumParameter.java b/java/google/registry/tools/params/EnumParameter.java new file mode 100644 index 000000000..3627f6128 --- /dev/null +++ b/java/google/registry/tools/params/EnumParameter.java @@ -0,0 +1,30 @@ +// Copyright 2016 The Domain Registry 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.params; + +import google.registry.util.TypeUtils.TypeInstantiator; + +/** Base class for Enum-based parameters. + * + *

This is not necessary for single-value Enum parameters (i.e. arity = 1) as JCommander natively + * supports them, but is necessary for variable-arity ({@code List<Enum>}) parameters. + */ +public abstract class EnumParameter> extends ParameterConverterValidator { + + @Override + public T convert(String value) { + return Enum.valueOf(new TypeInstantiator(getClass()){}.getExactType(), value); + } +} diff --git a/java/google/registry/tools/params/TldStateParameter.java b/java/google/registry/tools/params/TldStateParameter.java new file mode 100644 index 000000000..e6ad571a8 --- /dev/null +++ b/java/google/registry/tools/params/TldStateParameter.java @@ -0,0 +1,23 @@ +// Copyright 2016 The Domain Registry 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.params; + +import google.registry.model.registry.Registry.TldState; + +/** + * {@link TldState} CLI parameter converter/validator. Required to support multi-value + * TldState parameters. + */ +public final class TldStateParameter extends EnumParameter {} diff --git a/javatests/google/registry/model/registry/RegistryTest.java b/javatests/google/registry/model/registry/RegistryTest.java index 8a97f6a03..dcc2ef3fd 100644 --- a/javatests/google/registry/model/registry/RegistryTest.java +++ b/javatests/google/registry/model/registry/RegistryTest.java @@ -443,4 +443,21 @@ public class RegistryTest extends EntityTestCase { .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR))) .build(); } + + @Test + public void testFailure_lrpTldState_notInTransitions() { + Registry registry = Registry.get("tld").asBuilder() + .setTldStateTransitions(ImmutableSortedMap.naturalOrder() + .put(START_OF_TIME, TldState.PREDELEGATION) + .put(clock.nowUtc().plusMonths(1), TldState.SUNRISE) + .put(clock.nowUtc().plusMonths(3), TldState.LANDRUSH) + .put(clock.nowUtc().plusMonths(4), TldState.QUIET_PERIOD) + .put(clock.nowUtc().plusMonths(5), TldState.GENERAL_AVAILABILITY) + .build()) + .build(); + thrown.expect( + IllegalArgumentException.class, + "Cannot specify an LRP TLD state that is not part of the TLD state transitions."); + registry.asBuilder().setLrpTldStates(ImmutableSet.of(TldState.SUNRUSH)).build(); + } } diff --git a/javatests/google/registry/model/schema.txt b/javatests/google/registry/model/schema.txt index 2c037a4a3..1dc082955 100644 --- a/javatests/google/registry/model/schema.txt +++ b/javatests/google/registry/model/schema.txt @@ -683,6 +683,7 @@ class google.registry.model.registry.Registry { java.lang.String tldStr; java.lang.String tldUnicode; java.util.Set> reservedLists; + java.util.Set lrpTldStates; java.util.Set allowedFullyQualifiedHostNames; java.util.Set allowedRegistrantContactIds; org.joda.money.CurrencyUnit currency; diff --git a/javatests/google/registry/tools/CreateTldCommandTest.java b/javatests/google/registry/tools/CreateTldCommandTest.java index 6c565ebdc..2bd8a8b0f 100644 --- a/javatests/google/registry/tools/CreateTldCommandTest.java +++ b/javatests/google/registry/tools/CreateTldCommandTest.java @@ -211,6 +211,29 @@ public class CreateTldCommandTest extends CommandTestCase { .containsExactly("xn--q9jyb4c_abuse", "common_abuse"); } + @Test + public void testSuccess_addLrpTldState() throws Exception { + runCommandForced( + "--lrp_tld_states=SUNRISE", + "--initial_tld_state=SUNRISE", + "--roid_suffix=Q9JYB4C", + "xn--q9jyb4c"); + assertThat(Registry.get("xn--q9jyb4c").getLrpTldStates()) + .containsExactly(TldState.SUNRISE); + } + + @Test + public void testSuccess_addMultipleLrpTldStates() throws Exception { + DateTime now = DateTime.now(UTC); + runCommandForced( + "--lrp_tld_states=SUNRISE,LANDRUSH", + String.format("--tld_state_transitions=%s=SUNRISE,%s=LANDRUSH", START_OF_TIME, now.plus(1)), + "--roid_suffix=Q9JYB4C", + "xn--q9jyb4c"); + assertThat(Registry.get("xn--q9jyb4c").getLrpTldStates()) + .containsExactly(TldState.SUNRISE, TldState.LANDRUSH); + } + @Test public void testSuccess_setPremiumPriceAckRequired() throws Exception { runCommandForced("--premium_price_ack_required=true", "--roid_suffix=Q9JYB4C", "xn--q9jyb4c"); @@ -406,6 +429,30 @@ public class CreateTldCommandTest extends CommandTestCase { runCommandForced("--roid_suffix=BLAH", "randomtld"); } + @Test + public void testFailure_lrpTldState_notInTldStateTransitions() throws Exception { + thrown.expect( + IllegalArgumentException.class, + "Cannot specify an LRP TLD state that is not part of the TLD state transitions."); + runCommandForced( + "--lrp_tld_states=SUNRISE", + "--initial_tld_state=PREDELEGATION", + "--roid_suffix=Q9JYB4C", + "xn--q9jyb4c"); + } + + @Test + public void testFailure_lrpTldState_badTldState() throws Exception { + thrown.expect( + IllegalArgumentException.class, + "No enum constant google.registry.model.registry.Registry.TldState.LANDRISE"); + runCommandForced( + "--lrp_tld_states=LANDRISE", + "--initial_tld_state=PREDELEGATION", + "--roid_suffix=Q9JYB4C", + "xn--q9jyb4c"); + } + private void runSuccessfulReservedListsTest(String reservedLists) throws Exception { runCommandForced("--reserved_lists", reservedLists, "--roid_suffix=Q9JYB4C", "xn--q9jyb4c"); } diff --git a/javatests/google/registry/tools/UpdateTldCommandTest.java b/javatests/google/registry/tools/UpdateTldCommandTest.java index 13ab2c5d1..13c8a6d06 100644 --- a/javatests/google/registry/tools/UpdateTldCommandTest.java +++ b/javatests/google/registry/tools/UpdateTldCommandTest.java @@ -814,6 +814,68 @@ public class UpdateTldCommandTest extends CommandTestCase { runCommandForced("--premium_list=phonies", "xn--q9jyb4c"); } + @Test + public void testSuccess_updateLrpTldState() throws Exception { + persistResource( + Registry.get("xn--q9jyb4c").asBuilder() + .setTldStateTransitions( + ImmutableSortedMap.of( + START_OF_TIME, TldState.PREDELEGATION, + now.minusMonths(2), TldState.SUNRISE, + now.minusMonths(1), TldState.LANDRUSH, + now, TldState.GENERAL_AVAILABILITY)) + .setLrpTldStates(ImmutableSet.of(TldState.SUNRISE)) + .build()); + runCommandForced("--lrp_tld_states=LANDRUSH", "xn--q9jyb4c"); + assertThat(Registry.get("xn--q9jyb4c").getLrpTldStates()).containsExactly(TldState.LANDRUSH); + } + + @Test + public void testSuccess_updateMultipleLrpTldStates() throws Exception { + persistResource( + Registry.get("xn--q9jyb4c").asBuilder() + .setTldStateTransitions( + ImmutableSortedMap.of( + START_OF_TIME, TldState.PREDELEGATION, + now.minusMonths(2), TldState.SUNRISE, + now.minusMonths(1), TldState.LANDRUSH, + now, TldState.GENERAL_AVAILABILITY)) + .setLrpTldStates(ImmutableSet.of()) + .build()); + runCommandForced("--lrp_tld_states=SUNRISE,LANDRUSH", "xn--q9jyb4c"); + assertThat(Registry.get("xn--q9jyb4c").getLrpTldStates()) + .containsExactly(TldState.LANDRUSH, TldState.SUNRISE); + } + + @Test + public void testFailure_updateLrpTldStates_notInTransitions() throws Exception { + persistResource( + Registry.get("xn--q9jyb4c").asBuilder() + .setTldStateTransitions( + ImmutableSortedMap.of( + START_OF_TIME, TldState.PREDELEGATION, + now.minusMonths(2), TldState.SUNRISE, + now, TldState.GENERAL_AVAILABILITY)) + .setLrpTldStates(ImmutableSet.of(TldState.SUNRISE)) + .build()); + thrown.expect( + IllegalArgumentException.class, + "Cannot specify an LRP TLD state that is not part of the TLD state transitions."); + runCommandForced("--lrp_tld_states=LANDRUSH", "xn--q9jyb4c"); + } + + @Test + public void testFailure_updateLrpTldStates_badTldState() throws Exception { + thrown.expect( + IllegalArgumentException.class, + "No enum constant google.registry.model.registry.Registry.TldState.LOUD_PERIOD"); + runCommandForced( + "--lrp_tld_states=LOUD_PERIOD", + "--initial_tld_state=PREDELEGATION", + "--roid_suffix=Q9JYB4C", + "xn--q9jyb4c"); + } + private void runSuccessfulReservedListsTest(String reservedLists) throws Exception { runCommandForced("--reserved_lists", reservedLists, "xn--q9jyb4c"); } diff --git a/javatests/google/registry/tools/params/BUILD b/javatests/google/registry/tools/params/BUILD index a3a73f9cc..b02b98799 100644 --- a/javatests/google/registry/tools/params/BUILD +++ b/javatests/google/registry/tools/params/BUILD @@ -17,6 +17,7 @@ java_library( "//third_party/java/joda_time", "//third_party/java/junit", "//third_party/java/truth", + "//java/google/registry/model", "//java/google/registry/tools/params", "//javatests/google/registry/testing", ], diff --git a/javatests/google/registry/tools/params/EnumParameterTest.java b/javatests/google/registry/tools/params/EnumParameterTest.java new file mode 100644 index 000000000..173c4c316 --- /dev/null +++ b/javatests/google/registry/tools/params/EnumParameterTest.java @@ -0,0 +1,49 @@ +// Copyright 2016 The Domain Registry 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.params; + +import static com.google.common.truth.Truth.assertThat; + +import google.registry.model.registry.Registry.TldState; +import google.registry.testing.ExceptionRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Unit tests for {@link EnumParameter}. */ +@RunWith(JUnit4.class) +public class EnumParameterTest { + + @Rule + public final ExceptionRule thrown = new ExceptionRule(); + + // There's no additional functionality exposed by this (or any other) EnumParameter, but using + // this in the test as EnumParameter is abstract. + private final TldStateParameter instance = new TldStateParameter(); + + @Test + public void testSuccess_convertEnum() throws Exception { + assertThat(instance.convert("PREDELEGATION")).isEqualTo(TldState.PREDELEGATION); + } + + @Test + public void testFailure_badValue() throws Exception { + thrown.expect( + IllegalArgumentException.class, + "No enum constant google.registry.model.registry.Registry.TldState.GENERAL_SUNRUSH"); + instance.convert("GENERAL_SUNRUSH"); + } +}