diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/DrillRoot.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/DrillRoot.java index ae99fa4687d..8c15283235c 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/DrillRoot.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/DrillRoot.java @@ -154,6 +154,11 @@ public Response shutdownDrillbit() throws Exception { @Operation(externalDocs = @ExternalDocumentation(description = "Apache Drill REST API documentation:", url = "https://drill.apache.org/docs/stopping-drill/")) public String shutdownDrillbitByName(@PathParam("hostname") String hostname) throws Exception { + if (Strings.isNullOrEmpty(hostname) || work.getContext().getAvailableBits().stream() + .noneMatch(db -> db.getAddress().equals(hostname))) { + throw new IllegalArgumentException("Invalid drillbit hostname: " + hostname); + } + URL shutdownURL = WebUtils.getDrillbitURL(work, request, hostname, "/gracefulShutdown"); return WebUtils.doHTTPRequest(new HttpPost(shutdownURL.toURI()), work.getContext().getConfig()); }