This is an automated email from the ASF dual-hosted git repository.
vatsrahul1001 pushed a commit to branch v3-4-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v3-4-test by this push:
new a54dad45479 [v3-4-test] Vendor the Java SDK supervisor schema from
this repository (#75942) (#76724)
a54dad45479 is described below
commit a54dad4547952afec914325d168caf295b568ff5
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Fri Nov 27 09:12:16 2026 +0000
[v3-4-test] Vendor the Java SDK supervisor schema from this repository
(#75942) (#76724)
* Vendor the Java SDK supervisor schema from this repository
The vendored copy was refreshed by downloading the version named in
gradle.properties. The remote only publishes released versions, so an
in-progress one cannot be fetched, and a schema change that leaves
api_version alone moved nothing, so the copy went stale unnoticed.
It is now copied from the schema the Python Task SDK owns and compared by
content, the way sync-go-sdk-schemas already does for the Go SDK, so any
change to the source moves it in the same commit. The download stays as the
fallback for a build with no monorepo around it, which is what the source
distribution needs.
The refreshed copy is the content it never received while it was refreshed
by version; api_version is unchanged.
* Separate the Java SDK schema pin from the vendored schema's version
The pin is the supervisor schema version the Java SDK speaks; the vendored
schema.json is a copy of whatever the bundle carries. Requiring the two to
be
equal made the pin follow main every time a supervisor version was cut.
The prek hook now copies the source by content and only checks that the pin
is
a version the bundle defines, and the Gradle task copies the in-repo source
whenever it exists instead of falling back to the download on a version
mismatch, so the build and the hook agree.
* Move the Java SDK to supervisor schema 2027-02-28
* Copy the Task SDK supervisor schema only for the pinned version
* Remove unreachable Gradle download from schema sync hook
* Treat Task SDK schema as always configured in syncSupervisorSchema
* Remove Supervisor Schema download from Java SDK build
* Remove unneeded comments
* Rename schema sync and takenewest version from bundle
* Move Java SDK supervisor schema back to 2026-10-30
* Test schema sync hook exit code and output stream
* Point the schema sync hook at the release for older pins
---------
(cherry picked from commit b4501418ddb6c015676378a0e4455b688eae0318)
Co-authored-by: Jason(Zhe-You) Liu
<[email protected]>
Co-authored-by: Tzu-ping Chung <[email protected]>
---
.pre-commit-config.yaml | 9 +-
java-sdk/DEVELOPMENT.md | 2 +-
java-sdk/sdk/build.gradle.kts | 49 +++----
scripts/ci/prek/sync_java_sdk_supervisor_schema.py | 95 +++++++++----
.../prek/test_sync_java_sdk_supervisor_schema.py | 157 +++++++++++++++++++++
5 files changed, 248 insertions(+), 64 deletions(-)
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index e860b200e97..a9517fe169c 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -365,17 +365,20 @@ repos:
additional_dependencies: ['rich>=13.6.0']
pass_filenames: false
- id: sync-java-sdk-supervisor-schema
- name: Sync Java SDK supervisor schema with configured version
+ name: Sync Java SDK supervisor schema with the distribution that owns
it
env:
PYTHONPYCACHEPREFIX: .build/pycache
- description: "Download the Supervisor Schema when Java SDK's bundled
schema.json drifts"
+ description: "Copy task-sdk's supervisor schema when Java SDK's
vendored schema.json drifts"
entry: ./scripts/ci/prek/sync_java_sdk_supervisor_schema.py
language: python
pass_filenames: false
files: >
(?x)
+ ^task-sdk/src/airflow/sdk/execution_time/schema/schema\.json$|
+
^task-sdk/src/airflow/sdk/execution_time/schema/versions/v\d{4}_\d{2}_\d{2}\.py$|
^java-sdk/gradle\.properties$|
- ^java-sdk/sdk/schema/schema\.json$
+ ^java-sdk/sdk/schema/schema\.json$|
+ ^scripts/ci/prek/sync_java_sdk_supervisor_schema\.py$
- id: regenerate-java-sdk-verification-metadata
name: Regenerate the Java SDK dependency verification metadata
env:
diff --git a/java-sdk/DEVELOPMENT.md b/java-sdk/DEVELOPMENT.md
index 0afccaa8426..f3f54a34fd8 100644
--- a/java-sdk/DEVELOPMENT.md
+++ b/java-sdk/DEVELOPMENT.md
@@ -55,7 +55,7 @@ Gradle only appends to the file, so the script empties the
component list before
Review every entry in the diff. Generating the file records what the
repositories served at that moment; it does not make those bytes trustworthy.
Cross-check new coordinates and checksums against the dependency's official
release information, and never bypass a failure with lenient or disabled
verification.
-Not covered: the `example/`, `scala_spark_example/`, and
`kubernetes-tests/lang_sdk/java_example/` builds, the JDK auto-provisioned by
the foojay resolver, and the Supervisor Schema fetched by
`:sdk:syncSupervisorSchema`.
+Not covered: the `example/`, `scala_spark_example/`, and
`kubernetes-tests/lang_sdk/java_example/` builds, and the JDK auto-provisioned
by the foojay resolver.
## Building documentation
diff --git a/java-sdk/sdk/build.gradle.kts b/java-sdk/sdk/build.gradle.kts
index 41ae85343a1..09d4ed6c692 100644
--- a/java-sdk/sdk/build.gradle.kts
+++ b/java-sdk/sdk/build.gradle.kts
@@ -18,7 +18,6 @@
*/
import java.io.File
-import java.net.URI
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import java.time.Duration
@@ -38,7 +37,6 @@ plugins {
kotlin("plugin.serialization") version "2.4.21"
}
-val schemaBaseUrl = "https://airflow.apache.org/schemas/supervisor-schema"
val schemaInput = layout.projectDirectory.file("schema/schema.json")
val pointersDir = layout.buildDirectory.dir("schema-pointers/main")
val jsonSchemaPackage = "org.apache.airflow.sdk.execution.comm"
@@ -164,12 +162,13 @@ abstract class SyncSupervisorSchemaTask : DefaultTask() {
@get:Input
abstract val schemaVersion: Property<String>
- @get:Input
- abstract val baseUrl: Property<String>
-
@get:Internal
abstract val schemaFile: RegularFileProperty
+ /** The Task SDK schema; missing outside the monorepo. */
+ @get:Internal
+ abstract val sourceFile: RegularFileProperty
+
private fun apiVersionOf(file: File): String =
if (file.exists()) {
com.fasterxml.jackson.databind
@@ -185,32 +184,24 @@ abstract class SyncSupervisorSchemaTask : DefaultTask() {
fun sync() {
val file = schemaFile.get().asFile
val version = schemaVersion.get()
- if (apiVersionOf(file) == version) {
- logger.lifecycle("Supervisor Schema is up-to-date
(api_version=$version).")
+ val source = sourceFile.get().asFile
+ if (apiVersionOf(source) == version) {
+ if (file.exists() &&
file.readBytes().contentEquals(source.readBytes())) {
+ logger.lifecycle("Supervisor Schema is up-to-date
(api_version=$version).")
+ return
+ }
+ logger.lifecycle("Refreshing Supervisor Schema from $source")
+ file.parentFile.mkdirs()
+ Files.copy(source.toPath(), file.toPath(),
StandardCopyOption.REPLACE_EXISTING)
return
}
- val url = "${baseUrl.get()}/$version.json"
- logger.lifecycle("Refreshing Supervisor Schema with $url")
- file.parentFile.mkdirs()
- val tempTarget = Files.createTempFile(file.parentFile.toPath(),
"schema", ".json")
- try {
- val connection =
- URI(url).toURL().openConnection().apply {
- // Timeout values are arbitrary.
- connectTimeout = 30_000
- readTimeout = 30_000
- }
- connection.getInputStream().use { input ->
- Files.copy(input, tempTarget,
StandardCopyOption.REPLACE_EXISTING)
- }
- val downloaded = apiVersionOf(tempTarget.toFile())
- if (downloaded != version) {
- throw GradleException("Schema declares
api_version='$downloaded' but expected '$version' ($url)")
- }
- Files.move(tempTarget, file.toPath(),
StandardCopyOption.REPLACE_EXISTING)
- } finally {
- Files.deleteIfExists(tempTarget)
+ val vendored = apiVersionOf(file)
+ if (vendored != version) {
+ throw GradleException(
+ "${file.name} is api_version='$vendored' but
airflowSupervisorSchemaVersion is '$version'",
+ )
}
+ logger.lifecycle("Supervisor Schema is up-to-date
(api_version=$version).")
}
}
@@ -816,8 +807,8 @@ abstract class GenerateDagDslTask : DefaultTask() {
val syncSupervisorSchema by tasks.registering(SyncSupervisorSchemaTask::class)
{
description = "Ensure the bundled Supervisor Schema is up-to-date with the
Gradle property."
schemaVersion = airflowSupervisorSchemaVersion
- baseUrl = schemaBaseUrl
schemaFile = schemaInput
+ sourceFile =
layout.projectDirectory.file("../../task-sdk/src/airflow/sdk/execution_time/schema/schema.json")
}
tasks.register<GenerateDiscriminatorTask>("generateDiscriminator") {
diff --git a/scripts/ci/prek/sync_java_sdk_supervisor_schema.py
b/scripts/ci/prek/sync_java_sdk_supervisor_schema.py
index d3f4d271a5f..258039f1b5d 100755
--- a/scripts/ci/prek/sync_java_sdk_supervisor_schema.py
+++ b/scripts/ci/prek/sync_java_sdk_supervisor_schema.py
@@ -16,64 +16,97 @@
# specific language governing permissions and limitations
# under the License.
"""
-Keep the Java SDK's bundled Supervisor Schema in sync with
``airflowSupervisorSchemaVersion``.
+Keep the Java SDK's vendored ``schema.json`` at the pinned supervisor schema
version.
-The Gradle task ``:sdk:syncSupervisorSchema`` downloads a fresh
``schema.json`` when the
-``api_version`` inside it differs from the version declared in
``java-sdk/gradle.properties``.
-Starting Gradle for that comparison costs over a minute on a cold CI runner
(wrapper download,
-JVM start, plugin resolution), so this hook does the same comparison in Python
first and only
-hands over to Gradle when the two versions actually differ.
+``airflowSupervisorSchemaVersion`` in ``java-sdk/gradle.properties`` is the
version the Java SDK
+speaks and must be one the Task SDK schema bundle defines. When it is the
bundle's newest version,
+the vendored copy is compared by content with the Task SDK schema and
refreshed from it. When it is
+older, the vendored copy must already declare that version, as copied from the
release that ships it.
+
+Exits 0 when the copy is in sync, 1 when it was refreshed or needs attention.
"""
from __future__ import annotations
import json
import re
-import subprocess
+import shutil
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[3]
-JAVA_SDK_DIR = REPO_ROOT / "java-sdk"
-GRADLE_PROPERTIES = JAVA_SDK_DIR / "gradle.properties"
-SCHEMA_FILE = JAVA_SDK_DIR / "sdk" / "schema" / "schema.json"
+
+GRADLE_PROPERTIES = Path("java-sdk/gradle.properties")
+VENDORED_SCHEMA = Path("java-sdk/sdk/schema/schema.json")
+SOURCE_SCHEMA =
Path("task-sdk/src/airflow/sdk/execution_time/schema/schema.json")
+SCHEMA_VERSIONS =
Path("task-sdk/src/airflow/sdk/execution_time/schema/versions")
VERSION_PATTERN =
re.compile(r"^airflowSupervisorSchemaVersion\s*=\s*(\S+)\s*$", re.MULTILINE)
+VERSION_MODULE_PATTERN = re.compile(r"^v(\d{4})_(\d{2})_(\d{2})\.py$")
-def configured_version() -> str:
- match = VERSION_PATTERN.search(GRADLE_PROPERTIES.read_text())
+def configured_version(repo_root: Path = REPO_ROOT) -> str:
+ properties = repo_root / GRADLE_PROPERTIES
+ match = VERSION_PATTERN.search(properties.read_text())
if not match:
- print(f"airflowSupervisorSchemaVersion is not set in
{GRADLE_PROPERTIES}", file=sys.stderr)
- sys.exit(1)
+ raise SystemExit(f"airflowSupervisorSchemaVersion is not set in
{GRADLE_PROPERTIES}")
return match.group(1)
-def bundled_version() -> str | None:
- if not SCHEMA_FILE.exists():
+def api_version_of(path: Path) -> str | None:
+ if not path.is_file():
return None
try:
- with SCHEMA_FILE.open() as schema:
+ with path.open() as schema:
return json.load(schema).get("api_version")
except json.JSONDecodeError:
- # A truncated or conflict-marked file counts as drift; Gradle
overwrites it.
return None
-def main() -> int:
- expected = configured_version()
- actual = bundled_version()
- if actual == expected:
- print(f"Supervisor Schema is up-to-date (api_version={expected}).")
- return 0
- print(
- f"Supervisor Schema api_version={actual!r} differs from configured
{expected!r}, syncing via Gradle."
- )
- result = subprocess.run(
- [str(JAVA_SDK_DIR / "gradlew"), "-p", str(JAVA_SDK_DIR),
":sdk:syncSupervisorSchema"],
- check=False,
+def known_versions(repo_root: Path = REPO_ROOT) -> list[str]:
+ """The supervisor schema versions the bundle defines, oldest first."""
+ versions = [
+ "-".join(match.groups())
+ for path in (repo_root / SCHEMA_VERSIONS).glob("v*.py")
+ if (match := VERSION_MODULE_PATTERN.match(path.name))
+ ]
+ return sorted(versions)
+
+
+def sync_vendored_schema(expected: str, repo_root: Path = REPO_ROOT) ->
tuple[int, str]:
+ source = repo_root / SOURCE_SCHEMA
+ vendored = repo_root / VENDORED_SCHEMA
+ if expected not in (versions := known_versions(repo_root)):
+ return 1, (
+ f"{GRADLE_PROPERTIES} declares
airflowSupervisorSchemaVersion={expected!r}, which "
+ f"{SCHEMA_VERSIONS} does not define.\n"
+ f"Known versions: {', '.join(versions) or 'none'}."
+ )
+ if expected != (newest := versions[-1]):
+ if (vendored_version := api_version_of(vendored)) == expected:
+ return 0, f"{VENDORED_SCHEMA} is pinned to api_version={expected}
(newest is {newest})."
+ return 1, (
+ f"{VENDORED_SCHEMA} is api_version={vendored_version!r} but
{GRADLE_PROPERTIES} pins {expected!r}.\n"
+ f"Copy {SOURCE_SCHEMA} from the release that ships that version,
or move the pin."
+ )
+ if (source_version := api_version_of(source)) != newest:
+ return 1, (
+ f"{SOURCE_SCHEMA} is api_version={source_version!r} but
{SCHEMA_VERSIONS} defines {newest!r}.\n"
+ "Regenerate the Task SDK schema before syncing the Java SDK copy."
+ )
+ if vendored.is_file() and vendored.read_bytes() == source.read_bytes():
+ return 0, f"{VENDORED_SCHEMA} matches the schema it is vendored from
(api_version={expected})."
+ vendored.parent.mkdir(parents=True, exist_ok=True)
+ shutil.copyfile(source, vendored)
+ return 1, (
+ f"Refreshed {VENDORED_SCHEMA} from {SOURCE_SCHEMA}.\nReview the diff,
then git add it and recommit."
)
- return result.returncode
+
+
+def main(repo_root: Path = REPO_ROOT) -> int:
+ exit_code, report = sync_vendored_schema(configured_version(repo_root),
repo_root)
+ print(report, file=sys.stderr if exit_code else sys.stdout)
+ return exit_code
if __name__ == "__main__":
diff --git a/scripts/tests/ci/prek/test_sync_java_sdk_supervisor_schema.py
b/scripts/tests/ci/prek/test_sync_java_sdk_supervisor_schema.py
new file mode 100644
index 00000000000..4088bf0b4b4
--- /dev/null
+++ b/scripts/tests/ci/prek/test_sync_java_sdk_supervisor_schema.py
@@ -0,0 +1,157 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import json
+
+import pytest
+import sync_java_sdk_supervisor_schema as syncer
+
+VERSION = "2027-02-28"
+
+
+def write_schema(path, api_version=VERSION, **extra):
+ path.parent.mkdir(parents=True, exist_ok=True)
+ path.write_text(json.dumps({"api_version": api_version, **extra}))
+ return path
+
+
[email protected]
+def repo(tmp_path):
+ versions = tmp_path / syncer.SCHEMA_VERSIONS
+ versions.mkdir(parents=True, exist_ok=True)
+ for version in (VERSION, "2026-10-30"):
+ (versions / f"v{version.replace('-', '_')}.py").touch()
+ (tmp_path / syncer.GRADLE_PROPERTIES).parent.mkdir(parents=True,
exist_ok=True)
+ (tmp_path / syncer.GRADLE_PROPERTIES).write_text(
+ f"org.gradle.caching=true\nairflowSupervisorSchemaVersion={VERSION}\n"
+ )
+ write_schema(tmp_path / syncer.SOURCE_SCHEMA, title="supervisor")
+ write_schema(tmp_path / syncer.VENDORED_SCHEMA, title="supervisor")
+ return tmp_path
+
+
+def test_the_declared_version_is_read_from_gradle_properties(repo):
+ assert syncer.configured_version(repo) == VERSION
+
+
+def test_a_gradle_properties_without_the_version_is_an_error(repo):
+ (repo / syncer.GRADLE_PROPERTIES).write_text("org.gradle.caching=true\n")
+
+ with pytest.raises(SystemExit, match="airflowSupervisorSchemaVersion"):
+ syncer.configured_version(repo)
+
+
+def test_a_copy_in_step_is_left_alone(repo):
+ exit_code, report = syncer.sync_vendored_schema(VERSION, repo)
+
+ assert exit_code == 0
+ assert report == (
+ f"java-sdk/sdk/schema/schema.json matches the schema it is vendored
from (api_version={VERSION})."
+ )
+
+
+def
test_a_copy_that_drifted_without_moving_api_version_is_still_refreshed(repo):
+ vendored = write_schema(repo / syncer.VENDORED_SCHEMA, title="stale")
+
+ exit_code, report = syncer.sync_vendored_schema(VERSION, repo)
+
+ assert exit_code == 1
+ assert report == (
+ "Refreshed java-sdk/sdk/schema/schema.json from "
+ "task-sdk/src/airflow/sdk/execution_time/schema/schema.json.\n"
+ "Review the diff, then git add it and recommit."
+ )
+ assert vendored.read_bytes() == (repo / syncer.SOURCE_SCHEMA).read_bytes()
+
+
+def test_a_missing_copy_is_created(repo):
+ (repo / syncer.VENDORED_SCHEMA).unlink()
+
+ exit_code, _ = syncer.sync_vendored_schema(VERSION, repo)
+
+ assert exit_code == 1
+ assert (repo / syncer.VENDORED_SCHEMA).read_bytes() == (repo /
syncer.SOURCE_SCHEMA).read_bytes()
+
+
+def test_an_older_pin_keeps_its_vendored_copy(repo):
+ vendored = write_schema(repo / syncer.VENDORED_SCHEMA,
api_version="2026-10-30", title="released")
+
+ exit_code, report = syncer.sync_vendored_schema("2026-10-30", repo)
+
+ assert exit_code == 0
+ assert report == (
+ f"java-sdk/sdk/schema/schema.json is pinned to api_version=2026-10-30
(newest is {VERSION})."
+ )
+ assert json.loads(vendored.read_text())["title"] == "released"
+
+
+def test_an_older_pin_with_a_different_vendored_version_is_reported(repo):
+ exit_code, report = syncer.sync_vendored_schema("2026-10-30", repo)
+
+ assert exit_code == 1
+ assert report == (
+ f"java-sdk/sdk/schema/schema.json is api_version='{VERSION}' but "
+ "java-sdk/gradle.properties pins '2026-10-30'.\n"
+ "Copy task-sdk/src/airflow/sdk/execution_time/schema/schema.json from
the release that ships "
+ "that version, or move the pin."
+ )
+ assert json.loads((repo / syncer.VENDORED_SCHEMA).read_text())["title"] ==
"supervisor"
+
+
+def test_a_pin_the_bundle_does_not_define_is_reported_not_copied(repo):
+ exit_code, report = syncer.sync_vendored_schema("2025-01-01", repo)
+
+ assert exit_code == 1
+ assert report == (
+ "java-sdk/gradle.properties declares
airflowSupervisorSchemaVersion='2025-01-01', which "
+ "task-sdk/src/airflow/sdk/execution_time/schema/versions does not
define.\n"
+ f"Known versions: 2026-10-30, {VERSION}."
+ )
+ assert json.loads((repo / syncer.VENDORED_SCHEMA).read_text())["title"] ==
"supervisor"
+
+
+def test_an_unreadable_source_for_the_newest_pin_is_reported_not_copied(repo):
+ (repo / syncer.SOURCE_SCHEMA).write_text("<<<<<<< HEAD")
+
+ exit_code, report = syncer.sync_vendored_schema(VERSION, repo)
+
+ assert exit_code == 1
+ assert report == (
+ "task-sdk/src/airflow/sdk/execution_time/schema/schema.json is
api_version=None but "
+ f"task-sdk/src/airflow/sdk/execution_time/schema/versions defines
'{VERSION}'.\n"
+ "Regenerate the Task SDK schema before syncing the Java SDK copy."
+ )
+ assert json.loads((repo / syncer.VENDORED_SCHEMA).read_text())["title"] ==
"supervisor"
+
+
+def test_main_reports_a_copy_in_step_on_stdout(repo, capsys):
+ assert syncer.main(repo) == 0
+
+ out, err = capsys.readouterr()
+ assert out.startswith("java-sdk/sdk/schema/schema.json matches")
+ assert err == ""
+
+
+def test_main_reports_a_refresh_on_stderr(repo, capsys):
+ write_schema(repo / syncer.VENDORED_SCHEMA, title="stale")
+
+ assert syncer.main(repo) == 1
+
+ out, err = capsys.readouterr()
+ assert out == ""
+ assert err.startswith("Refreshed java-sdk/sdk/schema/schema.json")