@@ -115,7 +115,7 @@ sleep 5
115115
116116server_health () {
117117 # tag::server-health[]
118- curl -s -XGET http://localhost:8080/api/v1 /health
118+ curl -s -XGET http://localhost:8080/api/v2/monitor /health
119119 # end::server-health[]
120120}
121121
130130
131131enable_dag () {
132132 # tag::enable-dag[]
133- curl -s --user airflow:airflow -H ' Content-Type:application/json' \
134- -XPATCH http://localhost:8080/api/v1/dags/example_trigger_target_dag \
135- -d ' {"is_paused": false}'
133+ ACCESS_TOKEN=$(
134+ curl -s -XPOST http://localhost:8080/auth/token \
135+ -H ' Content-Type: application/json' \
136+ -d ' {
137+ "username": "airflow",
138+ "password": "airflow"
139+ }' | jq ' .access_token' | tr -d ' "'
140+ )
141+ curl -s -H " Authorization: Bearer $ACCESS_TOKEN " -H " Content-Type: application/json" \
142+ -XPATCH http://localhost:8080/api/v2/dags/example_trigger_target_dag \
143+ -d ' {"is_paused": false}' | jq ' .is_paused'
136144 # end::enable-dag[]
137145}
138- SLEEP_SECONDS=120
146+ SLEEP_SECONDS=10
139147echo " Sleeping for $SLEEP_SECONDS seconds to wait for the DAG to be registered"
140148sleep " $SLEEP_SECONDS "
141149echo " Triggering a DAG run. Enable DAG..."
142- enable_dag
150+ paused=$( enable_dag)
151+ echo " DAG paused: $paused "
143152
144153run_dag () {
145154 # tag::run-dag[]
146- curl -s --user airflow:airflow -H ' Content-Type:application/json' \
147- -XPOST http://localhost:8080/api/v1/dags/example_trigger_target_dag/dagRuns \
148- -d ' {}' | jq -r ' .dag_run_id'
155+ ACCESS_TOKEN=$(
156+ curl -s -XPOST http://localhost:8080/auth/token \
157+ -H ' Content-Type: application/json' \
158+ -d ' {
159+ "username": "airflow",
160+ "password": "airflow"
161+ }' | jq ' .access_token' | tr -d ' "'
162+ )
163+ curl -s -H " Authorization: Bearer $ACCESS_TOKEN " -H " Content-Type: application/json" \
164+ -XPOST http://localhost:8080/api/v2/dags/example_trigger_target_dag/dagRuns \
165+ -d ' {"logical_date": null,"conf": {"message": "Hello World"}}' | jq -r ' .dag_run_id'
149166 # end::run-dag[]
150167}
151168
152169dag_id=$( run_dag)
153170
154171request_dag_status () {
155172 # tag::check-dag[]
156- curl -s --user airflow:airflow -H ' Content-Type:application/json' \
157- -XGET http://localhost:8080/api/v1/dags/example_trigger_target_dag/dagRuns/" $dag_id " | jq -r ' .state'
173+ ACCESS_TOKEN=$(
174+ curl -s -XPOST http://localhost:8080/auth/token \
175+ -H ' Content-Type: application/json' \
176+ -d ' {
177+ "username": "airflow",
178+ "password": "airflow"
179+ }' | jq ' .access_token' | tr -d ' "'
180+ )
181+ curl -s -H " Authorization: Bearer $ACCESS_TOKEN " -H ' Content-Type:application/json' \
182+ -XGET http://localhost:8080/api/v2/dags/example_trigger_target_dag/dagRuns/" $dag_id " | jq -r ' .state'
158183 # end::check-dag[]
159184}
160185
168193
169194echo " Checking DAG result ..."
170195if [ " $dag_state " == " success" ]; then
171- echo " DAG run successful for ID: " " $dag_id "
196+ echo " DAG run successful for ID: $dag_id "
172197else
173- echo " The DAG was not successful. State: " " $dag_state "
198+ echo " The DAG was not successful. State: $dag_state "
174199 exit 1
175200fi
0 commit comments