mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Wrap ModulesService in new AppEngineServiceUtils
ModulesService does not provide a great API. Specifically, it doesn't have a way to get the hostname for a specific service; you have to get the hostname for a specific version as well. This is very rarely what we want, as we publish new versions every week and don't expect old ones to hang around for very long, so a task should execute against whatever the live version is, not whatever the current version was back when the task was enqueued (especially because that version might be deleted by now). This new and improved wrapper API removes the confusion and plays better with dependency injection to boot. We can also fold in other methods having to do with App Engine services, whereas ModulesService was quite limited in scope. This also has the side effect of fixing ResaveEntityAction, which is currently broken because the tasks it's enqueuing to execute up to 30 days in the future have the version hard-coded into the hostname, and we typically delete old versions sooner than that. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=206173763
This commit is contained in:
parent
c87fde605c
commit
6e74ba0587
27 changed files with 422 additions and 286 deletions
|
@ -20,16 +20,15 @@ import static com.google.common.base.Strings.nullToEmpty;
|
||||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||||
|
|
||||||
import com.google.appengine.api.datastore.Query;
|
import com.google.appengine.api.datastore.Query;
|
||||||
import com.google.appengine.api.modules.ModulesService;
|
|
||||||
import com.google.appengine.api.modules.ModulesServiceFactory;
|
|
||||||
import com.google.appengine.api.taskqueue.TaskHandle;
|
import com.google.appengine.api.taskqueue.TaskHandle;
|
||||||
import com.google.appengine.api.taskqueue.TaskOptions;
|
import com.google.appengine.api.taskqueue.TaskOptions;
|
||||||
import com.google.appengine.api.taskqueue.TaskOptions.Method;
|
import com.google.appengine.api.taskqueue.TaskOptions.Method;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Streams;
|
import com.google.common.collect.Streams;
|
||||||
import google.registry.util.NonFinalForTesting;
|
import google.registry.util.AppEngineServiceUtils;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
/** An object providing methods for starting and querying Datastore backups. */
|
/** An object providing methods for starting and querying Datastore backups. */
|
||||||
public class DatastoreBackupService {
|
public class DatastoreBackupService {
|
||||||
|
@ -40,19 +39,11 @@ public class DatastoreBackupService {
|
||||||
/** The name of the app version used for hosting the Datastore Admin functionality. */
|
/** The name of the app version used for hosting the Datastore Admin functionality. */
|
||||||
static final String DATASTORE_ADMIN_VERSION_NAME = "ah-builtin-python-bundle";
|
static final String DATASTORE_ADMIN_VERSION_NAME = "ah-builtin-python-bundle";
|
||||||
|
|
||||||
@NonFinalForTesting
|
private final AppEngineServiceUtils appEngineServiceUtils;
|
||||||
private static ModulesService modulesService = ModulesServiceFactory.getModulesService();
|
|
||||||
|
|
||||||
/**
|
@Inject
|
||||||
* Returns an instance of this service.
|
public DatastoreBackupService(AppEngineServiceUtils appEngineServiceUtils) {
|
||||||
*
|
this.appEngineServiceUtils = appEngineServiceUtils;
|
||||||
* <p>This method exists to allow for making the service a singleton object if desired at some
|
|
||||||
* future point; the choice is meaningless right now because the service maintains no state.
|
|
||||||
* That means its client-facing methods could in theory be static methods, but they are not
|
|
||||||
* because that makes it difficult to mock this service in clients.
|
|
||||||
*/
|
|
||||||
public static DatastoreBackupService get() {
|
|
||||||
return new DatastoreBackupService();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,9 +51,10 @@ public class DatastoreBackupService {
|
||||||
*
|
*
|
||||||
* @see <a href="https://developers.google.com/appengine/articles/scheduled_backups">Scheduled Backups</a>
|
* @see <a href="https://developers.google.com/appengine/articles/scheduled_backups">Scheduled Backups</a>
|
||||||
*/
|
*/
|
||||||
private static TaskOptions makeTaskOptions(
|
private TaskOptions makeTaskOptions(
|
||||||
String queue, String name, String gcsBucket, ImmutableSet<String> kinds) {
|
String queue, String name, String gcsBucket, ImmutableSet<String> kinds) {
|
||||||
String hostname = modulesService.getVersionHostname("default", DATASTORE_ADMIN_VERSION_NAME);
|
String hostname =
|
||||||
|
appEngineServiceUtils.getVersionHostname("default", DATASTORE_ADMIN_VERSION_NAME);
|
||||||
TaskOptions options = TaskOptions.Builder.withUrl("/_ah/datastore_admin/backup.create")
|
TaskOptions options = TaskOptions.Builder.withUrl("/_ah/datastore_admin/backup.create")
|
||||||
.header("Host", hostname)
|
.header("Host", hostname)
|
||||||
.method(Method.GET)
|
.method(Method.GET)
|
||||||
|
|
|
@ -103,9 +103,4 @@ public final class ExportRequestModule {
|
||||||
static String provideProjectId(HttpServletRequest req) {
|
static String provideProjectId(HttpServletRequest req) {
|
||||||
return extractRequiredHeader(req, PROJECT_ID_HEADER);
|
return extractRequiredHeader(req, PROJECT_ID_HEADER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
|
||||||
static DatastoreBackupService provideDatastoreBackupService() {
|
|
||||||
return DatastoreBackupService.get();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,6 @@ import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
|
||||||
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
|
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
|
||||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||||
|
|
||||||
import com.google.appengine.api.modules.ModulesService;
|
|
||||||
import com.google.appengine.api.modules.ModulesServiceFactory;
|
|
||||||
import com.google.appengine.api.taskqueue.TaskHandle;
|
|
||||||
import com.google.appengine.api.taskqueue.TaskOptions.Method;
|
import com.google.appengine.api.taskqueue.TaskOptions.Method;
|
||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
import google.registry.config.RegistryConfig.Config;
|
import google.registry.config.RegistryConfig.Config;
|
||||||
|
@ -34,7 +31,6 @@ import google.registry.request.Parameter;
|
||||||
import google.registry.request.Response;
|
import google.registry.request.Response;
|
||||||
import google.registry.request.auth.Auth;
|
import google.registry.request.auth.Auth;
|
||||||
import google.registry.request.lock.LockHandler;
|
import google.registry.request.lock.LockHandler;
|
||||||
import google.registry.util.NonFinalForTesting;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
@ -108,9 +104,6 @@ public class SyncRegistrarsSheetAction implements Runnable {
|
||||||
private static final String LOCK_NAME = "Synchronize registrars sheet";
|
private static final String LOCK_NAME = "Synchronize registrars sheet";
|
||||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||||
|
|
||||||
@NonFinalForTesting
|
|
||||||
private static ModulesService modulesService = ModulesServiceFactory.getModulesService();
|
|
||||||
|
|
||||||
@Inject Response response;
|
@Inject Response response;
|
||||||
@Inject SyncRegistrarsSheet syncRegistrarsSheet;
|
@Inject SyncRegistrarsSheet syncRegistrarsSheet;
|
||||||
@Inject @Config("sheetLockTimeout") Duration timeout;
|
@Inject @Config("sheetLockTimeout") Duration timeout;
|
||||||
|
@ -152,9 +145,10 @@ public class SyncRegistrarsSheetAction implements Runnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates, enqueues, and returns a new backend task to sync registrar spreadsheets. */
|
/**
|
||||||
public static TaskHandle enqueueBackendTask() {
|
* Enqueues a sync registrar sheet task targeting the App Engine service specified by hostname.
|
||||||
String hostname = modulesService.getVersionHostname("backend", null);
|
*/
|
||||||
return getQueue(QUEUE).add(withUrl(PATH).method(Method.GET).header("Host", hostname));
|
public static void enqueueRegistrarSheetSync(String hostname) {
|
||||||
|
getQueue(QUEUE).add(withUrl(PATH).method(Method.GET).header("Host", hostname));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ package google.registry.flows.async;
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static google.registry.util.DateTimeUtils.isBeforeOrAt;
|
import static google.registry.util.DateTimeUtils.isBeforeOrAt;
|
||||||
|
|
||||||
import com.google.appengine.api.modules.ModulesService;
|
|
||||||
import com.google.appengine.api.taskqueue.Queue;
|
import com.google.appengine.api.taskqueue.Queue;
|
||||||
import com.google.appengine.api.taskqueue.TaskOptions;
|
import com.google.appengine.api.taskqueue.TaskOptions;
|
||||||
import com.google.appengine.api.taskqueue.TaskOptions.Method;
|
import com.google.appengine.api.taskqueue.TaskOptions.Method;
|
||||||
|
@ -32,6 +31,7 @@ import google.registry.model.EppResource;
|
||||||
import google.registry.model.ImmutableObject;
|
import google.registry.model.ImmutableObject;
|
||||||
import google.registry.model.eppcommon.Trid;
|
import google.registry.model.eppcommon.Trid;
|
||||||
import google.registry.model.host.HostResource;
|
import google.registry.model.host.HostResource;
|
||||||
|
import google.registry.util.AppEngineServiceUtils;
|
||||||
import google.registry.util.Retrier;
|
import google.registry.util.Retrier;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
@ -65,7 +65,7 @@ public final class AsyncFlowEnqueuer {
|
||||||
private final Queue asyncActionsPushQueue;
|
private final Queue asyncActionsPushQueue;
|
||||||
private final Queue asyncDeletePullQueue;
|
private final Queue asyncDeletePullQueue;
|
||||||
private final Queue asyncDnsRefreshPullQueue;
|
private final Queue asyncDnsRefreshPullQueue;
|
||||||
private final ModulesService modulesService;
|
private final AppEngineServiceUtils appEngineServiceUtils;
|
||||||
private final Retrier retrier;
|
private final Retrier retrier;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
@ -75,13 +75,13 @@ public final class AsyncFlowEnqueuer {
|
||||||
@Named(QUEUE_ASYNC_DELETE) Queue asyncDeletePullQueue,
|
@Named(QUEUE_ASYNC_DELETE) Queue asyncDeletePullQueue,
|
||||||
@Named(QUEUE_ASYNC_HOST_RENAME) Queue asyncDnsRefreshPullQueue,
|
@Named(QUEUE_ASYNC_HOST_RENAME) Queue asyncDnsRefreshPullQueue,
|
||||||
@Config("asyncDeleteFlowMapreduceDelay") Duration asyncDeleteDelay,
|
@Config("asyncDeleteFlowMapreduceDelay") Duration asyncDeleteDelay,
|
||||||
ModulesService modulesService,
|
AppEngineServiceUtils appEngineServiceUtils,
|
||||||
Retrier retrier) {
|
Retrier retrier) {
|
||||||
this.asyncActionsPushQueue = asyncActionsPushQueue;
|
this.asyncActionsPushQueue = asyncActionsPushQueue;
|
||||||
this.asyncDeletePullQueue = asyncDeletePullQueue;
|
this.asyncDeletePullQueue = asyncDeletePullQueue;
|
||||||
this.asyncDnsRefreshPullQueue = asyncDnsRefreshPullQueue;
|
this.asyncDnsRefreshPullQueue = asyncDnsRefreshPullQueue;
|
||||||
this.asyncDeleteDelay = asyncDeleteDelay;
|
this.asyncDeleteDelay = asyncDeleteDelay;
|
||||||
this.modulesService = modulesService;
|
this.appEngineServiceUtils = appEngineServiceUtils;
|
||||||
this.retrier = retrier;
|
this.retrier = retrier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ public final class AsyncFlowEnqueuer {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.atInfo().log("Enqueuing async re-save of %s to run at %s.", entityKey, whenToResave);
|
logger.atInfo().log("Enqueuing async re-save of %s to run at %s.", entityKey, whenToResave);
|
||||||
String backendHostname = modulesService.getVersionHostname("backend", null);
|
String backendHostname = appEngineServiceUtils.getServiceHostname("backend");
|
||||||
TaskOptions task =
|
TaskOptions task =
|
||||||
TaskOptions.Builder.withUrl(PATH_RESAVE_ENTITY)
|
TaskOptions.Builder.withUrl(PATH_RESAVE_ENTITY)
|
||||||
.method(Method.POST)
|
.method(Method.POST)
|
||||||
|
|
|
@ -34,13 +34,13 @@ import google.registry.request.Modules.AppIdentityCredentialModule;
|
||||||
import google.registry.request.Modules.DatastoreServiceModule;
|
import google.registry.request.Modules.DatastoreServiceModule;
|
||||||
import google.registry.request.Modules.GoogleCredentialModule;
|
import google.registry.request.Modules.GoogleCredentialModule;
|
||||||
import google.registry.request.Modules.Jackson2Module;
|
import google.registry.request.Modules.Jackson2Module;
|
||||||
import google.registry.request.Modules.ModulesServiceModule;
|
|
||||||
import google.registry.request.Modules.NetHttpTransportModule;
|
import google.registry.request.Modules.NetHttpTransportModule;
|
||||||
import google.registry.request.Modules.URLFetchServiceModule;
|
import google.registry.request.Modules.URLFetchServiceModule;
|
||||||
import google.registry.request.Modules.UrlFetchTransportModule;
|
import google.registry.request.Modules.UrlFetchTransportModule;
|
||||||
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
||||||
import google.registry.request.Modules.UserServiceModule;
|
import google.registry.request.Modules.UserServiceModule;
|
||||||
import google.registry.request.auth.AuthModule;
|
import google.registry.request.auth.AuthModule;
|
||||||
|
import google.registry.util.AppEngineServiceUtilsImpl.AppEngineServiceUtilsModule;
|
||||||
import google.registry.util.SystemClock.SystemClockModule;
|
import google.registry.util.SystemClock.SystemClockModule;
|
||||||
import google.registry.util.SystemSleeper.SystemSleeperModule;
|
import google.registry.util.SystemSleeper.SystemSleeperModule;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
@ -48,37 +48,36 @@ import javax.inject.Singleton;
|
||||||
/** Dagger component with instance lifetime for "backend" App Engine module. */
|
/** Dagger component with instance lifetime for "backend" App Engine module. */
|
||||||
@Singleton
|
@Singleton
|
||||||
@Component(
|
@Component(
|
||||||
modules = {
|
modules = {
|
||||||
AppIdentityCredentialModule.class,
|
AppEngineServiceUtilsModule.class,
|
||||||
AuthModule.class,
|
AppIdentityCredentialModule.class,
|
||||||
BackendRequestComponentModule.class,
|
AuthModule.class,
|
||||||
BigqueryModule.class,
|
BackendRequestComponentModule.class,
|
||||||
ConfigModule.class,
|
BigqueryModule.class,
|
||||||
DatastoreServiceModule.class,
|
ConfigModule.class,
|
||||||
DirectoryModule.class,
|
DatastoreServiceModule.class,
|
||||||
google.registry.keyring.api.DummyKeyringModule.class,
|
DirectoryModule.class,
|
||||||
DriveModule.class,
|
google.registry.keyring.api.DummyKeyringModule.class,
|
||||||
GcsServiceModule.class,
|
DriveModule.class,
|
||||||
GoogleCredentialModule.class,
|
GcsServiceModule.class,
|
||||||
GroupsModule.class,
|
GoogleCredentialModule.class,
|
||||||
GroupssettingsModule.class,
|
GroupsModule.class,
|
||||||
JSchModule.class,
|
GroupssettingsModule.class,
|
||||||
Jackson2Module.class,
|
JSchModule.class,
|
||||||
KeyModule.class,
|
Jackson2Module.class,
|
||||||
KmsModule.class,
|
KeyModule.class,
|
||||||
ModulesServiceModule.class,
|
KmsModule.class,
|
||||||
NetHttpTransportModule.class,
|
NetHttpTransportModule.class,
|
||||||
SheetsServiceModule.class,
|
SheetsServiceModule.class,
|
||||||
StackdriverModule.class,
|
StackdriverModule.class,
|
||||||
SystemClockModule.class,
|
SystemClockModule.class,
|
||||||
SystemSleeperModule.class,
|
SystemSleeperModule.class,
|
||||||
URLFetchServiceModule.class,
|
URLFetchServiceModule.class,
|
||||||
UrlFetchTransportModule.class,
|
UrlFetchTransportModule.class,
|
||||||
UseAppIdentityCredentialForGoogleApisModule.class,
|
UseAppIdentityCredentialForGoogleApisModule.class,
|
||||||
UserServiceModule.class,
|
UserServiceModule.class,
|
||||||
google.registry.dns.writer.VoidDnsWriterModule.class,
|
google.registry.dns.writer.VoidDnsWriterModule.class,
|
||||||
}
|
})
|
||||||
)
|
|
||||||
interface BackendComponent {
|
interface BackendComponent {
|
||||||
BackendRequestHandler requestHandler();
|
BackendRequestHandler requestHandler();
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,13 @@ import google.registry.monitoring.whitebox.StackdriverModule;
|
||||||
import google.registry.request.Modules.AppIdentityCredentialModule;
|
import google.registry.request.Modules.AppIdentityCredentialModule;
|
||||||
import google.registry.request.Modules.GoogleCredentialModule;
|
import google.registry.request.Modules.GoogleCredentialModule;
|
||||||
import google.registry.request.Modules.Jackson2Module;
|
import google.registry.request.Modules.Jackson2Module;
|
||||||
import google.registry.request.Modules.ModulesServiceModule;
|
|
||||||
import google.registry.request.Modules.NetHttpTransportModule;
|
import google.registry.request.Modules.NetHttpTransportModule;
|
||||||
import google.registry.request.Modules.UrlFetchTransportModule;
|
import google.registry.request.Modules.UrlFetchTransportModule;
|
||||||
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
||||||
import google.registry.request.Modules.UserServiceModule;
|
import google.registry.request.Modules.UserServiceModule;
|
||||||
import google.registry.request.auth.AuthModule;
|
import google.registry.request.auth.AuthModule;
|
||||||
import google.registry.ui.ConsoleDebug.ConsoleConfigModule;
|
import google.registry.ui.ConsoleDebug.ConsoleConfigModule;
|
||||||
|
import google.registry.util.AppEngineServiceUtilsImpl.AppEngineServiceUtilsModule;
|
||||||
import google.registry.util.SystemClock.SystemClockModule;
|
import google.registry.util.SystemClock.SystemClockModule;
|
||||||
import google.registry.util.SystemSleeper.SystemSleeperModule;
|
import google.registry.util.SystemSleeper.SystemSleeperModule;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
@ -41,29 +41,28 @@ import javax.inject.Singleton;
|
||||||
/** Dagger component with instance lifetime for "default" App Engine module. */
|
/** Dagger component with instance lifetime for "default" App Engine module. */
|
||||||
@Singleton
|
@Singleton
|
||||||
@Component(
|
@Component(
|
||||||
modules = {
|
modules = {
|
||||||
AppIdentityCredentialModule.class,
|
AppEngineServiceUtilsModule.class,
|
||||||
AuthModule.class,
|
AppIdentityCredentialModule.class,
|
||||||
ConfigModule.class,
|
AuthModule.class,
|
||||||
ConsoleConfigModule.class,
|
ConfigModule.class,
|
||||||
CustomLogicFactoryModule.class,
|
ConsoleConfigModule.class,
|
||||||
google.registry.keyring.api.DummyKeyringModule.class,
|
CustomLogicFactoryModule.class,
|
||||||
FrontendRequestComponentModule.class,
|
google.registry.keyring.api.DummyKeyringModule.class,
|
||||||
GoogleCredentialModule.class,
|
FrontendRequestComponentModule.class,
|
||||||
Jackson2Module.class,
|
GoogleCredentialModule.class,
|
||||||
KeyModule.class,
|
Jackson2Module.class,
|
||||||
KmsModule.class,
|
KeyModule.class,
|
||||||
ModulesServiceModule.class,
|
KmsModule.class,
|
||||||
NetHttpTransportModule.class,
|
NetHttpTransportModule.class,
|
||||||
ServerTridProviderModule.class,
|
ServerTridProviderModule.class,
|
||||||
StackdriverModule.class,
|
StackdriverModule.class,
|
||||||
SystemClockModule.class,
|
SystemClockModule.class,
|
||||||
SystemSleeperModule.class,
|
SystemSleeperModule.class,
|
||||||
UrlFetchTransportModule.class,
|
UrlFetchTransportModule.class,
|
||||||
UseAppIdentityCredentialForGoogleApisModule.class,
|
UseAppIdentityCredentialForGoogleApisModule.class,
|
||||||
UserServiceModule.class,
|
UserServiceModule.class,
|
||||||
}
|
})
|
||||||
)
|
|
||||||
interface FrontendComponent {
|
interface FrontendComponent {
|
||||||
FrontendRequestHandler requestHandler();
|
FrontendRequestHandler requestHandler();
|
||||||
|
|
||||||
|
|
|
@ -27,12 +27,12 @@ import google.registry.monitoring.whitebox.StackdriverModule;
|
||||||
import google.registry.request.Modules.AppIdentityCredentialModule;
|
import google.registry.request.Modules.AppIdentityCredentialModule;
|
||||||
import google.registry.request.Modules.GoogleCredentialModule;
|
import google.registry.request.Modules.GoogleCredentialModule;
|
||||||
import google.registry.request.Modules.Jackson2Module;
|
import google.registry.request.Modules.Jackson2Module;
|
||||||
import google.registry.request.Modules.ModulesServiceModule;
|
|
||||||
import google.registry.request.Modules.NetHttpTransportModule;
|
import google.registry.request.Modules.NetHttpTransportModule;
|
||||||
import google.registry.request.Modules.UrlFetchTransportModule;
|
import google.registry.request.Modules.UrlFetchTransportModule;
|
||||||
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
||||||
import google.registry.request.Modules.UserServiceModule;
|
import google.registry.request.Modules.UserServiceModule;
|
||||||
import google.registry.request.auth.AuthModule;
|
import google.registry.request.auth.AuthModule;
|
||||||
|
import google.registry.util.AppEngineServiceUtilsImpl.AppEngineServiceUtilsModule;
|
||||||
import google.registry.util.SystemClock.SystemClockModule;
|
import google.registry.util.SystemClock.SystemClockModule;
|
||||||
import google.registry.util.SystemSleeper.SystemSleeperModule;
|
import google.registry.util.SystemSleeper.SystemSleeperModule;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
@ -40,28 +40,27 @@ import javax.inject.Singleton;
|
||||||
/** Dagger component with instance lifetime for "pubapi" App Engine module. */
|
/** Dagger component with instance lifetime for "pubapi" App Engine module. */
|
||||||
@Singleton
|
@Singleton
|
||||||
@Component(
|
@Component(
|
||||||
modules = {
|
modules = {
|
||||||
AppIdentityCredentialModule.class,
|
AppEngineServiceUtilsModule.class,
|
||||||
AuthModule.class,
|
AppIdentityCredentialModule.class,
|
||||||
ConfigModule.class,
|
AuthModule.class,
|
||||||
CustomLogicFactoryModule.class,
|
ConfigModule.class,
|
||||||
google.registry.keyring.api.DummyKeyringModule.class,
|
CustomLogicFactoryModule.class,
|
||||||
PubApiRequestComponentModule.class,
|
google.registry.keyring.api.DummyKeyringModule.class,
|
||||||
GoogleCredentialModule.class,
|
PubApiRequestComponentModule.class,
|
||||||
Jackson2Module.class,
|
GoogleCredentialModule.class,
|
||||||
KeyModule.class,
|
Jackson2Module.class,
|
||||||
KmsModule.class,
|
KeyModule.class,
|
||||||
ModulesServiceModule.class,
|
KmsModule.class,
|
||||||
NetHttpTransportModule.class,
|
NetHttpTransportModule.class,
|
||||||
ServerTridProviderModule.class,
|
ServerTridProviderModule.class,
|
||||||
StackdriverModule.class,
|
StackdriverModule.class,
|
||||||
SystemClockModule.class,
|
SystemClockModule.class,
|
||||||
SystemSleeperModule.class,
|
SystemSleeperModule.class,
|
||||||
UrlFetchTransportModule.class,
|
UrlFetchTransportModule.class,
|
||||||
UseAppIdentityCredentialForGoogleApisModule.class,
|
UseAppIdentityCredentialForGoogleApisModule.class,
|
||||||
UserServiceModule.class,
|
UserServiceModule.class,
|
||||||
}
|
})
|
||||||
)
|
|
||||||
interface PubApiComponent {
|
interface PubApiComponent {
|
||||||
PubApiRequestHandler requestHandler();
|
PubApiRequestHandler requestHandler();
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,12 @@ import google.registry.request.Modules.AppIdentityCredentialModule;
|
||||||
import google.registry.request.Modules.DatastoreServiceModule;
|
import google.registry.request.Modules.DatastoreServiceModule;
|
||||||
import google.registry.request.Modules.GoogleCredentialModule;
|
import google.registry.request.Modules.GoogleCredentialModule;
|
||||||
import google.registry.request.Modules.Jackson2Module;
|
import google.registry.request.Modules.Jackson2Module;
|
||||||
import google.registry.request.Modules.ModulesServiceModule;
|
|
||||||
import google.registry.request.Modules.NetHttpTransportModule;
|
import google.registry.request.Modules.NetHttpTransportModule;
|
||||||
import google.registry.request.Modules.UrlFetchTransportModule;
|
import google.registry.request.Modules.UrlFetchTransportModule;
|
||||||
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
||||||
import google.registry.request.Modules.UserServiceModule;
|
import google.registry.request.Modules.UserServiceModule;
|
||||||
import google.registry.request.auth.AuthModule;
|
import google.registry.request.auth.AuthModule;
|
||||||
|
import google.registry.util.AppEngineServiceUtilsImpl.AppEngineServiceUtilsModule;
|
||||||
import google.registry.util.SystemClock.SystemClockModule;
|
import google.registry.util.SystemClock.SystemClockModule;
|
||||||
import google.registry.util.SystemSleeper.SystemSleeperModule;
|
import google.registry.util.SystemSleeper.SystemSleeperModule;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
@ -43,33 +43,32 @@ import javax.inject.Singleton;
|
||||||
/** Dagger component with instance lifetime for "tools" App Engine module. */
|
/** Dagger component with instance lifetime for "tools" App Engine module. */
|
||||||
@Singleton
|
@Singleton
|
||||||
@Component(
|
@Component(
|
||||||
modules = {
|
modules = {
|
||||||
AppIdentityCredentialModule.class,
|
AppEngineServiceUtilsModule.class,
|
||||||
AuthModule.class,
|
AppIdentityCredentialModule.class,
|
||||||
ConfigModule.class,
|
AuthModule.class,
|
||||||
CustomLogicFactoryModule.class,
|
ConfigModule.class,
|
||||||
DatastoreServiceModule.class,
|
CustomLogicFactoryModule.class,
|
||||||
DirectoryModule.class,
|
DatastoreServiceModule.class,
|
||||||
google.registry.keyring.api.DummyKeyringModule.class,
|
DirectoryModule.class,
|
||||||
DriveModule.class,
|
google.registry.keyring.api.DummyKeyringModule.class,
|
||||||
GcsServiceModule.class,
|
DriveModule.class,
|
||||||
GoogleCredentialModule.class,
|
GcsServiceModule.class,
|
||||||
GroupsModule.class,
|
GoogleCredentialModule.class,
|
||||||
GroupssettingsModule.class,
|
GroupsModule.class,
|
||||||
Jackson2Module.class,
|
GroupssettingsModule.class,
|
||||||
KeyModule.class,
|
Jackson2Module.class,
|
||||||
KmsModule.class,
|
KeyModule.class,
|
||||||
ModulesServiceModule.class,
|
KmsModule.class,
|
||||||
NetHttpTransportModule.class,
|
NetHttpTransportModule.class,
|
||||||
ServerTridProviderModule.class,
|
ServerTridProviderModule.class,
|
||||||
SystemClockModule.class,
|
SystemClockModule.class,
|
||||||
SystemSleeperModule.class,
|
SystemSleeperModule.class,
|
||||||
ToolsRequestComponentModule.class,
|
ToolsRequestComponentModule.class,
|
||||||
UrlFetchTransportModule.class,
|
UrlFetchTransportModule.class,
|
||||||
UseAppIdentityCredentialForGoogleApisModule.class,
|
UseAppIdentityCredentialForGoogleApisModule.class,
|
||||||
UserServiceModule.class,
|
UserServiceModule.class,
|
||||||
}
|
})
|
||||||
)
|
|
||||||
interface ToolsComponent {
|
interface ToolsComponent {
|
||||||
ToolsRequestHandler requestHandler();
|
ToolsRequestHandler requestHandler();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,12 @@ package google.registry.monitoring.whitebox;
|
||||||
|
|
||||||
import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl;
|
import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl;
|
||||||
|
|
||||||
import com.google.appengine.api.modules.ModulesService;
|
|
||||||
import com.google.appengine.api.taskqueue.Queue;
|
import com.google.appengine.api.taskqueue.Queue;
|
||||||
import com.google.appengine.api.taskqueue.TaskOptions;
|
import com.google.appengine.api.taskqueue.TaskOptions;
|
||||||
import com.google.appengine.api.taskqueue.TransientFailureException;
|
import com.google.appengine.api.taskqueue.TransientFailureException;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
|
import google.registry.util.AppEngineServiceUtils;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
@ -38,7 +38,7 @@ public class BigQueryMetricsEnqueuer {
|
||||||
|
|
||||||
public static final String QUEUE_BIGQUERY_STREAMING_METRICS = "bigquery-streaming-metrics";
|
public static final String QUEUE_BIGQUERY_STREAMING_METRICS = "bigquery-streaming-metrics";
|
||||||
|
|
||||||
@Inject ModulesService modulesService;
|
@Inject AppEngineServiceUtils appEngineServiceUtils;
|
||||||
@Inject @Named("insertIdGenerator") Supplier<String> idGenerator;
|
@Inject @Named("insertIdGenerator") Supplier<String> idGenerator;
|
||||||
@Inject @Named(QUEUE_BIGQUERY_STREAMING_METRICS) Queue queue;
|
@Inject @Named(QUEUE_BIGQUERY_STREAMING_METRICS) Queue queue;
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ public class BigQueryMetricsEnqueuer {
|
||||||
|
|
||||||
public void export(BigQueryMetric metric) {
|
public void export(BigQueryMetric metric) {
|
||||||
try {
|
try {
|
||||||
String hostname = modulesService.getVersionHostname("backend", null);
|
String hostname = appEngineServiceUtils.getCurrentVersionHostname("backend");
|
||||||
TaskOptions opts =
|
TaskOptions opts =
|
||||||
withUrl(MetricsExportAction.PATH)
|
withUrl(MetricsExportAction.PATH)
|
||||||
.header("Host", hostname)
|
.header("Host", hostname)
|
||||||
|
|
|
@ -27,8 +27,6 @@ import com.google.api.client.http.javanet.NetHttpTransport;
|
||||||
import com.google.api.client.json.JsonFactory;
|
import com.google.api.client.json.JsonFactory;
|
||||||
import com.google.api.client.json.jackson2.JacksonFactory;
|
import com.google.api.client.json.jackson2.JacksonFactory;
|
||||||
import com.google.appengine.api.datastore.DatastoreService;
|
import com.google.appengine.api.datastore.DatastoreService;
|
||||||
import com.google.appengine.api.modules.ModulesService;
|
|
||||||
import com.google.appengine.api.modules.ModulesServiceFactory;
|
|
||||||
import com.google.appengine.api.urlfetch.URLFetchService;
|
import com.google.appengine.api.urlfetch.URLFetchService;
|
||||||
import com.google.appengine.api.urlfetch.URLFetchServiceFactory;
|
import com.google.appengine.api.urlfetch.URLFetchServiceFactory;
|
||||||
import com.google.appengine.api.users.UserService;
|
import com.google.appengine.api.users.UserService;
|
||||||
|
@ -61,17 +59,6 @@ public final class Modules {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dagger module for {@link ModulesService}. */
|
|
||||||
@Module
|
|
||||||
public static final class ModulesServiceModule {
|
|
||||||
private static final ModulesService modulesService = ModulesServiceFactory.getModulesService();
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
static ModulesService provideModulesService() {
|
|
||||||
return modulesService;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Dagger module for {@link URLFetchService}. */
|
/** Dagger module for {@link URLFetchService}. */
|
||||||
@Module
|
@Module
|
||||||
public static final class URLFetchServiceModule {
|
public static final class URLFetchServiceModule {
|
||||||
|
|
|
@ -17,9 +17,11 @@ package google.registry.tools;
|
||||||
import com.beust.jcommander.Parameter;
|
import com.beust.jcommander.Parameter;
|
||||||
import com.beust.jcommander.Parameters;
|
import com.beust.jcommander.Parameters;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.collect.Streams;
|
||||||
import google.registry.export.DatastoreBackupInfo;
|
import google.registry.export.DatastoreBackupInfo;
|
||||||
import google.registry.export.DatastoreBackupService;
|
import google.registry.export.DatastoreBackupService;
|
||||||
import google.registry.tools.Command.RemoteApiCommand;
|
import google.registry.tools.Command.RemoteApiCommand;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command to check the status of a Datastore backup, or "snapshot".
|
* Command to check the status of a Datastore backup, or "snapshot".
|
||||||
|
@ -33,16 +35,16 @@ public class CheckSnapshotCommand implements RemoteApiCommand {
|
||||||
required = true)
|
required = true)
|
||||||
private String snapshotName;
|
private String snapshotName;
|
||||||
|
|
||||||
|
@Inject DatastoreBackupService datastoreBackupService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Iterable<DatastoreBackupInfo> backups =
|
Iterable<DatastoreBackupInfo> backups =
|
||||||
DatastoreBackupService.get().findAllByNamePrefix(snapshotName);
|
datastoreBackupService.findAllByNamePrefix(snapshotName);
|
||||||
if (Iterables.isEmpty(backups)) {
|
if (Iterables.isEmpty(backups)) {
|
||||||
System.err.println("No snapshot found with name: " + snapshotName);
|
System.err.println("No snapshot found with name: " + snapshotName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (DatastoreBackupInfo backup : backups) {
|
Streams.stream(backups).map(DatastoreBackupInfo::getInformation).forEach(System.out::println);
|
||||||
System.out.println(backup.getInformation());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,13 +26,13 @@ import static google.registry.request.RequestParameters.PARAM_TLDS;
|
||||||
import com.beust.jcommander.Parameter;
|
import com.beust.jcommander.Parameter;
|
||||||
import com.beust.jcommander.ParameterException;
|
import com.beust.jcommander.ParameterException;
|
||||||
import com.beust.jcommander.Parameters;
|
import com.beust.jcommander.Parameters;
|
||||||
import com.google.appengine.api.modules.ModulesService;
|
|
||||||
import com.google.appengine.api.taskqueue.Queue;
|
import com.google.appengine.api.taskqueue.Queue;
|
||||||
import com.google.appengine.api.taskqueue.TaskOptions;
|
import com.google.appengine.api.taskqueue.TaskOptions;
|
||||||
import google.registry.model.rde.RdeMode;
|
import google.registry.model.rde.RdeMode;
|
||||||
import google.registry.rde.RdeStagingAction;
|
import google.registry.rde.RdeStagingAction;
|
||||||
import google.registry.tools.Command.RemoteApiCommand;
|
import google.registry.tools.Command.RemoteApiCommand;
|
||||||
import google.registry.tools.params.DateTimeParameter;
|
import google.registry.tools.params.DateTimeParameter;
|
||||||
|
import google.registry.util.AppEngineServiceUtils;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -75,7 +75,7 @@ final class GenerateEscrowDepositCommand implements RemoteApiCommand {
|
||||||
required = true)
|
required = true)
|
||||||
private String outdir;
|
private String outdir;
|
||||||
|
|
||||||
@Inject ModulesService modulesService;
|
@Inject AppEngineServiceUtils appEngineServiceUtils;
|
||||||
@Inject @Named("rde-report") Queue queue;
|
@Inject @Named("rde-report") Queue queue;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -102,7 +102,7 @@ final class GenerateEscrowDepositCommand implements RemoteApiCommand {
|
||||||
|
|
||||||
// Unlike many tool commands, this command is actually invoking an action on the backend module
|
// Unlike many tool commands, this command is actually invoking an action on the backend module
|
||||||
// (because it's a mapreduce). So we invoke it in a different way.
|
// (because it's a mapreduce). So we invoke it in a different way.
|
||||||
String hostname = modulesService.getVersionHostname("backend", null);
|
String hostname = appEngineServiceUtils.getCurrentVersionHostname("backend");
|
||||||
TaskOptions opts =
|
TaskOptions opts =
|
||||||
withUrl(RdeStagingAction.PATH)
|
withUrl(RdeStagingAction.PATH)
|
||||||
.header("Host", hostname)
|
.header("Host", hostname)
|
||||||
|
|
|
@ -26,11 +26,11 @@ import google.registry.request.Modules.AppIdentityCredentialModule;
|
||||||
import google.registry.request.Modules.DatastoreServiceModule;
|
import google.registry.request.Modules.DatastoreServiceModule;
|
||||||
import google.registry.request.Modules.GoogleCredentialModule;
|
import google.registry.request.Modules.GoogleCredentialModule;
|
||||||
import google.registry.request.Modules.Jackson2Module;
|
import google.registry.request.Modules.Jackson2Module;
|
||||||
import google.registry.request.Modules.ModulesServiceModule;
|
|
||||||
import google.registry.request.Modules.URLFetchServiceModule;
|
import google.registry.request.Modules.URLFetchServiceModule;
|
||||||
import google.registry.request.Modules.UrlFetchTransportModule;
|
import google.registry.request.Modules.UrlFetchTransportModule;
|
||||||
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
||||||
import google.registry.request.Modules.UserServiceModule;
|
import google.registry.request.Modules.UserServiceModule;
|
||||||
|
import google.registry.util.AppEngineServiceUtilsImpl.AppEngineServiceUtilsModule;
|
||||||
import google.registry.util.SystemClock.SystemClockModule;
|
import google.registry.util.SystemClock.SystemClockModule;
|
||||||
import google.registry.util.SystemSleeper.SystemSleeperModule;
|
import google.registry.util.SystemSleeper.SystemSleeperModule;
|
||||||
import google.registry.whois.WhoisModule;
|
import google.registry.whois.WhoisModule;
|
||||||
|
@ -44,37 +44,37 @@ import javax.inject.Singleton;
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
@Component(
|
@Component(
|
||||||
modules = {
|
modules = {
|
||||||
AppEngineConnectionFlags.FlagsModule.class,
|
AppEngineConnectionFlags.FlagsModule.class,
|
||||||
// TODO(b/36866706): Find a way to replace this with a command-line friendly version
|
AppEngineServiceUtilsModule.class,
|
||||||
AppIdentityCredentialModule.class,
|
// TODO(b/36866706): Find a way to replace this with a command-line friendly version
|
||||||
AuthModule.class,
|
AppIdentityCredentialModule.class,
|
||||||
ConfigModule.class,
|
AuthModule.class,
|
||||||
DatastoreServiceModule.class,
|
ConfigModule.class,
|
||||||
google.registry.keyring.api.DummyKeyringModule.class,
|
DatastoreServiceModule.class,
|
||||||
CloudDnsWriterModule.class,
|
google.registry.keyring.api.DummyKeyringModule.class,
|
||||||
DefaultRequestFactoryModule.class,
|
CloudDnsWriterModule.class,
|
||||||
DefaultRequestFactoryModule.RequestFactoryModule.class,
|
DefaultRequestFactoryModule.class,
|
||||||
DnsUpdateWriterModule.class,
|
DefaultRequestFactoryModule.RequestFactoryModule.class,
|
||||||
GoogleCredentialModule.class,
|
DnsUpdateWriterModule.class,
|
||||||
Jackson2Module.class,
|
GoogleCredentialModule.class,
|
||||||
KeyModule.class,
|
Jackson2Module.class,
|
||||||
KmsModule.class,
|
KeyModule.class,
|
||||||
ModulesServiceModule.class,
|
KmsModule.class,
|
||||||
RdeModule.class,
|
RdeModule.class,
|
||||||
RegistryToolModule.class,
|
RegistryToolModule.class,
|
||||||
SystemClockModule.class,
|
SystemClockModule.class,
|
||||||
SystemSleeperModule.class,
|
SystemSleeperModule.class,
|
||||||
URLFetchServiceModule.class,
|
URLFetchServiceModule.class,
|
||||||
UrlFetchTransportModule.class,
|
UrlFetchTransportModule.class,
|
||||||
// TODO(b/36866706): Find a way to replace this with a command-line friendly version
|
// TODO(b/36866706): Find a way to replace this with a command-line friendly version
|
||||||
UseAppIdentityCredentialForGoogleApisModule.class,
|
UseAppIdentityCredentialForGoogleApisModule.class,
|
||||||
UserServiceModule.class,
|
UserServiceModule.class,
|
||||||
VoidDnsWriterModule.class,
|
VoidDnsWriterModule.class,
|
||||||
WhoisModule.class,
|
WhoisModule.class,
|
||||||
}
|
})
|
||||||
)
|
|
||||||
interface RegistryToolComponent {
|
interface RegistryToolComponent {
|
||||||
|
void inject(CheckSnapshotCommand command);
|
||||||
void inject(CountDomainsCommand command);
|
void inject(CountDomainsCommand command);
|
||||||
void inject(CreateAnchorTenantCommand command);
|
void inject(CreateAnchorTenantCommand command);
|
||||||
void inject(CreateCdnsTld command);
|
void inject(CreateCdnsTld command);
|
||||||
|
|
|
@ -16,6 +16,7 @@ package google.registry.ui.server.registrar;
|
||||||
|
|
||||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||||
import static com.google.common.collect.Sets.difference;
|
import static com.google.common.collect.Sets.difference;
|
||||||
|
import static google.registry.export.sheet.SyncRegistrarsSheetAction.enqueueRegistrarSheetSync;
|
||||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||||
import static google.registry.security.JsonResponseHelper.Status.ERROR;
|
import static google.registry.security.JsonResponseHelper.Status.ERROR;
|
||||||
import static google.registry.security.JsonResponseHelper.Status.SUCCESS;
|
import static google.registry.security.JsonResponseHelper.Status.SUCCESS;
|
||||||
|
@ -29,7 +30,6 @@ import com.google.common.collect.Multimap;
|
||||||
import com.google.common.collect.Streams;
|
import com.google.common.collect.Streams;
|
||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
import google.registry.config.RegistryConfig.Config;
|
import google.registry.config.RegistryConfig.Config;
|
||||||
import google.registry.export.sheet.SyncRegistrarsSheetAction;
|
|
||||||
import google.registry.model.registrar.Registrar;
|
import google.registry.model.registrar.Registrar;
|
||||||
import google.registry.model.registrar.RegistrarContact;
|
import google.registry.model.registrar.RegistrarContact;
|
||||||
import google.registry.model.registrar.RegistrarContact.Builder;
|
import google.registry.model.registrar.RegistrarContact.Builder;
|
||||||
|
@ -43,6 +43,7 @@ import google.registry.security.JsonResponseHelper;
|
||||||
import google.registry.ui.forms.FormException;
|
import google.registry.ui.forms.FormException;
|
||||||
import google.registry.ui.forms.FormFieldException;
|
import google.registry.ui.forms.FormFieldException;
|
||||||
import google.registry.ui.server.RegistrarFormFields;
|
import google.registry.ui.server.RegistrarFormFields;
|
||||||
|
import google.registry.util.AppEngineServiceUtils;
|
||||||
import google.registry.util.CollectionUtils;
|
import google.registry.util.CollectionUtils;
|
||||||
import google.registry.util.DiffUtils;
|
import google.registry.util.DiffUtils;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -76,6 +77,7 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
|
||||||
|
|
||||||
@Inject HttpServletRequest request;
|
@Inject HttpServletRequest request;
|
||||||
@Inject JsonActionRunner jsonActionRunner;
|
@Inject JsonActionRunner jsonActionRunner;
|
||||||
|
@Inject AppEngineServiceUtils appEngineServiceUtils;
|
||||||
@Inject AuthResult authResult;
|
@Inject AuthResult authResult;
|
||||||
@Inject SendEmailUtils sendEmailUtils;
|
@Inject SendEmailUtils sendEmailUtils;
|
||||||
@Inject SessionUtils sessionUtils;
|
@Inject SessionUtils sessionUtils;
|
||||||
|
@ -368,7 +370,7 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
|
||||||
if (CollectionUtils.difference(changedKeys, "lastUpdateTime").isEmpty()) {
|
if (CollectionUtils.difference(changedKeys, "lastUpdateTime").isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SyncRegistrarsSheetAction.enqueueBackendTask();
|
enqueueRegistrarSheetSync(appEngineServiceUtils.getCurrentVersionHostname("backend"));
|
||||||
if (!registrarChangesNotificationEmailAddresses.isEmpty()) {
|
if (!registrarChangesNotificationEmailAddresses.isEmpty()) {
|
||||||
sendEmailUtils.sendEmail(
|
sendEmailUtils.sendEmail(
|
||||||
registrarChangesNotificationEmailAddresses,
|
registrarChangesNotificationEmailAddresses,
|
||||||
|
|
40
java/google/registry/util/AppEngineServiceUtils.java
Normal file
40
java/google/registry/util/AppEngineServiceUtils.java
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
// Copyright 2018 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.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wrapper for {@link com.google.appengine.api.modules.ModulesService} that provides a saner API.
|
||||||
|
*/
|
||||||
|
public interface AppEngineServiceUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a host name to use for the given service.
|
||||||
|
*
|
||||||
|
* <p>Note that this host name will not include a version, so it will always be whatever the live
|
||||||
|
* version is at the time that you hit the URL.
|
||||||
|
*/
|
||||||
|
String getServiceHostname(String service);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a host name to use for the given service and current version.
|
||||||
|
*
|
||||||
|
* <p>Note that this host name will include the current version now at time of URL generation,
|
||||||
|
* which will not be the live version in the future.
|
||||||
|
*/
|
||||||
|
String getCurrentVersionHostname(String service);
|
||||||
|
|
||||||
|
/** Returns a host name to use for the given service and version. */
|
||||||
|
String getVersionHostname(String service, String version);
|
||||||
|
}
|
70
java/google/registry/util/AppEngineServiceUtilsImpl.java
Normal file
70
java/google/registry/util/AppEngineServiceUtilsImpl.java
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
// Copyright 2018 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.util;
|
||||||
|
|
||||||
|
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||||
|
|
||||||
|
import com.google.appengine.api.modules.ModulesService;
|
||||||
|
import com.google.appengine.api.modules.ModulesServiceFactory;
|
||||||
|
import dagger.Binds;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
/** A wrapper for {@link ModulesService} that provides a saner API. */
|
||||||
|
public class AppEngineServiceUtilsImpl implements AppEngineServiceUtils {
|
||||||
|
|
||||||
|
private final ModulesService modulesService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public AppEngineServiceUtilsImpl(ModulesService modulesService) {
|
||||||
|
this.modulesService = modulesService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getServiceHostname(String service) {
|
||||||
|
// This will be in the format "version.service.projectid.appspot.com"
|
||||||
|
String hostnameWithVersion = modulesService.getVersionHostname(service, null);
|
||||||
|
// Strip off the version and return just "service.projectid.appspot.com"
|
||||||
|
return hostnameWithVersion.replaceFirst("^[^.]+\\.", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCurrentVersionHostname(String service) {
|
||||||
|
return modulesService.getVersionHostname(service, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getVersionHostname(String service, String version) {
|
||||||
|
checkArgumentNotNull(version, "Must specify the version");
|
||||||
|
return modulesService.getVersionHostname(service, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Dagger module for AppEngineServiceUtils. */
|
||||||
|
@Module
|
||||||
|
public abstract static class AppEngineServiceUtilsModule {
|
||||||
|
|
||||||
|
private static final ModulesService modulesService = ModulesServiceFactory.getModulesService();
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
static ModulesService provideModulesService() {
|
||||||
|
return modulesService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
abstract AppEngineServiceUtils provideAppEngineServiceUtils(
|
||||||
|
AppEngineServiceUtilsImpl appEngineServiceUtilsImpl);
|
||||||
|
}
|
||||||
|
}
|
|
@ -61,7 +61,6 @@ import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.appengine.api.modules.ModulesService;
|
|
||||||
import com.google.appengine.api.taskqueue.TaskOptions;
|
import com.google.appengine.api.taskqueue.TaskOptions;
|
||||||
import com.google.appengine.api.taskqueue.TaskOptions.Method;
|
import com.google.appengine.api.taskqueue.TaskOptions.Method;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
@ -102,6 +101,7 @@ import google.registry.testing.InjectRule;
|
||||||
import google.registry.testing.MockitoJUnitRule;
|
import google.registry.testing.MockitoJUnitRule;
|
||||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
import google.registry.testing.mapreduce.MapreduceTestCase;
|
import google.registry.testing.mapreduce.MapreduceTestCase;
|
||||||
|
import google.registry.util.AppEngineServiceUtils;
|
||||||
import google.registry.util.RequestStatusChecker;
|
import google.registry.util.RequestStatusChecker;
|
||||||
import google.registry.util.Retrier;
|
import google.registry.util.Retrier;
|
||||||
import google.registry.util.Sleeper;
|
import google.registry.util.Sleeper;
|
||||||
|
@ -160,7 +160,7 @@ public class DeleteContactsAndHostsActionTest
|
||||||
getQueue(QUEUE_ASYNC_DELETE),
|
getQueue(QUEUE_ASYNC_DELETE),
|
||||||
getQueue(QUEUE_ASYNC_HOST_RENAME),
|
getQueue(QUEUE_ASYNC_HOST_RENAME),
|
||||||
Duration.ZERO,
|
Duration.ZERO,
|
||||||
mock(ModulesService.class),
|
mock(AppEngineServiceUtils.class),
|
||||||
new Retrier(new FakeSleeper(clock), 1));
|
new Retrier(new FakeSleeper(clock), 1));
|
||||||
AsyncFlowMetrics asyncFlowMetricsMock = mock(AsyncFlowMetrics.class);
|
AsyncFlowMetrics asyncFlowMetricsMock = mock(AsyncFlowMetrics.class);
|
||||||
action = new DeleteContactsAndHostsAction();
|
action = new DeleteContactsAndHostsAction();
|
||||||
|
|
|
@ -45,7 +45,6 @@ import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.appengine.api.modules.ModulesService;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.googlecode.objectify.Key;
|
import com.googlecode.objectify.Key;
|
||||||
import google.registry.batch.RefreshDnsOnHostRenameAction.RefreshDnsOnHostRenameReducer;
|
import google.registry.batch.RefreshDnsOnHostRenameAction.RefreshDnsOnHostRenameReducer;
|
||||||
|
@ -61,6 +60,7 @@ import google.registry.testing.InjectRule;
|
||||||
import google.registry.testing.MockitoJUnitRule;
|
import google.registry.testing.MockitoJUnitRule;
|
||||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
import google.registry.testing.mapreduce.MapreduceTestCase;
|
import google.registry.testing.mapreduce.MapreduceTestCase;
|
||||||
|
import google.registry.util.AppEngineServiceUtils;
|
||||||
import google.registry.util.RequestStatusChecker;
|
import google.registry.util.RequestStatusChecker;
|
||||||
import google.registry.util.Retrier;
|
import google.registry.util.Retrier;
|
||||||
import google.registry.util.Sleeper;
|
import google.registry.util.Sleeper;
|
||||||
|
@ -97,7 +97,7 @@ public class RefreshDnsOnHostRenameActionTest
|
||||||
getQueue(QUEUE_ASYNC_DELETE),
|
getQueue(QUEUE_ASYNC_DELETE),
|
||||||
getQueue(QUEUE_ASYNC_HOST_RENAME),
|
getQueue(QUEUE_ASYNC_HOST_RENAME),
|
||||||
Duration.ZERO,
|
Duration.ZERO,
|
||||||
mock(ModulesService.class),
|
mock(AppEngineServiceUtils.class),
|
||||||
new Retrier(new FakeSleeper(clock), 1));
|
new Retrier(new FakeSleeper(clock), 1));
|
||||||
AsyncFlowMetrics asyncFlowMetricsMock = mock(AsyncFlowMetrics.class);
|
AsyncFlowMetrics asyncFlowMetricsMock = mock(AsyncFlowMetrics.class);
|
||||||
action = new RefreshDnsOnHostRenameAction();
|
action = new RefreshDnsOnHostRenameAction();
|
||||||
|
|
|
@ -32,11 +32,9 @@ import static google.registry.testing.DatastoreHelper.persistResource;
|
||||||
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
||||||
import static org.joda.time.Duration.standardDays;
|
import static org.joda.time.Duration.standardDays;
|
||||||
import static org.joda.time.Duration.standardSeconds;
|
import static org.joda.time.Duration.standardSeconds;
|
||||||
import static org.mockito.Matchers.any;
|
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.appengine.api.modules.ModulesService;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.ImmutableSortedSet;
|
import com.google.common.collect.ImmutableSortedSet;
|
||||||
import com.googlecode.objectify.Key;
|
import com.googlecode.objectify.Key;
|
||||||
|
@ -55,6 +53,7 @@ import google.registry.testing.InjectRule;
|
||||||
import google.registry.testing.MockitoJUnitRule;
|
import google.registry.testing.MockitoJUnitRule;
|
||||||
import google.registry.testing.ShardableTestCase;
|
import google.registry.testing.ShardableTestCase;
|
||||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
|
import google.registry.util.AppEngineServiceUtils;
|
||||||
import google.registry.util.Retrier;
|
import google.registry.util.Retrier;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
|
@ -76,7 +75,7 @@ public class ResaveEntityActionTest extends ShardableTestCase {
|
||||||
@Rule public final InjectRule inject = new InjectRule();
|
@Rule public final InjectRule inject = new InjectRule();
|
||||||
@Rule public final MockitoJUnitRule mocks = MockitoJUnitRule.create();
|
@Rule public final MockitoJUnitRule mocks = MockitoJUnitRule.create();
|
||||||
|
|
||||||
@Mock private ModulesService modulesService;
|
@Mock private AppEngineServiceUtils appEngineServiceUtils;
|
||||||
@Mock private Response response;
|
@Mock private Response response;
|
||||||
private final FakeClock clock = new FakeClock(DateTime.parse("2016-02-11T10:00:00Z"));
|
private final FakeClock clock = new FakeClock(DateTime.parse("2016-02-11T10:00:00Z"));
|
||||||
private AsyncFlowEnqueuer asyncFlowEnqueuer;
|
private AsyncFlowEnqueuer asyncFlowEnqueuer;
|
||||||
|
@ -84,15 +83,14 @@ public class ResaveEntityActionTest extends ShardableTestCase {
|
||||||
@Before
|
@Before
|
||||||
public void before() {
|
public void before() {
|
||||||
inject.setStaticField(Ofy.class, "clock", clock);
|
inject.setStaticField(Ofy.class, "clock", clock);
|
||||||
when(modulesService.getVersionHostname(any(String.class), any(String.class)))
|
when(appEngineServiceUtils.getServiceHostname("backend")).thenReturn("backend.hostname.fake");
|
||||||
.thenReturn("backend.hostname.fake");
|
|
||||||
asyncFlowEnqueuer =
|
asyncFlowEnqueuer =
|
||||||
new AsyncFlowEnqueuer(
|
new AsyncFlowEnqueuer(
|
||||||
getQueue(QUEUE_ASYNC_ACTIONS),
|
getQueue(QUEUE_ASYNC_ACTIONS),
|
||||||
getQueue(QUEUE_ASYNC_DELETE),
|
getQueue(QUEUE_ASYNC_DELETE),
|
||||||
getQueue(QUEUE_ASYNC_HOST_RENAME),
|
getQueue(QUEUE_ASYNC_HOST_RENAME),
|
||||||
Duration.ZERO,
|
Duration.ZERO,
|
||||||
modulesService,
|
appEngineServiceUtils,
|
||||||
new Retrier(new FakeSleeper(clock), 1));
|
new Retrier(new FakeSleeper(clock), 1));
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,16 +19,15 @@ import static com.google.common.collect.Iterables.transform;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||||
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.appengine.api.datastore.Entity;
|
import com.google.appengine.api.datastore.Entity;
|
||||||
import com.google.appengine.api.modules.ModulesService;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.InjectRule;
|
import google.registry.testing.MockitoJUnitRule;
|
||||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
|
import google.registry.util.AppEngineServiceUtils;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -36,30 +35,28 @@ import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.JUnit4;
|
import org.junit.runners.JUnit4;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
|
||||||
/** Unit tests for {@link DatastoreBackupService}. */
|
/** Unit tests for {@link DatastoreBackupService}. */
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public class DatastoreBackupServiceTest {
|
public class DatastoreBackupServiceTest {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final InjectRule inject = new InjectRule();
|
public final AppEngineRule appEngine =
|
||||||
|
AppEngineRule.builder().withDatastore().withTaskQueue().build();
|
||||||
|
|
||||||
@Rule
|
@Rule public final MockitoJUnitRule mocks = MockitoJUnitRule.create();
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
|
||||||
.withDatastore()
|
|
||||||
.withTaskQueue()
|
|
||||||
.build();
|
|
||||||
|
|
||||||
private final ModulesService modulesService = mock(ModulesService.class);
|
@Mock private AppEngineServiceUtils appEngineServiceUtils;
|
||||||
|
|
||||||
private static final DateTime START_TIME = DateTime.parse("2014-08-01T01:02:03Z");
|
private static final DateTime START_TIME = DateTime.parse("2014-08-01T01:02:03Z");
|
||||||
|
|
||||||
private final DatastoreBackupService backupService = DatastoreBackupService.get();
|
private DatastoreBackupService backupService;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() {
|
public void before() {
|
||||||
inject.setStaticField(DatastoreBackupService.class, "modulesService", modulesService);
|
backupService = new DatastoreBackupService(appEngineServiceUtils);
|
||||||
when(modulesService.getVersionHostname("default", "ah-builtin-python-bundle"))
|
when(appEngineServiceUtils.getVersionHostname("default", "ah-builtin-python-bundle"))
|
||||||
.thenReturn("ah-builtin-python-bundle.default.localhost");
|
.thenReturn("ah-builtin-python-bundle.default.localhost");
|
||||||
|
|
||||||
persistBackupEntityWithName("backupA1");
|
persistBackupEntityWithName("backupA1");
|
||||||
|
|
|
@ -18,11 +18,9 @@ import static com.google.appengine.api.taskqueue.QueueFactory.getQueue;
|
||||||
import static google.registry.flows.async.AsyncFlowEnqueuer.QUEUE_ASYNC_ACTIONS;
|
import static google.registry.flows.async.AsyncFlowEnqueuer.QUEUE_ASYNC_ACTIONS;
|
||||||
import static google.registry.flows.async.AsyncFlowEnqueuer.QUEUE_ASYNC_DELETE;
|
import static google.registry.flows.async.AsyncFlowEnqueuer.QUEUE_ASYNC_DELETE;
|
||||||
import static google.registry.flows.async.AsyncFlowEnqueuer.QUEUE_ASYNC_HOST_RENAME;
|
import static google.registry.flows.async.AsyncFlowEnqueuer.QUEUE_ASYNC_HOST_RENAME;
|
||||||
import static org.mockito.Matchers.any;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.appengine.api.modules.ModulesService;
|
|
||||||
import dagger.Component;
|
import dagger.Component;
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
|
@ -43,6 +41,7 @@ import google.registry.testing.FakeLockHandler;
|
||||||
import google.registry.testing.FakeSleeper;
|
import google.registry.testing.FakeSleeper;
|
||||||
import google.registry.tmch.TmchCertificateAuthority;
|
import google.registry.tmch.TmchCertificateAuthority;
|
||||||
import google.registry.tmch.TmchXmlSignature;
|
import google.registry.tmch.TmchXmlSignature;
|
||||||
|
import google.registry.util.AppEngineServiceUtils;
|
||||||
import google.registry.util.Clock;
|
import google.registry.util.Clock;
|
||||||
import google.registry.util.Retrier;
|
import google.registry.util.Retrier;
|
||||||
import google.registry.util.Sleeper;
|
import google.registry.util.Sleeper;
|
||||||
|
@ -71,7 +70,7 @@ interface EppTestComponent {
|
||||||
private EppMetric.Builder metricBuilder;
|
private EppMetric.Builder metricBuilder;
|
||||||
private FakeClock clock;
|
private FakeClock clock;
|
||||||
private FakeLockHandler lockHandler;
|
private FakeLockHandler lockHandler;
|
||||||
private ModulesService modulesService;
|
private AppEngineServiceUtils appEngineServiceUtils;
|
||||||
private Sleeper sleeper;
|
private Sleeper sleeper;
|
||||||
|
|
||||||
public static FakesAndMocksModule create() {
|
public static FakesAndMocksModule create() {
|
||||||
|
@ -91,23 +90,22 @@ interface EppTestComponent {
|
||||||
EppMetric.Builder eppMetricBuilder,
|
EppMetric.Builder eppMetricBuilder,
|
||||||
TmchXmlSignature tmchXmlSignature) {
|
TmchXmlSignature tmchXmlSignature) {
|
||||||
FakesAndMocksModule instance = new FakesAndMocksModule();
|
FakesAndMocksModule instance = new FakesAndMocksModule();
|
||||||
ModulesService modulesService = mock(ModulesService.class);
|
AppEngineServiceUtils appEngineServiceUtils = mock(AppEngineServiceUtils.class);
|
||||||
when(modulesService.getVersionHostname(any(String.class), any(String.class)))
|
when(appEngineServiceUtils.getServiceHostname("backend")).thenReturn("backend.hostname.fake");
|
||||||
.thenReturn("backend.hostname.fake");
|
|
||||||
instance.asyncFlowEnqueuer =
|
instance.asyncFlowEnqueuer =
|
||||||
new AsyncFlowEnqueuer(
|
new AsyncFlowEnqueuer(
|
||||||
getQueue(QUEUE_ASYNC_ACTIONS),
|
getQueue(QUEUE_ASYNC_ACTIONS),
|
||||||
getQueue(QUEUE_ASYNC_DELETE),
|
getQueue(QUEUE_ASYNC_DELETE),
|
||||||
getQueue(QUEUE_ASYNC_HOST_RENAME),
|
getQueue(QUEUE_ASYNC_HOST_RENAME),
|
||||||
Duration.standardSeconds(90),
|
Duration.standardSeconds(90),
|
||||||
modulesService,
|
appEngineServiceUtils,
|
||||||
new Retrier(new FakeSleeper(clock), 1));
|
new Retrier(new FakeSleeper(clock), 1));
|
||||||
instance.clock = clock;
|
instance.clock = clock;
|
||||||
instance.domainFlowTmchUtils = new DomainFlowTmchUtils(tmchXmlSignature);
|
instance.domainFlowTmchUtils = new DomainFlowTmchUtils(tmchXmlSignature);
|
||||||
instance.sleeper = new FakeSleeper(clock);
|
instance.sleeper = new FakeSleeper(clock);
|
||||||
instance.dnsQueue = DnsQueue.create();
|
instance.dnsQueue = DnsQueue.create();
|
||||||
instance.metricBuilder = eppMetricBuilder;
|
instance.metricBuilder = eppMetricBuilder;
|
||||||
instance.modulesService = modulesService;
|
instance.appEngineServiceUtils = appEngineServiceUtils;
|
||||||
instance.metricsEnqueuer = mock(BigQueryMetricsEnqueuer.class);
|
instance.metricsEnqueuer = mock(BigQueryMetricsEnqueuer.class);
|
||||||
instance.lockHandler = new FakeLockHandler(true);
|
instance.lockHandler = new FakeLockHandler(true);
|
||||||
return instance;
|
return instance;
|
||||||
|
@ -154,8 +152,8 @@ interface EppTestComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
ModulesService provideModulesService() {
|
AppEngineServiceUtils provideAppEngineServiceUtils() {
|
||||||
return modulesService;
|
return appEngineServiceUtils;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|
|
@ -29,10 +29,8 @@ import static google.registry.testing.TestLogHandlerUtils.assertLogMessage;
|
||||||
import static org.joda.time.Duration.standardDays;
|
import static org.joda.time.Duration.standardDays;
|
||||||
import static org.joda.time.Duration.standardHours;
|
import static org.joda.time.Duration.standardHours;
|
||||||
import static org.joda.time.Duration.standardSeconds;
|
import static org.joda.time.Duration.standardSeconds;
|
||||||
import static org.mockito.Matchers.any;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.appengine.api.modules.ModulesService;
|
|
||||||
import com.google.common.collect.ImmutableSortedSet;
|
import com.google.common.collect.ImmutableSortedSet;
|
||||||
import com.google.common.flogger.LoggerConfig;
|
import com.google.common.flogger.LoggerConfig;
|
||||||
import com.googlecode.objectify.Key;
|
import com.googlecode.objectify.Key;
|
||||||
|
@ -44,6 +42,7 @@ import google.registry.testing.InjectRule;
|
||||||
import google.registry.testing.MockitoJUnitRule;
|
import google.registry.testing.MockitoJUnitRule;
|
||||||
import google.registry.testing.ShardableTestCase;
|
import google.registry.testing.ShardableTestCase;
|
||||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
|
import google.registry.util.AppEngineServiceUtils;
|
||||||
import google.registry.util.CapturingLogHandler;
|
import google.registry.util.CapturingLogHandler;
|
||||||
import google.registry.util.Retrier;
|
import google.registry.util.Retrier;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
@ -67,7 +66,7 @@ public class AsyncFlowEnqueuerTest extends ShardableTestCase {
|
||||||
|
|
||||||
@Rule public final MockitoJUnitRule mocks = MockitoJUnitRule.create();
|
@Rule public final MockitoJUnitRule mocks = MockitoJUnitRule.create();
|
||||||
|
|
||||||
@Mock private ModulesService modulesService;
|
@Mock private AppEngineServiceUtils appEngineServiceUtils;
|
||||||
|
|
||||||
private AsyncFlowEnqueuer asyncFlowEnqueuer;
|
private AsyncFlowEnqueuer asyncFlowEnqueuer;
|
||||||
private final CapturingLogHandler logHandler = new CapturingLogHandler();
|
private final CapturingLogHandler logHandler = new CapturingLogHandler();
|
||||||
|
@ -76,15 +75,14 @@ public class AsyncFlowEnqueuerTest extends ShardableTestCase {
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
LoggerConfig.getConfig(AsyncFlowEnqueuer.class).addHandler(logHandler);
|
LoggerConfig.getConfig(AsyncFlowEnqueuer.class).addHandler(logHandler);
|
||||||
when(modulesService.getVersionHostname(any(String.class), any(String.class)))
|
when(appEngineServiceUtils.getServiceHostname("backend")).thenReturn("backend.hostname.fake");
|
||||||
.thenReturn("backend.hostname.fake");
|
|
||||||
asyncFlowEnqueuer =
|
asyncFlowEnqueuer =
|
||||||
new AsyncFlowEnqueuer(
|
new AsyncFlowEnqueuer(
|
||||||
getQueue(QUEUE_ASYNC_ACTIONS),
|
getQueue(QUEUE_ASYNC_ACTIONS),
|
||||||
getQueue(QUEUE_ASYNC_DELETE),
|
getQueue(QUEUE_ASYNC_DELETE),
|
||||||
getQueue(QUEUE_ASYNC_HOST_RENAME),
|
getQueue(QUEUE_ASYNC_HOST_RENAME),
|
||||||
standardSeconds(90),
|
standardSeconds(90),
|
||||||
modulesService,
|
appEngineServiceUtils,
|
||||||
new Retrier(new FakeSleeper(clock), 1));
|
new Retrier(new FakeSleeper(clock), 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ java_library(
|
||||||
"//java/google/registry/bigquery",
|
"//java/google/registry/bigquery",
|
||||||
"//java/google/registry/model",
|
"//java/google/registry/model",
|
||||||
"//java/google/registry/monitoring/whitebox",
|
"//java/google/registry/monitoring/whitebox",
|
||||||
|
"//java/google/registry/util",
|
||||||
"//javatests/google/registry/testing",
|
"//javatests/google/registry/testing",
|
||||||
"//third_party/objectify:objectify-v4_1",
|
"//third_party/objectify:objectify-v4_1",
|
||||||
"@com_google_apis_google_api_services_bigquery",
|
"@com_google_apis_google_api_services_bigquery",
|
||||||
|
|
|
@ -18,41 +18,36 @@ import static com.google.appengine.api.taskqueue.QueueFactory.getQueue;
|
||||||
import static google.registry.bigquery.BigqueryUtils.toBigqueryTimestamp;
|
import static google.registry.bigquery.BigqueryUtils.toBigqueryTimestamp;
|
||||||
import static google.registry.monitoring.whitebox.BigQueryMetricsEnqueuer.QUEUE_BIGQUERY_STREAMING_METRICS;
|
import static google.registry.monitoring.whitebox.BigQueryMetricsEnqueuer.QUEUE_BIGQUERY_STREAMING_METRICS;
|
||||||
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.api.services.bigquery.model.TableFieldSchema;
|
import com.google.api.services.bigquery.model.TableFieldSchema;
|
||||||
import com.google.appengine.api.modules.ModulesService;
|
|
||||||
import com.google.auto.value.AutoValue;
|
import com.google.auto.value.AutoValue;
|
||||||
import com.google.common.base.Suppliers;
|
import com.google.common.base.Suppliers;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.InjectRule;
|
import google.registry.testing.MockitoJUnitRule;
|
||||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
|
import google.registry.util.AppEngineServiceUtils;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.JUnit4;
|
import org.junit.runners.JUnit4;
|
||||||
import org.mockito.Matchers;
|
import org.mockito.Mock;
|
||||||
|
|
||||||
/** Unit tests for {@link BigQueryMetricsEnqueuer}. */
|
/** Unit tests for {@link BigQueryMetricsEnqueuer}. */
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public class BigQueryMetricsEnqueuerTest {
|
public class BigQueryMetricsEnqueuerTest {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final InjectRule inject = new InjectRule();
|
public final AppEngineRule appEngine =
|
||||||
|
AppEngineRule.builder().withDatastore().withLocalModules().withTaskQueue().build();
|
||||||
|
|
||||||
@Rule
|
@Rule public final MockitoJUnitRule mocks = MockitoJUnitRule.create();
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
|
||||||
.withDatastore()
|
|
||||||
.withLocalModules()
|
|
||||||
.withTaskQueue()
|
|
||||||
.build();
|
|
||||||
|
|
||||||
private final ModulesService modulesService = mock(ModulesService.class);
|
@Mock private AppEngineServiceUtils appEngineServiceUtils;
|
||||||
|
|
||||||
private BigQueryMetricsEnqueuer enqueuer;
|
private BigQueryMetricsEnqueuer enqueuer;
|
||||||
|
|
||||||
|
@ -60,10 +55,10 @@ public class BigQueryMetricsEnqueuerTest {
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
enqueuer = new BigQueryMetricsEnqueuer();
|
enqueuer = new BigQueryMetricsEnqueuer();
|
||||||
enqueuer.idGenerator = Suppliers.ofInstance("laffo");
|
enqueuer.idGenerator = Suppliers.ofInstance("laffo");
|
||||||
enqueuer.modulesService = modulesService;
|
enqueuer.appEngineServiceUtils = appEngineServiceUtils;
|
||||||
enqueuer.queue = getQueue(QUEUE_BIGQUERY_STREAMING_METRICS);
|
enqueuer.queue = getQueue(QUEUE_BIGQUERY_STREAMING_METRICS);
|
||||||
when(modulesService.getVersionHostname(Matchers.anyString(), Matchers.anyString()))
|
when(appEngineServiceUtils.getCurrentVersionHostname("backend"))
|
||||||
.thenReturn("1.backend.test.localhost");
|
.thenReturn("backend.test.localhost");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -77,7 +72,7 @@ public class BigQueryMetricsEnqueuerTest {
|
||||||
assertTasksEnqueued("bigquery-streaming-metrics",
|
assertTasksEnqueued("bigquery-streaming-metrics",
|
||||||
new TaskMatcher()
|
new TaskMatcher()
|
||||||
.url("/_dr/task/metrics")
|
.url("/_dr/task/metrics")
|
||||||
.header("Host", "1.backend.test.localhost")
|
.header("Host", "backend.test.localhost")
|
||||||
.param("tableId", "test")
|
.param("tableId", "test")
|
||||||
.param("startTime", "472176000.000000")
|
.param("startTime", "472176000.000000")
|
||||||
.param("endTime", "472176000.001000")
|
.param("endTime", "472176000.001000")
|
||||||
|
|
|
@ -22,13 +22,12 @@ import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.beust.jcommander.ParameterException;
|
import com.beust.jcommander.ParameterException;
|
||||||
import com.google.appengine.api.modules.ModulesService;
|
|
||||||
import google.registry.testing.InjectRule;
|
import google.registry.testing.InjectRule;
|
||||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
|
import google.registry.util.AppEngineServiceUtils;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Matchers;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
|
||||||
/** Unit tests for {@link GenerateEscrowDepositCommand}. */
|
/** Unit tests for {@link GenerateEscrowDepositCommand}. */
|
||||||
|
@ -38,17 +37,17 @@ public class GenerateEscrowDepositCommandTest
|
||||||
@Rule
|
@Rule
|
||||||
public final InjectRule inject = new InjectRule();
|
public final InjectRule inject = new InjectRule();
|
||||||
|
|
||||||
@Mock ModulesService modulesService;
|
@Mock AppEngineServiceUtils appEngineServiceUtils;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() {
|
public void before() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
createTld("anothertld");
|
createTld("anothertld");
|
||||||
command = new GenerateEscrowDepositCommand();
|
command = new GenerateEscrowDepositCommand();
|
||||||
command.modulesService = modulesService;
|
command.appEngineServiceUtils = appEngineServiceUtils;
|
||||||
command.queue = getQueue("rde-report");
|
command.queue = getQueue("rde-report");
|
||||||
when(modulesService.getVersionHostname(Matchers.anyString(), Matchers.anyString()))
|
when(appEngineServiceUtils.getCurrentVersionHostname("backend"))
|
||||||
.thenReturn("1.backend.test.localhost");
|
.thenReturn("backend.test.localhost");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -191,7 +190,7 @@ public class GenerateEscrowDepositCommandTest
|
||||||
assertTasksEnqueued("rde-report",
|
assertTasksEnqueued("rde-report",
|
||||||
new TaskMatcher()
|
new TaskMatcher()
|
||||||
.url("/_dr/task/rdeStaging")
|
.url("/_dr/task/rdeStaging")
|
||||||
.header("Host", "1.backend.test.localhost")
|
.header("Host", "backend.test.localhost")
|
||||||
.param("mode", "THIN")
|
.param("mode", "THIN")
|
||||||
.param("watermarks", "2017-01-01T00:00:00.000Z")
|
.param("watermarks", "2017-01-01T00:00:00.000Z")
|
||||||
.param("tlds", "tld")
|
.param("tlds", "tld")
|
||||||
|
@ -207,7 +206,7 @@ public class GenerateEscrowDepositCommandTest
|
||||||
assertTasksEnqueued("rde-report",
|
assertTasksEnqueued("rde-report",
|
||||||
new TaskMatcher()
|
new TaskMatcher()
|
||||||
.url("/_dr/task/rdeStaging")
|
.url("/_dr/task/rdeStaging")
|
||||||
.header("Host", "1.backend.test.localhost")
|
.header("Host", "backend.test.localhost")
|
||||||
.param("mode", "THIN")
|
.param("mode", "THIN")
|
||||||
.param("watermarks", "2017-01-01T00:00:00.000Z")
|
.param("watermarks", "2017-01-01T00:00:00.000Z")
|
||||||
.param("tlds", "tld")
|
.param("tlds", "tld")
|
||||||
|
@ -222,7 +221,7 @@ public class GenerateEscrowDepositCommandTest
|
||||||
assertTasksEnqueued("rde-report",
|
assertTasksEnqueued("rde-report",
|
||||||
new TaskMatcher()
|
new TaskMatcher()
|
||||||
.url("/_dr/task/rdeStaging")
|
.url("/_dr/task/rdeStaging")
|
||||||
.header("Host", "1.backend.test.localhost")
|
.header("Host", "backend.test.localhost")
|
||||||
.param("mode", "FULL")
|
.param("mode", "FULL")
|
||||||
.param("watermarks", "2017-01-01T00:00:00.000Z")
|
.param("watermarks", "2017-01-01T00:00:00.000Z")
|
||||||
.param("tlds", "tld")
|
.param("tlds", "tld")
|
||||||
|
@ -243,7 +242,7 @@ public class GenerateEscrowDepositCommandTest
|
||||||
assertTasksEnqueued("rde-report",
|
assertTasksEnqueued("rde-report",
|
||||||
new TaskMatcher()
|
new TaskMatcher()
|
||||||
.url("/_dr/task/rdeStaging")
|
.url("/_dr/task/rdeStaging")
|
||||||
.header("Host", "1.backend.test.localhost")
|
.header("Host", "backend.test.localhost")
|
||||||
.param("mode", "THIN")
|
.param("mode", "THIN")
|
||||||
.param("watermarks", "2017-01-01T00:00:00.000Z,2017-01-02T00:00:00.000Z")
|
.param("watermarks", "2017-01-01T00:00:00.000Z,2017-01-02T00:00:00.000Z")
|
||||||
.param("tlds", "tld,anothertld")
|
.param("tlds", "tld,anothertld")
|
||||||
|
|
|
@ -17,17 +17,12 @@ package google.registry.ui.server.registrar;
|
||||||
import static google.registry.config.RegistryConfig.getGSuiteOutgoingEmailAddress;
|
import static google.registry.config.RegistryConfig.getGSuiteOutgoingEmailAddress;
|
||||||
import static google.registry.config.RegistryConfig.getGSuiteOutgoingEmailDisplayName;
|
import static google.registry.config.RegistryConfig.getGSuiteOutgoingEmailDisplayName;
|
||||||
import static google.registry.security.JsonHttpTestUtils.createJsonPayload;
|
import static google.registry.security.JsonHttpTestUtils.createJsonPayload;
|
||||||
import static google.registry.security.JsonHttpTestUtils.createJsonResponseSupplier;
|
|
||||||
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.appengine.api.modules.ModulesService;
|
|
||||||
import com.google.appengine.api.users.User;
|
import com.google.appengine.api.users.User;
|
||||||
import com.google.common.base.Supplier;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import google.registry.export.sheet.SyncRegistrarsSheetAction;
|
|
||||||
import google.registry.model.ofy.Ofy;
|
import google.registry.model.ofy.Ofy;
|
||||||
import google.registry.request.JsonActionRunner;
|
import google.registry.request.JsonActionRunner;
|
||||||
import google.registry.request.JsonResponse;
|
import google.registry.request.JsonResponse;
|
||||||
|
@ -38,10 +33,11 @@ import google.registry.request.auth.UserAuthInfo;
|
||||||
import google.registry.testing.AppEngineRule;
|
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.testing.MockitoJUnitRule;
|
||||||
|
import google.registry.util.AppEngineServiceUtils;
|
||||||
import google.registry.util.SendEmailService;
|
import google.registry.util.SendEmailService;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import javax.mail.Message;
|
import javax.mail.Message;
|
||||||
import javax.mail.Session;
|
import javax.mail.Session;
|
||||||
|
@ -53,6 +49,7 @@ import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.JUnit4;
|
import org.junit.runners.JUnit4;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
|
||||||
/** Base class for tests using {@link RegistrarSettingsAction}. */
|
/** Base class for tests using {@link RegistrarSettingsAction}. */
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
|
@ -61,32 +58,31 @@ public class RegistrarSettingsActionTestCase {
|
||||||
static final String CLIENT_ID = "TheRegistrar";
|
static final String CLIENT_ID = "TheRegistrar";
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
public final AppEngineRule appEngine =
|
||||||
.withDatastore()
|
AppEngineRule.builder().withDatastore().withTaskQueue().build();
|
||||||
.withTaskQueue()
|
|
||||||
.build();
|
|
||||||
|
|
||||||
@Rule
|
@Rule public final InjectRule inject = new InjectRule();
|
||||||
public final InjectRule inject = new InjectRule();
|
@Rule public final MockitoJUnitRule mocks = MockitoJUnitRule.create();
|
||||||
|
|
||||||
final HttpServletRequest req = mock(HttpServletRequest.class);
|
@Mock AppEngineServiceUtils appEngineServiceUtils;
|
||||||
final HttpServletResponse rsp = mock(HttpServletResponse.class);
|
@Mock HttpServletRequest req;
|
||||||
final SendEmailService emailService = mock(SendEmailService.class);
|
@Mock HttpServletResponse rsp;
|
||||||
final ModulesService modulesService = mock(ModulesService.class);
|
@Mock SendEmailService emailService;
|
||||||
final SessionUtils sessionUtils = mock(SessionUtils.class);
|
@Mock SessionUtils sessionUtils;
|
||||||
final User user = new User("user", "gmail.com");
|
final User user = new User("user", "gmail.com");
|
||||||
|
|
||||||
Message message;
|
Message message;
|
||||||
|
|
||||||
final RegistrarSettingsAction action = new RegistrarSettingsAction();
|
final RegistrarSettingsAction action = new RegistrarSettingsAction();
|
||||||
final StringWriter writer = new StringWriter();
|
final StringWriter writer = new StringWriter();
|
||||||
final Supplier<Map<String, Object>> json = createJsonResponseSupplier(writer);
|
|
||||||
final FakeClock clock = new FakeClock(DateTime.parse("2014-01-01T00:00:00Z"));
|
final FakeClock clock = new FakeClock(DateTime.parse("2014-01-01T00:00:00Z"));
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
action.request = req;
|
action.request = req;
|
||||||
action.sessionUtils = sessionUtils;
|
action.sessionUtils = sessionUtils;
|
||||||
|
action.appEngineServiceUtils = appEngineServiceUtils;
|
||||||
|
when(appEngineServiceUtils.getCurrentVersionHostname("backend")).thenReturn("backend.hostname");
|
||||||
action.authResult = AuthResult.create(AuthLevel.USER, UserAuthInfo.create(user, false));
|
action.authResult = AuthResult.create(AuthLevel.USER, UserAuthInfo.create(user, false));
|
||||||
action.jsonActionRunner = new JsonActionRunner(
|
action.jsonActionRunner = new JsonActionRunner(
|
||||||
ImmutableMap.of(), new JsonResponse(new ResponseImpl(rsp)));
|
ImmutableMap.of(), new JsonResponse(new ResponseImpl(rsp)));
|
||||||
|
@ -96,7 +92,6 @@ public class RegistrarSettingsActionTestCase {
|
||||||
new SendEmailUtils(getGSuiteOutgoingEmailAddress(), getGSuiteOutgoingEmailDisplayName());
|
new SendEmailUtils(getGSuiteOutgoingEmailAddress(), getGSuiteOutgoingEmailDisplayName());
|
||||||
inject.setStaticField(Ofy.class, "clock", clock);
|
inject.setStaticField(Ofy.class, "clock", clock);
|
||||||
inject.setStaticField(SendEmailUtils.class, "emailService", emailService);
|
inject.setStaticField(SendEmailUtils.class, "emailService", emailService);
|
||||||
inject.setStaticField(SyncRegistrarsSheetAction.class, "modulesService", modulesService);
|
|
||||||
message = new MimeMessage(Session.getDefaultInstance(new Properties(), null));
|
message = new MimeMessage(Session.getDefaultInstance(new Properties(), null));
|
||||||
when(emailService.createMessage()).thenReturn(message);
|
when(emailService.createMessage()).thenReturn(message);
|
||||||
when(req.getMethod()).thenReturn("POST");
|
when(req.getMethod()).thenReturn("POST");
|
||||||
|
@ -109,6 +104,5 @@ public class RegistrarSettingsActionTestCase {
|
||||||
// would still return the old value)
|
// would still return the old value)
|
||||||
when(sessionUtils.getRegistrarForAuthResult(req, action.authResult))
|
when(sessionUtils.getRegistrarForAuthResult(req, action.authResult))
|
||||||
.thenAnswer(x -> loadRegistrar(CLIENT_ID));
|
.thenAnswer(x -> loadRegistrar(CLIENT_ID));
|
||||||
when(modulesService.getVersionHostname("backend", null)).thenReturn("backend.hostname");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
// Copyright 2018 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.util;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||||
|
import static org.mockito.Matchers.anyString;
|
||||||
|
import static org.mockito.Matchers.eq;
|
||||||
|
import static org.mockito.Matchers.isNull;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import com.google.appengine.api.modules.ModulesService;
|
||||||
|
import google.registry.testing.MockitoJUnitRule;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.JUnit4;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
|
||||||
|
/** Unit tests for {@link AppEngineServiceUtilsImpl}. */
|
||||||
|
@RunWith(JUnit4.class)
|
||||||
|
public class AppEngineServiceUtilsImplTest {
|
||||||
|
|
||||||
|
@Rule public final MockitoJUnitRule mocks = MockitoJUnitRule.create();
|
||||||
|
|
||||||
|
@Mock private ModulesService modulesService;
|
||||||
|
|
||||||
|
private AppEngineServiceUtils appEngineServiceUtils;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void before() {
|
||||||
|
appEngineServiceUtils = new AppEngineServiceUtilsImpl(modulesService);
|
||||||
|
when(modulesService.getVersionHostname(anyString(), isNull(String.class)))
|
||||||
|
.thenReturn("1234.servicename.projectid.appspot.fake");
|
||||||
|
when(modulesService.getVersionHostname(anyString(), eq("2345")))
|
||||||
|
.thenReturn("2345.servicename.projectid.appspot.fake");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_getServiceHostname_doesntIncludeVersionId() {
|
||||||
|
assertThat(appEngineServiceUtils.getServiceHostname("servicename"))
|
||||||
|
.isEqualTo("servicename.projectid.appspot.fake");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_getVersionHostname_doesIncludeVersionId() {
|
||||||
|
assertThat(appEngineServiceUtils.getCurrentVersionHostname("servicename"))
|
||||||
|
.isEqualTo("1234.servicename.projectid.appspot.fake");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_getVersionHostname_worksWithVersionId() {
|
||||||
|
assertThat(appEngineServiceUtils.getVersionHostname("servicename", "2345"))
|
||||||
|
.isEqualTo("2345.servicename.projectid.appspot.fake");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_getVersionHostname_throwsWhenVersionIdIsNull() {
|
||||||
|
IllegalArgumentException thrown =
|
||||||
|
assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> appEngineServiceUtils.getVersionHostname("servicename", null));
|
||||||
|
assertThat(thrown).hasMessageThat().isEqualTo("Must specify the version");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue