public class DataflowExampleUtils extends Object
It is used to run Dataflow examples, such as TrafficMaxLaneFlow and TrafficRoutes.
| Constructor and Description |
|---|
DataflowExampleUtils(DataflowPipelineOptions options) |
DataflowExampleUtils(DataflowPipelineOptions options,
boolean isUnbounded)
Do resources and runner options setup.
|
| Modifier and Type | Method and Description |
|---|---|
void |
mockUnboundedSource(String inputFile,
PipelineResult result)
Start the auxiliary injector pipeline, then wait for this pipeline to finish.
|
void |
runInjectorPipeline(Pipeline injectorPipeline)
Runs the provided pipeline to inject data into the PubSubIO input topic.
|
void |
runInjectorPipeline(PTransform<? super PBegin,PCollection<String>> readSource,
String topic,
String pubsubTimestampTabelKey)
Runs a batch pipeline to inject data into the PubSubIO input topic.
|
void |
runInjectorPipeline(String inputFile,
String topic)
Runs a batch pipeline to inject data into the PubSubIO input topic.
|
void |
setup()
Sets up external resources that are required by the example,
such as Pub/Sub topics and BigQuery tables.
|
void |
setupBigQueryTable()
Sets up the BigQuery table with the given schema.
|
void |
setupPubsub()
Sets up the Google Cloud Pub/Sub topic.
|
void |
setupResourcesAndRunner(boolean isUnbounded)
Set up external resources, and configure the runner appropriately.
|
void |
setupRunner()
Do some runner setup: check that the DirectPipelineRunner is not used in conjunction with
streaming, and if streaming is specified, use the DataflowPipelineRunner.
|
void |
startInjectorIfNeeded(String inputFile)
If this is an unbounded (streaming) pipeline, and both inputFile and pubsub topic are defined,
start an 'injector' pipeline that publishes the contents of the file to the given topic, first
creating the topic if necessary.
|
void |
waitToFinish(PipelineResult result)
If DataflowPipelineRunner or BlockingDataflowPipelineRunner is used,
waits for the pipeline to finish and cancels it (and the injector) before the program exists.
|
public DataflowExampleUtils(DataflowPipelineOptions options)
public DataflowExampleUtils(DataflowPipelineOptions options, boolean isUnbounded) throws IOException
IOExceptionpublic void setup()
throws IOException
IOException - if there is a problem setting up the resourcespublic void setupResourcesAndRunner(boolean isUnbounded)
throws IOException
IOExceptionpublic void setupPubsub()
throws IOException
If the topic doesn't exist, a new topic with the given name will be created.
IOException - if there is a problem setting up the Pub/Sub topicpublic void setupBigQueryTable()
throws IOException
If the table already exists, the schema has to match the given one. Otherwise, the example will throw a RuntimeException. If the table doesn't exist, a new table with the given schema will be created.
IOException - if there is a problem setting up the BigQuery tablepublic void startInjectorIfNeeded(String inputFile)
public void setupRunner()
public void runInjectorPipeline(String inputFile, String topic)
The injector pipeline will read from the given text file, and inject data into the Google Cloud Pub/Sub topic.
public void runInjectorPipeline(PTransform<? super PBegin,PCollection<String>> readSource, String topic, String pubsubTimestampTabelKey)
The injector pipeline will read from the given source, and inject data into the Google Cloud Pub/Sub topic.
public void runInjectorPipeline(Pipeline injectorPipeline)
public void mockUnboundedSource(String inputFile, PipelineResult result)
public void waitToFinish(PipelineResult result)