Ankur Chauhan Ankur Chauhan - 1 year ago 71
Java Question

Launching dataflow jobs from a java application

I am writing a application that attempts to launch a batch dataflow pipeline based on parameters provides. For this i use

followed by setters to configure options.

But when I create a pipeline object object using
I get the following error:

04:48:08.711 [pool-4-thread-9] ERROR c.g.c.d.s.r.DataflowPipelineRunner - Unable to convert url (jar:file:/ferric.jar!/) to file.
04:48:08.711 [pool-4-thread-9] WARN BatchJobManager - unable to start materialization for view
java.lang.RuntimeException: Failed to construct instance from factory method DataflowPipelineRunner#fromOptions(interface
at com.brightcove.rna.dataflow.MaterializationPipeline.<init>(
at com.brightcove.rna.dataflow.MaterializationPipeline.create(
at com.brightcove.rna.ferric.DataflowJobService.createPipeline(
at javaslang.control.Try.mapTry(
at com.brightcove.rna.ferric.DataflowJobService.create(
at com.brightcove.rna.ferric.BatchJobScheduler.lambda$null$13(
at javaslang.Value.forEach(
at com.brightcove.rna.ferric.BatchJobScheduler.lambda$startMaterializationJobs$14(
at javaslang.control.Try.onSuccess(
at com.brightcove.rna.ferric.BatchJobScheduler.startMaterializationJobs(
at sun.reflect.GeneratedMethodAccessor94.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at java.util.concurrent.Executors$
at java.util.concurrent.FutureTask.runAndReset(
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(
at java.util.concurrent.ScheduledThreadPoolExecutor$
at java.util.concurrent.ThreadPoolExecutor.runWorker(
at java.util.concurrent.ThreadPoolExecutor$
Caused by: java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
... 27 common frames omitted
Caused by: java.lang.IllegalArgumentException: Unable to convert url (jar:file:/ferric.jar!/) to file.
... 32 common frames omitted
Caused by: java.lang.IllegalArgumentException: URI is not hierarchical
... 33 common frames omitted

It seems like the pipeline runner is attempting to determine the path of the jar that contains the classes that it needs to upload. There is only one jar (uberjar) which has all the required classes. And clearly, the path being considered is not correct.

What are the possible workarounds that I can use to launch dataflow jobs programmatically.

Answer Source

The classpath detection and uploading logic is limited to files and doesn't support scenarios where jars are embedded within other jars. Some ways that you could resolve this is:

  1. Flatten the multi-jar jar into one jar containing all the extracted jars. This is good since you keep your one jar property and don't need to write any code to change the pipeline but if you build this regularly, will make your build more complicated. I would look into the Maven shade plugin and bundling to do this for you or an equivalent technology dependent on your build system.
  2. Use a more traditional setup where you specify each individual jar separately. You can use the Maven exec plugin to help with scenarios to build and launch your application.
  3. Extract out all the jars during runtime and set the filesToStage property within PipelineOptions with all the resources you want to have staged.
  4. Add support for embedded jar scenarios to Apache Beam/Dataflow. I filed this tracking issue if you want to take a look at performing this contribution.

There is this very related SO question as well where a user uses their IDE to generate an uberjar for execution and had hit a similar scenario to what your asking about.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download