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
This commit is contained in:
mcilwain 2017-02-01 10:18:40 -08:00 committed by Ben McIlwain
parent 1577ab2c26
commit 636da9f7f0
10 changed files with 120 additions and 52 deletions

View file

@ -78,6 +78,9 @@ description of each option:
```yaml ```yaml
appEngine: appEngine:
projectId: # Your App Engine project ID projectId: # Your App Engine project ID
toolsServiceUrl:
hostName: tools-dot-PROJECT-ID.appspot.com # Insert your project ID
port: 443
gSuite: gSuite:
domainName: # Your G Suite domain name domainName: # Your G Suite domain name

View file

@ -18,7 +18,6 @@ import static com.google.common.base.Suppliers.memoize;
import static google.registry.config.ConfigUtils.makeUrl; import static google.registry.config.ConfigUtils.makeUrl;
import static google.registry.config.YamlUtils.getConfigSettings; import static google.registry.config.YamlUtils.getConfigSettings;
import static java.lang.annotation.RetentionPolicy.RUNTIME; 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.Optional;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
@ -27,6 +26,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.net.HostAndPort; import com.google.common.net.HostAndPort;
import dagger.Module; import dagger.Module;
import dagger.Provides; import dagger.Provides;
import google.registry.config.RegistryConfigSettings.AppEngine.ToolsServiceUrl;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.net.URI; import java.net.URI;
@ -855,8 +855,8 @@ public final class RegistryConfig {
*/ */
@Provides @Provides
@Config("contactAutomaticTransferLength") @Config("contactAutomaticTransferLength")
public static Duration provideContactAutomaticTransferLength() { public static Duration provideContactAutomaticTransferLength(RegistryConfigSettings config) {
return standardDays(5); return Duration.standardDays(config.registryPolicy.contactAutomaticTransferDays);
} }
/** /**
@ -909,16 +909,14 @@ public final class RegistryConfig {
@Provides @Provides
@Config("customLogicFactoryClass") @Config("customLogicFactoryClass")
public static String provideCustomLogicFactoryClass() { public static String provideCustomLogicFactoryClass(RegistryConfigSettings config) {
// TODO(b/32875427): This will be converted to YAML configuration in a future refactor. return config.registryPolicy.customLogicFactoryClass;
return "google.registry.flows.custom.CustomLogicFactory";
} }
@Provides @Provides
@Config("whoisCommandFactoryClass") @Config("whoisCommandFactoryClass")
public static String provideWhoisCommandFactoryClass() { public static String provideWhoisCommandFactoryClass(RegistryConfigSettings config) {
// TODO(b/32875427): This will be converted to YAML configuration in a future refactor. return config.registryPolicy.whoisCommandFactoryClass;
return "google.registry.whois.WhoisCommandFactory";
} }
private static final String RESERVED_TERMS_EXPORT_DISCLAIMER = "" private static final String RESERVED_TERMS_EXPORT_DISCLAIMER = ""
@ -1092,27 +1090,13 @@ public final class RegistryConfig {
* <p>This is used by the {@code nomulus} tool to connect to the App Engine remote API. * <p>This is used by the {@code nomulus} tool to connect to the App Engine remote API.
*/ */
public static HostAndPort getServer() { public static HostAndPort getServer() {
switch (RegistryEnvironment.get()) { ToolsServiceUrl url = CONFIG_SETTINGS.get().appEngine.toolsServiceUrl;
case LOCAL: return HostAndPort.fromParts(url.hostName, url.port);
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);
}
} }
/** Returns the amount of time a singleton should be cached, before expiring. */ /** Returns the amount of time a singleton should be cached, before expiring. */
public static Duration getSingletonCacheRefreshDuration() { public static Duration getSingletonCacheRefreshDuration() {
switch (RegistryEnvironment.get()) { return Duration.standardSeconds(CONFIG_SETTINGS.get().caching.singletonCacheRefreshSeconds);
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);
}
} }
/** /**
@ -1122,22 +1106,12 @@ public final class RegistryConfig {
* @see google.registry.model.registry.label.PremiumList * @see google.registry.model.registry.label.PremiumList
*/ */
public static Duration getDomainLabelListCacheDuration() { public static Duration getDomainLabelListCacheDuration() {
switch (RegistryEnvironment.get()) { return Duration.standardSeconds(CONFIG_SETTINGS.get().caching.domainLabelCachingSeconds);
case UNITTEST:
return Duration.ZERO;
default:
return Duration.standardHours(1);
}
} }
/** Returns the amount of time a singleton should be cached in persist mode, before expiring. */ /** Returns the amount of time a singleton should be cached in persist mode, before expiring. */
public static Duration getSingletonCachePersistDuration() { public static Duration getSingletonCachePersistDuration() {
switch (RegistryEnvironment.get()) { return Duration.standardSeconds(CONFIG_SETTINGS.get().caching.singletonCachePersistSeconds);
case UNITTEST:
return Duration.ZERO;
default:
return Duration.standardDays(365);
}
} }
/** /**
@ -1168,12 +1142,7 @@ public final class RegistryConfig {
* Returns the base retry duration that gets doubled after each failure within {@code Ofy}. * Returns the base retry duration that gets doubled after each failure within {@code Ofy}.
*/ */
public static Duration getBaseOfyRetryDuration() { public static Duration getBaseOfyRetryDuration() {
switch (RegistryEnvironment.get()) { return Duration.millis(CONFIG_SETTINGS.get().datastore.baseOfyRetryMillis);
case UNITTEST:
return Duration.ZERO;
default:
return Duration.millis(100);
}
} }
/** Returns the roid suffix to be used for the roids of all contacts and hosts. */ /** 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; 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. * 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_SEND_FROM_EMAIL_ADDRESS = "noreply@testing.example";
public static final String GOOGLE_APPS_ADMIN_EMAIL_DISPLAY_NAME = "Testing Nomulus"; public static final String GOOGLE_APPS_ADMIN_EMAIL_DISPLAY_NAME = "Testing Nomulus";
public static final Duration CONTACT_AUTOMATIC_TRANSFER_LENGTH = standardDays(5);
} }
private RegistryConfig() {} private RegistryConfig() {}

View file

@ -23,6 +23,7 @@ public class RegistryConfigSettings {
public GSuite gSuite; public GSuite gSuite;
public RegistryPolicy registryPolicy; public RegistryPolicy registryPolicy;
public Datastore datastore; public Datastore datastore;
public Caching caching;
public Rde rde; public Rde rde;
public RegistrarConsole registrarConsole; public RegistrarConsole registrarConsole;
public Monitoring monitoring; public Monitoring monitoring;
@ -31,6 +32,13 @@ public class RegistryConfigSettings {
/** Configuration options that apply to the entire App Engine project. */ /** Configuration options that apply to the entire App Engine project. */
public static class AppEngine { public static class AppEngine {
public String projectId; 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. */ /** Configuration options for the G Suite account used by Nomulus. */
@ -45,6 +53,9 @@ public class RegistryConfigSettings {
public static class RegistryPolicy { public static class RegistryPolicy {
public String contactAndHostRoidSuffix; public String contactAndHostRoidSuffix;
public String productName; public String productName;
public String customLogicFactoryClass;
public String whoisCommandFactoryClass;
public int contactAutomaticTransferDays;
public List<String> registrarChangesNotificationEmailAddresses; public List<String> registrarChangesNotificationEmailAddresses;
public String defaultRegistrarWhoisServer; public String defaultRegistrarWhoisServer;
public String defaultRegistrarReferralUrl; public String defaultRegistrarReferralUrl;
@ -57,6 +68,14 @@ public class RegistryConfigSettings {
public static class Datastore { public static class Datastore {
public int commitLogBucketsNum; public int commitLogBucketsNum;
public int eppResourceIndexBucketsNum; 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). */ /** Configuration for Registry Data Escrow (RDE). */

View file

@ -7,7 +7,12 @@
appEngine: appEngine:
# Globally unique App Engine project ID # 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: gSuite:
# Publicly accessible domain name of the running G Suite instance. # 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. # Product name of the registry. Used throughout the registrar console.
productName: Nomulus 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 # List of email addresses that notifications of registrar and/or registrar
# contact updates should be sent to, or empty list for no notifications. # contact updates should be sent to, or empty list for no notifications.
registrarChangesNotificationEmailAddresses: [] registrarChangesNotificationEmailAddresses: []
@ -57,6 +73,19 @@ datastore:
# initial install. # initial install.
eppResourceIndexBucketsNum: 997 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: rde:
# URL prefix of ICANN's server to upload RDE reports to. Nomulus adds /TLD/ID # URL prefix of ICANN's server to upload RDE reports to. Nomulus adds /TLD/ID

View file

@ -4,6 +4,11 @@
appEngine: appEngine:
projectId: placeholder 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: gSuite:
domainName: placeholder domainName: placeholder

View file

@ -1,6 +1,12 @@
# This is the configuration file used by unit tests. These values ARE NOT # This is the configuration file used by unit tests. These values ARE NOT
# SUITABLE for use in a real deployed environment. # 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: registryPolicy:
registrarChangesNotificationEmailAddresses: registrarChangesNotificationEmailAddresses:
- notification@test.example - notification@test.example
@ -11,3 +17,9 @@ registryPolicy:
datastore: datastore:
commitLogBucketsNum: 3 commitLogBucketsNum: 3
eppResourceIndexBucketsNum: 3 eppResourceIndexBucketsNum: 3
baseOfyRetryMillis: 0
caching:
singletonCacheRefreshSeconds: 0
domainLabelCachingSeconds: 0
singletonCachePersistSeconds: 0

View file

@ -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; package google.registry.export;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;

View file

@ -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; package google.registry.export;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
@ -45,7 +59,7 @@ public class ExportSnapshotActionTest {
.launchNewBackup( .launchNewBackup(
ExportSnapshotAction.QUEUE, ExportSnapshotAction.QUEUE,
"auto_snapshot_20140801_010203", "auto_snapshot_20140801_010203",
"domain-registry-snapshots", "registry-project-id-snapshots",
ExportConstants.getBackupKinds()); ExportConstants.getBackupKinds());
assertTasksEnqueued( assertTasksEnqueued(
CheckSnapshotAction.QUEUE, CheckSnapshotAction.QUEUE,

View file

@ -15,6 +15,7 @@
package google.registry.flows.contact; package google.registry.flows.contact;
import static com.google.common.truth.Truth.assertThat; 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.ContactResourceSubject.assertAboutContacts;
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.deleteResource; 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.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import google.registry.config.RegistryConfig.LocalTestConfig;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException; import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
import google.registry.flows.exceptions.AlreadyPendingTransferException; import google.registry.flows.exceptions.AlreadyPendingTransferException;
@ -57,7 +57,7 @@ public class ContactTransferRequestFlowTest
private void doSuccessfulTest(String commandFilename, String expectedXmlFilename) private void doSuccessfulTest(String commandFilename, String expectedXmlFilename)
throws Exception { throws Exception {
setEppInput(commandFilename); setEppInput(commandFilename);
DateTime afterTransfer = clock.nowUtc().plus(LocalTestConfig.CONTACT_AUTOMATIC_TRANSFER_LENGTH); DateTime afterTransfer = clock.nowUtc().plus(getContactAutomaticTransferLength());
// Setup done; run the test. // Setup done; run the test.
assertTransactionalFlow(true); assertTransactionalFlow(true);

View file

@ -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.collect.Iterables.toArray;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage; 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.getContactAndHostRoidSuffix;
import static google.registry.config.RegistryConfig.getContactAutomaticTransferLength;
import static google.registry.flows.ResourceFlowUtils.createTransferResponse; import static google.registry.flows.ResourceFlowUtils.createTransferResponse;
import static google.registry.model.EppResourceUtils.createDomainRepoId; import static google.registry.model.EppResourceUtils.createDomainRepoId;
import static google.registry.model.EppResourceUtils.createRepoId; import static google.registry.model.EppResourceUtils.createRepoId;
@ -482,7 +482,7 @@ public class DatastoreHelper {
.setCurrentSponsorClientId("TheRegistrar") .setCurrentSponsorClientId("TheRegistrar")
.addStatusValue(StatusValue.PENDING_TRANSFER) .addStatusValue(StatusValue.PENDING_TRANSFER)
.setTransferData(createTransferDataBuilder(requestTime, expirationTime) .setTransferData(createTransferDataBuilder(requestTime, expirationTime)
.setPendingTransferExpirationTime(now.plus(CONTACT_AUTOMATIC_TRANSFER_LENGTH)) .setPendingTransferExpirationTime(now.plus(getContactAutomaticTransferLength()))
.setServerApproveEntities( .setServerApproveEntities(
ImmutableSet.<Key<? extends TransferServerApproveEntity>>of( ImmutableSet.<Key<? extends TransferServerApproveEntity>>of(
// Pretend it's 3 days since the request // Pretend it's 3 days since the request