diff --git a/java/google/registry/dns/BUILD b/java/google/registry/dns/BUILD index 7be1444fe..be0fd98ac 100644 --- a/java/google/registry/dns/BUILD +++ b/java/google/registry/dns/BUILD @@ -36,6 +36,7 @@ java_library( "//third_party/java/objectify:objectify-v4_1", "//third_party/java/servlet/servlet_api", "//java/google/registry/config", + "//java/google/registry/dns/writer", "//java/google/registry/model", "//java/google/registry/request", "//java/google/registry/util", diff --git a/java/google/registry/dns/DnsModule.java b/java/google/registry/dns/DnsModule.java index d5aaf491b..a999e8702 100644 --- a/java/google/registry/dns/DnsModule.java +++ b/java/google/registry/dns/DnsModule.java @@ -30,7 +30,7 @@ import dagger.Binds; import dagger.Module; import dagger.Provides; import google.registry.dns.DnsConstants.TargetType; -import google.registry.model.dns.DnsWriterZone; +import google.registry.dns.writer.DnsWriterZone; import google.registry.request.Parameter; import google.registry.request.RequestParameters; import java.util.Set; diff --git a/java/google/registry/dns/DnsWriterProxy.java b/java/google/registry/dns/DnsWriterProxy.java new file mode 100644 index 000000000..b6ec031b2 --- /dev/null +++ b/java/google/registry/dns/DnsWriterProxy.java @@ -0,0 +1,42 @@ +// 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.dns; + +import static com.google.common.base.Preconditions.checkState; + +import com.google.common.collect.ImmutableMap; +import google.registry.dns.writer.DnsWriter; +import google.registry.model.registry.Registry; +import java.util.Map; +import javax.inject.Inject; + +/** Proxy for retrieving {@link DnsWriter} implementations. */ +public final class DnsWriterProxy { + + private final ImmutableMap dnsWriters; + + @Inject + DnsWriterProxy(Map dnsWriters) { + this.dnsWriters = ImmutableMap.copyOf(dnsWriters); + } + + /** Return the {@link DnsWriter} for the given tld. */ + public DnsWriter getForTld(String tld) { + String clazz = Registry.get(tld).getDnsWriter(); + DnsWriter dnsWriter = dnsWriters.get(clazz); + checkState(dnsWriter != null, "Could not load DnsWriter %s for TLD %s", clazz, tld); + return dnsWriter; + } +} diff --git a/java/google/registry/dns/PublishDnsUpdatesAction.java b/java/google/registry/dns/PublishDnsUpdatesAction.java index 2ea2d045f..3766503f3 100644 --- a/java/google/registry/dns/PublishDnsUpdatesAction.java +++ b/java/google/registry/dns/PublishDnsUpdatesAction.java @@ -20,7 +20,7 @@ import static google.registry.util.CollectionUtils.nullToEmpty; import com.google.common.net.InternetDomainName; import google.registry.config.ConfigModule.Config; -import google.registry.model.dns.DnsWriter; +import google.registry.dns.writer.DnsWriter; import google.registry.request.Action; import google.registry.request.HttpException.ServiceUnavailableException; import google.registry.request.Parameter; @@ -30,7 +30,6 @@ import google.registry.util.FormattingLogger; import java.util.Set; import java.util.concurrent.Callable; import javax.inject.Inject; -import javax.inject.Provider; import org.joda.time.Duration; /** Task that sends domain and host updates to the DNS server. */ @@ -44,7 +43,7 @@ public final class PublishDnsUpdatesAction implements Runnable, Callable { private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass(); @Inject DnsQueue dnsQueue; - @Inject Provider writerProvider; + @Inject DnsWriterProxy dnsWriterProxy; @Inject @Config("dnsWriteLockTimeout") Duration timeout; @Inject @Parameter(RequestParameters.PARAM_TLD) String tld; @Inject @Parameter(DOMAINS_PARAM) Set domains; @@ -73,7 +72,7 @@ public final class PublishDnsUpdatesAction implements Runnable, Callable { /** Steps through the domain and host refreshes contained in the parameters and processes them. */ private void processBatch() { - try (DnsWriter writer = writerProvider.get()) { + try (DnsWriter writer = dnsWriterProxy.getForTld(tld)) { for (String domain : nullToEmpty(domains)) { if (!DomainNameUtils.isUnder( InternetDomainName.from(domain), InternetDomainName.from(tld))) { diff --git a/java/google/registry/dns/writer/BUILD b/java/google/registry/dns/writer/BUILD deleted file mode 100644 index 8ddc01bf8..000000000 --- a/java/google/registry/dns/writer/BUILD +++ /dev/null @@ -1,18 +0,0 @@ -package( - default_visibility = ["//java/google/registry:registry_project"], -) - -licenses(["notice"]) # Apache 2.0 - - -java_library( - name = "writer", - srcs = glob(["*.java"]), - deps = [ - "//java/com/google/common/base", - "//third_party/java/dagger", - "//third_party/java/jsr305_annotations", - "//third_party/java/jsr330_inject", - "//java/google/registry/model", - ], -) diff --git a/java/google/registry/dns/writer/VoidDnsWriter.java b/java/google/registry/dns/writer/VoidDnsWriter.java deleted file mode 100644 index 88d9895a5..000000000 --- a/java/google/registry/dns/writer/VoidDnsWriter.java +++ /dev/null @@ -1,49 +0,0 @@ -// 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.dns.writer; - -import com.google.common.base.Joiner; -import google.registry.model.dns.DnsWriter; -import java.util.HashSet; -import java.util.Set; -import java.util.logging.Logger; - -/** - * {@link DnsWriter} that doesn't actually update records in a DNS server. - * - *

All this class does is write its displeasure to the logs. - */ -public final class VoidDnsWriter implements DnsWriter { - - private static final Logger logger = Logger.getLogger(VoidDnsWriter.class.getName()); - - private final Set names = new HashSet<>(); - - @Override - public void publishDomain(String domainName) { - names.add(domainName); - } - - @Override - public void publishHost(String hostName) { - names.add(hostName); - } - - @Override - public void close() { - logger.warning("Ignoring DNS zone updates! No DnsWriterFactory implementation specified!\n" - + Joiner.on('\n').join(names)); - } -} diff --git a/java/google/registry/dns/writer/VoidDnsWriterModule.java b/java/google/registry/dns/writer/VoidDnsWriterModule.java deleted file mode 100644 index 7e1698c0b..000000000 --- a/java/google/registry/dns/writer/VoidDnsWriterModule.java +++ /dev/null @@ -1,29 +0,0 @@ -// 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.dns.writer; - -import dagger.Module; -import dagger.Provides; -import google.registry.model.dns.DnsWriter; - -/** Dagger module that disables DNS updates. */ -@Module -public final class VoidDnsWriterModule { - - @Provides - static DnsWriter provideDnsWriter() { - return new VoidDnsWriter(); - } -} diff --git a/java/google/registry/dns/writer/clouddns/BUILD b/java/google/registry/dns/writer/clouddns/BUILD index 41d487764..6c6be6b24 100644 --- a/java/google/registry/dns/writer/clouddns/BUILD +++ b/java/google/registry/dns/writer/clouddns/BUILD @@ -21,6 +21,7 @@ java_library( "//third_party/java/dagger", "//third_party/java/joda_time", "//java/google/registry/config", + "//java/google/registry/dns/writer", "//java/google/registry/model", "//java/google/registry/util", ], diff --git a/java/google/registry/dns/writer/clouddns/CloudDnsModule.java b/java/google/registry/dns/writer/clouddns/CloudDnsModule.java index 62cb2b408..40a3afc7c 100644 --- a/java/google/registry/dns/writer/clouddns/CloudDnsModule.java +++ b/java/google/registry/dns/writer/clouddns/CloudDnsModule.java @@ -22,7 +22,10 @@ import com.google.api.services.dns.DnsScopes; import com.google.common.base.Function; import dagger.Module; import dagger.Provides; +import dagger.multibindings.IntoMap; +import dagger.multibindings.StringKey; import google.registry.config.ConfigModule.Config; +import google.registry.dns.writer.DnsWriter; import java.util.Set; /** Dagger module for Google Cloud DNS service connection objects. */ @@ -39,4 +42,11 @@ public final class CloudDnsModule { .setApplicationName(projectId) .build(); } + + @Provides + @IntoMap + @StringKey(CloudDnsWriter.NAME) + static DnsWriter provideCloudDnsWriter(CloudDnsWriter writer) { + return writer; + } } diff --git a/java/google/registry/dns/writer/clouddns/CloudDnsWriter.java b/java/google/registry/dns/writer/clouddns/CloudDnsWriter.java index 6d3ebb184..229294cfd 100644 --- a/java/google/registry/dns/writer/clouddns/CloudDnsWriter.java +++ b/java/google/registry/dns/writer/clouddns/CloudDnsWriter.java @@ -32,8 +32,8 @@ import com.google.common.collect.ImmutableSet.Builder; import com.google.common.net.InternetDomainName; import com.google.common.util.concurrent.RateLimiter; import google.registry.config.ConfigModule.Config; -import google.registry.model.dns.DnsWriter; -import google.registry.model.dns.DnsWriterZone; +import google.registry.dns.writer.DnsWriter; +import google.registry.dns.writer.DnsWriterZone; import google.registry.model.domain.DomainResource; import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.host.HostResource; @@ -59,6 +59,12 @@ import org.joda.time.Duration; */ class CloudDnsWriter implements DnsWriter { + /** + * The name of the pricing engine, as used in {@code Registry.dnsWriter}. Remember to change + * the value on affected Registry objects to prevent runtime failures. + */ + public static final String NAME = "CloudDnsWriter"; + private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass(); // This is the default max QPS for Cloud DNS. It can be increased by contacting the team diff --git a/java/google/registry/dns/writer/dnsupdate/BUILD b/java/google/registry/dns/writer/dnsupdate/BUILD index 5e7edb066..ee7bfecf4 100644 --- a/java/google/registry/dns/writer/dnsupdate/BUILD +++ b/java/google/registry/dns/writer/dnsupdate/BUILD @@ -21,6 +21,7 @@ java_library( "//third_party/java/jsr305_annotations", "//third_party/java/jsr330_inject", "//java/google/registry/config", + "//java/google/registry/dns/writer", "//java/google/registry/model", "//java/google/registry/util", ], diff --git a/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriter.java b/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriter.java index 8493e1109..831735115 100644 --- a/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriter.java +++ b/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriter.java @@ -25,7 +25,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.net.InternetDomainName; import google.registry.config.ConfigModule.Config; -import google.registry.model.dns.DnsWriter; +import google.registry.dns.writer.DnsWriter; import google.registry.model.domain.DomainResource; import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.host.HostResource; @@ -75,6 +75,12 @@ import org.xbill.DNS.Update; */ public class DnsUpdateWriter implements DnsWriter { + /** + * The name of the pricing engine, as used in {@code Registry.dnsWriter}. Remember to change + * the value on affected Registry objects to prevent runtime failures. + */ + public static final String NAME = "DnsUpdateWriter"; + private final Duration dnsTimeToLive; private final DnsMessageTransport transport; private final Clock clock; diff --git a/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriterModule.java b/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriterModule.java index f3df1b7af..a4fabd858 100644 --- a/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriterModule.java +++ b/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriterModule.java @@ -14,21 +14,26 @@ package google.registry.dns.writer.dnsupdate; -import dagger.Binds; import dagger.Module; import dagger.Provides; -import google.registry.model.dns.DnsWriter; +import dagger.multibindings.IntoMap; +import dagger.multibindings.StringKey; +import google.registry.dns.writer.DnsWriter; import javax.net.SocketFactory; /** Dagger module that provides a DnsUpdateWriter. */ @Module public abstract class DnsUpdateWriterModule { - @Binds - abstract DnsWriter provideDnsWriter(DnsUpdateWriter dnsWriter); - @Provides static SocketFactory provideSocketFactory() { return SocketFactory.getDefault(); } + + @Provides + @IntoMap + @StringKey(DnsUpdateWriter.NAME) + static DnsWriter provideDnsUpdateWriter(DnsUpdateWriter writer) { + return writer; + } } diff --git a/java/google/registry/model/dns/DnsWriter.java b/java/google/registry/model/dns/DnsWriter.java deleted file mode 100644 index a8bb59346..000000000 --- a/java/google/registry/model/dns/DnsWriter.java +++ /dev/null @@ -1,56 +0,0 @@ -// 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.model.dns; - -/** - * Transaction object for sending an atomic batch of updates for a single zone to the DNS server. - * - *

Here's an example of how you would publish updates for a domain and host: - *

- * @Inject Provider<DnsWriter> dnsWriter;
- * try (DnsWriter writer = dnsWriter.get()) {
- *   writer.publishDomain(domainName);
- *   writer.publishHost(hostName);
- * }
- * 
- */ -public interface DnsWriter extends AutoCloseable { - - /** - * Loads {@code domainName} from datastore and publishes its NS/DS records to the DNS server. - * Replaces existing records for the exact name supplied with an NS record for each name server - * and a DS record for each delegation signer stored in the registry for the supplied domain name. - * If the domain is deleted or is in a "non-publish" state then any existing records are deleted. - * - * @param domainName the fully qualified domain name, with no trailing dot - */ - void publishDomain(String domainName); - - /** - * Loads {@code hostName} from datastore and publishes its A/AAAA glue records to the DNS server, - * if it is used as an in-bailiwick nameserver. Orphaned glue records are prohibited. Replaces - * existing records for the exact name supplied, with an A or AAAA record (as appropriate) for - * each address stored in the registry, for the supplied host name. If the host is deleted then - * the existing records are deleted. Assumes that this method will only be called for in-bailiwick - * hosts. The registry does not have addresses for other hosts. - * - * @param hostName the fully qualified host name, with no trailing dot - */ - void publishHost(String hostName); - - /** Commits the updates to the DNS server atomically. */ - @Override - void close(); -} diff --git a/java/google/registry/model/dns/DnsWriterZone.java b/java/google/registry/model/dns/DnsWriterZone.java deleted file mode 100644 index b96ff4f80..000000000 --- a/java/google/registry/model/dns/DnsWriterZone.java +++ /dev/null @@ -1,23 +0,0 @@ -// 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.model.dns; - -import java.lang.annotation.Documented; -import javax.inject.Qualifier; - -/** Dagger qualifier for the fully-qualified zone name that's being updated. */ -@Qualifier -@Documented -public @interface DnsWriterZone {} diff --git a/java/google/registry/model/registry/Registry.java b/java/google/registry/model/registry/Registry.java index b0e8de742..d8e1de28a 100644 --- a/java/google/registry/model/registry/Registry.java +++ b/java/google/registry/model/registry/Registry.java @@ -255,6 +255,16 @@ public class Registry extends ImmutableObject implements Buildable { } } + /** Backfill the Registry entities that were saved before this field was added. */ + // TODO(shikhman): Remove this backfill once it is populated on all Registry entities. + @OnLoad + void backfillDnsWriter() { + if (dnsWriter == null) { + dnsWriter = "VoidDnsWriter"; + } + } + + /** * The name of the pricing engine that this TLD uses. * @@ -266,6 +276,14 @@ public class Registry extends ImmutableObject implements Buildable { */ String pricingEngineClassName; + /** + * The name of the DnsWriter that this TLD uses. + * + *

This must be a valid key for the map of DnsWriters injected by + * @Inject Map + */ + String dnsWriter; + /** * The unicode-aware representation of the TLD associated with this {@link Registry}. * @@ -545,6 +563,10 @@ public class Registry extends ImmutableObject implements Buildable { return pricingEngineClassName; } + public String getDnsWriter() { + return dnsWriter; + } + public ImmutableSet getAllowedRegistrantContactIds() { return nullToEmptyImmutableCopy(allowedRegistrantContactIds); } @@ -616,6 +638,12 @@ public class Registry extends ImmutableObject implements Buildable { return this; } + public Builder setDnsWriter(String dnsWriter) { + getInstance().dnsWriter = checkArgumentNotNull(dnsWriter); + return this; + } + + public Builder setAddGracePeriodLength(Duration addGracePeriodLength) { checkArgument(addGracePeriodLength.isLongerThan(Duration.ZERO), "addGracePeriodLength must be non-zero"); diff --git a/java/google/registry/module/backend/BUILD b/java/google/registry/module/backend/BUILD index 3c5dfc2e2..e5b470a89 100644 --- a/java/google/registry/module/backend/BUILD +++ b/java/google/registry/module/backend/BUILD @@ -13,6 +13,12 @@ java_library( "//java/com/google/common/base", "//java/com/google/common/collect", "//java/com/google/common/net", + "//third_party/java/bouncycastle", + "//third_party/java/dagger", + "//third_party/java/joda_time", + "//third_party/java/jsr305_annotations", + "//third_party/java/jsr330_inject", + "//third_party/java/servlet/servlet_api", "//java/google/registry/backup", "//java/google/registry/bigquery", "//java/google/registry/billing", @@ -20,6 +26,8 @@ java_library( "//java/google/registry/cron", "//java/google/registry/dns", "//java/google/registry/dns/writer", + "//java/google/registry/dns/writer/clouddns", + "//java/google/registry/dns/writer/dnsupdate", "//java/google/registry/export", "//java/google/registry/export/sheet", "//java/google/registry/flows", @@ -34,12 +42,6 @@ java_library( "//java/google/registry/request:modules", "//java/google/registry/tmch", "//java/google/registry/util", - "//third_party/java/bouncycastle", - "//third_party/java/dagger", - "//third_party/java/joda_time", - "//third_party/java/jsr305_annotations", - "//third_party/java/jsr330_inject", - "//third_party/java/servlet/servlet_api", ], ) diff --git a/java/google/registry/module/backend/BackendRequestComponent.java b/java/google/registry/module/backend/BackendRequestComponent.java index e31adc4fa..81d4a7a16 100644 --- a/java/google/registry/module/backend/BackendRequestComponent.java +++ b/java/google/registry/module/backend/BackendRequestComponent.java @@ -28,6 +28,8 @@ import google.registry.dns.DnsModule; import google.registry.dns.PublishDnsUpdatesAction; import google.registry.dns.ReadDnsQueueAction; import google.registry.dns.RefreshDnsAction; +import google.registry.dns.writer.clouddns.CloudDnsModule; +import google.registry.dns.writer.dnsupdate.DnsUpdateWriterModule; import google.registry.export.BigqueryPollJobAction; import google.registry.export.ExportDomainListsAction; import google.registry.export.ExportRequestModule; @@ -67,8 +69,10 @@ import google.registry.tmch.TmchSmdrlAction; AsyncFlowsModule.class, BackendModule.class, BackupModule.class, + CloudDnsModule.class, CronModule.class, DnsModule.class, + DnsUpdateWriterModule.class, ExportRequestModule.class, MapreduceModule.class, RdeModule.class, diff --git a/java/google/registry/tools/BUILD b/java/google/registry/tools/BUILD index 9e2e3715d..caa2513fa 100644 --- a/java/google/registry/tools/BUILD +++ b/java/google/registry/tools/BUILD @@ -45,6 +45,7 @@ java_library( "//java/com/google/common/util/concurrent", "//java/google/registry/bigquery", "//java/google/registry/config", + "//java/google/registry/dns/writer", "//java/google/registry/export", "//java/google/registry/flows", "//java/google/registry/keyring/api", diff --git a/java/google/registry/tools/CreateOrUpdateTldCommand.java b/java/google/registry/tools/CreateOrUpdateTldCommand.java index 63018a38c..0d44a2303 100644 --- a/java/google/registry/tools/CreateOrUpdateTldCommand.java +++ b/java/google/registry/tools/CreateOrUpdateTldCommand.java @@ -15,6 +15,7 @@ package google.registry.tools; import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; import static google.registry.model.RoidSuffixes.isRoidSuffixUsed; import static google.registry.util.CollectionUtils.findDuplicates; import static google.registry.util.DomainNameUtils.canonicalizeDomainName; @@ -26,6 +27,7 @@ import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedMap; +import google.registry.dns.writer.DnsWriter; import google.registry.model.pricing.StaticPremiumListPricingEngine; import google.registry.model.registry.Registries; import google.registry.model.registry.Registry; @@ -39,6 +41,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import javax.annotation.Nullable; +import javax.inject.Inject; import org.joda.money.Money; import org.joda.time.DateTime; import org.joda.time.Duration; @@ -46,6 +49,8 @@ import org.joda.time.Duration; /** Shared base class for commands to create or update a TLD. */ abstract class CreateOrUpdateTldCommand extends MutatingCommand { + @Inject Map dnsWriters; + @Parameter( description = "Names of the TLDs", required = true) @@ -205,6 +210,15 @@ abstract class CreateOrUpdateTldCommand extends MutatingCommand { description = "The end of the claims period") DateTime claimsPeriodEnd; + @Nullable + @Parameter( + names = "--dns_writer", + description = "The name of the DnsWriter implementation to use", + converter = OptionalStringParameter.class, + validateWith = OptionalStringParameter.class + ) + Optional dnsWriter; + /** Returns the existing registry (for update) or null (for creates). */ @Nullable abstract Registry getOldRegistry(String tld); @@ -361,6 +375,16 @@ abstract class CreateOrUpdateTldCommand extends MutatingCommand { } } + if (dnsWriter != null) { + if (dnsWriter.isPresent()) { + checkNotNull( + dnsWriters.get(dnsWriter.get()), + "The DNS writer '%s' doesn't exist", + dnsWriter.get()); + builder.setDnsWriter(dnsWriter.get()); + } + } + ImmutableSet newReservedListNames = getReservedLists(oldRegistry); checkReservedListValidityForTld(tld, newReservedListNames); builder.setReservedListsByName(newReservedListNames); diff --git a/javatests/google/registry/dns/PublishDnsUpdatesActionTest.java b/javatests/google/registry/dns/PublishDnsUpdatesActionTest.java index 69e740037..3f6792659 100644 --- a/javatests/google/registry/dns/PublishDnsUpdatesActionTest.java +++ b/javatests/google/registry/dns/PublishDnsUpdatesActionTest.java @@ -17,18 +17,20 @@ package google.registry.dns; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.persistActiveDomain; import static google.registry.testing.DatastoreHelper.persistActiveSubordinateHost; +import static google.registry.testing.DatastoreHelper.persistResource; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import google.registry.model.dns.DnsWriter; +import google.registry.dns.writer.DnsWriter; import google.registry.model.domain.DomainResource; import google.registry.model.ofy.Ofy; +import google.registry.model.registry.Registry; import google.registry.testing.AppEngineRule; import google.registry.testing.FakeClock; import google.registry.testing.InjectRule; -import javax.inject.Provider; import org.joda.time.DateTime; import org.joda.time.Duration; import org.junit.Before; @@ -58,6 +60,7 @@ 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()); DomainResource domain1 = persistActiveDomain("example.xn--q9jyb4c"); persistActiveSubordinateHost("ns1.example.xn--q9jyb4c", domain1); persistActiveSubordinateHost("ns2.example.xn--q9jyb4c", domain1); @@ -66,17 +69,13 @@ public class PublishDnsUpdatesActionTest { clock.advanceOneMilli(); } - private PublishDnsUpdatesAction createAction(String tld) { + private PublishDnsUpdatesAction createAction(String tld) throws Exception { PublishDnsUpdatesAction action = new PublishDnsUpdatesAction(); action.timeout = Duration.standardSeconds(10); action.tld = tld; action.hosts = ImmutableSet.of(); action.domains = ImmutableSet.of(); - action.writerProvider = new Provider() { - @Override - public DnsWriter get() { - return dnsWriter; - }}; + action.dnsWriterProxy = new DnsWriterProxy(ImmutableMap.of("mock", dnsWriter)); return action; } diff --git a/javatests/google/registry/model/schema.txt b/javatests/google/registry/model/schema.txt index 44c50dc76..2c037a4a3 100644 --- a/javatests/google/registry/model/schema.txt +++ b/javatests/google/registry/model/schema.txt @@ -675,6 +675,7 @@ class google.registry.model.registry.Registry { google.registry.model.common.TimedTransitionProperty eapFeeSchedule; google.registry.model.common.TimedTransitionProperty renewBillingCostTransitions; google.registry.model.registry.Registry$TldType tldType; + java.lang.String dnsWriter; java.lang.String driveFolderId; java.lang.String lordnUsername; java.lang.String pricingEngineClassName; diff --git a/javatests/google/registry/testing/BUILD b/javatests/google/registry/testing/BUILD index 0768d2a7a..71fb7b840 100644 --- a/javatests/google/registry/testing/BUILD +++ b/javatests/google/registry/testing/BUILD @@ -51,6 +51,7 @@ java_library( "//third_party/java/truth", "//java/google/registry/config", "//java/google/registry/dns:constants", + "//java/google/registry/dns/writer", "//java/google/registry/flows", "//java/google/registry/model", "//java/google/registry/pricing", diff --git a/javatests/google/registry/testing/DatastoreHelper.java b/javatests/google/registry/testing/DatastoreHelper.java index fa00e5a25..fa9e6ea7f 100644 --- a/javatests/google/registry/testing/DatastoreHelper.java +++ b/javatests/google/registry/testing/DatastoreHelper.java @@ -53,6 +53,7 @@ import com.googlecode.objectify.VoidWork; import com.googlecode.objectify.Work; import com.googlecode.objectify.cmd.Saver; import google.registry.config.RegistryEnvironment; +import google.registry.dns.writer.VoidDnsWriter; import google.registry.model.Buildable; import google.registry.model.EppResource; import google.registry.model.EppResource.ForeignKeyedEppResource; @@ -222,19 +223,20 @@ public class DatastoreHelper { public static Registry newRegistry( String tld, String roidSuffix, ImmutableSortedMap tldStates) { return new Registry.Builder() - .setTldStr(tld) - .setRoidSuffix(roidSuffix) - .setTldStateTransitions(tldStates) - // Set billing costs to distinct small primes to avoid masking bugs in tests. - .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 11))) - .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(USD))) - .setCreateBillingCost(Money.of(USD, 13)) - .setRestoreBillingCost(Money.of(USD, 17)) - .setServerStatusChangeBillingCost(Money.of(USD, 19)) - // 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) - .build(); + .setTldStr(tld) + .setRoidSuffix(roidSuffix) + .setTldStateTransitions(tldStates) + // Set billing costs to distinct small primes to avoid masking bugs in tests. + .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 11))) + .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(USD))) + .setCreateBillingCost(Money.of(USD, 13)) + .setRestoreBillingCost(Money.of(USD, 17)) + .setServerStatusChangeBillingCost(Money.of(USD, 19)) + // 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) + .build(); } public static ContactResource persistActiveContact(String contactId) {