mirror of
https://github.com/google/nomulus.git
synced 2025-07-21 10:16:07 +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 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.TaskOptions;
|
||||
import com.google.appengine.api.taskqueue.TaskOptions.Method;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Streams;
|
||||
import google.registry.util.NonFinalForTesting;
|
||||
import google.registry.util.AppEngineServiceUtils;
|
||||
import java.util.NoSuchElementException;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/** An object providing methods for starting and querying Datastore backups. */
|
||||
public class DatastoreBackupService {
|
||||
|
@ -40,19 +39,11 @@ public class DatastoreBackupService {
|
|||
/** The name of the app version used for hosting the Datastore Admin functionality. */
|
||||
static final String DATASTORE_ADMIN_VERSION_NAME = "ah-builtin-python-bundle";
|
||||
|
||||
@NonFinalForTesting
|
||||
private static ModulesService modulesService = ModulesServiceFactory.getModulesService();
|
||||
private final AppEngineServiceUtils appEngineServiceUtils;
|
||||
|
||||
/**
|
||||
* Returns an instance of this service.
|
||||
*
|
||||
* <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();
|
||||
@Inject
|
||||
public DatastoreBackupService(AppEngineServiceUtils appEngineServiceUtils) {
|
||||
this.appEngineServiceUtils = appEngineServiceUtils;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,9 +51,10 @@ public class DatastoreBackupService {
|
|||
*
|
||||
* @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 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")
|
||||
.header("Host", hostname)
|
||||
.method(Method.GET)
|
||||
|
|
|
@ -103,9 +103,4 @@ public final class ExportRequestModule {
|
|||
static String provideProjectId(HttpServletRequest req) {
|
||||
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_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.common.flogger.FluentLogger;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
|
@ -34,7 +31,6 @@ import google.registry.request.Parameter;
|
|||
import google.registry.request.Response;
|
||||
import google.registry.request.auth.Auth;
|
||||
import google.registry.request.lock.LockHandler;
|
||||
import google.registry.util.NonFinalForTesting;
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
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 FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
@NonFinalForTesting
|
||||
private static ModulesService modulesService = ModulesServiceFactory.getModulesService();
|
||||
|
||||
@Inject Response response;
|
||||
@Inject SyncRegistrarsSheet syncRegistrarsSheet;
|
||||
@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() {
|
||||
String hostname = modulesService.getVersionHostname("backend", null);
|
||||
return getQueue(QUEUE).add(withUrl(PATH).method(Method.GET).header("Host", hostname));
|
||||
/**
|
||||
* Enqueues a sync registrar sheet task targeting the App Engine service specified by 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 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.TaskOptions;
|
||||
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.eppcommon.Trid;
|
||||
import google.registry.model.host.HostResource;
|
||||
import google.registry.util.AppEngineServiceUtils;
|
||||
import google.registry.util.Retrier;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
@ -65,7 +65,7 @@ public final class AsyncFlowEnqueuer {
|
|||
private final Queue asyncActionsPushQueue;
|
||||
private final Queue asyncDeletePullQueue;
|
||||
private final Queue asyncDnsRefreshPullQueue;
|
||||
private final ModulesService modulesService;
|
||||
private final AppEngineServiceUtils appEngineServiceUtils;
|
||||
private final Retrier retrier;
|
||||
|
||||
@VisibleForTesting
|
||||
|
@ -75,13 +75,13 @@ public final class AsyncFlowEnqueuer {
|
|||
@Named(QUEUE_ASYNC_DELETE) Queue asyncDeletePullQueue,
|
||||
@Named(QUEUE_ASYNC_HOST_RENAME) Queue asyncDnsRefreshPullQueue,
|
||||
@Config("asyncDeleteFlowMapreduceDelay") Duration asyncDeleteDelay,
|
||||
ModulesService modulesService,
|
||||
AppEngineServiceUtils appEngineServiceUtils,
|
||||
Retrier retrier) {
|
||||
this.asyncActionsPushQueue = asyncActionsPushQueue;
|
||||
this.asyncDeletePullQueue = asyncDeletePullQueue;
|
||||
this.asyncDnsRefreshPullQueue = asyncDnsRefreshPullQueue;
|
||||
this.asyncDeleteDelay = asyncDeleteDelay;
|
||||
this.modulesService = modulesService;
|
||||
this.appEngineServiceUtils = appEngineServiceUtils;
|
||||
this.retrier = retrier;
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ public final class AsyncFlowEnqueuer {
|
|||
return;
|
||||
}
|
||||
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.Builder.withUrl(PATH_RESAVE_ENTITY)
|
||||
.method(Method.POST)
|
||||
|
|
|
@ -34,13 +34,13 @@ import google.registry.request.Modules.AppIdentityCredentialModule;
|
|||
import google.registry.request.Modules.DatastoreServiceModule;
|
||||
import google.registry.request.Modules.GoogleCredentialModule;
|
||||
import google.registry.request.Modules.Jackson2Module;
|
||||
import google.registry.request.Modules.ModulesServiceModule;
|
||||
import google.registry.request.Modules.NetHttpTransportModule;
|
||||
import google.registry.request.Modules.URLFetchServiceModule;
|
||||
import google.registry.request.Modules.UrlFetchTransportModule;
|
||||
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
||||
import google.registry.request.Modules.UserServiceModule;
|
||||
import google.registry.request.auth.AuthModule;
|
||||
import google.registry.util.AppEngineServiceUtilsImpl.AppEngineServiceUtilsModule;
|
||||
import google.registry.util.SystemClock.SystemClockModule;
|
||||
import google.registry.util.SystemSleeper.SystemSleeperModule;
|
||||
import javax.inject.Singleton;
|
||||
|
@ -48,37 +48,36 @@ import javax.inject.Singleton;
|
|||
/** Dagger component with instance lifetime for "backend" App Engine module. */
|
||||
@Singleton
|
||||
@Component(
|
||||
modules = {
|
||||
AppIdentityCredentialModule.class,
|
||||
AuthModule.class,
|
||||
BackendRequestComponentModule.class,
|
||||
BigqueryModule.class,
|
||||
ConfigModule.class,
|
||||
DatastoreServiceModule.class,
|
||||
DirectoryModule.class,
|
||||
google.registry.keyring.api.DummyKeyringModule.class,
|
||||
DriveModule.class,
|
||||
GcsServiceModule.class,
|
||||
GoogleCredentialModule.class,
|
||||
GroupsModule.class,
|
||||
GroupssettingsModule.class,
|
||||
JSchModule.class,
|
||||
Jackson2Module.class,
|
||||
KeyModule.class,
|
||||
KmsModule.class,
|
||||
ModulesServiceModule.class,
|
||||
NetHttpTransportModule.class,
|
||||
SheetsServiceModule.class,
|
||||
StackdriverModule.class,
|
||||
SystemClockModule.class,
|
||||
SystemSleeperModule.class,
|
||||
URLFetchServiceModule.class,
|
||||
UrlFetchTransportModule.class,
|
||||
UseAppIdentityCredentialForGoogleApisModule.class,
|
||||
UserServiceModule.class,
|
||||
google.registry.dns.writer.VoidDnsWriterModule.class,
|
||||
}
|
||||
)
|
||||
modules = {
|
||||
AppEngineServiceUtilsModule.class,
|
||||
AppIdentityCredentialModule.class,
|
||||
AuthModule.class,
|
||||
BackendRequestComponentModule.class,
|
||||
BigqueryModule.class,
|
||||
ConfigModule.class,
|
||||
DatastoreServiceModule.class,
|
||||
DirectoryModule.class,
|
||||
google.registry.keyring.api.DummyKeyringModule.class,
|
||||
DriveModule.class,
|
||||
GcsServiceModule.class,
|
||||
GoogleCredentialModule.class,
|
||||
GroupsModule.class,
|
||||
GroupssettingsModule.class,
|
||||
JSchModule.class,
|
||||
Jackson2Module.class,
|
||||
KeyModule.class,
|
||||
KmsModule.class,
|
||||
NetHttpTransportModule.class,
|
||||
SheetsServiceModule.class,
|
||||
StackdriverModule.class,
|
||||
SystemClockModule.class,
|
||||
SystemSleeperModule.class,
|
||||
URLFetchServiceModule.class,
|
||||
UrlFetchTransportModule.class,
|
||||
UseAppIdentityCredentialForGoogleApisModule.class,
|
||||
UserServiceModule.class,
|
||||
google.registry.dns.writer.VoidDnsWriterModule.class,
|
||||
})
|
||||
interface BackendComponent {
|
||||
BackendRequestHandler requestHandler();
|
||||
|
||||
|
|
|
@ -27,13 +27,13 @@ import google.registry.monitoring.whitebox.StackdriverModule;
|
|||
import google.registry.request.Modules.AppIdentityCredentialModule;
|
||||
import google.registry.request.Modules.GoogleCredentialModule;
|
||||
import google.registry.request.Modules.Jackson2Module;
|
||||
import google.registry.request.Modules.ModulesServiceModule;
|
||||
import google.registry.request.Modules.NetHttpTransportModule;
|
||||
import google.registry.request.Modules.UrlFetchTransportModule;
|
||||
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
||||
import google.registry.request.Modules.UserServiceModule;
|
||||
import google.registry.request.auth.AuthModule;
|
||||
import google.registry.ui.ConsoleDebug.ConsoleConfigModule;
|
||||
import google.registry.util.AppEngineServiceUtilsImpl.AppEngineServiceUtilsModule;
|
||||
import google.registry.util.SystemClock.SystemClockModule;
|
||||
import google.registry.util.SystemSleeper.SystemSleeperModule;
|
||||
import javax.inject.Singleton;
|
||||
|
@ -41,29 +41,28 @@ import javax.inject.Singleton;
|
|||
/** Dagger component with instance lifetime for "default" App Engine module. */
|
||||
@Singleton
|
||||
@Component(
|
||||
modules = {
|
||||
AppIdentityCredentialModule.class,
|
||||
AuthModule.class,
|
||||
ConfigModule.class,
|
||||
ConsoleConfigModule.class,
|
||||
CustomLogicFactoryModule.class,
|
||||
google.registry.keyring.api.DummyKeyringModule.class,
|
||||
FrontendRequestComponentModule.class,
|
||||
GoogleCredentialModule.class,
|
||||
Jackson2Module.class,
|
||||
KeyModule.class,
|
||||
KmsModule.class,
|
||||
ModulesServiceModule.class,
|
||||
NetHttpTransportModule.class,
|
||||
ServerTridProviderModule.class,
|
||||
StackdriverModule.class,
|
||||
SystemClockModule.class,
|
||||
SystemSleeperModule.class,
|
||||
UrlFetchTransportModule.class,
|
||||
UseAppIdentityCredentialForGoogleApisModule.class,
|
||||
UserServiceModule.class,
|
||||
}
|
||||
)
|
||||
modules = {
|
||||
AppEngineServiceUtilsModule.class,
|
||||
AppIdentityCredentialModule.class,
|
||||
AuthModule.class,
|
||||
ConfigModule.class,
|
||||
ConsoleConfigModule.class,
|
||||
CustomLogicFactoryModule.class,
|
||||
google.registry.keyring.api.DummyKeyringModule.class,
|
||||
FrontendRequestComponentModule.class,
|
||||
GoogleCredentialModule.class,
|
||||
Jackson2Module.class,
|
||||
KeyModule.class,
|
||||
KmsModule.class,
|
||||
NetHttpTransportModule.class,
|
||||
ServerTridProviderModule.class,
|
||||
StackdriverModule.class,
|
||||
SystemClockModule.class,
|
||||
SystemSleeperModule.class,
|
||||
UrlFetchTransportModule.class,
|
||||
UseAppIdentityCredentialForGoogleApisModule.class,
|
||||
UserServiceModule.class,
|
||||
})
|
||||
interface FrontendComponent {
|
||||
FrontendRequestHandler requestHandler();
|
||||
|
||||
|
|
|
@ -27,12 +27,12 @@ import google.registry.monitoring.whitebox.StackdriverModule;
|
|||
import google.registry.request.Modules.AppIdentityCredentialModule;
|
||||
import google.registry.request.Modules.GoogleCredentialModule;
|
||||
import google.registry.request.Modules.Jackson2Module;
|
||||
import google.registry.request.Modules.ModulesServiceModule;
|
||||
import google.registry.request.Modules.NetHttpTransportModule;
|
||||
import google.registry.request.Modules.UrlFetchTransportModule;
|
||||
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
||||
import google.registry.request.Modules.UserServiceModule;
|
||||
import google.registry.request.auth.AuthModule;
|
||||
import google.registry.util.AppEngineServiceUtilsImpl.AppEngineServiceUtilsModule;
|
||||
import google.registry.util.SystemClock.SystemClockModule;
|
||||
import google.registry.util.SystemSleeper.SystemSleeperModule;
|
||||
import javax.inject.Singleton;
|
||||
|
@ -40,28 +40,27 @@ import javax.inject.Singleton;
|
|||
/** Dagger component with instance lifetime for "pubapi" App Engine module. */
|
||||
@Singleton
|
||||
@Component(
|
||||
modules = {
|
||||
AppIdentityCredentialModule.class,
|
||||
AuthModule.class,
|
||||
ConfigModule.class,
|
||||
CustomLogicFactoryModule.class,
|
||||
google.registry.keyring.api.DummyKeyringModule.class,
|
||||
PubApiRequestComponentModule.class,
|
||||
GoogleCredentialModule.class,
|
||||
Jackson2Module.class,
|
||||
KeyModule.class,
|
||||
KmsModule.class,
|
||||
ModulesServiceModule.class,
|
||||
NetHttpTransportModule.class,
|
||||
ServerTridProviderModule.class,
|
||||
StackdriverModule.class,
|
||||
SystemClockModule.class,
|
||||
SystemSleeperModule.class,
|
||||
UrlFetchTransportModule.class,
|
||||
UseAppIdentityCredentialForGoogleApisModule.class,
|
||||
UserServiceModule.class,
|
||||
}
|
||||
)
|
||||
modules = {
|
||||
AppEngineServiceUtilsModule.class,
|
||||
AppIdentityCredentialModule.class,
|
||||
AuthModule.class,
|
||||
ConfigModule.class,
|
||||
CustomLogicFactoryModule.class,
|
||||
google.registry.keyring.api.DummyKeyringModule.class,
|
||||
PubApiRequestComponentModule.class,
|
||||
GoogleCredentialModule.class,
|
||||
Jackson2Module.class,
|
||||
KeyModule.class,
|
||||
KmsModule.class,
|
||||
NetHttpTransportModule.class,
|
||||
ServerTridProviderModule.class,
|
||||
StackdriverModule.class,
|
||||
SystemClockModule.class,
|
||||
SystemSleeperModule.class,
|
||||
UrlFetchTransportModule.class,
|
||||
UseAppIdentityCredentialForGoogleApisModule.class,
|
||||
UserServiceModule.class,
|
||||
})
|
||||
interface PubApiComponent {
|
||||
PubApiRequestHandler requestHandler();
|
||||
|
||||
|
|
|
@ -30,12 +30,12 @@ import google.registry.request.Modules.AppIdentityCredentialModule;
|
|||
import google.registry.request.Modules.DatastoreServiceModule;
|
||||
import google.registry.request.Modules.GoogleCredentialModule;
|
||||
import google.registry.request.Modules.Jackson2Module;
|
||||
import google.registry.request.Modules.ModulesServiceModule;
|
||||
import google.registry.request.Modules.NetHttpTransportModule;
|
||||
import google.registry.request.Modules.UrlFetchTransportModule;
|
||||
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
||||
import google.registry.request.Modules.UserServiceModule;
|
||||
import google.registry.request.auth.AuthModule;
|
||||
import google.registry.util.AppEngineServiceUtilsImpl.AppEngineServiceUtilsModule;
|
||||
import google.registry.util.SystemClock.SystemClockModule;
|
||||
import google.registry.util.SystemSleeper.SystemSleeperModule;
|
||||
import javax.inject.Singleton;
|
||||
|
@ -43,33 +43,32 @@ import javax.inject.Singleton;
|
|||
/** Dagger component with instance lifetime for "tools" App Engine module. */
|
||||
@Singleton
|
||||
@Component(
|
||||
modules = {
|
||||
AppIdentityCredentialModule.class,
|
||||
AuthModule.class,
|
||||
ConfigModule.class,
|
||||
CustomLogicFactoryModule.class,
|
||||
DatastoreServiceModule.class,
|
||||
DirectoryModule.class,
|
||||
google.registry.keyring.api.DummyKeyringModule.class,
|
||||
DriveModule.class,
|
||||
GcsServiceModule.class,
|
||||
GoogleCredentialModule.class,
|
||||
GroupsModule.class,
|
||||
GroupssettingsModule.class,
|
||||
Jackson2Module.class,
|
||||
KeyModule.class,
|
||||
KmsModule.class,
|
||||
ModulesServiceModule.class,
|
||||
NetHttpTransportModule.class,
|
||||
ServerTridProviderModule.class,
|
||||
SystemClockModule.class,
|
||||
SystemSleeperModule.class,
|
||||
ToolsRequestComponentModule.class,
|
||||
UrlFetchTransportModule.class,
|
||||
UseAppIdentityCredentialForGoogleApisModule.class,
|
||||
UserServiceModule.class,
|
||||
}
|
||||
)
|
||||
modules = {
|
||||
AppEngineServiceUtilsModule.class,
|
||||
AppIdentityCredentialModule.class,
|
||||
AuthModule.class,
|
||||
ConfigModule.class,
|
||||
CustomLogicFactoryModule.class,
|
||||
DatastoreServiceModule.class,
|
||||
DirectoryModule.class,
|
||||
google.registry.keyring.api.DummyKeyringModule.class,
|
||||
DriveModule.class,
|
||||
GcsServiceModule.class,
|
||||
GoogleCredentialModule.class,
|
||||
GroupsModule.class,
|
||||
GroupssettingsModule.class,
|
||||
Jackson2Module.class,
|
||||
KeyModule.class,
|
||||
KmsModule.class,
|
||||
NetHttpTransportModule.class,
|
||||
ServerTridProviderModule.class,
|
||||
SystemClockModule.class,
|
||||
SystemSleeperModule.class,
|
||||
ToolsRequestComponentModule.class,
|
||||
UrlFetchTransportModule.class,
|
||||
UseAppIdentityCredentialForGoogleApisModule.class,
|
||||
UserServiceModule.class,
|
||||
})
|
||||
interface ToolsComponent {
|
||||
ToolsRequestHandler requestHandler();
|
||||
}
|
||||
|
|
|
@ -16,12 +16,12 @@ package google.registry.monitoring.whitebox;
|
|||
|
||||
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.TaskOptions;
|
||||
import com.google.appengine.api.taskqueue.TransientFailureException;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import google.registry.util.AppEngineServiceUtils;
|
||||
import java.util.Map.Entry;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
@ -38,7 +38,7 @@ public class BigQueryMetricsEnqueuer {
|
|||
|
||||
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(QUEUE_BIGQUERY_STREAMING_METRICS) Queue queue;
|
||||
|
||||
|
@ -46,7 +46,7 @@ public class BigQueryMetricsEnqueuer {
|
|||
|
||||
public void export(BigQueryMetric metric) {
|
||||
try {
|
||||
String hostname = modulesService.getVersionHostname("backend", null);
|
||||
String hostname = appEngineServiceUtils.getCurrentVersionHostname("backend");
|
||||
TaskOptions opts =
|
||||
withUrl(MetricsExportAction.PATH)
|
||||
.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.jackson2.JacksonFactory;
|
||||
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.URLFetchServiceFactory;
|
||||
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}. */
|
||||
@Module
|
||||
public static final class URLFetchServiceModule {
|
||||
|
|
|
@ -17,9 +17,11 @@ package google.registry.tools;
|
|||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Streams;
|
||||
import google.registry.export.DatastoreBackupInfo;
|
||||
import google.registry.export.DatastoreBackupService;
|
||||
import google.registry.tools.Command.RemoteApiCommand;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Command to check the status of a Datastore backup, or "snapshot".
|
||||
|
@ -33,16 +35,16 @@ public class CheckSnapshotCommand implements RemoteApiCommand {
|
|||
required = true)
|
||||
private String snapshotName;
|
||||
|
||||
@Inject DatastoreBackupService datastoreBackupService;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Iterable<DatastoreBackupInfo> backups =
|
||||
DatastoreBackupService.get().findAllByNamePrefix(snapshotName);
|
||||
datastoreBackupService.findAllByNamePrefix(snapshotName);
|
||||
if (Iterables.isEmpty(backups)) {
|
||||
System.err.println("No snapshot found with name: " + snapshotName);
|
||||
return;
|
||||
}
|
||||
for (DatastoreBackupInfo backup : backups) {
|
||||
System.out.println(backup.getInformation());
|
||||
}
|
||||
Streams.stream(backups).map(DatastoreBackupInfo::getInformation).forEach(System.out::println);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,13 +26,13 @@ import static google.registry.request.RequestParameters.PARAM_TLDS;
|
|||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.ParameterException;
|
||||
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.TaskOptions;
|
||||
import google.registry.model.rde.RdeMode;
|
||||
import google.registry.rde.RdeStagingAction;
|
||||
import google.registry.tools.Command.RemoteApiCommand;
|
||||
import google.registry.tools.params.DateTimeParameter;
|
||||
import google.registry.util.AppEngineServiceUtils;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.inject.Inject;
|
||||
|
@ -75,7 +75,7 @@ final class GenerateEscrowDepositCommand implements RemoteApiCommand {
|
|||
required = true)
|
||||
private String outdir;
|
||||
|
||||
@Inject ModulesService modulesService;
|
||||
@Inject AppEngineServiceUtils appEngineServiceUtils;
|
||||
@Inject @Named("rde-report") Queue queue;
|
||||
|
||||
@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
|
||||
// (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 =
|
||||
withUrl(RdeStagingAction.PATH)
|
||||
.header("Host", hostname)
|
||||
|
|
|
@ -26,11 +26,11 @@ import google.registry.request.Modules.AppIdentityCredentialModule;
|
|||
import google.registry.request.Modules.DatastoreServiceModule;
|
||||
import google.registry.request.Modules.GoogleCredentialModule;
|
||||
import google.registry.request.Modules.Jackson2Module;
|
||||
import google.registry.request.Modules.ModulesServiceModule;
|
||||
import google.registry.request.Modules.URLFetchServiceModule;
|
||||
import google.registry.request.Modules.UrlFetchTransportModule;
|
||||
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
||||
import google.registry.request.Modules.UserServiceModule;
|
||||
import google.registry.util.AppEngineServiceUtilsImpl.AppEngineServiceUtilsModule;
|
||||
import google.registry.util.SystemClock.SystemClockModule;
|
||||
import google.registry.util.SystemSleeper.SystemSleeperModule;
|
||||
import google.registry.whois.WhoisModule;
|
||||
|
@ -44,37 +44,37 @@ import javax.inject.Singleton;
|
|||
*/
|
||||
@Singleton
|
||||
@Component(
|
||||
modules = {
|
||||
AppEngineConnectionFlags.FlagsModule.class,
|
||||
// TODO(b/36866706): Find a way to replace this with a command-line friendly version
|
||||
AppIdentityCredentialModule.class,
|
||||
AuthModule.class,
|
||||
ConfigModule.class,
|
||||
DatastoreServiceModule.class,
|
||||
google.registry.keyring.api.DummyKeyringModule.class,
|
||||
CloudDnsWriterModule.class,
|
||||
DefaultRequestFactoryModule.class,
|
||||
DefaultRequestFactoryModule.RequestFactoryModule.class,
|
||||
DnsUpdateWriterModule.class,
|
||||
GoogleCredentialModule.class,
|
||||
Jackson2Module.class,
|
||||
KeyModule.class,
|
||||
KmsModule.class,
|
||||
ModulesServiceModule.class,
|
||||
RdeModule.class,
|
||||
RegistryToolModule.class,
|
||||
SystemClockModule.class,
|
||||
SystemSleeperModule.class,
|
||||
URLFetchServiceModule.class,
|
||||
UrlFetchTransportModule.class,
|
||||
// TODO(b/36866706): Find a way to replace this with a command-line friendly version
|
||||
UseAppIdentityCredentialForGoogleApisModule.class,
|
||||
UserServiceModule.class,
|
||||
VoidDnsWriterModule.class,
|
||||
WhoisModule.class,
|
||||
}
|
||||
)
|
||||
modules = {
|
||||
AppEngineConnectionFlags.FlagsModule.class,
|
||||
AppEngineServiceUtilsModule.class,
|
||||
// TODO(b/36866706): Find a way to replace this with a command-line friendly version
|
||||
AppIdentityCredentialModule.class,
|
||||
AuthModule.class,
|
||||
ConfigModule.class,
|
||||
DatastoreServiceModule.class,
|
||||
google.registry.keyring.api.DummyKeyringModule.class,
|
||||
CloudDnsWriterModule.class,
|
||||
DefaultRequestFactoryModule.class,
|
||||
DefaultRequestFactoryModule.RequestFactoryModule.class,
|
||||
DnsUpdateWriterModule.class,
|
||||
GoogleCredentialModule.class,
|
||||
Jackson2Module.class,
|
||||
KeyModule.class,
|
||||
KmsModule.class,
|
||||
RdeModule.class,
|
||||
RegistryToolModule.class,
|
||||
SystemClockModule.class,
|
||||
SystemSleeperModule.class,
|
||||
URLFetchServiceModule.class,
|
||||
UrlFetchTransportModule.class,
|
||||
// TODO(b/36866706): Find a way to replace this with a command-line friendly version
|
||||
UseAppIdentityCredentialForGoogleApisModule.class,
|
||||
UserServiceModule.class,
|
||||
VoidDnsWriterModule.class,
|
||||
WhoisModule.class,
|
||||
})
|
||||
interface RegistryToolComponent {
|
||||
void inject(CheckSnapshotCommand command);
|
||||
void inject(CountDomainsCommand command);
|
||||
void inject(CreateAnchorTenantCommand 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.Sets.difference;
|
||||
import static google.registry.export.sheet.SyncRegistrarsSheetAction.enqueueRegistrarSheetSync;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.security.JsonResponseHelper.Status.ERROR;
|
||||
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.flogger.FluentLogger;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.export.sheet.SyncRegistrarsSheetAction;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.model.registrar.RegistrarContact;
|
||||
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.FormFieldException;
|
||||
import google.registry.ui.server.RegistrarFormFields;
|
||||
import google.registry.util.AppEngineServiceUtils;
|
||||
import google.registry.util.CollectionUtils;
|
||||
import google.registry.util.DiffUtils;
|
||||
import java.util.HashSet;
|
||||
|
@ -76,6 +77,7 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
|
|||
|
||||
@Inject HttpServletRequest request;
|
||||
@Inject JsonActionRunner jsonActionRunner;
|
||||
@Inject AppEngineServiceUtils appEngineServiceUtils;
|
||||
@Inject AuthResult authResult;
|
||||
@Inject SendEmailUtils sendEmailUtils;
|
||||
@Inject SessionUtils sessionUtils;
|
||||
|
@ -368,7 +370,7 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
|
|||
if (CollectionUtils.difference(changedKeys, "lastUpdateTime").isEmpty()) {
|
||||
return;
|
||||
}
|
||||
SyncRegistrarsSheetAction.enqueueBackendTask();
|
||||
enqueueRegistrarSheetSync(appEngineServiceUtils.getCurrentVersionHostname("backend"));
|
||||
if (!registrarChangesNotificationEmailAddresses.isEmpty()) {
|
||||
sendEmailUtils.sendEmail(
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue