使用Gcloud Composer DAG运行Spark作业的困难

问题描述 投票:0回答:1

我正在玩Gcloud Composer,尝试创建一个创建DataProc集群的DAG,运行一个简单的Spark作业,然后拆除集群。我正在尝试运行Spark PI示例作业。

据我所知,在调用DataProcSparkOperator时,我只能选择定义main_jarmain_class属性。当我定义main_class时,作业失败并显示错误:

java.lang.ClassNotFoundException: org.apache.spark.examples.SparkPi
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.apache.spark.util.Utils$.classForName(Utils.scala:239)
    at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:851)
    at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:198)
    at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:228)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:137)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

当我选择定义main_jar属性时,作业失败并显示错误:

Error: No main class set in JAR; please specify one with --class
Run with --help for usage help or --verbose for debug output

我对如何解决这个问题感到有点失落,因为我对Spark和DataProc都不熟悉。

我的一天:

import datetime as dt
from airflow import DAG, models
from airflow.contrib.operators import dataproc_operator as dpo
from airflow.utils import trigger_rule

MAIN_JAR = 'file:///usr/lib/spark/examples/jars/spark-examples.jar'
MAIN_CLASS = 'org.apache.spark.examples.SparkPi'
CLUSTER_NAME = 'quickspark-cluster-{{ ds_nodash }}'

yesterday = dt.datetime.combine(
    dt.datetime.today() - dt.timedelta(1),
    dt.datetime.min.time())

default_dag_args = {
    'start_date': yesterday,
    'email_on_failure': False,
    'email_on_retry': False,
    'retries': 1,
    'retry_delay': dt.timedelta(seconds=30),
    'project_id': models.Variable.get('gcp_project')
}

with DAG('dataproc_spark_submit', schedule_interval='0 17 * * *',
    default_args=default_dag_args) as dag:

    create_dataproc_cluster = dpo.DataprocClusterCreateOperator(
        project_id = default_dag_args['project_id'],
        task_id = 'create_dataproc_cluster',
        cluster_name = CLUSTER_NAME,
        num_workers = 2,
        zone = models.Variable.get('gce_zone')
    )

    run_spark_job = dpo.DataProcSparkOperator(
        task_id = 'run_spark_job',
        #main_jar = MAIN_JAR,
        main_class = MAIN_CLASS,
        cluster_name = CLUSTER_NAME
    )

    delete_dataproc_cluster = dpo.DataprocClusterDeleteOperator(
        project_id = default_dag_args['project_id'],
        task_id = 'delete_dataproc_cluster',
        cluster_name = CLUSTER_NAME,
        trigger_rule = trigger_rule.TriggerRule.ALL_DONE
    )

    create_dataproc_cluster >> run_spark_job >> delete_dataproc_cluster
apache-spark airflow google-cloud-dataproc google-cloud-composer
1个回答
2
投票

我将它与使用CLI的成功作业进行了比较,并发现即使在类填充Main class or jar字段时,jar的路径也在Jar files中指定:

enter image description here

检查操作员我注意到还有一个dataproc_spark_jars parametermain_class不相互排斥:

run_spark_job = dpo.DataProcSparkOperator(
    task_id = 'run_spark_job',
    dataproc_spark_jars = [MAIN_JAR],
    main_class = MAIN_CLASS,
    cluster_name = CLUSTER_NAME
)

添加它就可以了:

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.