Migrate plural DNS writers field to being the canonical one

After this point all data is migrated to use the new canonical
plural version, and subsequent code changes can be made that use
multiple writers.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=161673486
This commit is contained in:
mcilwain 2017-07-12 09:19:52 -07:00 committed by Ben McIlwain
parent 24587491c9
commit 37f33e5e7a
6 changed files with 15 additions and 13 deletions

View file

@ -18,10 +18,10 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Predicates.equalTo;
import static com.google.common.base.Predicates.not;
import static com.google.common.collect.Iterables.getOnlyElement;
import static google.registry.config.RegistryConfig.getSingletonCacheRefreshDuration;
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.CollectionUtils.isNullOrEmpty;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
@ -290,8 +290,8 @@ public class Registry extends ImmutableObject implements Buildable {
@OnLoad
public void migrateDnsWriters() {
if (isNullOrEmpty(dnsWriters)) {
dnsWriters = ImmutableSet.of(dnsWriter);
if (dnsWriter == null) {
dnsWriter = getOnlyElement(dnsWriters);
}
}
@ -613,7 +613,7 @@ public class Registry extends ImmutableObject implements Buildable {
@Deprecated
public String getDnsWriter() {
return dnsWriter;
return getOnlyElement(dnsWriters);
}
public ImmutableSet<String> getDnsWriters() {
@ -702,13 +702,13 @@ public class Registry extends ImmutableObject implements Buildable {
return this;
}
public Builder setDnsWriter(String dnsWriter) {
getInstance().dnsWriter = checkArgumentNotNull(dnsWriter);
getInstance().dnsWriters = ImmutableSet.of(dnsWriter);
public Builder setDnsWriters(ImmutableSet<String> dnsWriters) {
checkArgument(dnsWriters.size() == 1, "Multiple DNS writers are not yet supported");
getInstance().dnsWriters = dnsWriters;
getInstance().dnsWriter = getOnlyElement(dnsWriters);
return this;
}
public Builder setAddGracePeriodLength(Duration addGracePeriodLength) {
checkArgument(addGracePeriodLength.isLongerThan(Duration.ZERO),
"addGracePeriodLength must be non-zero");

View file

@ -393,7 +393,7 @@ abstract class CreateOrUpdateTldCommand extends MutatingCommand {
dnsWriterNames.contains(dnsWriter.get()),
"The DNS writer '%s' doesn't exist",
dnsWriter.get());
builder.setDnsWriter(dnsWriter.get());
builder.setDnsWriters(ImmutableSet.of(dnsWriter.get()));
}
if (lrpPeriod != null) {

View file

@ -63,7 +63,8 @@ public class PublishDnsUpdatesActionTest {
public void setUp() throws Exception {
inject.setStaticField(Ofy.class, "clock", clock);
createTld("xn--q9jyb4c");
persistResource(Registry.get("xn--q9jyb4c").asBuilder().setDnsWriter("mock").build());
persistResource(
Registry.get("xn--q9jyb4c").asBuilder().setDnsWriters(ImmutableSet.of("mock")).build());
DomainResource domain1 = persistActiveDomain("example.xn--q9jyb4c");
persistActiveSubordinateHost("ns1.example.xn--q9jyb4c", domain1);
persistActiveSubordinateHost("ns2.example.xn--q9jyb4c", domain1);

View file

@ -37,6 +37,7 @@ import static org.joda.time.Duration.standardMinutes;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.VoidWork;
import google.registry.dns.writer.VoidDnsWriter;
@ -98,7 +99,7 @@ public class PremiumListUtilsTest {
new Registry.Builder()
.setTldStr("ghost")
.setPremiumPricingEngine(StaticPremiumListPricingEngine.NAME)
.setDnsWriter(VoidDnsWriter.NAME)
.setDnsWriters(ImmutableSet.of(VoidDnsWriter.NAME))
.build());
assertThat(Registry.get("ghost").getPremiumList()).isNull();
assertThat(getPremiumPrice("blah", Registry.get("ghost"))).isAbsent();

View file

@ -268,7 +268,7 @@ public class DatastoreHelper {
// Always set a default premium list. Tests that don't want it can delete it.
.setPremiumList(persistPremiumList(tld, DEFAULT_PREMIUM_LIST_CONTENTS.get()))
.setPremiumPricingEngine(StaticPremiumListPricingEngine.NAME)
.setDnsWriter(VoidDnsWriter.NAME)
.setDnsWriters(ImmutableSet.of(VoidDnsWriter.NAME))
.build();
}

View file

@ -66,7 +66,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
assertThat(registry.getAddGracePeriodLength()).isEqualTo(Registry.DEFAULT_ADD_GRACE_PERIOD);
assertThat(registry.getCreationTime()).isIn(Range.closed(before, after));
assertThat(registry.getDomainCreateRestricted()).isFalse();
assertThat(registry.getDnsWriter()).isEqualTo("FooDnsWriter");
assertThat(registry.getDnsWriters()).containsExactly("FooDnsWriter");
assertThat(registry.getTldState(registry.getCreationTime())).isEqualTo(TldState.PREDELEGATION);
assertThat(registry.getRedemptionGracePeriodLength())
.isEqualTo(Registry.DEFAULT_REDEMPTION_GRACE_PERIOD);