Update DryDock Operator
There is a need to pass workflow-related information in the form
of JSON string to Airflow via the ACTION API call from Shipyard.
In this way, we will be able to keep track/correlate actions
performed via Shipyard as well as to pass in the parameters that
we want Airflow to consume for its workflow.
A sample JSON string that we will pass in via Shipyard using the
Action API call will be similar to the following:
{
"action": {
"id": "1234567890",
"name": "node_filter",
"parameters": {
"servername": "node2,node3"
}
}
}
This patch set is meant to update the DryDock Operator and its
related dags in order to support this implementation
The node_filter information will be passed in via the Shipyard
API call instead
Change-Id: I324959d5f42c98c5fcb1ac44c9677f818bfebbc1
This commit is contained in:
@@ -18,7 +18,6 @@ import configparser
|
||||
from airflow import DAG
|
||||
from airflow.operators import DryDockOperator
|
||||
|
||||
|
||||
def sub_dag(parent_dag_name, child_dag_name, args, schedule_interval):
|
||||
dag = DAG(
|
||||
'%s.%s' % (parent_dag_name, child_dag_name),
|
||||
@@ -41,11 +40,6 @@ def sub_dag(parent_dag_name, child_dag_name, args, schedule_interval):
|
||||
drydock_conf = config.get('drydock', 'site_yaml')
|
||||
promenade_conf = config.get('drydock', 'prom_yaml')
|
||||
|
||||
# Convert to Dictionary
|
||||
k8_masters_sting = config.get('drydock', 'k8_masters')
|
||||
k8_masters_list = k8_masters_sting.split(',')
|
||||
k8_masters = {'node_names': k8_masters_list}
|
||||
|
||||
# Create Drydock Client
|
||||
t1 = DryDockOperator(
|
||||
task_id='create_drydock_client',
|
||||
@@ -92,14 +86,12 @@ def sub_dag(parent_dag_name, child_dag_name, args, schedule_interval):
|
||||
t7 = DryDockOperator(
|
||||
task_id='drydock_prepare_node',
|
||||
action='prepare_node',
|
||||
node_filter=k8_masters,
|
||||
dag=dag)
|
||||
|
||||
# Deploy Node
|
||||
t8 = DryDockOperator(
|
||||
task_id='drydock_deploy_node',
|
||||
action='deploy_node',
|
||||
node_filter=k8_masters,
|
||||
dag=dag)
|
||||
|
||||
# Define dependencies
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
import airflow
|
||||
from airflow import DAG
|
||||
from datetime import timedelta
|
||||
from airflow.operators.python_operator import PythonOperator
|
||||
from airflow.operators.subdag_operator import SubDagOperator
|
||||
from drydock_operator_child import sub_dag
|
||||
|
||||
@@ -40,9 +41,24 @@ main_dag = DAG(
|
||||
max_active_runs=1
|
||||
)
|
||||
|
||||
# Define push function to store the content of 'action' that is
|
||||
# defined via 'dag_run' in XCOM so that it can be used by the
|
||||
# DryDock Operators
|
||||
def push(**kwargs):
|
||||
# Pushes action XCom
|
||||
kwargs['ti'].xcom_push(key='action',
|
||||
value=kwargs['dag_run'].conf['action'])
|
||||
|
||||
|
||||
action_xcom = PythonOperator(
|
||||
task_id='action_xcom', dag=main_dag, python_callable=push)
|
||||
|
||||
subdag = SubDagOperator(
|
||||
subdag=sub_dag(parent_dag_name, child_dag_name, args,
|
||||
main_dag.schedule_interval),
|
||||
task_id=child_dag_name,
|
||||
default_args=args,
|
||||
dag=main_dag)
|
||||
|
||||
# Set dependencies
|
||||
subdag.set_upstream(action_xcom)
|
||||
|
||||
Reference in New Issue
Block a user