kfaraz commented on code in PR #19949:
URL: https://github.com/apache/druid/pull/19949#discussion_r3751516030


##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/supervisor/SupervisorManager.java:
##########
@@ -747,11 +744,31 @@ private boolean 
createAndStartSupervisorInternal(SupervisorSpec spec, boolean pe
 
   private StreamSupervisor requireStreamSupervisor(final String supervisorId, 
final String operation)
   {
-    Pair<Supervisor, SupervisorSpec> supervisor = 
supervisors.get(supervisorId);
-    if (supervisor.lhs instanceof StreamSupervisor) {
-      return (StreamSupervisor) supervisor.lhs;
+    return getSupervisorOfType(supervisorId, StreamSupervisor.class, 
SupervisorSpec.class, operation).lhs;
+  }
+
+  /**
+   * Finds the non-null supervisor for the given ID only and its corresponding
+   * spec only if they are of the specified type.
+   *
+   * @throws DruidException if the supervisor does not exist or is not of the
+   * specified type.
+   */
+  @SuppressWarnings("unchecked")
+  public <S extends Supervisor, T extends SupervisorSpec> Pair<S, T> 
getSupervisorOfType(
+      String supervisorId,
+      Class<S> supervisorType,
+      Class<T> supervisorSpecType,
+      String operation
+  )
+  {
+    final Pair<Supervisor, SupervisorSpec> supervisor = 
supervisors.get(supervisorId);
+    if (supervisor == null) {
+      throw NotFound.exception("Supervisor[%s] does not exist", supervisorId);
+    } else if (supervisorType.isInstance(supervisor.lhs) && 
supervisorSpecType.isInstance(supervisor.rhs)) {
+      return (Pair<S, T>) supervisor;
     } else {
-      throw DruidException.forPersona(DruidException.Persona.USER)
+      throw DruidException.forPersona(DruidException.Persona.ADMIN)

Review Comment:
   Yeah, makes sense. The original response code here was 500 but 400 does seem 
better. Fixing 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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to