jerryshao commented on code in PR #7939:
URL: https://github.com/apache/gravitino/pull/7939#discussion_r2255695539


##########
server/src/main/java/org/apache/gravitino/server/web/rest/JobOperations.java:
##########
@@ -191,7 +199,111 @@ public Response deleteJobTemplate(
     }
   }
 
-  private static List<JobTemplateDTO> toDTOs(List<JobTemplateEntity> 
jobTemplateEntities) {
+  @GET
+  @Path("runs")
+  @Produces("application/vnd.gravitino.v1+json")
+  @Timed(name = "list-jobs." + MetricNames.HTTP_PROCESS_DURATION, absolute = 
true)
+  @ResponseMetered(name = "list-jobs", absolute = true)
+  public Response listJobs(
+      @PathParam("metalake") String metalake,
+      @QueryParam("jobTemplateName") String jobTemplateName) {
+    LOG.info(
+        "Received request to list jobs in metalake {}{}",
+        metalake,
+        jobTemplateName != null ? " for job template " + jobTemplateName : "");
+
+    try {
+      return Utils.doAs(
+          httpRequest,
+          () -> {
+            List<JobEntity> jobEntities =
+                jobOperationDispatcher.listJobs(metalake, 
Optional.ofNullable(jobTemplateName));
+            List<JobDTO> jobDTOs = toJobDTOs(jobEntities);
+
+            LOG.info("Listed {} jobs in metalake {}", jobEntities.size(), 
metalake);
+            return Utils.ok(new JobListResponse(jobDTOs));
+          });
+
+    } catch (Exception e) {
+      return ExceptionHandlers.handleJobException(OperationType.LIST, "", 
metalake, e);
+    }
+  }
+
+  @GET
+  @Path("runs/{jobId}")
+  @Produces("application/vnd.gravitino.v1+json")
+  @Timed(name = "get-job." + MetricNames.HTTP_PROCESS_DURATION, absolute = 
true)
+  @ResponseMetered(name = "get-job", absolute = true)
+  public Response getJob(@PathParam("metalake") String metalake, 
@PathParam("jobId") String jobId) {
+    LOG.info("Received request to get job {} in metalake {}", jobId, metalake);
+
+    try {
+      return Utils.doAs(
+          httpRequest,
+          () -> {
+            JobEntity jobEntity = jobOperationDispatcher.getJob(metalake, 
jobId);
+            LOG.info("Retrieved job {} in metalake: {}", jobId, metalake);
+            return Utils.ok(new JobResponse(toDTO(jobEntity)));
+          });
+
+    } catch (Exception e) {
+      return ExceptionHandlers.handleJobException(OperationType.GET, jobId, 
metalake, e);
+    }
+  }
+
+  @POST
+  @Path("runs")
+  @Produces("application/vnd.gravitino.v1+json")
+  @Timed(name = "run-job." + MetricNames.HTTP_PROCESS_DURATION, absolute = 
true)
+  @ResponseMetered(name = "run-job", absolute = true)
+  public Response runJob(@PathParam("metalake") String metalake, JobRunRequest 
request) {
+    LOG.info("Received request to run job in metalake: {}", metalake);
+
+    try {
+      return Utils.doAs(
+          httpRequest,
+          () -> {
+            request.validate();
+            Map<String, String> jobConf =
+                request.getJobConf() != null ? request.getJobConf() : 
Collections.emptyMap();
+
+            JobEntity jobEntity =
+                jobOperationDispatcher.runJob(metalake, 
request.getJobTemplateName(), jobConf);
+
+            LOG.info("Run job {} in metalake: {}", jobEntity.name(), metalake);
+            return Utils.ok(new JobResponse(toDTO(jobEntity)));
+          });
+
+    } catch (Exception e) {
+      return ExceptionHandlers.handleJobException(OperationType.RUN, "", 
metalake, e);
+    }
+  }
+
+  @DELETE

Review Comment:
   I asked the chatgpt, and it recommends me to use `@DELETE`. I don't have a 
strong preference on it.



-- 
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]

Reply via email to