气流异常:DataFlow失败,返回码为1

时间:2017-09-12 11:56:38

标签: python jar google-cloud-dataflow airflow apache-airflow

我正在尝试通过气流脚本执行数据流jar。为此,我使用DataFlowJavaOperator。在param jar中,我传递了本地系统中存在的可执行jar文件的路径。但是当我尝试运行此作业时,我收到错误

{gcp_dataflow_hook.py:108} INFO - Start waiting for DataFlow process to complete.
[2017-09-12 16:59:38,225] {models.py:1417} ERROR - DataFlow failed with return code 1
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/airflow/models.py", line 1374, in run
    result = task_copy.execute(context=context)
  File "/usr/lib/python2.7/site-packages/airflow/contrib/operators/dataflow_operator.py", line 116, in execute
    hook.start_java_dataflow(self.task_id, dataflow_options, self.jar)
  File "/usr/lib/python2.7/site-packages/airflow/contrib/hooks/gcp_dataflow_hook.py", line 146, in start_java_dataflow
    task_id, variables, dataflow, name, ["java", "-jar"])
  File "/usr/lib/python2.7/site-packages/airflow/contrib/hooks/gcp_dataflow_hook.py", line 138, in _start_dataflow
    _Dataflow(cmd).wait_for_done()
  File "/usr/lib/python2.7/site-packages/airflow/contrib/hooks/gcp_dataflow_hook.py", line 119, in wait_for_done
    self._proc.returncode))
Exception: DataFlow failed with return code 1`

我的气流脚本是:

from airflow.contrib.operators.dataflow_operator import DataFlowJavaOperator
from airflow.contrib.hooks.gcs_hook import GoogleCloudStorageHook
from airflow.models import BaseOperator
from airflow.utils.decorators import apply_defaults
from datetime import datetime, timedelta


default_args = {
'owner': 'airflow',
'start_date': datetime(2017, 03, 16),
'email': [<EmailID>],

'dataflow_default_options': {
        'project': '<ProjectId>',
       # 'zone': 'europe-west1-d', (i am not sure what should i pass here)
        'stagingLocation': 'gs://spark_3/staging/'
    }
 }

 dag = DAG('Dataflow',schedule_interval=timedelta(minutes=2), 
 default_args=default_args)

 dataflow1 = DataFlowJavaOperator(
 task_id='dataflow_example',
 jar ='/root/airflow_scripts/csvwriter.jar',
 gcp_conn_id  = 'GCP_smoke', 
 dag=dag)

我不确定我犯的是什么错误,有人可以帮助我摆脱这个

Note :I am creating this jar while selecting option as Runnable JAR file by packaging all the external dependencies.

1 个答案:

答案 0 :(得分:1)

问题在于我正在使用的罐子。在使用jar之前,请确保jar正在按预期执行。

示例: 如果你的jar是dataflow_job1.jar,请使用

执行jar
java -jar dataflow_job_1.jar --parameters_if_any

一旦你的jar成功运行,继续在Airflow DataflowJavaOperator jar中使用jar。

<强>此外, 如果您遇到与Coders相关的错误,您可能必须让自己的编码器执行代码。 例如,我遇到了TableRow类的问题,因为它没有默认编码器,因此我不得不这样做:

TableRowCoder:

public class TableRowCoder extends Coder<TableRow> {
private static final long serialVersionUID = 1L;
private static final Coder<TableRow> tableRow = TableRowJsonCoder.of();
@Override
public void encode(TableRow value, OutputStream outStream) throws CoderException, IOException {
    tableRow.encode(value, outStream);

}
@Override
public TableRow decode(InputStream inStream) throws CoderException, IOException {
    return new TableRow().set("F1", tableRow.decode(inStream));
}
@Override
public List<? extends Coder<?>> getCoderArguments() {
    // TODO Auto-generated method stub
    return null;
}
@Override
public void verifyDeterministic() throws org.apache.beam.sdk.coders.Coder.NonDeterministicException {


}
}

然后使用

在您的代码中注册此编码器
pipeline.getCoderRegistry().registerCoderForClass(TableRow.class, new TableRowCoder())

如果仍有错误(与编码器无关)导航至:

*.jar\META-INF\services\FileSystemRegistrar 

并添加可能发生的任何依赖项。

例如,可能存在分段错误:

Unable to find registrar for gs

我必须添加以下行才能使其正常工作。

org.apache.beam.sdk.extensions.gcp.storage.GcsFileSystemRegistrar