You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "jerryshao (via GitHub)" <gi...@apache.org> on 2026/08/28 09:05:30 UTC
[PR] [#12676] feat(job): Persist and expose the resolved runtime job template [gravitino]
jerryshao opened a new pull request, #12715:
URL: https://github.com/apache/gravitino/pull/12715
### What changes were proposed in this pull request?
When a job is run, the job template's placeholders are resolved and any referenced files are downloaded before submission to the job executor. This PR captures that *resolved* template (not just the original one) and persists it alongside the job entity as a new `runtimeJobTemplate` field, exposed end-to-end:
- Storage: schema migration + `JobPO` column + MySQL/PostgreSQL/H2 mapper providers
- Core: `JobManager` serializes the resolved template before submission (so a serialization failure never leaves an orphaned job running on the executor without a tracked entity) and `JobInfo` deserializes it for listener events
- REST API: new `runtimeJobTemplate` field on the job response (`docs/open-api/jobs.yaml`)
- Common: `JobDTO`/`DTOConverters` gain a shared `fromRuntimeJobTemplateJson` helper used by both core and server
- Clients: `JobHandle.runtimeJobTemplate()` on Java and Python clients
Also folds in an unrelated black-formatting fix for 3 Python files (`fileset_change.py`, `test_model_catalog.py`, `test_relational_catalog.py`) as a drive-by style fix.
### Why are the changes needed?
Job templates can contain placeholders and template files that get resolved/downloaded at run time. Without this change, callers can only see the original template definition, not what was actually submitted for execution — making it hard to debug or audit a specific job run after the fact.
Fix: #12676
### Does this PR introduce _any_ user-facing change?
Yes:
- New `runtimeJobTemplate` field in the Job REST API response (nullable; omitted for jobs run before this field existed)
- New `JobHandle.runtimeJobTemplate()` accessor on the Java and Python clients
### How was this patch tested?
Added/updated unit tests across storage (PO/mapper/service), core (`JobManager`, `JobInfo`), common (`JobDTO`, `DTOConverters`), server (`JobOperations`), and both Java and Python clients, including full serialization round-trips. Also validated `docs/open-api/jobs.yaml` via `./gradlew :docs:build`.
https://claude.ai/code/session_01NLuzEFs3CmzP5duYonCUue
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12676] feat(job): Persist and expose the resolved runtime job template [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #12715:
URL: https://github.com/apache/gravitino/pull/12715#discussion_r3894003065
##########
common/src/main/java/org/apache/gravitino/dto/util/DTOConverters.java:
##########
@@ -1413,6 +1415,79 @@ public static JobTemplate fromDTO(JobTemplateDTO jobTemplateDTO) {
}
}
+ /**
+ * Converts a JobTemplate to a JobTemplateDTO.
+ *
+ * @param jobTemplate The job template to be converted.
+ * @param audit The audit information to attach to the DTO. A bare {@link JobTemplate} carries no
+ * audit info of its own, so the caller supplies it (e.g. the originating template entity's
+ * audit info, when serializing a resolved runtime template).
+ * @return The job template DTO.
+ */
+ public static JobTemplateDTO toDTO(JobTemplate jobTemplate, AuditDTO audit) {
+ switch (jobTemplate.jobType()) {
+ case SHELL:
+ ShellJobTemplate shellJobTemplate = (ShellJobTemplate) jobTemplate;
+ return ShellJobTemplateDTO.builder()
+ .withName(shellJobTemplate.name())
+ .withComment(shellJobTemplate.comment())
+ .withJobType(shellJobTemplate.jobType())
+ .withExecutable(shellJobTemplate.executable())
+ .withArguments(shellJobTemplate.arguments())
+ .withEnvironments(shellJobTemplate.environments())
+ .withCustomFields(shellJobTemplate.customFields())
+ .withScripts(shellJobTemplate.scripts())
+ .withAudit(audit)
+ .build();
+
+ case SPARK:
+ SparkJobTemplate sparkJobTemplate = (SparkJobTemplate) jobTemplate;
+ return SparkJobTemplateDTO.builder()
+ .withName(sparkJobTemplate.name())
+ .withComment(sparkJobTemplate.comment())
+ .withJobType(sparkJobTemplate.jobType())
+ .withExecutable(sparkJobTemplate.executable())
+ .withArguments(sparkJobTemplate.arguments())
+ .withEnvironments(sparkJobTemplate.environments())
+ .withCustomFields(sparkJobTemplate.customFields())
+ .withClassName(sparkJobTemplate.className())
+ .withJars(sparkJobTemplate.jars())
+ .withFiles(sparkJobTemplate.files())
+ .withArchives(sparkJobTemplate.archives())
+ .withConfigs(sparkJobTemplate.configs())
+ .withAudit(audit)
+ .build();
+
+ default:
+ throw new IllegalArgumentException(
+ "Unsupported job template type: " + jobTemplate.jobType());
+ }
+ }
+
+ /**
+ * Deserializes a job entity's stored runtime job template JSON, if any, back into a {@link
+ * JobTemplateDTO}. {@link JobTemplateDTO}'s {@code @JsonTypeInfo} handles the Shell/Spark
+ * dispatch automatically.
+ *
+ * @param runtimeJobTemplateJson The serialized runtime job template, or null if the job has none.
+ * @param jobName The name of the job the template belongs to, used in the error message on
+ * failure.
+ * @return The deserialized job template DTO, or null if runtimeJobTemplateJson is null.
+ */
+ public static JobTemplateDTO fromRuntimeJobTemplateJson(
+ String runtimeJobTemplateJson, String jobName) {
+ if (runtimeJobTemplateJson == null) {
+ return null;
+ }
+
+ try {
+ return JsonUtils.anyFieldMapper().readValue(runtimeJobTemplateJson, JobTemplateDTO.class);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(
+ String.format("Failed to deserialize the runtime job template for job %s", jobName), e);
Review Comment:
Let me see how to improve this.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12676] feat(job): Persist and expose the resolved runtime job template [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #12715:
URL: https://github.com/apache/gravitino/pull/12715#discussion_r3901832329
##########
clients/client-python/gravitino/dto/job/job_template_dto.py:
##########
@@ -97,17 +97,25 @@ def validate(self) -> None:
raise ValueError('"executable" is required and cannot be empty')
@classmethod
- def from_json(
- cls, s: str, infer_missing: bool = False, **kwargs
+ def from_dict_by_type(
+ cls, data: Dict, infer_missing: bool = False
) -> "JobTemplateDTO":
- """Creates a JobTemplateDTO from a JSON string."""
- data = json.loads(s)
+ """Creates a JobTemplateDTO from a dict, dispatching to the concrete subclass based
+ on the "jobType" field.
+ """
job_type = JobType.job_type_deserialize(data.get("jobType"))
subclass = JOB_TYPE_TEMPLATE_MAPPING.get(job_type)
if not subclass:
raise ValueError(f"Unsupported job type: {job_type}")
return subclass.from_dict(data, infer_missing=infer_missing)
+ @classmethod
+ def from_json(
+ cls, s: str, infer_missing: bool = False, **kwargs
+ ) -> "JobTemplateDTO":
+ """Creates a JobTemplateDTO from a JSON string."""
+ return cls.from_dict_by_type(json.loads(s), infer_missing=infer_missing)
Review Comment:
Fixed — now forwards `**kwargs` to `json.loads(...)` instead of dropping it, matching the base `DataClassJsonMixin.from_json` contract. (Removing the parameter outright trips pylint's `arguments-differ` check against the base class.)
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12676] feat(job): Persist and expose the resolved runtime job template [gravitino]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #12715:
URL: https://github.com/apache/gravitino/pull/12715#issuecomment-5451944554
<!-- coverage-report -->
### Code Coverage Report
|Overall Project|68.5% **`+0.1%`**|:green_circle:|
|:-|:-|:-:|
|Files changed|72.66%|:green_circle:|
<br>
|Module|Coverage||
|:-|:-|:-:|
|aliyun|19.74%|:red_circle:|
|api|52.05% **`-0.15%`**|:green_circle:|
|authorization-common|85.96%|:green_circle:|
|authorization-ranger|4.38%|:red_circle:|
|aws|53.54%|:green_circle:|
|azure|32.1%|:red_circle:|
|catalog-common|9.9%|:red_circle:|
|catalog-fileset|80.21%|:green_circle:|
|catalog-glue|69.24%|:green_circle:|
|catalog-hive|82.96%|:green_circle:|
|catalog-jdbc-common|45.69%|:green_circle:|
|catalog-jdbc-doris|82.44%|:green_circle:|
|catalog-jdbc-mysql|79.33%|:green_circle:|
|catalog-jdbc-postgresql|83.39%|:green_circle:|
|catalog-jdbc-starrocks|79.16%|:green_circle:|
|catalog-kafka|76.99%|:green_circle:|
|catalog-lakehouse-generic|60.55%|:green_circle:|
|catalog-lakehouse-hudi|79.1%|:green_circle:|
|catalog-lakehouse-iceberg|85.93%|:green_circle:|
|catalog-lakehouse-paimon|84.26%|:green_circle:|
|catalog-model|77.99%|:green_circle:|
|cli|44.48%|:green_circle:|
|client-java|77.45% **`+0.07%`**|:green_circle:|
|common|56.2% **`-1.63%`**|:green_circle:|
|core|83.55% **`+0.12%`**|:green_circle:|
|filesystem-hadoop3|76.45%|:green_circle:|
|flink|0.0%|:red_circle:|
|flink-common|50.29%|:green_circle:|
|flink-runtime|0.0%|:red_circle:|
|gcp|32.2%|:red_circle:|
|hadoop-auth|68.0%|:green_circle:|
|hadoop-common|17.84%|:red_circle:|
|hive-metastore-common|53.4%|:green_circle:|
|iceberg-aliyun-bundle|0.0%|:red_circle:|
|iceberg-common|64.75%|:green_circle:|
|iceberg-rest-server|75.61%|:green_circle:|
|idp-basic|85.98%|:green_circle:|
|integration-test-common|0.0%|:red_circle:|
|jobs|62.92%|:green_circle:|
|lance-common|32.63%|:red_circle:|
|lance-rest-server|63.87%|:green_circle:|
|lineage|53.02%|:green_circle:|
|optimizer|83.24%|:green_circle:|
|optimizer-api|21.95%|:red_circle:|
|server|88.05% **`+0.38%`**|:green_circle:|
|server-common|80.5%|:green_circle:|
|spark|28.57%|:red_circle:|
|spark-common|48.92%|:green_circle:|
|tencent|69.84%|:green_circle:|
|trino-connector|47.44%|:green_circle:|
<details>
<summary>Files</summary>
|Module|File|Coverage||
|:-|:-|:-|:-:|
|api|[JobHandle.java](https://github.com/jerryshao/gravitino/blob/4b01bebd33cd57821b4a5eb24a46a390af64018b/api/src/main/java/org/apache/gravitino/job/JobHandle.java)|0.0%|:red_circle:|
|client-java|[GenericJobHandle.java](https://github.com/jerryshao/gravitino/blob/4b01bebd33cd57821b4a5eb24a46a390af64018b/clients/client-java/src/main/java/org/apache/gravitino/client/GenericJobHandle.java)|100.0%|:green_circle:|
|common|[JobDTO.java](https://github.com/jerryshao/gravitino/blob/4b01bebd33cd57821b4a5eb24a46a390af64018b/common/src/main/java/org/apache/gravitino/dto/job/JobDTO.java)|90.0%|:green_circle:|
||[DTOConverters.java](https://github.com/jerryshao/gravitino/blob/4b01bebd33cd57821b4a5eb24a46a390af64018b/common/src/main/java/org/apache/gravitino/dto/util/DTOConverters.java)|35.51%|:red_circle:|
|core|[JobMetaBaseSQLProvider.java](https://github.com/jerryshao/gravitino/blob/4b01bebd33cd57821b4a5eb24a46a390af64018b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/JobMetaBaseSQLProvider.java)|100.0%|:green_circle:|
||[JobMetaPostgreSQLProvider.java](https://github.com/jerryshao/gravitino/blob/4b01bebd33cd57821b4a5eb24a46a390af64018b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/JobMetaPostgreSQLProvider.java)|100.0%|:green_circle:|
||[JobEntity.java](https://github.com/jerryshao/gravitino/blob/4b01bebd33cd57821b4a5eb24a46a390af64018b/core/src/main/java/org/apache/gravitino/meta/JobEntity.java)|97.47%|:green_circle:|
||[JobInfo.java](https://github.com/jerryshao/gravitino/blob/4b01bebd33cd57821b4a5eb24a46a390af64018b/core/src/main/java/org/apache/gravitino/listener/api/info/JobInfo.java)|96.43%|:green_circle:|
||[JobMetaSQLProviderFactory.java](https://github.com/jerryshao/gravitino/blob/4b01bebd33cd57821b4a5eb24a46a390af64018b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/JobMetaSQLProviderFactory.java)|95.65%|:green_circle:|
||[JobMetaService.java](https://github.com/jerryshao/gravitino/blob/4b01bebd33cd57821b4a5eb24a46a390af64018b/core/src/main/java/org/apache/gravitino/storage/relational/service/JobMetaService.java)|92.59%|:green_circle:|
||[JobManager.java](https://github.com/jerryshao/gravitino/blob/4b01bebd33cd57821b4a5eb24a46a390af64018b/core/src/main/java/org/apache/gravitino/job/JobManager.java)|86.35%|:green_circle:|
||[JDBCBackend.java](https://github.com/jerryshao/gravitino/blob/4b01bebd33cd57821b4a5eb24a46a390af64018b/core/src/main/java/org/apache/gravitino/storage/relational/JDBCBackend.java)|83.61%|:green_circle:|
||[JobPO.java](https://github.com/jerryshao/gravitino/blob/4b01bebd33cd57821b4a5eb24a46a390af64018b/core/src/main/java/org/apache/gravitino/storage/relational/po/JobPO.java)|79.45%|:green_circle:|
||[JobMetaMapper.java](https://github.com/jerryshao/gravitino/blob/4b01bebd33cd57821b4a5eb24a46a390af64018b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/JobMetaMapper.java)|0.0%|:red_circle:|
|server|[JobOperations.java](https://github.com/jerryshao/gravitino/blob/4b01bebd33cd57821b4a5eb24a46a390af64018b/server/src/main/java/org/apache/gravitino/server/web/rest/JobOperations.java)|93.58%|:green_circle:|
</details>
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12676] feat(job): Persist and expose the resolved runtime job template [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #12715:
URL: https://github.com/apache/gravitino/pull/12715#discussion_r3893999902
##########
docs/open-api/jobs.yaml:
##########
@@ -1005,7 +1009,23 @@ components:
},
"queuedAt": "2025-08-12T02:14:28.205023Z",
"startedAt": "2025-08-12T02:14:31.098231Z",
- "finishedAt": "2025-08-12T02:15:03.512847Z"
+ "finishedAt": "2025-08-12T02:15:03.512847Z",
+ "runtimeJobTemplate": {
+ "name": "test_run_get",
+ "jobType": "shell",
+ "comment": "Test shell job template",
+ "executable": "/var/folders/90/v1d9hxsd6pj8m0jnn6f22tkr0000gn/T/tmpy65fiugc/test-job.sh",
Review Comment:
ok, sure.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12676] feat(job): Persist and expose the resolved runtime job template [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #12715:
URL: https://github.com/apache/gravitino/pull/12715#discussion_r3901830571
##########
common/src/main/java/org/apache/gravitino/dto/util/DTOConverters.java:
##########
@@ -1413,6 +1415,82 @@ public static JobTemplate fromDTO(JobTemplateDTO jobTemplateDTO) {
}
}
+ /**
+ * Converts a JobTemplate to a JobTemplateDTO.
+ *
+ * @param jobTemplate The job template to be converted.
+ * @param audit The audit information to attach to the DTO. A bare {@link JobTemplate} carries no
+ * audit info of its own, so the caller supplies it (e.g. the originating template entity's
+ * audit info, when serializing a resolved runtime template).
+ * @return The job template DTO.
+ */
+ public static JobTemplateDTO toDTO(JobTemplate jobTemplate, AuditDTO audit) {
+ switch (jobTemplate.jobType()) {
+ case SHELL:
+ ShellJobTemplate shellJobTemplate = (ShellJobTemplate) jobTemplate;
+ return ShellJobTemplateDTO.builder()
+ .withName(shellJobTemplate.name())
+ .withComment(shellJobTemplate.comment())
+ .withJobType(shellJobTemplate.jobType())
+ .withExecutable(shellJobTemplate.executable())
+ .withArguments(shellJobTemplate.arguments())
+ .withEnvironments(shellJobTemplate.environments())
+ .withCustomFields(shellJobTemplate.customFields())
+ .withScripts(shellJobTemplate.scripts())
+ .withAudit(audit)
+ .build();
+
+ case SPARK:
+ SparkJobTemplate sparkJobTemplate = (SparkJobTemplate) jobTemplate;
+ return SparkJobTemplateDTO.builder()
+ .withName(sparkJobTemplate.name())
+ .withComment(sparkJobTemplate.comment())
+ .withJobType(sparkJobTemplate.jobType())
+ .withExecutable(sparkJobTemplate.executable())
+ .withArguments(sparkJobTemplate.arguments())
+ .withEnvironments(sparkJobTemplate.environments())
+ .withCustomFields(sparkJobTemplate.customFields())
+ .withClassName(sparkJobTemplate.className())
+ .withJars(sparkJobTemplate.jars())
+ .withFiles(sparkJobTemplate.files())
+ .withArchives(sparkJobTemplate.archives())
+ .withConfigs(sparkJobTemplate.configs())
+ .withAudit(audit)
+ .build();
+
+ default:
+ throw new IllegalArgumentException(
+ "Unsupported job template type: " + jobTemplate.jobType());
+ }
+ }
+
+ /**
+ * Deserializes a job entity's stored runtime job template JSON, if any, back into a {@link
+ * JobTemplateDTO}. {@link JobTemplateDTO}'s {@code @JsonTypeInfo} handles the Shell/Spark
+ * dispatch automatically.
+ *
+ * @param runtimeJobTemplateJson The serialized runtime job template, or null if the job has none.
+ * @param jobName The name of the job the template belongs to, used in the error message on
+ * failure.
+ * @return The deserialized job template DTO, or null if runtimeJobTemplateJson is null.
+ */
+ public static JobTemplateDTO fromRuntimeJobTemplateJson(
+ String runtimeJobTemplateJson, String jobName) {
+ if (runtimeJobTemplateJson == null) {
+ return null;
+ }
+
+ try {
+ return JsonUtils.anyFieldMapper().readValue(runtimeJobTemplateJson, JobTemplateDTO.class);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(
+ String.format(
+ "Failed to deserialize the runtime job template for job %s, raw content: %s",
+ jobName, runtimeJobTemplateJson),
+ e);
+ }
+ }
Review Comment:
Fixed — the message now includes the job name and content length instead of the raw JSON, avoiding both the sensitive-data leak and the log-injection risk.
##########
docs/open-api/jobs.yaml:
##########
@@ -586,6 +586,10 @@ components:
format: date-time
nullable: true
description: The time when the job finished execution, or null if the job has not finished execution yet
+ runtimeJobTemplate:
+ description: The resolved job template that was actually submitted for execution, with placeholders replaced and referenced files downloaded. Omitted for jobs run before this field was introduced
+ allOf:
+ - $ref: "#/components/schemas/JobTemplate"
Review Comment:
Fixed — added `nullable: true`. Redocly's linter rejected `nullable` on a bare `allOf`+`$ref` with no co-located `type` ("nullable cannot be used without type"), so added `type: object` alongside it too. Re-validated with `./gradlew :docs:build`.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12676] feat(job): Persist and expose the resolved runtime job template [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #12715:
URL: https://github.com/apache/gravitino/pull/12715#issuecomment-5490563034
Thanks for the thorough review! Addressed #1 and #2:
1. `JobInfo.fromJobEntity` (`toRuntimeJobTemplate`) now catches and logs instead of throwing, so a malformed/forward-incompatible stored template no longer turns an already-successful `getJob`/`runJob`/`cancelJob` into a 500. Added `TestJobInfo.testFromJobEntityWithMalformedRuntimeJobTemplateDoesNotThrow`.
2. Moved the guard into `JobOperations.toDTO()` itself (wrapping only the runtime-template deserialization step), so it now covers `get`/`run`/`cancel`/`list` uniformly instead of just `listJobs`. Added `TestJobOperations.testCancelJobWithMalformedRuntimeJobTemplateDoesNotFail`.
On #3 (resolved `jobConf` values, including any secrets a caller substituted via placeholders, now being persisted/returned) - agreed this is real, but it's a design question (redaction? explicit opt-in? docs warning?) rather than a bug fix, so I'd like to handle it separately rather than block this PR on it. Will follow up in a dedicated issue.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12676] feat(job): Persist and expose the resolved runtime job template [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #12715:
URL: https://github.com/apache/gravitino/pull/12715#issuecomment-5494374921
@yuqi1129 @mchades can you please review this PR again?
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12676] feat(job): Persist and expose the resolved runtime job template [gravitino]
Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades merged PR #12715:
URL: https://github.com/apache/gravitino/pull/12715
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12676] feat(job): Persist and expose the resolved runtime job template [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #12715:
URL: https://github.com/apache/gravitino/pull/12715#issuecomment-5478420313
Reviewed the full diff. The storage/mapper/PO plumbing looks complete and consistent: all four `JobEntity.builder()` sites carry the new field, all six job SELECTs plus both inserts and the update were changed, column counts match, and the nullable TEXT column follows existing precedent.
Three things I think are worth addressing before merge:
**1. `JobInfo.fromJobEntity` can now throw, and it is called inside the dispatcher's try blocks** — `core/src/main/java/org/apache/gravitino/listener/api/info/JobInfo.java:90`
`toRuntimeJobTemplate` makes a previously total function partial: `fromRuntimeJobTemplateJson` throws `RuntimeException` on malformed JSON, Jackson throws `InvalidTypeIdException` on an unknown `jobType`, and `DTOConverters.fromDTO` throws `IllegalArgumentException` on an unsupported type (or builds a template that trips its own `Preconditions` when a required field is missing).
`JobEventDispatcher` calls `JobInfo.fromJobEntity(job)` *inside* the try block of `getJob` (line 212), `runJob` (236) and `cancelJob` (255), so one such row fails the whole operation with a 500 and dispatches a failure event. `cancelJob` is the worst case: `jobExecutor.cancelJob()` has already succeeded and the entity has already been updated to `CANCELLING` by the time the event is built, so the caller gets an error for an operation that did happen.
Concrete scenario: a metalake is written by a newer server that supports a third job type and then rolled back — every `getJob`/`cancelJob` on those rows 500s. Suggest catching and logging inside `toRuntimeJobTemplate` and returning `null`, matching the defensive stance this PR already takes in `toJobDTOs`.
**2. The tolerance for a bad stored template was only added to the list path** — `server/src/main/java/org/apache/gravitino/server/web/rest/JobOperations.java:514`
`toDTO(JobEntity)` is still called unguarded at lines 378, 418 and 444 (get / run / cancel job). The same corrupt or forward-incompatible `runtime_job_template` value that `listJobs` now survives makes those three endpoints return 500 permanently, i.e. the job becomes both unreadable and uncancellable through the API. Either guard inside `toDTO` itself, or apply the same fallback at the three single-job call sites.
**3. Resolved `jobConf` values are now persisted and returned** — `core/src/main/java/org/apache/gravitino/job/JobManager.java:454`
`createRuntimeJobTemplate` substitutes caller-supplied `jobConf` values into `arguments`, `environments`, `customFields` and (for Spark) `configs`. Those *resolved* values now land in `job_run_meta.runtime_job_template` and are returned by `GET /jobs/{id}` and `GET /jobs`. Previously `jobConf` was transient and only the template with `{{placeholder}}` markers was stored.
Any deployment that passes a token, password or connection string as a job parameter — a normal use of placeholders — will now write that secret to the metadata store in cleartext and hand it back to every principal who can read the job. This is a silent behavior change for existing templates, so it probably needs at least a redaction hook, or an explicit note in the docs and release notes.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12676] feat(job): Persist and expose the resolved runtime job template [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #12715:
URL: https://github.com/apache/gravitino/pull/12715#discussion_r3892338050
##########
docs/open-api/jobs.yaml:
##########
@@ -1005,7 +1009,23 @@ components:
},
"queuedAt": "2025-08-12T02:14:28.205023Z",
"startedAt": "2025-08-12T02:14:31.098231Z",
- "finishedAt": "2025-08-12T02:15:03.512847Z"
+ "finishedAt": "2025-08-12T02:15:03.512847Z",
+ "runtimeJobTemplate": {
+ "name": "test_run_get",
+ "jobType": "shell",
+ "comment": "Test shell job template",
+ "executable": "/var/folders/90/v1d9hxsd6pj8m0jnn6f22tkr0000gn/T/tmpy65fiugc/test-job.sh",
Review Comment:
This should be a real path on your Mac; it's better to replace with a format like `/tmp/gravitino-job-staging/<job-id>/test-job.sh`.
##########
common/src/main/java/org/apache/gravitino/dto/util/DTOConverters.java:
##########
@@ -1413,6 +1415,79 @@ public static JobTemplate fromDTO(JobTemplateDTO jobTemplateDTO) {
}
}
+ /**
+ * Converts a JobTemplate to a JobTemplateDTO.
+ *
+ * @param jobTemplate The job template to be converted.
+ * @param audit The audit information to attach to the DTO. A bare {@link JobTemplate} carries no
+ * audit info of its own, so the caller supplies it (e.g. the originating template entity's
+ * audit info, when serializing a resolved runtime template).
+ * @return The job template DTO.
+ */
+ public static JobTemplateDTO toDTO(JobTemplate jobTemplate, AuditDTO audit) {
+ switch (jobTemplate.jobType()) {
+ case SHELL:
+ ShellJobTemplate shellJobTemplate = (ShellJobTemplate) jobTemplate;
+ return ShellJobTemplateDTO.builder()
+ .withName(shellJobTemplate.name())
+ .withComment(shellJobTemplate.comment())
+ .withJobType(shellJobTemplate.jobType())
+ .withExecutable(shellJobTemplate.executable())
+ .withArguments(shellJobTemplate.arguments())
+ .withEnvironments(shellJobTemplate.environments())
+ .withCustomFields(shellJobTemplate.customFields())
+ .withScripts(shellJobTemplate.scripts())
+ .withAudit(audit)
+ .build();
+
+ case SPARK:
+ SparkJobTemplate sparkJobTemplate = (SparkJobTemplate) jobTemplate;
+ return SparkJobTemplateDTO.builder()
+ .withName(sparkJobTemplate.name())
+ .withComment(sparkJobTemplate.comment())
+ .withJobType(sparkJobTemplate.jobType())
+ .withExecutable(sparkJobTemplate.executable())
+ .withArguments(sparkJobTemplate.arguments())
+ .withEnvironments(sparkJobTemplate.environments())
+ .withCustomFields(sparkJobTemplate.customFields())
+ .withClassName(sparkJobTemplate.className())
+ .withJars(sparkJobTemplate.jars())
+ .withFiles(sparkJobTemplate.files())
+ .withArchives(sparkJobTemplate.archives())
+ .withConfigs(sparkJobTemplate.configs())
+ .withAudit(audit)
+ .build();
+
+ default:
+ throw new IllegalArgumentException(
+ "Unsupported job template type: " + jobTemplate.jobType());
+ }
+ }
+
+ /**
+ * Deserializes a job entity's stored runtime job template JSON, if any, back into a {@link
+ * JobTemplateDTO}. {@link JobTemplateDTO}'s {@code @JsonTypeInfo} handles the Shell/Spark
+ * dispatch automatically.
+ *
+ * @param runtimeJobTemplateJson The serialized runtime job template, or null if the job has none.
+ * @param jobName The name of the job the template belongs to, used in the error message on
+ * failure.
+ * @return The deserialized job template DTO, or null if runtimeJobTemplateJson is null.
+ */
+ public static JobTemplateDTO fromRuntimeJobTemplateJson(
+ String runtimeJobTemplateJson, String jobName) {
+ if (runtimeJobTemplateJson == null) {
+ return null;
+ }
+
+ try {
+ return JsonUtils.anyFieldMapper().readValue(runtimeJobTemplateJson, JobTemplateDTO.class);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(
+ String.format("Failed to deserialize the runtime job template for job %s", jobName), e);
Review Comment:
This method is called by `listJobs` and will stop if any of them are wrong. Another thing is that the log only logs the failed job name, no details of `runtimeJobTemplateJson`, which will make it hard to debug the problem.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12676] feat(job): Persist and expose the resolved runtime job template [gravitino]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #12715:
URL: https://github.com/apache/gravitino/pull/12715#discussion_r3894476113
##########
docs/open-api/jobs.yaml:
##########
@@ -586,6 +586,10 @@ components:
format: date-time
nullable: true
description: The time when the job finished execution, or null if the job has not finished execution yet
+ runtimeJobTemplate:
+ description: The resolved job template that was actually submitted for execution, with placeholders replaced and referenced files downloaded. Omitted for jobs run before this field was introduced
+ allOf:
+ - $ref: "#/components/schemas/JobTemplate"
Review Comment:
The API description states this field can be omitted for older jobs, but the server-side behavior/tests also indicate it may be present as `null` (e.g., malformed stored JSON or missing historical data). To match actual responses, mark `runtimeJobTemplate` as `nullable: true` (and keep it non-required). Optionally replace `allOf` with a direct `$ref` unless you plan to extend it with additional constraints.
##########
clients/client-python/gravitino/dto/job/job_template_dto.py:
##########
@@ -97,17 +97,25 @@ def validate(self) -> None:
raise ValueError('"executable" is required and cannot be empty')
@classmethod
- def from_json(
- cls, s: str, infer_missing: bool = False, **kwargs
+ def from_dict_by_type(
+ cls, data: Dict, infer_missing: bool = False
) -> "JobTemplateDTO":
- """Creates a JobTemplateDTO from a JSON string."""
- data = json.loads(s)
+ """Creates a JobTemplateDTO from a dict, dispatching to the concrete subclass based
+ on the "jobType" field.
+ """
job_type = JobType.job_type_deserialize(data.get("jobType"))
subclass = JOB_TYPE_TEMPLATE_MAPPING.get(job_type)
if not subclass:
raise ValueError(f"Unsupported job type: {job_type}")
return subclass.from_dict(data, infer_missing=infer_missing)
+ @classmethod
+ def from_json(
+ cls, s: str, infer_missing: bool = False, **kwargs
+ ) -> "JobTemplateDTO":
+ """Creates a JobTemplateDTO from a JSON string."""
+ return cls.from_dict_by_type(json.loads(s), infer_missing=infer_missing)
Review Comment:
`from_json(..., **kwargs)` now silently ignores `**kwargs`, which can be confusing for callers and makes future changes harder (it looks like kwargs are supported but they aren’t). Consider either removing `**kwargs` from the signature, or explicitly documenting that kwargs are ignored; if backward compatibility requires keeping it, pass through supported options where applicable.
##########
common/src/main/java/org/apache/gravitino/dto/util/DTOConverters.java:
##########
@@ -1413,6 +1415,82 @@ public static JobTemplate fromDTO(JobTemplateDTO jobTemplateDTO) {
}
}
+ /**
+ * Converts a JobTemplate to a JobTemplateDTO.
+ *
+ * @param jobTemplate The job template to be converted.
+ * @param audit The audit information to attach to the DTO. A bare {@link JobTemplate} carries no
+ * audit info of its own, so the caller supplies it (e.g. the originating template entity's
+ * audit info, when serializing a resolved runtime template).
+ * @return The job template DTO.
+ */
+ public static JobTemplateDTO toDTO(JobTemplate jobTemplate, AuditDTO audit) {
+ switch (jobTemplate.jobType()) {
+ case SHELL:
+ ShellJobTemplate shellJobTemplate = (ShellJobTemplate) jobTemplate;
+ return ShellJobTemplateDTO.builder()
+ .withName(shellJobTemplate.name())
+ .withComment(shellJobTemplate.comment())
+ .withJobType(shellJobTemplate.jobType())
+ .withExecutable(shellJobTemplate.executable())
+ .withArguments(shellJobTemplate.arguments())
+ .withEnvironments(shellJobTemplate.environments())
+ .withCustomFields(shellJobTemplate.customFields())
+ .withScripts(shellJobTemplate.scripts())
+ .withAudit(audit)
+ .build();
+
+ case SPARK:
+ SparkJobTemplate sparkJobTemplate = (SparkJobTemplate) jobTemplate;
+ return SparkJobTemplateDTO.builder()
+ .withName(sparkJobTemplate.name())
+ .withComment(sparkJobTemplate.comment())
+ .withJobType(sparkJobTemplate.jobType())
+ .withExecutable(sparkJobTemplate.executable())
+ .withArguments(sparkJobTemplate.arguments())
+ .withEnvironments(sparkJobTemplate.environments())
+ .withCustomFields(sparkJobTemplate.customFields())
+ .withClassName(sparkJobTemplate.className())
+ .withJars(sparkJobTemplate.jars())
+ .withFiles(sparkJobTemplate.files())
+ .withArchives(sparkJobTemplate.archives())
+ .withConfigs(sparkJobTemplate.configs())
+ .withAudit(audit)
+ .build();
+
+ default:
+ throw new IllegalArgumentException(
+ "Unsupported job template type: " + jobTemplate.jobType());
+ }
+ }
+
+ /**
+ * Deserializes a job entity's stored runtime job template JSON, if any, back into a {@link
+ * JobTemplateDTO}. {@link JobTemplateDTO}'s {@code @JsonTypeInfo} handles the Shell/Spark
+ * dispatch automatically.
+ *
+ * @param runtimeJobTemplateJson The serialized runtime job template, or null if the job has none.
+ * @param jobName The name of the job the template belongs to, used in the error message on
+ * failure.
+ * @return The deserialized job template DTO, or null if runtimeJobTemplateJson is null.
+ */
+ public static JobTemplateDTO fromRuntimeJobTemplateJson(
+ String runtimeJobTemplateJson, String jobName) {
+ if (runtimeJobTemplateJson == null) {
+ return null;
+ }
+
+ try {
+ return JsonUtils.anyFieldMapper().readValue(runtimeJobTemplateJson, JobTemplateDTO.class);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(
+ String.format(
+ "Failed to deserialize the runtime job template for job %s, raw content: %s",
+ jobName, runtimeJobTemplateJson),
+ e);
+ }
+ }
Review Comment:
The exception message includes the full raw runtime template JSON, which can contain sensitive data (e.g., environment variables, custom fields, local paths) and can also introduce log-injection risk if logged (newlines/control chars). Prefer not embedding full raw content in exception messages; instead include safe metadata (job id, content length, a hash, and/or a truncated/sanitized prefix) and keep full content only behind an explicit debug flag if needed.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12676] feat(job): Persist and expose the resolved runtime job template [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #12715:
URL: https://github.com/apache/gravitino/pull/12715#issuecomment-5474764251
@yuqi1129 can you please help me to review this PR?
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org