mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 16:07:15 +02:00
Remove the util package's dependency on the config package
This allows us to use util methods from within config, which is a useful thing to be able to do for, e.g., being able to log errors while loading configuration. It makes sense that the util package should be at the very base of the class inheritance hierarchy; config seems logically higher than it. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=144324273
This commit is contained in:
parent
b0bcc1bb3d
commit
9f142c6767
15 changed files with 29 additions and 38 deletions
|
@ -15,6 +15,7 @@
|
||||||
package google.registry.config;
|
package google.registry.config;
|
||||||
|
|
||||||
import static google.registry.config.ConfigUtils.makeUrl;
|
import static google.registry.config.ConfigUtils.makeUrl;
|
||||||
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
import static org.joda.time.Duration.standardDays;
|
import static org.joda.time.Duration.standardDays;
|
||||||
|
|
||||||
import com.google.appengine.api.utils.SystemProperty;
|
import com.google.appengine.api.utils.SystemProperty;
|
||||||
|
@ -26,9 +27,11 @@ import com.google.common.net.HostAndPort;
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import javax.inject.Named;
|
||||||
import javax.inject.Qualifier;
|
import javax.inject.Qualifier;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import org.joda.money.CurrencyUnit;
|
import org.joda.money.CurrencyUnit;
|
||||||
|
@ -42,6 +45,7 @@ public final class RegistryConfig {
|
||||||
|
|
||||||
/** Dagger qualifier for configuration settings. */
|
/** Dagger qualifier for configuration settings. */
|
||||||
@Qualifier
|
@Qualifier
|
||||||
|
@Retention(RUNTIME)
|
||||||
@Documented
|
@Documented
|
||||||
public static @interface Config {
|
public static @interface Config {
|
||||||
String value() default "";
|
String value() default "";
|
||||||
|
@ -474,7 +478,7 @@ public final class RegistryConfig {
|
||||||
/**
|
/**
|
||||||
* The email address that outgoing emails from the app are sent from.
|
* The email address that outgoing emails from the app are sent from.
|
||||||
*
|
*
|
||||||
* @see google.registry.util.SendEmailUtils
|
* @see google.registry.ui.server.registrar.SendEmailUtils
|
||||||
*/
|
*/
|
||||||
@Provides
|
@Provides
|
||||||
@Config("googleAppsSendFromEmailAddress")
|
@Config("googleAppsSendFromEmailAddress")
|
||||||
|
@ -485,7 +489,7 @@ public final class RegistryConfig {
|
||||||
/**
|
/**
|
||||||
* The display name that is used on outgoing emails sent by Nomulus.
|
* The display name that is used on outgoing emails sent by Nomulus.
|
||||||
*
|
*
|
||||||
* @see google.registry.util.SendEmailUtils
|
* @see google.registry.ui.server.registrar.SendEmailUtils
|
||||||
*/
|
*/
|
||||||
@Provides
|
@Provides
|
||||||
@Config("googleAppsAdminEmailDisplayName")
|
@Config("googleAppsAdminEmailDisplayName")
|
||||||
|
@ -724,10 +728,13 @@ public final class RegistryConfig {
|
||||||
*
|
*
|
||||||
* <p>The number of milliseconds it'll sleep before giving up is {@code 2^n - 2}.
|
* <p>The number of milliseconds it'll sleep before giving up is {@code 2^n - 2}.
|
||||||
*
|
*
|
||||||
|
* <p>Note that this uses {@code @Named} instead of {@code @Config} so that it can be used from
|
||||||
|
* the low-level util package, which cannot have a dependency on the config package.
|
||||||
|
*
|
||||||
* @see google.registry.util.TaskEnqueuer
|
* @see google.registry.util.TaskEnqueuer
|
||||||
*/
|
*/
|
||||||
@Provides
|
@Provides
|
||||||
@Config("transientFailureRetries")
|
@Named("transientFailureRetries")
|
||||||
public static int provideTransientFailureRetries() {
|
public static int provideTransientFailureRetries() {
|
||||||
return 12; // Four seconds.
|
return 12; // Four seconds.
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class CloudDnsWriter implements DnsWriter {
|
||||||
|
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
private final RateLimiter rateLimiter;
|
private final RateLimiter rateLimiter;
|
||||||
// TODO(shikhman): This uses @Config("transientFailureRetries") which may not be tuned for this
|
// TODO(shikhman): This uses @Named("transientFailureRetries") which may not be tuned for this
|
||||||
// application.
|
// application.
|
||||||
private final Retrier retrier;
|
private final Retrier retrier;
|
||||||
private final Duration defaultTtl;
|
private final Duration defaultTtl;
|
||||||
|
|
|
@ -12,10 +12,9 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package google.registry.util;
|
package google.registry.model;
|
||||||
|
|
||||||
import static com.google.common.base.Suppliers.memoizeWithExpiration;
|
import static com.google.common.base.Suppliers.memoizeWithExpiration;
|
||||||
import static google.registry.config.RegistryConfig.getSingletonCachePersistDuration;
|
|
||||||
import static google.registry.config.RegistryConfig.getSingletonCacheRefreshDuration;
|
import static google.registry.config.RegistryConfig.getSingletonCacheRefreshDuration;
|
||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
import static org.joda.time.Duration.ZERO;
|
import static org.joda.time.Duration.ZERO;
|
||||||
|
@ -23,7 +22,7 @@ import static org.joda.time.Duration.ZERO;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
|
|
||||||
/** Utility methods related to caching. */
|
/** Utility methods related to caching Datastore entities. */
|
||||||
public class CacheUtils {
|
public class CacheUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,25 +32,9 @@ public class CacheUtils {
|
||||||
* lists downloaded from the TMCH get updated in datastore and the caches need to be refreshed.)
|
* lists downloaded from the TMCH get updated in datastore and the caches need to be refreshed.)
|
||||||
*/
|
*/
|
||||||
public static <T> Supplier<T> memoizeWithShortExpiration(Supplier<T> original) {
|
public static <T> Supplier<T> memoizeWithShortExpiration(Supplier<T> original) {
|
||||||
return memoizeForDuration(original, getSingletonCacheRefreshDuration());
|
Duration expiration = getSingletonCacheRefreshDuration();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Memoize a supplier, with a long expiration specified in the environment config.
|
|
||||||
*
|
|
||||||
* <p>Use this for things that are loaded lazily but then will never change. This allows the test
|
|
||||||
* config to set the expiration time to zero so that different test values can be substituted in,
|
|
||||||
* while allowing the production config to set the expiration to forever.
|
|
||||||
*/
|
|
||||||
public static <T> Supplier<T> memoizeWithLongExpiration(Supplier<T> original) {
|
|
||||||
return memoizeForDuration(original, getSingletonCachePersistDuration());
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Memoize a supplier, with a given expiration. */
|
|
||||||
private static <T> Supplier<T> memoizeForDuration(Supplier<T> original, Duration expiration) {
|
|
||||||
return expiration.isEqual(ZERO)
|
return expiration.isEqual(ZERO)
|
||||||
? original // memoizeWithExpiration won't accept 0 as a refresh duration.
|
? original
|
||||||
: memoizeWithExpiration(original, expiration.getMillis(), MILLISECONDS);
|
: memoizeWithExpiration(original, expiration.getMillis(), MILLISECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,9 @@
|
||||||
package google.registry.model;
|
package google.registry.model;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
import static google.registry.model.CacheUtils.memoizeWithShortExpiration;
|
||||||
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
|
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
|
||||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||||
import static google.registry.util.CacheUtils.memoizeWithShortExpiration;
|
|
||||||
|
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
|
|
|
@ -25,10 +25,10 @@ import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Maps.EntryTransformer;
|
import com.google.common.collect.Maps.EntryTransformer;
|
||||||
import com.google.common.collect.Ordering;
|
import com.google.common.collect.Ordering;
|
||||||
import com.googlecode.objectify.cmd.Query;
|
import com.googlecode.objectify.cmd.Query;
|
||||||
|
import google.registry.model.CacheUtils;
|
||||||
import google.registry.model.registrar.Registrar;
|
import google.registry.model.registrar.Registrar;
|
||||||
import google.registry.model.registry.Registries;
|
import google.registry.model.registry.Registries;
|
||||||
import google.registry.model.registry.Registry;
|
import google.registry.model.registry.Registry;
|
||||||
import google.registry.util.CacheUtils;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.joda.money.CurrencyUnit;
|
import org.joda.money.CurrencyUnit;
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
|
|
|
@ -19,9 +19,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Predicates.equalTo;
|
import static com.google.common.base.Predicates.equalTo;
|
||||||
import static com.google.common.base.Strings.emptyToNull;
|
import static com.google.common.base.Strings.emptyToNull;
|
||||||
import static com.google.common.collect.Maps.filterValues;
|
import static com.google.common.collect.Maps.filterValues;
|
||||||
|
import static google.registry.model.CacheUtils.memoizeWithShortExpiration;
|
||||||
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
|
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
|
||||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||||
import static google.registry.util.CacheUtils.memoizeWithShortExpiration;
|
|
||||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
|
|
|
@ -17,10 +17,10 @@ package google.registry.model.smd;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static com.google.common.collect.Iterables.isEmpty;
|
import static com.google.common.collect.Iterables.isEmpty;
|
||||||
|
import static google.registry.model.CacheUtils.memoizeWithShortExpiration;
|
||||||
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
|
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
|
||||||
import static google.registry.model.ofy.ObjectifyService.allocateId;
|
import static google.registry.model.ofy.ObjectifyService.allocateId;
|
||||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||||
import static google.registry.util.CacheUtils.memoizeWithShortExpiration;
|
|
||||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||||
import static google.registry.util.DateTimeUtils.isBeforeOrAt;
|
import static google.registry.util.DateTimeUtils.isBeforeOrAt;
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,10 @@ package google.registry.model.tmch;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static com.google.common.base.Verify.verify;
|
import static com.google.common.base.Verify.verify;
|
||||||
|
import static google.registry.model.CacheUtils.memoizeWithShortExpiration;
|
||||||
import static google.registry.model.ofy.ObjectifyService.allocateId;
|
import static google.registry.model.ofy.ObjectifyService.allocateId;
|
||||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||||
import static google.registry.model.ofy.Ofy.RECOMMENDED_MEMCACHE_EXPIRATION;
|
import static google.registry.model.ofy.Ofy.RECOMMENDED_MEMCACHE_EXPIRATION;
|
||||||
import static google.registry.util.CacheUtils.memoizeWithShortExpiration;
|
|
||||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
|
|
@ -45,7 +45,6 @@ import google.registry.ui.server.RegistrarFormFields;
|
||||||
import google.registry.util.CidrAddressBlock;
|
import google.registry.util.CidrAddressBlock;
|
||||||
import google.registry.util.CollectionUtils;
|
import google.registry.util.CollectionUtils;
|
||||||
import google.registry.util.DiffUtils;
|
import google.registry.util.DiffUtils;
|
||||||
import google.registry.util.SendEmailUtils;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package google.registry.util;
|
package google.registry.ui.server.registrar;
|
||||||
|
|
||||||
import static com.google.common.collect.Iterables.toArray;
|
import static com.google.common.collect.Iterables.toArray;
|
||||||
|
|
||||||
|
@ -21,6 +21,9 @@ import com.google.common.base.Joiner;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import com.google.common.collect.FluentIterable;
|
import com.google.common.collect.FluentIterable;
|
||||||
import google.registry.config.RegistryConfig.Config;
|
import google.registry.config.RegistryConfig.Config;
|
||||||
|
import google.registry.util.FormattingLogger;
|
||||||
|
import google.registry.util.NonFinalForTesting;
|
||||||
|
import google.registry.util.SendEmailService;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.mail.Message;
|
import javax.mail.Message;
|
|
@ -8,7 +8,6 @@ java_library(
|
||||||
name = "util",
|
name = "util",
|
||||||
srcs = glob(["*.java"]),
|
srcs = glob(["*.java"]),
|
||||||
deps = [
|
deps = [
|
||||||
"//java/google/registry/config",
|
|
||||||
"//third_party/java/objectify:objectify-v4_1",
|
"//third_party/java/objectify:objectify-v4_1",
|
||||||
"@com_google_appengine_api_1_0_sdk",
|
"@com_google_appengine_api_1_0_sdk",
|
||||||
"@com_google_code_findbugs_jsr305",
|
"@com_google_code_findbugs_jsr305",
|
||||||
|
|
|
@ -21,11 +21,11 @@ import static google.registry.util.PredicateUtils.supertypeOf;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import google.registry.config.RegistryConfig.Config;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
|
|
||||||
/** Wrapper that does retry with exponential backoff. */
|
/** Wrapper that does retry with exponential backoff. */
|
||||||
|
@ -39,7 +39,7 @@ public class Retrier implements Serializable {
|
||||||
private final int attempts;
|
private final int attempts;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public Retrier(Sleeper sleeper, @Config("transientFailureRetries") int transientFailureRetries) {
|
public Retrier(Sleeper sleeper, @Named("transientFailureRetries") int transientFailureRetries) {
|
||||||
this.sleeper = sleeper;
|
this.sleeper = sleeper;
|
||||||
checkArgument(transientFailureRetries > 0, "Number of attempts must be positive");
|
checkArgument(transientFailureRetries > 0, "Number of attempts must be positive");
|
||||||
this.attempts = transientFailureRetries;
|
this.attempts = transientFailureRetries;
|
||||||
|
|
|
@ -16,7 +16,7 @@ package google.registry.whois;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Strings.isNullOrEmpty;
|
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||||
import static google.registry.util.CacheUtils.memoizeWithShortExpiration;
|
import static google.registry.model.CacheUtils.memoizeWithShortExpiration;
|
||||||
import static google.registry.util.RegistrarUtils.normalizeRegistrarName;
|
import static google.registry.util.RegistrarUtils.normalizeRegistrarName;
|
||||||
import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
|
import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,6 @@ import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.FakeClock;
|
import google.registry.testing.FakeClock;
|
||||||
import google.registry.testing.InjectRule;
|
import google.registry.testing.InjectRule;
|
||||||
import google.registry.util.SendEmailService;
|
import google.registry.util.SendEmailService;
|
||||||
import google.registry.util.SendEmailUtils;
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package google.registry.util;
|
package google.registry.ui.server.registrar;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
|
@ -25,6 +25,7 @@ import com.google.common.collect.ImmutableList;
|
||||||
import google.registry.config.RegistryConfig.LocalTestConfig;
|
import google.registry.config.RegistryConfig.LocalTestConfig;
|
||||||
import google.registry.testing.ExceptionRule;
|
import google.registry.testing.ExceptionRule;
|
||||||
import google.registry.testing.InjectRule;
|
import google.registry.testing.InjectRule;
|
||||||
|
import google.registry.util.SendEmailService;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import javax.mail.Message;
|
import javax.mail.Message;
|
||||||
import javax.mail.Message.RecipientType;
|
import javax.mail.Message.RecipientType;
|
Loading…
Add table
Add a link
Reference in a new issue