From 636da9f7f0fbc14e61ba1d514f4efa4a5b2a3de5 Mon Sep 17 00:00:00 2001 From: mcilwain Date: Wed, 1 Feb 2017 10:18:40 -0800 Subject: [PATCH] Convert yet more configuration options to YAML With a particular focus on custom logic and caching. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=146258446 --- docs/configuration.md | 3 + .../registry/config/RegistryConfig.java | 64 ++++++------------- .../config/RegistryConfigSettings.java | 19 ++++++ .../registry/config/default-config.yaml | 31 ++++++++- .../nomulus-config-production-sample.yaml | 5 ++ .../registry/config/unittest-config.yaml | 12 ++++ .../export/CheckSnapshotActionTest.java | 14 ++++ .../export/ExportSnapshotActionTest.java | 16 ++++- .../ContactTransferRequestFlowTest.java | 4 +- .../registry/testing/DatastoreHelper.java | 4 +- 10 files changed, 120 insertions(+), 52 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 4d48c3d38..2750a218d 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -78,6 +78,9 @@ description of each option: ```yaml appEngine: projectId: # Your App Engine project ID + toolsServiceUrl: + hostName: tools-dot-PROJECT-ID.appspot.com # Insert your project ID + port: 443 gSuite: domainName: # Your G Suite domain name diff --git a/java/google/registry/config/RegistryConfig.java b/java/google/registry/config/RegistryConfig.java index a63661ad4..57babdde7 100644 --- a/java/google/registry/config/RegistryConfig.java +++ b/java/google/registry/config/RegistryConfig.java @@ -18,7 +18,6 @@ import static com.google.common.base.Suppliers.memoize; import static google.registry.config.ConfigUtils.makeUrl; import static google.registry.config.YamlUtils.getConfigSettings; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import static org.joda.time.Duration.standardDays; import com.google.common.base.Optional; import com.google.common.base.Supplier; @@ -27,6 +26,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.net.HostAndPort; import dagger.Module; import dagger.Provides; +import google.registry.config.RegistryConfigSettings.AppEngine.ToolsServiceUrl; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.net.URI; @@ -855,8 +855,8 @@ public final class RegistryConfig { */ @Provides @Config("contactAutomaticTransferLength") - public static Duration provideContactAutomaticTransferLength() { - return standardDays(5); + public static Duration provideContactAutomaticTransferLength(RegistryConfigSettings config) { + return Duration.standardDays(config.registryPolicy.contactAutomaticTransferDays); } /** @@ -909,16 +909,14 @@ public final class RegistryConfig { @Provides @Config("customLogicFactoryClass") - public static String provideCustomLogicFactoryClass() { - // TODO(b/32875427): This will be converted to YAML configuration in a future refactor. - return "google.registry.flows.custom.CustomLogicFactory"; + public static String provideCustomLogicFactoryClass(RegistryConfigSettings config) { + return config.registryPolicy.customLogicFactoryClass; } @Provides @Config("whoisCommandFactoryClass") - public static String provideWhoisCommandFactoryClass() { - // TODO(b/32875427): This will be converted to YAML configuration in a future refactor. - return "google.registry.whois.WhoisCommandFactory"; + public static String provideWhoisCommandFactoryClass(RegistryConfigSettings config) { + return config.registryPolicy.whoisCommandFactoryClass; } private static final String RESERVED_TERMS_EXPORT_DISCLAIMER = "" @@ -1092,27 +1090,13 @@ public final class RegistryConfig { *

This is used by the {@code nomulus} tool to connect to the App Engine remote API. */ public static HostAndPort getServer() { - switch (RegistryEnvironment.get()) { - case LOCAL: - return HostAndPort.fromParts("localhost", 8080); - case UNITTEST: - throw new UnsupportedOperationException("Unit tests can't spin up a full server"); - default: - return HostAndPort.fromParts( - String.format("tools-dot-%s.appspot.com", getProjectId()), 443); - } + ToolsServiceUrl url = CONFIG_SETTINGS.get().appEngine.toolsServiceUrl; + return HostAndPort.fromParts(url.hostName, url.port); } /** Returns the amount of time a singleton should be cached, before expiring. */ public static Duration getSingletonCacheRefreshDuration() { - switch (RegistryEnvironment.get()) { - case UNITTEST: - // All cache durations are set to zero so that unit tests can update and then retrieve data - // immediately without failure. - return Duration.ZERO; - default: - return Duration.standardMinutes(10); - } + return Duration.standardSeconds(CONFIG_SETTINGS.get().caching.singletonCacheRefreshSeconds); } /** @@ -1122,22 +1106,12 @@ public final class RegistryConfig { * @see google.registry.model.registry.label.PremiumList */ public static Duration getDomainLabelListCacheDuration() { - switch (RegistryEnvironment.get()) { - case UNITTEST: - return Duration.ZERO; - default: - return Duration.standardHours(1); - } + return Duration.standardSeconds(CONFIG_SETTINGS.get().caching.domainLabelCachingSeconds); } /** Returns the amount of time a singleton should be cached in persist mode, before expiring. */ public static Duration getSingletonCachePersistDuration() { - switch (RegistryEnvironment.get()) { - case UNITTEST: - return Duration.ZERO; - default: - return Duration.standardDays(365); - } + return Duration.standardSeconds(CONFIG_SETTINGS.get().caching.singletonCachePersistSeconds); } /** @@ -1168,12 +1142,7 @@ public final class RegistryConfig { * Returns the base retry duration that gets doubled after each failure within {@code Ofy}. */ public static Duration getBaseOfyRetryDuration() { - switch (RegistryEnvironment.get()) { - case UNITTEST: - return Duration.ZERO; - default: - return Duration.millis(100); - } + return Duration.millis(CONFIG_SETTINGS.get().datastore.baseOfyRetryMillis); } /** Returns the roid suffix to be used for the roids of all contacts and hosts. */ @@ -1181,6 +1150,11 @@ public final class RegistryConfig { return CONFIG_SETTINGS.get().registryPolicy.contactAndHostRoidSuffix; } + /** Returns the global automatic transfer length for contacts. */ + public static Duration getContactAutomaticTransferLength() { + return Duration.standardDays(CONFIG_SETTINGS.get().registryPolicy.contactAutomaticTransferDays); + } + /** * Memoizes loading of the {@link RegistryConfigSettings} POJO. * @@ -1202,8 +1176,6 @@ public final class RegistryConfig { public static final String GOOGLE_APPS_SEND_FROM_EMAIL_ADDRESS = "noreply@testing.example"; public static final String GOOGLE_APPS_ADMIN_EMAIL_DISPLAY_NAME = "Testing Nomulus"; - - public static final Duration CONTACT_AUTOMATIC_TRANSFER_LENGTH = standardDays(5); } private RegistryConfig() {} diff --git a/java/google/registry/config/RegistryConfigSettings.java b/java/google/registry/config/RegistryConfigSettings.java index 76bc7bbdc..6a1d4a6c6 100644 --- a/java/google/registry/config/RegistryConfigSettings.java +++ b/java/google/registry/config/RegistryConfigSettings.java @@ -23,6 +23,7 @@ public class RegistryConfigSettings { public GSuite gSuite; public RegistryPolicy registryPolicy; public Datastore datastore; + public Caching caching; public Rde rde; public RegistrarConsole registrarConsole; public Monitoring monitoring; @@ -31,6 +32,13 @@ public class RegistryConfigSettings { /** Configuration options that apply to the entire App Engine project. */ public static class AppEngine { public String projectId; + public ToolsServiceUrl toolsServiceUrl; + + /** Configuration options for the tools service URL. */ + public static class ToolsServiceUrl { + public String hostName; + public int port; + } } /** Configuration options for the G Suite account used by Nomulus. */ @@ -45,6 +53,9 @@ public class RegistryConfigSettings { public static class RegistryPolicy { public String contactAndHostRoidSuffix; public String productName; + public String customLogicFactoryClass; + public String whoisCommandFactoryClass; + public int contactAutomaticTransferDays; public List registrarChangesNotificationEmailAddresses; public String defaultRegistrarWhoisServer; public String defaultRegistrarReferralUrl; @@ -57,6 +68,14 @@ public class RegistryConfigSettings { public static class Datastore { public int commitLogBucketsNum; public int eppResourceIndexBucketsNum; + public int baseOfyRetryMillis; + } + + /** Configuration for caching. */ + public static class Caching { + public int singletonCacheRefreshSeconds; + public int domainLabelCachingSeconds; + public int singletonCachePersistSeconds; } /** Configuration for Registry Data Escrow (RDE). */ diff --git a/java/google/registry/config/default-config.yaml b/java/google/registry/config/default-config.yaml index 4100edd19..b5fa93018 100644 --- a/java/google/registry/config/default-config.yaml +++ b/java/google/registry/config/default-config.yaml @@ -7,7 +7,12 @@ appEngine: # Globally unique App Engine project ID - projectId: domain-registry + projectId: registry-project-id + + # Hostname and port of the tools service for the project. + toolsServiceUrl: + hostName: localhost + port: 443 gSuite: # Publicly accessible domain name of the running G Suite instance. @@ -28,6 +33,17 @@ registryPolicy: # Product name of the registry. Used throughout the registrar console. productName: Nomulus + # Custom logic factory fully-qualified class name. + # See flows/custom/CustomLogicFactory.java + customLogicFactoryClass: google.registry.flows.custom.CustomLogicFactory + + # WHOIS command factory fully-qualified class name. + # See whois/WhoisCommandFactory.java + whoisCommandFactoryClass: google.registry.whois.WhoisCommandFactory + + # Length of time after which contact transfers automatically conclude. + contactAutomaticTransferDays: 5 + # List of email addresses that notifications of registrar and/or registrar # contact updates should be sent to, or empty list for no notifications. registrarChangesNotificationEmailAddresses: [] @@ -57,6 +73,19 @@ datastore: # initial install. eppResourceIndexBucketsNum: 997 + # Milliseconds that Objectify waits to retry a Datastore transaction (this + # doubles after each failure). + baseOfyRetryMillis: 100 + +caching: + # Length of time that a singleton should be cached before expiring. + singletonCacheRefreshSeconds: 600 + + # Length of time that a reserved/premium list should be cached before expiring. + domainLabelCachingSeconds: 3600 + + # Length of time that a long-lived singleton in persist mode should be cached. + singletonCachePersistSeconds: 31557600 # This is one year. rde: # URL prefix of ICANN's server to upload RDE reports to. Nomulus adds /TLD/ID diff --git a/java/google/registry/config/nomulus-config-production-sample.yaml b/java/google/registry/config/nomulus-config-production-sample.yaml index b8c7e06f4..a0090048a 100644 --- a/java/google/registry/config/nomulus-config-production-sample.yaml +++ b/java/google/registry/config/nomulus-config-production-sample.yaml @@ -4,6 +4,11 @@ appEngine: projectId: placeholder + # The "tools-dot-" prefix is used on the project ID in this URL in order to + # get around an issue with double-wildcard SSL certs. + toolsServiceUrl: + hostName: tools-dot-placeholder.appspot.com + port: 443 gSuite: domainName: placeholder diff --git a/java/google/registry/config/unittest-config.yaml b/java/google/registry/config/unittest-config.yaml index 5ccf08ebb..143e69a29 100644 --- a/java/google/registry/config/unittest-config.yaml +++ b/java/google/registry/config/unittest-config.yaml @@ -1,6 +1,12 @@ # This is the configuration file used by unit tests. These values ARE NOT # SUITABLE for use in a real deployed environment. +appEngine: + # Tests can't fire up a full server, so make them error out if they try to. + toolsServiceUrl: + hostName: null + port: 0 + registryPolicy: registrarChangesNotificationEmailAddresses: - notification@test.example @@ -11,3 +17,9 @@ registryPolicy: datastore: commitLogBucketsNum: 3 eppResourceIndexBucketsNum: 3 + baseOfyRetryMillis: 0 + +caching: + singletonCacheRefreshSeconds: 0 + domainLabelCachingSeconds: 0 + singletonCachePersistSeconds: 0 diff --git a/javatests/google/registry/export/CheckSnapshotActionTest.java b/javatests/google/registry/export/CheckSnapshotActionTest.java index fff52b07a..5e9cc63b1 100644 --- a/javatests/google/registry/export/CheckSnapshotActionTest.java +++ b/javatests/google/registry/export/CheckSnapshotActionTest.java @@ -1,3 +1,17 @@ +// Copyright 2017 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.export; import static com.google.common.truth.Truth.assertThat; diff --git a/javatests/google/registry/export/ExportSnapshotActionTest.java b/javatests/google/registry/export/ExportSnapshotActionTest.java index 981c469bb..9c298c8dc 100644 --- a/javatests/google/registry/export/ExportSnapshotActionTest.java +++ b/javatests/google/registry/export/ExportSnapshotActionTest.java @@ -1,3 +1,17 @@ +// Copyright 2017 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.export; import static com.google.common.truth.Truth.assertThat; @@ -45,7 +59,7 @@ public class ExportSnapshotActionTest { .launchNewBackup( ExportSnapshotAction.QUEUE, "auto_snapshot_20140801_010203", - "domain-registry-snapshots", + "registry-project-id-snapshots", ExportConstants.getBackupKinds()); assertTasksEnqueued( CheckSnapshotAction.QUEUE, diff --git a/javatests/google/registry/flows/contact/ContactTransferRequestFlowTest.java b/javatests/google/registry/flows/contact/ContactTransferRequestFlowTest.java index fa90ef5a9..00e8863ab 100644 --- a/javatests/google/registry/flows/contact/ContactTransferRequestFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactTransferRequestFlowTest.java @@ -15,6 +15,7 @@ package google.registry.flows.contact; import static com.google.common.truth.Truth.assertThat; +import static google.registry.config.RegistryConfig.getContactAutomaticTransferLength; import static google.registry.testing.ContactResourceSubject.assertAboutContacts; import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; import static google.registry.testing.DatastoreHelper.deleteResource; @@ -22,7 +23,6 @@ import static google.registry.testing.DatastoreHelper.getPollMessages; import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistResource; -import google.registry.config.RegistryConfig.LocalTestConfig; import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; import google.registry.flows.exceptions.AlreadyPendingTransferException; @@ -57,7 +57,7 @@ public class ContactTransferRequestFlowTest private void doSuccessfulTest(String commandFilename, String expectedXmlFilename) throws Exception { setEppInput(commandFilename); - DateTime afterTransfer = clock.nowUtc().plus(LocalTestConfig.CONTACT_AUTOMATIC_TRANSFER_LENGTH); + DateTime afterTransfer = clock.nowUtc().plus(getContactAutomaticTransferLength()); // Setup done; run the test. assertTransactionalFlow(true); diff --git a/javatests/google/registry/testing/DatastoreHelper.java b/javatests/google/registry/testing/DatastoreHelper.java index 87b5b8aae..4e0e29d10 100644 --- a/javatests/google/registry/testing/DatastoreHelper.java +++ b/javatests/google/registry/testing/DatastoreHelper.java @@ -20,8 +20,8 @@ import static com.google.common.base.Suppliers.memoize; import static com.google.common.collect.Iterables.toArray; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; -import static google.registry.config.RegistryConfig.LocalTestConfig.CONTACT_AUTOMATIC_TRANSFER_LENGTH; import static google.registry.config.RegistryConfig.getContactAndHostRoidSuffix; +import static google.registry.config.RegistryConfig.getContactAutomaticTransferLength; import static google.registry.flows.ResourceFlowUtils.createTransferResponse; import static google.registry.model.EppResourceUtils.createDomainRepoId; import static google.registry.model.EppResourceUtils.createRepoId; @@ -482,7 +482,7 @@ public class DatastoreHelper { .setCurrentSponsorClientId("TheRegistrar") .addStatusValue(StatusValue.PENDING_TRANSFER) .setTransferData(createTransferDataBuilder(requestTime, expirationTime) - .setPendingTransferExpirationTime(now.plus(CONTACT_AUTOMATIC_TRANSFER_LENGTH)) + .setPendingTransferExpirationTime(now.plus(getContactAutomaticTransferLength())) .setServerApproveEntities( ImmutableSet.>of( // Pretend it's 3 days since the request