Cloud Data Fusion中system.profile.name宏设置及Airflow传参
问题解答
1. 通过CloudDataFusionStartPipelineOperator的runtime_args传递Compute Profile名称
你当前的传值写法有误,system.profile.name是Cloud Data Fusion预留的系统级运行时参数,调用Operator触发pipeline时直接传入目标Compute Profile的准确名称字符串即可,不需要添加SYSTEM{}格式的包裹(该格式是CDF内部参数引用格式,不适用于外部API传参)。
正确配置示例:
start_pipeline = CloudDataFusionStartPipelineOperator( task_id="start_pipeline", location="us-central1", pipeline_name="cdf_pipeline", instance_name="cdf_instance", # 替换为你的CDF实例中已创建的Compute Profile实际名称,需*大小写完全匹配* runtime_args={"system.profile.name": "你的目标Compute Profile名称"}, dag=dag )
该传参方式的优先级高于pipeline部署时默认绑定的Compute Profile,不需要修改已部署的pipeline配置即可完成运行时覆盖,要求调用使用的服务账号对传入的Compute Profile有使用权限。
2. 为Compute Profile设置宏
根据是否允许重新部署pipeline,分两种场景处理:
- 不重新部署已上线pipeline的场景:不需要在CDF侧做任何宏配置,直接利用Airflow的Jinja模板能力渲染
runtime_args即可实现动态传参。CloudDataFusionStartPipelineOperator的runtime_args字段原生支持模板渲染,你可以直接引用Airflow变量、上游任务XCom值或者内置宏动态生成Profile名称,示例:
start_pipeline = CloudDataFusionStartPipelineOperator( task_id="start_pipeline", location="us-central1", pipeline_name="cdf_pipeline", instance_name="cdf_instance", runtime_args={ # 示例:从Airflow变量读取目标Profile名称,不存在时使用默认值 "system.profile.name": "{{ var.value.get('target_compute_profile', 'default-basic-profile') }}" }, dag=dag )
该方式效果和CDF侧配置宏完全一致,且不需要改动已部署的pipeline。
- 可重新部署pipeline的场景:如果需要在CDF pipeline侧显式配置宏,打开pipeline编辑页,进入顶部「Configure」>「Compute Config」配置页,在Profile选择下拉框中切换到宏模式,输入自定义宏变量名(例如
${cdp_profile})后保存配置,重新发布pipeline即可。后续Airflow侧传参时,直接在runtime_args中传入自定义宏名作为键即可,不需要再使用system.profile.name系统键,示例:
runtime_args={"cdp_profile": "要切换的目标Compute Profile名称"}
内容的提问来源于stack exchange,提问作者chetan
相关产品推荐
相关产品推荐

