This is an automated email from the ASF dual-hosted git repository.

gortiz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 953539ef32 Prevent 500 error for non-existent tasktype in 
/tasks/{taskType}/tasks API (#13537)
953539ef32 is described below

commit 953539ef32e92bc68296e304dfc5e1db76f8dd65
Author: soumitra-st <127247229+soumitra...@users.noreply.github.com>
AuthorDate: Mon Aug 5 06:49:42 2024 -0700

    Prevent 500 error for non-existent tasktype in /tasks/{taskType}/tasks API 
(#13537)
    
    * Prevent 500 error for non-existent tasktype in /tasks/{taskType}/tasks API
    
    * Changed the return code to 404 for non-existent task
    
    * Removed log and annotated with nullable for invalid task type
---
 .../controller/api/resources/PinotTaskRestletResource.java    |  7 ++++++-
 .../helix/core/minion/PinotHelixTaskResourceManager.java      | 11 ++++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git 
a/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTaskRestletResource.java
 
b/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTaskRestletResource.java
index 2147702f96..bc02a82ff5 100644
--- 
a/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTaskRestletResource.java
+++ 
b/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTaskRestletResource.java
@@ -192,7 +192,12 @@ public class PinotTaskRestletResource {
   @Produces(MediaType.APPLICATION_JSON)
   @ApiOperation("List all tasks for the given task type")
   public Set<String> getTasks(@ApiParam(value = "Task type", required = true) 
@PathParam("taskType") String taskType) {
-    return _pinotHelixTaskResourceManager.getTasks(taskType);
+    Set<String> tasks = _pinotHelixTaskResourceManager.getTasks(taskType);
+    if (tasks == null) {
+      throw new NotFoundException("No tasks found for task type: " + taskType);
+    }
+
+    return tasks;
   }
 
   @GET
diff --git 
a/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/PinotHelixTaskResourceManager.java
 
b/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/PinotHelixTaskResourceManager.java
index 7d77c76770..a28799314e 100644
--- 
a/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/PinotHelixTaskResourceManager.java
+++ 
b/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/PinotHelixTaskResourceManager.java
@@ -312,13 +312,15 @@ public class PinotHelixTaskResourceManager {
    * Get all tasks for the given task type.
    *
    * @param taskType Task type
-   * @return Set of task names
+   * @return Set of task names. Null for invalid task type.
    */
+  @Nullable
   public synchronized Set<String> getTasks(String taskType) {
     String helixJobQueueName = getHelixJobQueueName(taskType);
     WorkflowConfig workflowConfig = 
_taskDriver.getWorkflowConfig(helixJobQueueName);
-    Preconditions.checkArgument(workflowConfig != null, "Task queue: %s for 
task type: %s does not exist",
-        helixJobQueueName, taskType);
+    if (workflowConfig == null) {
+      return null;
+    }
     Set<String> helixJobs = workflowConfig.getJobDag().getAllNodes();
     Set<String> tasks = new HashSet<>(helixJobs.size());
     for (String helixJobName : helixJobs) {
@@ -751,6 +753,9 @@ public class PinotHelixTaskResourceManager {
    */
   public synchronized Map<String, TaskCount> getTaskCounts(String taskType) {
     Set<String> tasks = getTasks(taskType);
+    if (tasks == null) {
+      return Collections.emptyMap();
+    }
     Map<String, TaskCount> taskCounts = new TreeMap<>();
     for (String taskName : tasks) {
       taskCounts.put(taskName, getTaskCount(taskName));


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to