diff --git a/core/build.gradle b/core/build.gradle
index d2755d8b6..19c9a1631 100644
--- a/core/build.gradle
+++ b/core/build.gradle
@@ -76,6 +76,9 @@ def fragileTestPatterns = [
"google/registry/model/tmch/ClaimsListShardTest.*",
// Creates large object (64MBytes), occasionally throws OOM error.
"google/registry/model/server/KmsSecretRevisionTest.*",
+ // Changes cache timeouts and for some reason appears to have contention
+ // with other tests.
+ "google/registry/whois/WhoisCommandFactoryTest.*",
] + dockerIncompatibleTestPatterns
sourceSets {
diff --git a/core/src/main/java/google/registry/tools/RegistryToolComponent.java b/core/src/main/java/google/registry/tools/RegistryToolComponent.java
index cb68eb7be..31c0d6895 100644
--- a/core/src/main/java/google/registry/tools/RegistryToolComponent.java
+++ b/core/src/main/java/google/registry/tools/RegistryToolComponent.java
@@ -43,7 +43,7 @@ import google.registry.request.Modules.UrlFetchTransportModule;
import google.registry.request.Modules.UserServiceModule;
import google.registry.tools.AuthModule.LocalCredentialModule;
import google.registry.util.UtilsModule;
-import google.registry.whois.WhoisModule;
+import google.registry.whois.NonCachingWhoisModule;
import javax.annotation.Nullable;
import javax.inject.Singleton;
@@ -81,7 +81,7 @@ import javax.inject.Singleton;
UserServiceModule.class,
UtilsModule.class,
VoidDnsWriterModule.class,
- WhoisModule.class
+ NonCachingWhoisModule.class
})
interface RegistryToolComponent {
void inject(AckPollMessagesCommand command);
diff --git a/core/src/main/java/google/registry/whois/BaseWhoisModule.java b/core/src/main/java/google/registry/whois/BaseWhoisModule.java
new file mode 100644
index 000000000..aee86b24c
--- /dev/null
+++ b/core/src/main/java/google/registry/whois/BaseWhoisModule.java
@@ -0,0 +1,52 @@
+// Copyright 2021 The Nomulus 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.whois;
+
+import dagger.Module;
+import dagger.Provides;
+import google.registry.util.Clock;
+import google.registry.whois.WhoisMetrics.WhoisMetric;
+import java.io.IOException;
+import java.io.Reader;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * Dagger base module for the whois package.
+ *
+ *
Provides whois objects common to both the normal ({@link WhoisModule}) and non-caching ({@link
+ * NonCachingWhoisModule}) implementations.
+ */
+@Module
+class BaseWhoisModule {
+
+ @Provides
+ @SuppressWarnings("CloseableProvides")
+ static Reader provideHttpInputReader(HttpServletRequest req) {
+ try {
+ return req.getReader();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Provides a {@link WhoisMetrics.WhoisMetric.Builder} with the startTimestamp already
+ * initialized.
+ */
+ @Provides
+ static WhoisMetric.Builder provideEppMetricBuilder(Clock clock) {
+ return WhoisMetric.builderForRequest(clock);
+ }
+}
diff --git a/core/src/main/java/google/registry/whois/DomainLookupCommand.java b/core/src/main/java/google/registry/whois/DomainLookupCommand.java
index 57e2a5680..789d0dc41 100644
--- a/core/src/main/java/google/registry/whois/DomainLookupCommand.java
+++ b/core/src/main/java/google/registry/whois/DomainLookupCommand.java
@@ -14,6 +14,7 @@
package google.registry.whois;
+import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.EppResourceUtils.loadByForeignKeyCached;
import com.google.common.net.InternetDomainName;
@@ -25,20 +26,27 @@ import org.joda.time.DateTime;
public class DomainLookupCommand extends DomainOrHostLookupCommand {
private final boolean fullOutput;
+ private final boolean cached;
private final String whoisRedactedEmailText;
public DomainLookupCommand(
InternetDomainName domainName,
boolean fullOutput,
+ boolean cached,
String whoisRedactedEmailText) {
super(domainName, "Domain");
this.fullOutput = fullOutput;
+ this.cached = cached;
this.whoisRedactedEmailText = whoisRedactedEmailText;
}
@Override
protected Optional getResponse(InternetDomainName domainName, DateTime now) {
- return loadByForeignKeyCached(DomainBase.class, domainName.toString(), now)
- .map(domain -> new DomainWhoisResponse(domain, fullOutput, whoisRedactedEmailText, now));
+ Optional domainResource =
+ cached
+ ? loadByForeignKeyCached(DomainBase.class, domainName.toString(), now)
+ : loadByForeignKey(DomainBase.class, domainName.toString(), now);
+ return domainResource.map(
+ domain -> new DomainWhoisResponse(domain, fullOutput, whoisRedactedEmailText, now));
}
}
diff --git a/core/src/main/java/google/registry/whois/NameserverLookupByHostCommand.java b/core/src/main/java/google/registry/whois/NameserverLookupByHostCommand.java
index cad8a3d6b..3ca6432d3 100644
--- a/core/src/main/java/google/registry/whois/NameserverLookupByHostCommand.java
+++ b/core/src/main/java/google/registry/whois/NameserverLookupByHostCommand.java
@@ -14,6 +14,7 @@
package google.registry.whois;
+import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.EppResourceUtils.loadByForeignKeyCached;
import com.google.common.net.InternetDomainName;
@@ -24,13 +25,19 @@ import org.joda.time.DateTime;
/** Represents a WHOIS lookup on a nameserver based on its hostname. */
public class NameserverLookupByHostCommand extends DomainOrHostLookupCommand {
- NameserverLookupByHostCommand(InternetDomainName hostName) {
+ boolean cached;
+
+ NameserverLookupByHostCommand(InternetDomainName hostName, boolean cached) {
super(hostName, "Nameserver");
+ this.cached = cached;
}
@Override
protected Optional getResponse(InternetDomainName hostName, DateTime now) {
- return loadByForeignKeyCached(HostResource.class, hostName.toString(), now)
- .map(host -> new NameserverWhoisResponse(host, now));
+ Optional hostResource =
+ cached
+ ? loadByForeignKeyCached(HostResource.class, hostName.toString(), now)
+ : loadByForeignKey(HostResource.class, hostName.toString(), now);
+ return hostResource.map(host -> new NameserverWhoisResponse(host, now));
}
}
diff --git a/core/src/main/java/google/registry/whois/NonCachingWhoisModule.java b/core/src/main/java/google/registry/whois/NonCachingWhoisModule.java
new file mode 100644
index 000000000..6e4285bc4
--- /dev/null
+++ b/core/src/main/java/google/registry/whois/NonCachingWhoisModule.java
@@ -0,0 +1,39 @@
+// Copyright 2021 The Nomulus 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.whois;
+
+import dagger.Module;
+import dagger.Provides;
+import google.registry.config.RegistryConfig.Config;
+
+/**
+ * Whois module for systems that require that we not cache EPP resources (e.g. the nomulus tool).
+ *
+ * Dependencies
+ *
+ *
+ * - {@link google.registry.request.RequestModule RequestModule}
+ *
+ *
+ * @see "google.registry.tools.RegistryToolComponent"
+ */
+@Module
+public final class NonCachingWhoisModule extends BaseWhoisModule {
+ @Provides
+ @Config("whoisCommandFactory")
+ static WhoisCommandFactory provideWhoisCommandFactory() {
+ return WhoisCommandFactory.createNonCached();
+ }
+}
diff --git a/core/src/main/java/google/registry/whois/RegistrarLookupCommand.java b/core/src/main/java/google/registry/whois/RegistrarLookupCommand.java
index e90456c6f..51d801afe 100644
--- a/core/src/main/java/google/registry/whois/RegistrarLookupCommand.java
+++ b/core/src/main/java/google/registry/whois/RegistrarLookupCommand.java
@@ -39,61 +39,66 @@ final class RegistrarLookupCommand implements WhoisCommand {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
+ /** True if the command should return cached responses. */
+ private boolean cached;
+
/**
* Cache of a map from a stripped-down (letters and digits only) name to the registrar. This map
* includes only active, publicly visible registrars, because the others should be invisible to
* WHOIS.
*/
private static final Supplier