Running the Apache Beam samples With Apache Flink

Check the Supported Versions on the Getting Started With Beam page to find the latest supported Flink version for your Hop version.

For example, for Hop 1.2, the latest currently supported version is 1.13. Make sure to download Flink for a recent and JDK 8 compatible Scale version. For Flink 1.3.6, this is Scala 2.11.

Download your selected Flink version and unzip to a convenient location.

Apache Flink Download

To keep things as simple as possible, we’ll run a local single node Flink cluster with a single command.

In the folder where you unzipped Flink to, run:

bin/start-cluster.sh

Your output should look similar to the one below:

  1. Starting cluster.
  2. Starting standalonesession daemon on host <HOSTNAME>.
  3. Starting taskexecutor daemon on host <HOSTNAME>.

The cluster shouldn’t take more than a couple of seconds to start. Once Flink is available, you’ll be able to access your Flink Dashboard at http://localhost:8081/

Apache Flink Dashboard

In Hop Gui’s metadata perspective for the Samples project, edit the Flink pipeline run configuration and make sure the Fat jar file location (the very last option) points to the Hop fat jar you created earlier in the prerequisites.

Apache Beam - Flink run configuration

From Hop GUI

Running Hop pipelines on embedded Flink through Hop Gui will work just fine but is intended for testing purposes and won’t show in your Flink dashboard. You can leave the default Flink master to [local] to run the embedded Flink engine from Hop Gui.

Set your Flink master to your cluster’s master. For embedded Flink, [local] will do.

Go back to the data orchestration perspective and run one of the Beam pipelines in the samples project. In this example, we used samples/beam/pipelines/generate-synthetic-data.hpl

When you start your pipeline from Hop Gui, it will appear in your Flink Dashboard.

Apache Flink Dashboard - width="90%"

In a real-world setup, you’ll run your Flink pipelines from the Flink master through flink run.

Set your Flink master to [auto] and export your Hop metadata again (see prerequisites).

Apache Beam - Flink run configuration - master

Unlike Spark you can not pass java options at runtime to the TaskManager. So we also want to set the PROJECT_HOME variable in the run configuration. This variable is used during execution to know where the source files are. (Metadata perspective → Pipeline Run Configuration → Flink → Variables)

Apache Beam - Flink run configuration - master

Use a command like the one below to pass all the information required by flink run.

  1. bin/flink run \
  2. --class org.apache.hop.beam.run.MainBeam \
  3. --parallelism 2 \
  4. /opt/flink/hop-fat-jar.jar \
  5. <PATH>/hop/config/projects/samples/beam/pipelines/generate-synthetic-data.hpl \
  6. /opt/flink/hop-metadata.json \
  7. Flink

With your Hop and Flink set up correctly, your output will look similar to what’s shown below:

  1. Argument 1 : Pipeline filename (.hpl) : /home/bart/git-hop/hop/assemblies/client/target/hop/config/projects/samples/beam/pipelines/generate-synthetic-data.hpl
  2. Argument 2 : Metadata filename (.json) : /opt/flink/hop-metadata.json
  3. Argument 3 : Pipeline run configuration : Flink
  4. >>>>>> Initializing Hop...
  5. Hop configuration file not found, not serializing: /home/bart/Projects/flink/flink-1.13.5/config/hop-config.json
  6. >>>>>> Loading pipeline metadata
  7. >>>>>> Building Apache Beam Pipeline...
  8. >>>>>> Found Beam Input transform plugin class loader
  9. >>>>>> Pipeline executing starting...
  10. 2022/02/11 12:50:25 - General - Created Apache Beam pipeline with name 'generate-synthetic-data'
  11. 2022/02/11 12:50:26 - General - Handled transform (ROW GENERATOR) : 100M rows
  12. 2022/02/11 12:50:26 - General - Handled generic transform (TRANSFORM) : random data, gets data from 1 previous transform(s), targets=0, infos=0
  13. 2022/02/11 12:50:26 - General - Handled transform (OUTPUT) : generate-synthetic-data, gets data from random data
  14. 2022/02/11 12:50:26 - General - Executing this pipeline using the Beam Pipeline Engine with run configuration 'Flink'
  15. Job has been submitted with JobID 83f34cefa8d061994b7028df2dcebfcd
  16. Program execution finished
  17. Job with JobID 83f34cefa8d061994b7028df2dcebfcd has finished.
  18. Job Runtime: 129625 ms
  19. Accumulator Results:
  20. - __metricscontainers (org.apache.beam.runners.core.metrics.MetricsContainerStepMap): {
  21. "metrics": {
  22. "attempted": [{
  23. "urn": "beam:metric:user:sum_int64:v1",
  24. "type": "beam:metrics:sum_int64:v1",
  25. "payload": "Ag==",
  26. "labels": {
  27. "NAMESPACE": "startBundle",
  28. "NAME": "random data",
  29. "PTRANSFORM": "random data/ParMultiDo(Transform)"
  30. }
  31. }, {
  32. "urn": "beam:metric:user:sum_int64:v1",
  33. "type": "beam:metrics:sum_int64:v1",
  34. "payload": "oI0G",
  35. "labels": {
  36. "NAMESPACE": "read",
  37. "NAME": "random data",
  38. "PTRANSFORM": "random data/ParMultiDo(Transform)"
  39. }
  40. }, {
  41. "urn": "beam:metric:user:sum_int64:v1",
  42. "type": "beam:metrics:sum_int64:v1",
  43. "payload": "Ag==",
  44. "labels": {
  45. "NAMESPACE": "init",
  46. "NAME": "random data",
  47. "PTRANSFORM": "random data/ParMultiDo(Transform)"
  48. }
  49. }, {
  50. "urn": "beam:metric:user:sum_int64:v1",
  51. "type": "beam:metrics:sum_int64:v1",
  52. "payload": "oI0G",
  53. "labels": {
  54. "NAMESPACE": "written",
  55. "NAME": "random data",
  56. "PTRANSFORM": "random data/ParMultiDo(Transform)"
  57. }
  58. }, {
  59. "urn": "beam:metric:user:sum_int64:v1",
  60. "type": "beam:metrics:sum_int64:v1",
  61. "payload": "oI0G",
  62. "labels": {
  63. "NAMESPACE": "output",
  64. "NAME": "generate-synthetic-data",
  65. "PTRANSFORM": "BeamOutputTransform/generate-synthetic-data/ParMultiDo(HopToString)"
  66. }
  67. }, {
  68. "urn": "beam:metric:user:sum_int64:v1",
  69. "type": "beam:metrics:sum_int64:v1",
  70. "payload": "oI0G",
  71. "labels": {
  72. "NAMESPACE": "read",
  73. "NAME": "generate-synthetic-data",
  74. "PTRANSFORM": "BeamOutputTransform/generate-synthetic-data/ParMultiDo(HopToString)"
  75. }
  76. }]
  77. }
  78. }
  79. 2022/02/11 12:52:45 - General - Beam pipeline execution has finished.
  80. >>>>>> Execution finished...

After your pipeline finishes and the flink run command ends, your Flink dashboard will show a new entry in the ‘Completed Job List’. You can follow up any running applications in the ‘Running Job List’ and drill down into their execution details while running.

Apache Hop - Flink runner finished