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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]