Search code examples
pythonapache-sparkbigdataooziehue

Error submitting workflow in HUE | Dependencies Import error


I get an import error when I submit a workflow with Hue, which contains a Spark-Action.

The traceback is below:

2019-01-30 16:31:48,048 [main] INFO  org.apache.spark.deploy.yarn.ApplicationMaster  - Waiting for spark context initialization...

Traceback (most recent call last):
  File "mover.py", line 7, in <module>
    import happybase
ImportError: No module named happybase
2019-01-30 16:31:48,169 [Driver] ERROR org.apache.spark.deploy.yarn.ApplicationMaster  - User application exited with status 1

In my cluster I have a Python virtualenv enviroment with all my dependencies, my cluster was configured using the Cloudera instructions for Spark, here: https://www.cloudera.com/documentation/enterprise/latest/topics/spark_python.html

When I use the spark-submit command in the console, I can run my app without any problems. The problems just appears when I use Hue.

Researching I found this article http://www.learn4master.com/big-data/pyspark/run-pyspark-on-oozie and I tried to do the same thing without success.

My workflow code generated by Hue is:

<workflow-app name="Copy by hour" xmlns="uri:oozie:workflow:0.5">
<start to="spark-c88a"/>
<kill name="Kill">
<message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<action name="spark-c88a" retry-max="1" retry-interval="1">
<spark xmlns="uri:oozie:spark-action:0.2">
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<configuration>
<property>
<name>spark.executorEnv.PYSPARK_PYTHON</name>
<value>/opt/env_cluster/bin/python2</value>
</property>
<property>
<name>spark.yarn.appMasterEnv.PYSPARK_PYTHON</name>
<value>/opt/env_cluster/bin/python2</value>
</property>
</configuration>
<master>yarn</master>
<mode>cluster</mode>
<name>landing_to_daily</name>
<jar>mover.py</jar>
<arg>1</arg>
<arg>-s</arg>
<arg>eir_landing</arg>
<arg>-d</arg>
<arg>eir_daily</arg>
<file>/user/spark/eir/apps/mover.py#mover.py</file>
</spark>
<ok to="End"/>
<error to="email-77d4"/>
</action>
<action name="email-77d4">
<email xmlns="uri:oozie:email-action:0.2">
<to>[email protected]</to>
<subject>Error | Copy by hour</subject>
<body>Error in Workflow landing to daily </body>
<content_type>text/plain</content_type>
</email>
<ok to="Kill"/>
<error to="Kill"/>
</action>
<end name="End"/>
</workflow-app>

Solution

  • With the help of Cloudera Support I was solved this problem in this way:

    1. Add the below to the spark opts:

      --conf spark.yarn.appMasterEnv.PYSPARK_DRIVER_PYTHON=path_to_venv --conf spark.yarn.appMasterEnv.PYSPARK_PYTHON=path_to_venv

    2, The Spark Launcher also needs this environment variable set, so set this as a job property

    <property> 
    <name>oozie.launcher.mapred.child.env</name> 
    <value>PYSPARK_PYTHON=path_to_venv</value> 
    </property>
    
    • Obviously the path_to_venv must be in the same path in all the nodes of the cluster.