Add LRP TLD states to Registry and *_tld tools

Also had to add an EnumParameter class to support
List<T extends Enum<T>>, as these aren't natively supported by
JCommander (although single Enum parameters are.)

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=129464699
This commit is contained in:
Chris Tingue 2016-08-05 11:39:06 -07:00 committed by Justine Tunney
parent 751df4b488
commit 1ef8716177
10 changed files with 259 additions and 2 deletions

View file

@ -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<String> allowedFullyQualifiedHostNames;
/** The set of {@link TldState}s for which LRP applications are accepted (ignored if empty). */
Set<TldState> lrpTldStates;
public String getTldStr() {
return tldStr;
}
@ -575,6 +578,10 @@ public class Registry extends ImmutableObject implements Buildable {
return nullToEmptyImmutableCopy(allowedFullyQualifiedHostNames);
}
public ImmutableSet<TldState> 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<TldState> 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.

View file

@ -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<String> dnsWriter;
@Nullable
@Parameter(
names = "--lrp_tld_states",
converter = TldStateParameter.class,
description = "A comma-separated list of TLD states for which LRP is available")
List<TldState> 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<String> newReservedListNames = getReservedLists(oldRegistry);
checkReservedListValidityForTld(tld, newReservedListNames);
builder.setReservedListsByName(newReservedListNames);

View file

@ -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.
*
* <p>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&lt;Enum&gt;}) parameters.
*/
public abstract class EnumParameter<T extends Enum<T>> extends ParameterConverterValidator<T> {
@Override
public T convert(String value) {
return Enum.<T>valueOf(new TypeInstantiator<T>(getClass()){}.getExactType(), value);
}
}

View file

@ -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<TldState> {}

View file

@ -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.<DateTime, TldState>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();
}
}

View file

@ -683,6 +683,7 @@ class google.registry.model.registry.Registry {
java.lang.String tldStr;
java.lang.String tldUnicode;
java.util.Set<com.googlecode.objectify.Key<google.registry.model.registry.label.ReservedList>> reservedLists;
java.util.Set<google.registry.model.registry.Registry$TldState> lrpTldStates;
java.util.Set<java.lang.String> allowedFullyQualifiedHostNames;
java.util.Set<java.lang.String> allowedRegistrantContactIds;
org.joda.money.CurrencyUnit currency;

View file

@ -211,6 +211,29 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
.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<CreateTldCommand> {
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");
}

View file

@ -814,6 +814,68 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
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.<TldState>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");
}

View file

@ -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",
],

View file

@ -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");
}
}