mirror of
https://github.com/google/nomulus.git
synced 2025-08-04 08:52:12 +02:00
Remove old DNS queue processing code.
The old DNS processing was performed by WriteDnsAction, which was invoked by the standard cron fanout action. The new code, which has been running for several months in production, uses ReadDnsQueueAction to do a custom fanout to PublishDnsUpdatesAction. We no longer need the old code, so it's time to remove it. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=127983115
This commit is contained in:
parent
b83b3b313f
commit
2c9567e183
13 changed files with 24 additions and 418 deletions
|
@ -29,6 +29,7 @@ java_library(
|
|||
"//third_party/java/servlet/servlet_api",
|
||||
"//third_party/java/truth",
|
||||
"//java/google/registry/config",
|
||||
"//java/google/registry/cron",
|
||||
"//java/google/registry/dns",
|
||||
"//java/google/registry/dns:constants",
|
||||
"//java/google/registry/dns/writer/api",
|
||||
|
|
|
@ -75,12 +75,12 @@ public final class DnsInjectionTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testWriteDnsAction_injectsAndWorks() throws Exception {
|
||||
public void testReadDnsQueueAction_injectsAndWorks() throws Exception {
|
||||
persistActiveSubordinateHost("ns1.example.lol", persistActiveDomain("example.lol"));
|
||||
clock.advanceOneMilli();
|
||||
dnsQueue.addDomainRefreshTask("example.lol");
|
||||
when(req.getParameter("tld")).thenReturn("lol");
|
||||
component.writeDnsAction().run();
|
||||
component.readDnsQueueAction().run();
|
||||
assertNoDnsTasksEnqueued();
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public class DnsQueueTest {
|
|||
createTld("tld");
|
||||
dnsQueue.addHostRefreshTask("octopus.tld");
|
||||
assertTasksEnqueued("dns-pull",
|
||||
new TaskMatcher().tag("tld").payload("Target-Type=HOST&Target-Name=octopus.tld&tld=tld"));
|
||||
new TaskMatcher().payload("Target-Type=HOST&Target-Name=octopus.tld&tld=tld"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -76,7 +76,7 @@ public class DnsQueueTest {
|
|||
createTld("tld");
|
||||
dnsQueue.addDomainRefreshTask("octopus.tld");
|
||||
assertTasksEnqueued("dns-pull",
|
||||
new TaskMatcher().tag("tld").payload("Target-Type=DOMAIN&Target-Name=octopus.tld&tld=tld"));
|
||||
new TaskMatcher().payload("Target-Type=DOMAIN&Target-Name=octopus.tld&tld=tld"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -16,10 +16,12 @@ package google.registry.dns;
|
|||
|
||||
import dagger.Component;
|
||||
import google.registry.config.ConfigModule;
|
||||
import google.registry.cron.CronModule;
|
||||
import google.registry.dns.writer.api.VoidDnsWriterModule;
|
||||
import google.registry.module.backend.BackendModule;
|
||||
import google.registry.request.RequestModule;
|
||||
import google.registry.util.SystemClock.SystemClockModule;
|
||||
import google.registry.util.SystemSleeper.SystemSleeperModule;
|
||||
|
||||
@Component(modules = {
|
||||
SystemClockModule.class,
|
||||
|
@ -28,9 +30,11 @@ import google.registry.util.SystemClock.SystemClockModule;
|
|||
DnsModule.class,
|
||||
RequestModule.class,
|
||||
VoidDnsWriterModule.class,
|
||||
SystemSleeperModule.class,
|
||||
CronModule.class,
|
||||
})
|
||||
interface DnsTestComponent {
|
||||
DnsQueue dnsQueue();
|
||||
RefreshDnsAction refreshDns();
|
||||
WriteDnsAction writeDnsAction();
|
||||
ReadDnsQueueAction readDnsQueueAction();
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ import org.junit.rules.ExpectedException;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
/** Unit tests for {@link WriteDnsAction}. */
|
||||
/** Unit tests for {@link PublishDnsUpdatesAction}. */
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PublishDnsUpdatesActionTest {
|
||||
|
||||
|
|
|
@ -101,22 +101,13 @@ public class ReadDnsQueueActionTest {
|
|||
action.run();
|
||||
}
|
||||
|
||||
// TODO(b/24564175): remove
|
||||
private enum RefreshTld { AS_TAG, AS_PARAM }
|
||||
|
||||
private static TaskOptions createRefreshTask(
|
||||
String name, TargetType type, RefreshTld refreshTld) {
|
||||
private static TaskOptions createRefreshTask(String name, TargetType type) {
|
||||
TaskOptions options = TaskOptions.Builder
|
||||
.withMethod(Method.PULL)
|
||||
.param(DNS_TARGET_TYPE_PARAM, type.toString())
|
||||
.param(DNS_TARGET_NAME_PARAM, name);
|
||||
String tld = InternetDomainName.from(name).parts().reverse().get(0);
|
||||
switch (refreshTld) {
|
||||
case AS_TAG:
|
||||
return options.tag(tld);
|
||||
default:
|
||||
return options.param(PARAM_TLD, tld);
|
||||
}
|
||||
return options.param(PARAM_TLD, tld);
|
||||
}
|
||||
|
||||
private void assertTldsEnqueuedInPushQueue(String... tlds) throws Exception {
|
||||
|
@ -164,29 +155,9 @@ public class ReadDnsQueueActionTest {
|
|||
run(true);
|
||||
assertTasksEnqueued(
|
||||
DnsConstants.DNS_PULL_QUEUE_NAME,
|
||||
new TaskMatcher().tag("com"),
|
||||
new TaskMatcher().tag("net"),
|
||||
new TaskMatcher().tag("example"));
|
||||
assertTldsEnqueuedInPushQueue("com", "net", "example");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_allTldsNoTag() throws Exception {
|
||||
dnsQueue.queue.add(createRefreshTask("domain.com", TargetType.DOMAIN, RefreshTld.AS_PARAM));
|
||||
dnsQueue.queue.add(createRefreshTask("domain.net", TargetType.DOMAIN, RefreshTld.AS_PARAM));
|
||||
dnsQueue.queue.add(createRefreshTask("domain.example", TargetType.DOMAIN, RefreshTld.AS_PARAM));
|
||||
run(false);
|
||||
assertNoTasksEnqueued(DnsConstants.DNS_PULL_QUEUE_NAME);
|
||||
assertTldsEnqueuedInPushQueue("com", "net", "example");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_allTldsMixedOldAndNewTldStyles() throws Exception {
|
||||
dnsQueue.addDomainRefreshTask("domain.com");
|
||||
dnsQueue.queue.add(createRefreshTask("domain.net", TargetType.DOMAIN, RefreshTld.AS_PARAM));
|
||||
dnsQueue.queue.add(createRefreshTask("domain.example", TargetType.DOMAIN, RefreshTld.AS_TAG));
|
||||
run(false);
|
||||
assertNoTasksEnqueued(DnsConstants.DNS_PULL_QUEUE_NAME);
|
||||
new TaskMatcher().payload("Target-Type=DOMAIN&Target-Name=domain.com&tld=com"),
|
||||
new TaskMatcher().payload("Target-Type=DOMAIN&Target-Name=domain.net&tld=net"),
|
||||
new TaskMatcher().payload("Target-Type=DOMAIN&Target-Name=domain.example&tld=example"));
|
||||
assertTldsEnqueuedInPushQueue("com", "net", "example");
|
||||
}
|
||||
|
||||
|
@ -197,7 +168,7 @@ public class ReadDnsQueueActionTest {
|
|||
dnsQueue.addDomainRefreshTask("domain.net");
|
||||
dnsQueue.addDomainRefreshTask("domain.example");
|
||||
run(false);
|
||||
assertTasksEnqueued(DnsConstants.DNS_PULL_QUEUE_NAME, new TaskMatcher().tag("net"));
|
||||
assertTasksEnqueued(DnsConstants.DNS_PULL_QUEUE_NAME, new TaskMatcher());
|
||||
assertTldsEnqueuedInPushQueue("com", "example");
|
||||
}
|
||||
|
||||
|
@ -239,13 +210,11 @@ public class ReadDnsQueueActionTest {
|
|||
task.param("domains", domainName);
|
||||
break;
|
||||
case 1:
|
||||
dnsQueue.queue.add(
|
||||
createRefreshTask("ns1." + domainName, TargetType.HOST, RefreshTld.AS_TAG));
|
||||
dnsQueue.queue.add(createRefreshTask("ns1." + domainName, TargetType.HOST));
|
||||
task.param("hosts", "ns1." + domainName);
|
||||
break;
|
||||
case 2:
|
||||
dnsQueue.queue.add(
|
||||
createRefreshTask("ns2." + domainName, TargetType.HOST, RefreshTld.AS_PARAM));
|
||||
dnsQueue.queue.add(createRefreshTask("ns2." + domainName, TargetType.HOST));
|
||||
task.param("hosts", "ns2." + domainName);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,195 +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;
|
||||
|
||||
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 google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
|
||||
import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued;
|
||||
import static google.registry.testing.TaskQueueHelper.clearTaskQueue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
import com.google.appengine.api.taskqueue.QueueFactory;
|
||||
import google.registry.dns.writer.api.DnsWriter;
|
||||
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.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
/** Unit tests for {@link WriteDnsAction}. */
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class WriteDnsActionTest {
|
||||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.withTaskQueue()
|
||||
.build();
|
||||
|
||||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final FakeClock clock = new FakeClock(DateTime.parse("1971-01-01TZ"));
|
||||
|
||||
private final DnsWriter dnsWriter = mock(DnsWriter.class);
|
||||
private final DnsQueue dnsQueue = new DnsQueue();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
inject.setStaticField(Ofy.class, "clock", clock);
|
||||
createTld("xn--q9jyb4c");
|
||||
dnsQueue.queue = QueueFactory.getQueue(DnsConstants.DNS_PULL_QUEUE_NAME);
|
||||
dnsQueue.writeBatchSize = 7;
|
||||
dnsQueue.writeLockTimeout = Duration.standardSeconds(10);
|
||||
}
|
||||
|
||||
private void run(String tld) {
|
||||
WriteDnsAction action = new WriteDnsAction();
|
||||
action.dnsQueue = dnsQueue;
|
||||
action.timeout = Duration.standardSeconds(10);
|
||||
action.tld = tld;
|
||||
action.writerProvider = new Provider<DnsWriter>() {
|
||||
@Override
|
||||
public DnsWriter get() {
|
||||
return dnsWriter;
|
||||
}};
|
||||
action.run();
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() throws Exception {
|
||||
clearTaskQueue("dns-pull");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_host() throws Exception {
|
||||
persistActiveSubordinateHost(
|
||||
"ns1.example.xn--q9jyb4c", persistActiveDomain("example.xn--q9jyb4c"));
|
||||
clock.advanceOneMilli();
|
||||
dnsQueue.addHostRefreshTask("ns1.example.xn--q9jyb4c");
|
||||
assertDnsTasksEnqueued("ns1.example.xn--q9jyb4c");
|
||||
run("xn--q9jyb4c");
|
||||
verify(dnsWriter).publishHost("ns1.example.xn--q9jyb4c");
|
||||
verify(dnsWriter).close();
|
||||
verifyNoMoreInteractions(dnsWriter);
|
||||
assertNoDnsTasksEnqueued();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_domain() throws Exception {
|
||||
persistActiveSubordinateHost(
|
||||
"ns1.example.xn--q9jyb4c", persistActiveDomain("example.xn--q9jyb4c"));
|
||||
clock.advanceOneMilli();
|
||||
dnsQueue.addDomainRefreshTask("example.xn--q9jyb4c");
|
||||
assertDnsTasksEnqueued("example.xn--q9jyb4c");
|
||||
run("xn--q9jyb4c");
|
||||
verify(dnsWriter).publishDomain("example.xn--q9jyb4c");
|
||||
verify(dnsWriter).close();
|
||||
verifyNoMoreInteractions(dnsWriter);
|
||||
assertNoDnsTasksEnqueued();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_zone() throws Exception {
|
||||
dnsQueue.addZoneRefreshTask("xn--q9jyb4c");
|
||||
assertDnsTasksEnqueued("xn--q9jyb4c");
|
||||
run("xn--q9jyb4c");
|
||||
verify(dnsWriter).close();
|
||||
verifyNoMoreInteractions(dnsWriter);
|
||||
assertNoDnsTasksEnqueued();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_dnsPaused() throws Exception {
|
||||
persistActiveSubordinateHost(
|
||||
"ns1.example.xn--q9jyb4c", persistActiveDomain("example.xn--q9jyb4c"));
|
||||
clock.advanceOneMilli();
|
||||
dnsQueue.addDomainRefreshTask("example.xn--q9jyb4c");
|
||||
assertDnsTasksEnqueued("example.xn--q9jyb4c");
|
||||
persistResource(Registry.get("xn--q9jyb4c").asBuilder().setDnsPaused(true).build());
|
||||
clock.advanceOneMilli();
|
||||
run("xn--q9jyb4c");
|
||||
verifyZeroInteractions(dnsWriter);
|
||||
assertDnsTasksEnqueued("example.xn--q9jyb4c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_twoTasksFromTheSameTld() throws Exception {
|
||||
persistActiveSubordinateHost(
|
||||
"ns1.example.xn--q9jyb4c", persistActiveDomain("example.xn--q9jyb4c"));
|
||||
clock.advanceOneMilli();
|
||||
dnsQueue.addDomainRefreshTask("example.xn--q9jyb4c");
|
||||
|
||||
persistActiveSubordinateHost(
|
||||
"ns1.example2.xn--q9jyb4c", persistActiveDomain("example2.xn--q9jyb4c"));
|
||||
clock.advanceOneMilli();
|
||||
dnsQueue.addDomainRefreshTask("example2.xn--q9jyb4c");
|
||||
assertDnsTasksEnqueued("example.xn--q9jyb4c", "example2.xn--q9jyb4c");
|
||||
|
||||
run("xn--q9jyb4c");
|
||||
assertNoDnsTasksEnqueued();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_twoTasksInDifferentTlds() throws Exception {
|
||||
// refresh example.xn--q9jyb4c
|
||||
persistActiveSubordinateHost(
|
||||
"ns1.example.xn--q9jyb4c", persistActiveDomain("example.xn--q9jyb4c"));
|
||||
clock.advanceOneMilli();
|
||||
dnsQueue.addDomainRefreshTask("example.xn--q9jyb4c");
|
||||
// refresh example.example
|
||||
createTld("example");
|
||||
persistActiveSubordinateHost(
|
||||
"ns1.example.example", persistActiveDomain("example.example"));
|
||||
clock.advanceOneMilli();
|
||||
dnsQueue.addDomainRefreshTask("example.example");
|
||||
// there should now be two tasks enqueued
|
||||
assertDnsTasksEnqueued("example.example", "example.xn--q9jyb4c");
|
||||
// process one, leaving one
|
||||
run("example");
|
||||
assertDnsTasksEnqueued("example.xn--q9jyb4c");
|
||||
// process the other, leaving none
|
||||
run("xn--q9jyb4c");
|
||||
assertNoDnsTasksEnqueued();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_domainDeleted() throws Exception {
|
||||
dnsQueue.addDomainRefreshTask("example.xn--q9jyb4c");
|
||||
assertDnsTasksEnqueued("example.xn--q9jyb4c");
|
||||
|
||||
run("xn--q9jyb4c");
|
||||
assertNoDnsTasksEnqueued();
|
||||
}
|
||||
}
|
|
@ -73,7 +73,7 @@ public final class RegistryTestServer {
|
|||
google.registry.module.backend.BackendServlet.class),
|
||||
|
||||
// Process DNS pull queue
|
||||
route("/_dr/task/writeDns",
|
||||
route("/_dr/cron/readDnsQueue",
|
||||
google.registry.module.backend.BackendServlet.class),
|
||||
|
||||
// Registrar Console
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue