/
RunResource.java
117 lines (105 loc) · 3.32 KB
/
RunResource.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* Copyright 2018-2022 contributors to the Marquez project */
/* SPDX-License-Identifier: Apache-2.0 */
package marquez.api;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static marquez.common.models.RunState.ABORTED;
import static marquez.common.models.RunState.COMPLETED;
import static marquez.common.models.RunState.FAILED;
import static marquez.common.models.RunState.RUNNING;
import com.codahale.metrics.annotation.ExceptionMetered;
import com.codahale.metrics.annotation.ResponseMetered;
import com.codahale.metrics.annotation.Timed;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import lombok.NonNull;
import marquez.api.exceptions.RunNotFoundException;
import marquez.common.Utils;
import marquez.common.models.RunId;
import marquez.common.models.RunState;
import marquez.service.RunService;
import marquez.service.models.Run;
public class RunResource {
private final RunId runId;
private final RunService runService;
public RunResource(@NonNull final RunId runId, @NonNull final RunService runService) {
this.runId = runId;
this.runService = runService;
}
@Timed
@ResponseMetered
@ExceptionMetered
@GET
@Path("/")
@Produces(APPLICATION_JSON)
public Response getRun() {
final Run run =
runService
.findRunByUuid(runId.getValue())
.orElseThrow(() -> new RunNotFoundException(runId));
return Response.ok(run).build();
}
/**
* @deprecated Prefer OpenLineage, see <a
* href="https://openlineage.io">https://openlineage.io</a>. This method is scheduled to be
* removed in release {@code 0.25.0}.
*/
@Timed
@ResponseMetered
@ExceptionMetered
@POST
@Path("start")
@Produces(APPLICATION_JSON)
public Response markRunAsRunning(@QueryParam("at") String atAsIso) {
return markRunAs(RUNNING, atAsIso);
}
/**
* @deprecated Prefer OpenLineage, see <a
* href="https://openlineage.io">https://openlineage.io</a>. This method is scheduled to be
* removed in release {@code 0.25.0}.
*/
@Timed
@ResponseMetered
@ExceptionMetered
@POST
@Path("complete")
@Produces(APPLICATION_JSON)
public Response markRunAsCompleted(@QueryParam("at") String atAsIso) {
return markRunAs(COMPLETED, atAsIso);
}
/**
* @deprecated Prefer OpenLineage, see <a
* href="https://openlineage.io">https://openlineage.io</a>. This method is scheduled to be
* removed in release {@code 0.25.0}.
*/
@Timed
@ResponseMetered
@ExceptionMetered
@POST
@Path("fail")
@Produces(APPLICATION_JSON)
public Response markRunAsFailed(@QueryParam("at") String atAsIso) {
return markRunAs(FAILED, atAsIso);
}
/**
* @deprecated Prefer OpenLineage, see <a
* href="https://openlineage.io">https://openlineage.io</a>. This method is scheduled to be
* removed in release {@code 0.25.0}.
*/
@Timed
@ResponseMetered
@ExceptionMetered
@POST
@Path("abort")
@Produces(APPLICATION_JSON)
public Response markRunAsAborted(@QueryParam("at") String atAsIso) {
return markRunAs(ABORTED, atAsIso);
}
Response markRunAs(@NonNull RunState runState, @QueryParam("at") String atAsIso) {
runService.markRunAs(runId, runState, Utils.toInstant(atAsIso));
return getRun();
}
}