From 28e112dfddc8059fa453fa9ce4d2dbaf01226fe9 Mon Sep 17 00:00:00 2001 From: Anthony Lin Date: Mon, 9 Oct 2017 00:43:36 +0000 Subject: [PATCH] Update deckHand_get_design Dag This dag is likely going to be used by Shipyard in actions other than 'deploy_site'. Hence we should not be hard-coding values in the dag as it limits its reusability, e.g. it is likely going to be used in 'update_site' and in 'redeploy_server' as well. Hence there is a need to make use of the values that are passed into the function instead. This P.S. is meant to correct the current behavior. Change-Id: Ia88e91dbb114c34530e3240f120df8c11325090b --- shipyard_airflow/dags/deckhand_get_design.py | 28 +++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/shipyard_airflow/dags/deckhand_get_design.py b/shipyard_airflow/dags/deckhand_get_design.py index c233a2c1..e1a5a08c 100644 --- a/shipyard_airflow/dags/deckhand_get_design.py +++ b/shipyard_airflow/dags/deckhand_get_design.py @@ -20,13 +20,6 @@ from airflow.operators.subdag_operator import SubDagOperator # Location of shiyard.conf config_path = '/usr/local/airflow/plugins/shipyard.conf' -# Define Variables -parent_dag = 'deploy_site' -child_dag = 'deploy_site.deckhand_get_design_version' - -# Names used for sub-subdags in the deckhand subdag -DECKHAND_GET_DESIGN_VERSION_DAG_NAME = 'deckhand_get_design_version' - def get_design_version(parent_dag_name, child_dag_name, args): ''' @@ -36,12 +29,21 @@ def get_design_version(parent_dag_name, child_dag_name, args): '{}.{}'.format(parent_dag_name, child_dag_name), default_args=args) + # Note that in the event where the 'deploy_site' Action is + # triggered from Shipyard, the 'parent_dag_name' variable + # gets assigned with 'deploy_site.deckhand_get_design_version'. + # This is the name that we want to assign to the subdag so + # that we can reference it for xcom. The name of the main + # dag will be the front part of that value, i.e. 'deploy_site'. + # Hence we will extract the front part and assign it to main_dag. + # We will reuse this pattern for other Actions, e.g. update_site, + # redeploy_site as well. operator = DeckhandOperator( - task_id=DECKHAND_GET_DESIGN_VERSION_DAG_NAME, + task_id=child_dag_name, shipyard_conf=config_path, - action=DECKHAND_GET_DESIGN_VERSION_DAG_NAME, - main_dag_name=parent_dag, - sub_dag_name=child_dag, + action=child_dag_name, + main_dag_name=parent_dag_name[0:parent_dag_name.find('.')], + sub_dag_name=parent_dag_name, dag=dag) return dag @@ -57,9 +59,9 @@ def get_design_deckhand(parent_dag_name, child_dag_name, args): deckhand_design = SubDagOperator( subdag=get_design_version(dag.dag_id, - DECKHAND_GET_DESIGN_VERSION_DAG_NAME, + child_dag_name, args), - task_id=DECKHAND_GET_DESIGN_VERSION_DAG_NAME, + task_id=child_dag_name, dag=dag) return dag