Skip to content

Commit 0062561

Browse files
committed
updated getting-started script
1 parent cab5774 commit 0062561

File tree

2 files changed

+76
-26
lines changed

2 files changed

+76
-26
lines changed

docs/modules/airflow/examples/getting_started/code/getting_started.sh

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ sleep 5
115115

116116
server_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

@@ -130,31 +130,56 @@ fi
130130

131131
enable_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
139147
echo "Sleeping for $SLEEP_SECONDS seconds to wait for the DAG to be registered"
140148
sleep "$SLEEP_SECONDS"
141149
echo "Triggering a DAG run. Enable DAG..."
142-
enable_dag
150+
paused=$(enable_dag)
151+
echo "DAG paused: $paused"
143152

144153
run_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

152169
dag_id=$(run_dag)
153170

154171
request_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

@@ -168,8 +193,8 @@ done
168193

169194
echo "Checking DAG result ..."
170195
if [ "$dag_state" == "success" ]; then
171-
echo "DAG run successful for ID: " "$dag_id"
196+
echo "DAG run successful for ID: $dag_id"
172197
else
173-
echo "The DAG was not successful. State: " "$dag_state"
198+
echo "The DAG was not successful. State: $dag_state"
174199
exit 1
175200
fi

docs/modules/airflow/examples/getting_started/code/getting_started.sh.j2

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ sleep 5
115115

116116
server_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

@@ -130,31 +130,56 @@ fi
130130

131131
enable_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
139147
echo "Sleeping for $SLEEP_SECONDS seconds to wait for the DAG to be registered"
140148
sleep "$SLEEP_SECONDS"
141149
echo "Triggering a DAG run. Enable DAG..."
142-
enable_dag
150+
paused=$(enable_dag)
151+
echo "DAG paused: $paused"
143152

144153
run_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

152169
dag_id=$(run_dag)
153170

154171
request_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

@@ -168,8 +193,8 @@ done
168193

169194
echo "Checking DAG result ..."
170195
if [ "$dag_state" == "success" ]; then
171-
echo "DAG run successful for ID: " "$dag_id"
196+
echo "DAG run successful for ID: $dag_id"
172197
else
173-
echo "The DAG was not successful. State: " "$dag_state"
198+
echo "The DAG was not successful. State: $dag_state"
174199
exit 1
175200
fi

0 commit comments

Comments
 (0)