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

@ -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 {
* <p>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() {}

View file

@ -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<String> 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). */

View file

@ -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

View file

@ -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

View file

@ -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