Use Dagger to @Inject DnsQueue everywhere that is feasible

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=136062053
This commit is contained in:
mcilwain 2016-10-13 11:10:02 -07:00 committed by Ben McIlwain
parent a13f6aded8
commit 6a738557fb
17 changed files with 47 additions and 15 deletions

View file

@ -145,8 +145,13 @@ public class DnsQueue {
} }
} }
// TODO(b/19483428): Remove me when flows package is ported to Dagger. /**
/** Creates a new instance. */ * Creates a new instance.
*
* <p><b>Note:</b> Prefer <code>@Inject</code>ing DnsQueue instances instead. You should only use
* this helper method in situations for which injection does not work, e.g. inside mapper or
* reducer classes in mapreduces that need to be Serializable.
*/
public static DnsQueue create() { public static DnsQueue create() {
DnsQueue result = new DnsQueue(); DnsQueue result = new DnsQueue();
result.writeLockTimeout = Duration.standardSeconds(120); result.writeLockTimeout = Duration.standardSeconds(120);

View file

@ -18,6 +18,7 @@ import dagger.Module;
import dagger.Provides; import dagger.Provides;
import dagger.Subcomponent; import dagger.Subcomponent;
import google.registry.config.ConfigModule; import google.registry.config.ConfigModule;
import google.registry.dns.DnsModule;
import google.registry.flows.async.AsyncFlowsModule; import google.registry.flows.async.AsyncFlowsModule;
import google.registry.flows.contact.ContactCheckFlow; import google.registry.flows.contact.ContactCheckFlow;
import google.registry.flows.contact.ContactCreateFlow; import google.registry.flows.contact.ContactCreateFlow;
@ -65,6 +66,7 @@ import google.registry.util.SystemSleeper.SystemSleeperModule;
@Subcomponent(modules = { @Subcomponent(modules = {
AsyncFlowsModule.class, AsyncFlowsModule.class,
ConfigModule.class, ConfigModule.class,
DnsModule.class,
FlowModule.class, FlowModule.class,
FlowComponent.FlowComponentModule.class, FlowComponent.FlowComponentModule.class,
SystemSleeperModule.class}) SystemSleeperModule.class})

View file

@ -33,6 +33,7 @@ import google.registry.model.eppoutput.CreateData.DomainCreateData;
import google.registry.model.eppoutput.EppOutput; import google.registry.model.eppoutput.EppOutput;
import google.registry.model.eppoutput.Result; import google.registry.model.eppoutput.Result;
import google.registry.model.poll.PollMessage; import google.registry.model.poll.PollMessage;
import javax.inject.Inject;
import org.joda.time.DateTime; import org.joda.time.DateTime;
/** An EPP flow that creates or allocates a new domain resource. */ /** An EPP flow that creates or allocates a new domain resource. */
@ -41,6 +42,8 @@ public abstract class DomainCreateOrAllocateFlow
protected boolean isAnchorTenantViaExtension; protected boolean isAnchorTenantViaExtension;
@Inject DnsQueue dnsQueue;
@Override @Override
protected final void initDomainCreateFlow() { protected final void initDomainCreateFlow() {
isAnchorTenantViaExtension = isAnchorTenantViaExtension =
@ -85,7 +88,7 @@ public abstract class DomainCreateOrAllocateFlow
@Override @Override
protected final void enqueueTasks() { protected final void enqueueTasks() {
if (newResource.shouldPublishToDns()) { if (newResource.shouldPublishToDns()) {
DnsQueue.create().addDomainRefreshTask(newResource.getFullyQualifiedDomainName()); dnsQueue.addDomainRefreshTask(newResource.getFullyQualifiedDomainName());
} }
enqueueLordnTaskIfNeeded(); enqueueLordnTaskIfNeeded();
} }

View file

@ -94,6 +94,7 @@ public final class DomainDeleteFlow extends LoggedInFlow implements Transactiona
@Inject @ClientId String clientId; @Inject @ClientId String clientId;
@Inject @TargetId String targetId; @Inject @TargetId String targetId;
@Inject HistoryEntry.Builder historyBuilder; @Inject HistoryEntry.Builder historyBuilder;
@Inject DnsQueue dnsQueue;
@Inject DomainDeleteFlow() {} @Inject DomainDeleteFlow() {}
@Override @Override
@ -140,7 +141,7 @@ public final class DomainDeleteFlow extends LoggedInFlow implements Transactiona
// If there's a pending transfer, the gaining client's autorenew billing // If there's a pending transfer, the gaining client's autorenew billing
// event and poll message will already have been deleted in // event and poll message will already have been deleted in
// ResourceDeleteFlow since it's listed in serverApproveEntities. // ResourceDeleteFlow since it's listed in serverApproveEntities.
DnsQueue.create().addDomainRefreshTask(existingDomain.getFullyQualifiedDomainName()); dnsQueue.addDomainRefreshTask(existingDomain.getFullyQualifiedDomainName());
// Cancel any grace periods that were still active. // Cancel any grace periods that were still active.
for (GracePeriod gracePeriod : existingDomain.getGracePeriods()) { for (GracePeriod gracePeriod : existingDomain.getGracePeriods()) {
// No cancellation is written if the grace period was not for a billable event. // No cancellation is written if the grace period was not for a billable event.

View file

@ -108,6 +108,7 @@ public final class DomainRestoreRequestFlow extends LoggedInFlow implements Tran
@Inject @ClientId String clientId; @Inject @ClientId String clientId;
@Inject @TargetId String targetId; @Inject @TargetId String targetId;
@Inject HistoryEntry.Builder historyBuilder; @Inject HistoryEntry.Builder historyBuilder;
@Inject DnsQueue dnsQueue;
@Inject DomainRestoreRequestFlow() {} @Inject DomainRestoreRequestFlow() {}
@Override @Override
@ -157,7 +158,7 @@ public final class DomainRestoreRequestFlow extends LoggedInFlow implements Tran
entitiesToSave.add(newDomain, historyEntry, autorenewEvent, autorenewPollMessage); entitiesToSave.add(newDomain, historyEntry, autorenewEvent, autorenewPollMessage);
ofy().save().entities(entitiesToSave.build()); ofy().save().entities(entitiesToSave.build());
ofy().delete().key(existingDomain.getDeletePollMessage()); ofy().delete().key(existingDomain.getDeletePollMessage());
DnsQueue.create().addDomainRefreshTask(existingDomain.getFullyQualifiedDomainName()); dnsQueue.addDomainRefreshTask(existingDomain.getFullyQualifiedDomainName());
return createOutput(SUCCESS, null, createResponseExtensions(restoreCost, renewCost, feeUpdate)); return createOutput(SUCCESS, null, createResponseExtensions(restoreCost, renewCost, feeUpdate));
} }

View file

@ -132,6 +132,7 @@ public final class DomainUpdateFlow extends LoggedInFlow implements Transactiona
@Inject @ClientId String clientId; @Inject @ClientId String clientId;
@Inject @TargetId String targetId; @Inject @TargetId String targetId;
@Inject HistoryEntry.Builder historyBuilder; @Inject HistoryEntry.Builder historyBuilder;
@Inject DnsQueue dnsQueue;
@Inject DomainUpdateFlow() {} @Inject DomainUpdateFlow() {}
@Override @Override
@ -159,7 +160,7 @@ public final class DomainUpdateFlow extends LoggedInFlow implements Transactiona
} }
} }
validateNewState(newDomain); validateNewState(newDomain);
DnsQueue.create().addDomainRefreshTask(targetId); dnsQueue.addDomainRefreshTask(targetId);
handleExtraFlowLogic(existingDomain, historyEntry); handleExtraFlowLogic(existingDomain, historyEntry);
ImmutableList.Builder<ImmutableObject> entitiesToSave = new ImmutableList.Builder<>(); ImmutableList.Builder<ImmutableObject> entitiesToSave = new ImmutableList.Builder<>();
entitiesToSave.add(newDomain, historyEntry); entitiesToSave.add(newDomain, historyEntry);

View file

@ -74,6 +74,7 @@ public final class HostCreateFlow extends LoggedInFlow implements TransactionalF
@Inject @ClientId String clientId; @Inject @ClientId String clientId;
@Inject @TargetId String targetId; @Inject @TargetId String targetId;
@Inject HistoryEntry.Builder historyBuilder; @Inject HistoryEntry.Builder historyBuilder;
@Inject DnsQueue dnsQueue;
@Inject HostCreateFlow() {} @Inject HostCreateFlow() {}
@Override @Override
@ -126,7 +127,7 @@ public final class HostCreateFlow extends LoggedInFlow implements TransactionalF
.build()); .build());
// Only update DNS if this is a subordinate host. External hosts have no glue to write, so // Only update DNS if this is a subordinate host. External hosts have no glue to write, so
// they are only written as NS records from the referencing domain. // they are only written as NS records from the referencing domain.
DnsQueue.create().addHostRefreshTask(targetId); dnsQueue.addHostRefreshTask(targetId);
} }
ofy().save().entities(entitiesToSave); ofy().save().entities(entitiesToSave);
return createOutput(SUCCESS, HostCreateData.create(targetId, now)); return createOutput(SUCCESS, HostCreateData.create(targetId, now));

View file

@ -105,6 +105,7 @@ public final class HostUpdateFlow extends LoggedInFlow implements TransactionalF
@Inject @TargetId String targetId; @Inject @TargetId String targetId;
@Inject HistoryEntry.Builder historyBuilder; @Inject HistoryEntry.Builder historyBuilder;
@Inject AsyncFlowEnqueuer asyncFlowEnqueuer; @Inject AsyncFlowEnqueuer asyncFlowEnqueuer;
@Inject DnsQueue dnsQueue;
@Inject HostUpdateFlow() {} @Inject HostUpdateFlow() {}
@Override @Override
@ -219,14 +220,14 @@ public final class HostUpdateFlow extends LoggedInFlow implements TransactionalF
// Only update DNS for subordinate hosts. External hosts have no glue to write, so they // Only update DNS for subordinate hosts. External hosts have no glue to write, so they
// are only written as NS records from the referencing domain. // are only written as NS records from the referencing domain.
if (existingResource.getSuperordinateDomain() != null) { if (existingResource.getSuperordinateDomain() != null) {
DnsQueue.create().addHostRefreshTask(existingResource.getFullyQualifiedHostName()); dnsQueue.addHostRefreshTask(existingResource.getFullyQualifiedHostName());
} }
// In case of a rename, there are many updates we need to queue up. // In case of a rename, there are many updates we need to queue up.
if (((Update) resourceCommand).getInnerChange().getFullyQualifiedHostName() != null) { if (((Update) resourceCommand).getInnerChange().getFullyQualifiedHostName() != null) {
// If the renamed host is also subordinate, then we must enqueue an update to write the new // If the renamed host is also subordinate, then we must enqueue an update to write the new
// glue. // glue.
if (newResource.getSuperordinateDomain() != null) { if (newResource.getSuperordinateDomain() != null) {
DnsQueue.create().addHostRefreshTask(newResource.getFullyQualifiedHostName()); dnsQueue.addHostRefreshTask(newResource.getFullyQualifiedHostName());
} }
// We must also enqueue updates for all domains that use this host as their nameserver so // We must also enqueue updates for all domains that use this host as their nameserver so
// that their NS records can be updated to point at the new name. // that their NS records can be updated to point at the new name.

View file

@ -18,6 +18,7 @@ java_library(
"//third_party/java/servlet/servlet_api", "//third_party/java/servlet/servlet_api",
"//java/google/registry/braintree", "//java/google/registry/braintree",
"//java/google/registry/config", "//java/google/registry/config",
"//java/google/registry/dns",
"//java/google/registry/flows", "//java/google/registry/flows",
"//java/google/registry/keyring/api", "//java/google/registry/keyring/api",
"//java/google/registry/monitoring/metrics", "//java/google/registry/monitoring/metrics",

View file

@ -15,6 +15,7 @@
package google.registry.module.frontend; package google.registry.module.frontend;
import dagger.Subcomponent; import dagger.Subcomponent;
import google.registry.dns.DnsModule;
import google.registry.flows.CheckApiAction; import google.registry.flows.CheckApiAction;
import google.registry.flows.CheckApiAction.CheckApiModule; import google.registry.flows.CheckApiAction.CheckApiModule;
import google.registry.flows.EppConsoleAction; import google.registry.flows.EppConsoleAction;
@ -47,6 +48,7 @@ import google.registry.whois.WhoisServer;
@Subcomponent( @Subcomponent(
modules = { modules = {
CheckApiModule.class, CheckApiModule.class,
DnsModule.class,
EppTlsModule.class, EppTlsModule.class,
RdapModule.class, RdapModule.class,
RegistrarUserModule.class, RegistrarUserModule.class,

View file

@ -17,6 +17,7 @@ java_library(
"//third_party/java/jsr330_inject", "//third_party/java/jsr330_inject",
"//third_party/java/servlet/servlet_api", "//third_party/java/servlet/servlet_api",
"//java/google/registry/config", "//java/google/registry/config",
"//java/google/registry/dns",
"//java/google/registry/export", "//java/google/registry/export",
"//java/google/registry/flows", "//java/google/registry/flows",
"//java/google/registry/gcs", "//java/google/registry/gcs",

View file

@ -15,6 +15,7 @@
package google.registry.module.tools; package google.registry.module.tools;
import dagger.Subcomponent; import dagger.Subcomponent;
import google.registry.dns.DnsModule;
import google.registry.export.PublishDetailReportAction; import google.registry.export.PublishDetailReportAction;
import google.registry.flows.EppToolAction; import google.registry.flows.EppToolAction;
import google.registry.flows.EppToolAction.EppToolModule; import google.registry.flows.EppToolAction.EppToolModule;
@ -49,6 +50,7 @@ import google.registry.tools.server.javascrap.RefreshAllDomainsAction;
@RequestScope @RequestScope
@Subcomponent( @Subcomponent(
modules = { modules = {
DnsModule.class,
EppToolModule.class, EppToolModule.class,
LoadTestModule.class, LoadTestModule.class,
MapreduceModule.class, MapreduceModule.class,

View file

@ -31,7 +31,7 @@ public abstract class CreateOrUpdatePremiumListAction implements Runnable {
public static final String INPUT_PARAM = "inputData"; public static final String INPUT_PARAM = "inputData";
@Inject JsonResponse response; @Inject JsonResponse response;
@Inject @Parameter(NAME_PARAM) String name; @Inject @Parameter("premiumListName") String name;
@Inject @Parameter(INPUT_PARAM) String inputData; @Inject @Parameter(INPUT_PARAM) String inputData;
@Override @Override

View file

@ -57,7 +57,7 @@ public class ToolsServerModule {
} }
@Provides @Provides
@Parameter("name") @Parameter("premiumListName")
static String provideName(HttpServletRequest req) { static String provideName(HttpServletRequest req) {
return extractRequiredParameter(req, CreatePremiumListAction.NAME_PARAM); return extractRequiredParameter(req, CreatePremiumListAction.NAME_PARAM);
} }

View file

@ -36,8 +36,6 @@ public class RefreshAllDomainsAction implements Runnable {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass(); private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static DnsQueue dnsQueue = DnsQueue.create();
@Inject MapreduceRunner mrRunner; @Inject MapreduceRunner mrRunner;
@Inject Response response; @Inject Response response;
@Inject RefreshAllDomainsAction() {} @Inject RefreshAllDomainsAction() {}
@ -58,6 +56,7 @@ public class RefreshAllDomainsAction implements Runnable {
/** Mapper to refresh all active domain resources. */ /** Mapper to refresh all active domain resources. */
public static class RefreshAllDomainsActionMapper extends Mapper<DomainResource, Void, Void> { public static class RefreshAllDomainsActionMapper extends Mapper<DomainResource, Void, Void> {
private static final DnsQueue dnsQueue = DnsQueue.create();
private static final long serialVersionUID = 1356876487351666133L; private static final long serialVersionUID = 1356876487351666133L;
@Override @Override

View file

@ -14,8 +14,10 @@
package google.registry.dns; package google.registry.dns;
import static com.google.appengine.api.taskqueue.QueueFactory.getQueue;
import static com.google.common.collect.Lists.transform; import static com.google.common.collect.Lists.transform;
import static google.registry.dns.DnsConstants.DNS_PUBLISH_PUSH_QUEUE_NAME; import static google.registry.dns.DnsConstants.DNS_PUBLISH_PUSH_QUEUE_NAME;
import static google.registry.dns.DnsConstants.DNS_PULL_QUEUE_NAME;
import static google.registry.dns.DnsConstants.DNS_TARGET_NAME_PARAM; import static google.registry.dns.DnsConstants.DNS_TARGET_NAME_PARAM;
import static google.registry.dns.DnsConstants.DNS_TARGET_TYPE_PARAM; import static google.registry.dns.DnsConstants.DNS_TARGET_TYPE_PARAM;
import static google.registry.request.RequestParameters.PARAM_TLD; import static google.registry.request.RequestParameters.PARAM_TLD;
@ -84,7 +86,8 @@ public class ReadDnsQueueActionTest {
clock.setTo(DateTime.now(DateTimeZone.UTC)); clock.setTo(DateTime.now(DateTimeZone.UTC));
createTlds("com", "net", "example"); createTlds("com", "net", "example");
persistResource(Registry.get("example").asBuilder().setTldType(TldType.TEST).build()); persistResource(Registry.get("example").asBuilder().setTldType(TldType.TEST).build());
dnsQueue = DnsQueue.create(); dnsQueue = new DnsQueue();
dnsQueue.queue = getQueue(DNS_PULL_QUEUE_NAME);
dnsQueue.writeLockTimeout = Duration.standardSeconds(10); dnsQueue.writeLockTimeout = Duration.standardSeconds(10);
} }

View file

@ -22,6 +22,7 @@ import dagger.Module;
import dagger.Provides; import dagger.Provides;
import dagger.Subcomponent; import dagger.Subcomponent;
import google.registry.config.ConfigModule; import google.registry.config.ConfigModule;
import google.registry.dns.DnsQueue;
import google.registry.monitoring.whitebox.BigQueryMetricsEnqueuer; import google.registry.monitoring.whitebox.BigQueryMetricsEnqueuer;
import google.registry.monitoring.whitebox.EppMetric; import google.registry.monitoring.whitebox.EppMetric;
import google.registry.request.RequestScope; import google.registry.request.RequestScope;
@ -43,13 +44,16 @@ interface EppTestComponent {
/** Module for injecting fakes and mocks. */ /** Module for injecting fakes and mocks. */
@Module @Module
static class FakesAndMocksModule { static class FakesAndMocksModule {
final FakeClock clock; final FakeClock clock;
final EppMetric.Builder metricBuilder; final DnsQueue dnsQueue;
final BigQueryMetricsEnqueuer metricsEnqueuer; final BigQueryMetricsEnqueuer metricsEnqueuer;
final EppMetric.Builder metricBuilder;
final ModulesService modulesService; final ModulesService modulesService;
FakesAndMocksModule(FakeClock clock) { FakesAndMocksModule(FakeClock clock) {
this.clock = clock; this.clock = clock;
this.dnsQueue = DnsQueue.create();
this.metricBuilder = EppMetric.builderForRequest("request-id-1", clock); this.metricBuilder = EppMetric.builderForRequest("request-id-1", clock);
this.modulesService = mock(ModulesService.class); this.modulesService = mock(ModulesService.class);
this.metricsEnqueuer = mock(BigQueryMetricsEnqueuer.class); this.metricsEnqueuer = mock(BigQueryMetricsEnqueuer.class);
@ -60,6 +64,11 @@ interface EppTestComponent {
return clock; return clock;
} }
@Provides
DnsQueue provideDnsQueue() {
return dnsQueue;
}
@Provides @Provides
EppMetric.Builder provideMetrics() { EppMetric.Builder provideMetrics() {
return metricBuilder; return metricBuilder;