Files
airflow/java-sdk/example
Jason(Zhe-You) Liu c5f504366d Java SDK: Trigger another Dag's run from a native Java Dag (#74440)
* Java SDK: Trigger another Dag's run from a native Java Dag

A native Java Dag could not start another Dag's run. Airflow's
TriggerDagRunOperator is Python, and a Java bundle has no Python Dag file to
declare one in, so a Java Dag that fans out to another Dag needed a Python
counterpart for that one task.

A `TriggerDagRun` passed to `dag.task` declares a task that has no Java body
to run; the Java runtime runs it as `TriggerDagRunOperator` does. Its
settings are named as Python names the operator's parameters:

```java
dag.task("trigger_downstream",
    new TriggerDagRun("downstream_etl")
        .config("wait_for_completion", true)
        .config("conf", Map.of("rows", 2)));
```

An annotated Dag declares one from an ordinary `@Builder.Task` method that
returns a `TriggerDagRun`. The serialized Dag has to carry what is
triggered, so that method runs when the Dag is built rather than when the
task runs, and therefore takes no parameters.

The task serializes as Python's own `TriggerDagRunOperator`: its template
fields, its UI colour and extra link, and a `dag_dependencies` entry, so the
Airflow UI draws the dependency between the two Dags. Python writes only an
operator's template fields and keeps the rest in the Dag file; a Java Dag
has no such file, so every setting the author made is written too.

The runtime records the triggered run's link and ID as XComs, skips or fails
on a run that already exists, and waits for completion either by polling or,
with `deferrable`, by deferring to the Python triggerer's DagStateTrigger and
resuming from the event it fires. That makes this the first Java runtime to
emit DeferTask and a skipped TaskState.

`scripts/ci/lang_sdk_serialization/test_dags.yaml` now gives the shared
trigger Dag a real logical date instead of a Jinja template, because the SDK
takes one as a date-time. The Go SDK is making the same change in #74417;
whichever lands second drops that one line, and until then the Go
serialization conformance check reports that single difference.

* Java SDK: Point both example triggers at a Dag that triggers nothing

* Java SDK: Say why a switch cannot choose a task that triggers a Dag run

* Java SDK: Snapshot a TriggerDagRun when its task is declared

* Java SDK: Check a TriggerDagRun setting the way every other config key is checked

* Java SDK: Describe what a trigger task pushes and how it names a run

* Java SDK: Correct which runtimes already run trigger tasks

* Java SDK: Format a trigger task's date-times in one place

* Java SDK: Reject a trigger method that throws a checked exception

* Java SDK: Give the trigger fixture a logical date every SDK can write

* Java SDK: Run a trigger task through runTask in tests

* Java SDK: Check a trigger task polls the run it started
2026-10-09 14:30:53 +08:00
..
…