mirror of
https://github.com/google/nomulus.git
synced 2025-05-01 12:37:52 +02:00
This is a 'green' Flogger migration CL. Green CLs are intended to be as safe as possible and should be easy to review and submit. No changes should be necessary to the code itself prior to submission, but small changes to BUILD files may be required. Changes within files are completely independent of each other, so this CL can be safely split up for review using tools such as Rosie. For more information, see [] Base CL: 197826149 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=198560170
78 lines
3 KiB
Java
78 lines
3 KiB
Java
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package google.registry.export;
|
|
|
|
import static google.registry.export.CheckSnapshotAction.enqueuePollTask;
|
|
import static google.registry.request.Action.Method.POST;
|
|
|
|
import com.google.common.flogger.FluentLogger;
|
|
import google.registry.config.RegistryConfig;
|
|
import google.registry.request.Action;
|
|
import google.registry.request.Response;
|
|
import google.registry.request.auth.Auth;
|
|
import google.registry.util.Clock;
|
|
import javax.inject.Inject;
|
|
|
|
/**
|
|
* Action to trigger a Datastore backup job that writes a snapshot to Google Cloud Storage.
|
|
*
|
|
* <p>This is the first step of a four step workflow for exporting snapshots, with each step calling
|
|
* the next upon successful completion:
|
|
*
|
|
* <ol>
|
|
* <li>The snapshot is exported to Google Cloud Storage (this action).
|
|
* <li>The {@link CheckSnapshotAction} polls until the export is completed.
|
|
* <li>The {@link LoadSnapshotAction} imports the data from GCS to BigQuery.
|
|
* <li>The {@link UpdateSnapshotViewAction} updates the view in latest_snapshot.
|
|
* </ol>
|
|
*/
|
|
@Action(
|
|
path = ExportSnapshotAction.PATH,
|
|
method = POST,
|
|
automaticallyPrintOk = true,
|
|
auth = Auth.AUTH_INTERNAL_ONLY
|
|
)
|
|
public class ExportSnapshotAction implements Runnable {
|
|
|
|
/** Queue to use for enqueuing the task that will actually launch the backup. */
|
|
static final String QUEUE = "export-snapshot"; // See queue.xml.
|
|
|
|
static final String PATH = "/_dr/task/exportSnapshot"; // See web.xml.
|
|
|
|
/** Prefix to use for naming all snapshots that are started by this servlet. */
|
|
static final String SNAPSHOT_PREFIX = "auto_snapshot_";
|
|
|
|
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
|
|
|
@Inject Clock clock;
|
|
@Inject DatastoreBackupService backupService;
|
|
@Inject Response response;
|
|
|
|
@Inject
|
|
ExportSnapshotAction() {}
|
|
|
|
@Override
|
|
public void run() {
|
|
// Use a unique name for the snapshot so we can explicitly check its completion later.
|
|
String snapshotName = SNAPSHOT_PREFIX + clock.nowUtc().toString("YYYYMMdd_HHmmss");
|
|
backupService.launchNewBackup(
|
|
QUEUE, snapshotName, RegistryConfig.getSnapshotsBucket(), ExportConstants.getBackupKinds());
|
|
// Enqueue a poll task to monitor the backup and load reporting-related kinds into bigquery.
|
|
enqueuePollTask(snapshotName, ExportConstants.getReportingKinds());
|
|
String message = "Datastore backup started with name: " + snapshotName;
|
|
logger.atInfo().log(message);
|
|
response.setPayload(message);
|
|
}
|
|
}
|