nailo2c opened a new pull request, #62391:
URL: https://github.com/apache/airflow/pull/62391
closes: #49796
# Why
This request is from issue #49796. `ec2` and `gce` support these features,
so I think it would be great if Azure Virtual Machines also supported them.
# How
Implemented `hooks`, `operators`, `sensors`, and `triggers` following the
same pattern as the `ec2` provider, with deferrable mode support.
The whole process is shown in sequence diagram below:
```mermaid
sequenceDiagram
participant DAG as DAG
participant StartOp as StartOperator
participant Sensor as StateSensor
participant Trigger as StateTrigger
participant Hook as AzureComputeHook
participant Azure as Azure Compute API
DAG->>StartOp: execute()
StartOp->>Hook: start_instance(resource_group, vm_name)
Hook->>Azure: begin_start(...)
Hook->>Azure: poller.result() (when wait_for_completion=True)
StartOp-->>DAG: success
DAG->>Sensor: execute()
Sensor->>Hook: poke() -> get_power_state()
Hook->>Azure: instance_view(...)
alt state already reached
Sensor-->>DAG: success
else state not reached + deferrable=True
Sensor-->>Trigger: defer(trigger=AzureVirtualMachineStateTrigger)
loop poll until target state
Trigger->>Hook: async_get_power_state() [native async]
Hook->>Azure: instance_view(...)
end
Trigger-->>Sensor: TriggerEvent(status=success)
Sensor-->>DAG: execute_complete()
end
```
# What
### System Test
1. I prepared Azure cloud resources and DAGs from my local Airflow
environment.
<img width="2534" height="724" alt="af_49796_1_before_start"
src="https://github.com/user-attachments/assets/3803c546-662a-47cb-96a3-b8dd17d714d6"
/>
<br>
2. Starting
<img width="2528" height="789" alt="af_49796_2_starting"
src="https://github.com/user-attachments/assets/c8cfbe3c-821a-4e2c-b932-4ac6df968f22"
/>
<br>
3. Running
<img width="2532" height="751" alt="af_49796_3_running"
src="https://github.com/user-attachments/assets/0b8d0c30-a2d7-4650-847f-f01614f51b1e"
/>
<br>
4. Restarting
<img width="2539" height="717" alt="af_49796_4_restarting"
src="https://github.com/user-attachments/assets/ce20243f-c584-40f3-aa35-56b9273c0994"
/>
<br>
5. Deallocating
<img width="2543" height="748" alt="af_49796_5_deallocating"
src="https://github.com/user-attachments/assets/21bcce1f-99a4-4c27-b6ab-ded0864641d1"
/>
<br>
6. Stopped
<img width="2537" height="782" alt="af_49796_6_stopped"
src="https://github.com/user-attachments/assets/1be497f7-1a49-4b45-a4e9-30fcacdd880f"
/>
### Doc
<img width="2509" height="1320" alt="af_49796_7_doc"
src="https://github.com/user-attachments/assets/2fb7fe47-5168-45dc-98d9-610a0f71348f"
/>
---
##### Was generative AI tooling used to co-author this PR?
<!--
If generative AI tooling has been used in the process of authoring this PR,
please
change below checkbox to `[X]` followed by the name of the tool, uncomment
the "Generated-by".
-->
- [x] Yes (please specify the tool below)
Claude ( I've thoroughly reviewed all AI-generated code :) )
<!--
Generated-by: [Tool Name] following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
-->
---
* Read the **[Pull Request
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
for more information. Note: commit author/co-author name and email in commits
become permanently public when merged.
* For fundamental code changes, an Airflow Improvement Proposal
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
is needed.
* When adding dependency, check compliance with the [ASF 3rd Party License
Policy](https://www.apache.org/legal/resolved.html#category-x).
* For significant user-facing changes create newsfragment:
`{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]