mirror of
https://github.com/google/nomulus.git
synced 2025-07-21 10:16:07 +02:00
Add end-to-end code to run Beam template from App Engine
This serves as proof-of-concept to verify we can use Beam for our invoice generation use case. Namely, it checks that we can: - Deploy a Beam template to GCS - Read from Bigquery within the template - Run the template from App Engine ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=175755390
This commit is contained in:
parent
28417b7599
commit
99996121b5
9 changed files with 209 additions and 96 deletions
|
@ -15,15 +15,27 @@
|
|||
package google.registry.billing;
|
||||
|
||||
import static google.registry.request.Action.Method.POST;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
|
||||
import com.google.api.services.dataflow.Dataflow;
|
||||
import com.google.api.services.dataflow.model.LaunchTemplateParameters;
|
||||
import com.google.api.services.dataflow.model.LaunchTemplateResponse;
|
||||
import com.google.api.services.dataflow.model.RuntimeEnvironment;
|
||||
import com.google.common.net.MediaType;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.request.Action;
|
||||
import google.registry.request.Response;
|
||||
import google.registry.request.auth.Auth;
|
||||
import google.registry.util.FormattingLogger;
|
||||
import java.io.IOException;
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
||||
/**
|
||||
* Generates invoices for the month and stores them on GCS.
|
||||
*
|
||||
* <p>Currently this is just a stub runner that verifies we can deploy dataflow jobs from App
|
||||
* <p>Currently this is just a simplified runner that verifies we can deploy dataflow jobs from App
|
||||
* Engine.
|
||||
*/
|
||||
@Action(
|
||||
|
@ -33,13 +45,44 @@ import javax.inject.Inject;
|
|||
)
|
||||
public class GenerateInvoicesAction implements Runnable {
|
||||
|
||||
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
|
||||
|
||||
@Inject @Config("projectId") String projectId;
|
||||
@Inject @Config("apacheBeamBucketUrl") String beamBucketUrl;
|
||||
@Inject Dataflow dataflow;
|
||||
@Inject Response response;
|
||||
@Inject GenerateInvoicesAction() {}
|
||||
|
||||
static final String PATH = "/_dr/task/generateInvoices";
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// MinWordCount minWordCount = new MinWordCount();
|
||||
// minWordCount.run();
|
||||
logger.info("Launching dataflow job");
|
||||
try {
|
||||
LaunchTemplateParameters params =
|
||||
new LaunchTemplateParameters()
|
||||
.setJobName("test-bigquerytemplate1")
|
||||
.setEnvironment(
|
||||
new RuntimeEnvironment()
|
||||
.setZone("us-east1-c")
|
||||
.setTempLocation(beamBucketUrl + "/temp"));
|
||||
LaunchTemplateResponse launchResponse =
|
||||
dataflow
|
||||
.projects()
|
||||
.templates()
|
||||
.launch(projectId, params)
|
||||
.setGcsPath(beamBucketUrl + "/templates/bigquery1")
|
||||
.execute();
|
||||
logger.infofmt("Got response: %s", launchResponse.getJob().toPrettyString());
|
||||
} catch (IOException e) {
|
||||
logger.warningfmt("Template Launch failed due to: %s", e.getMessage());
|
||||
response.setStatus(SC_INTERNAL_SERVER_ERROR);
|
||||
response.setContentType(MediaType.PLAIN_TEXT_UTF_8);
|
||||
response.setPayload(String.format("Template launch failed: %s", e.getMessage()));
|
||||
return;
|
||||
}
|
||||
response.setStatus(SC_OK);
|
||||
response.setContentType(MediaType.PLAIN_TEXT_UTF_8);
|
||||
response.setPayload("Launched dataflow template.");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue