From 12b02e433b3e052add51f692d07d821589d5194d Mon Sep 17 00:00:00 2001 From: wslulciuc Date: Wed, 14 Oct 2020 11:20:34 -0700 Subject: [PATCH] Add runID to job meta Signed-off-by: wslulciuc --- src/main/java/marquez/api/JobResource.java | 9 ++++++--- src/main/java/marquez/service/models/JobMeta.java | 10 +++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/marquez/api/JobResource.java b/src/main/java/marquez/api/JobResource.java index 2ad9c8e77e..8d9ff90521 100644 --- a/src/main/java/marquez/api/JobResource.java +++ b/src/main/java/marquez/api/JobResource.java @@ -84,6 +84,7 @@ public Response createOrUpdate( @Valid JobMeta jobMeta) throws MarquezServiceException { throwIfNotExists(namespaceName); + throwIfNotExists(jobMeta.getRunId().orElse(null)); final Job job = jobService.createOrUpdate(namespaceName, jobName, jobMeta); return Response.ok(job).build(); @@ -264,9 +265,11 @@ void throwIfExists( } } - void throwIfNotExists(@NonNull RunId runId) throws MarquezServiceException { - if (!jobService.runExists(runId)) { - throw new RunNotFoundException(runId); + void throwIfNotExists(@Nullable RunId runId) throws MarquezServiceException { + if (runId != null) { + if (!jobService.runExists(runId)) { + throw new RunNotFoundException(runId); + } } } diff --git a/src/main/java/marquez/service/models/JobMeta.java b/src/main/java/marquez/service/models/JobMeta.java index f4488e217a..c63a58c7bd 100644 --- a/src/main/java/marquez/service/models/JobMeta.java +++ b/src/main/java/marquez/service/models/JobMeta.java @@ -35,6 +35,7 @@ import marquez.common.models.JobName; import marquez.common.models.JobType; import marquez.common.models.NamespaceName; +import marquez.common.models.RunId; @EqualsAndHashCode @ToString @@ -45,6 +46,7 @@ public final class JobMeta { @Nullable private final URL location; @Getter private final ImmutableMap context; @Nullable private final String description; + @Nullable private final RunId runId; public JobMeta( @NonNull final JobType type, @@ -52,13 +54,15 @@ public JobMeta( @NonNull final ImmutableSet outputs, @Nullable final URL location, @Nullable final ImmutableMap context, - @Nullable final String description) { + @Nullable final String description, + @Nullable final RunId runId) { this.type = type; this.inputs = inputs; this.outputs = outputs; this.location = location; this.context = (context == null) ? ImmutableMap.of() : context; this.description = description; + this.runId = runId; } public Optional getLocation() { @@ -69,6 +73,10 @@ public Optional getDescription() { return Optional.ofNullable(description); } + public Optional getRunId() { + return Optional.ofNullable(runId); + } + public Version version(@NonNull NamespaceName namespaceName, @NonNull JobName jobName) { final byte[] bytes = VERSION_JOINER