github-advanced-security[bot] commented on code in PR #18358:
URL: https://github.com/apache/druid/pull/18358#discussion_r2250764617


##########
embedded-tests/src/test/java/org/apache/druid/testing/embedded/compact/CompactionResourceTestClient.java:
##########
@@ -199,132 +130,77 @@
         simulateResult.getCompactionStates()
     );
 
-    String url = StringUtils.format("%scompaction/compact", 
getCoordinatorURL());
-    StatusResponseHolder response = httpClient().go(new 
Request(HttpMethod.POST, new URL(url)), responseHandler).get();
-    if (!response.getStatus().equals(HttpResponseStatus.OK)) {
-      throw new ISE(
-          "Error while force trigger auto compaction status[%s] content[%s]",
-          response.getStatus(),
-          response.getContent()
-      );
-    }
+    String url = StringUtils.format("%s/compaction/compact", 
getCoordinatorURL());
+    clients.onLeaderCoordinator(mapper -> new RequestBuilder(HttpMethod.POST, 
url), null);
   }
 
-  public void updateClusterConfig(ClusterCompactionConfig config) throws 
Exception
+  public void updateClusterConfig(ClusterCompactionConfig config)
   {
-    final String url = StringUtils.format(
-        "%s/compaction/config/cluster",
-        getOverlordURL()
-    );
-    StatusResponseHolder response = httpClient().go(
-        new Request(HttpMethod.POST, new URL(url)).setContent(
-            "application/json",
-            jsonMapper.writeValueAsBytes(config)
-        ),
-        responseHandler
-    ).get();
-    if (!response.getStatus().equals(HttpResponseStatus.OK)) {
-      throw new ISE(
-          "Error while updating cluster compaction config, status[%s], 
content[%s]",
-          response.getStatus(),
-          response.getContent()
-      );
-    }
+    clients.onLeaderOverlord(o -> o.updateClusterCompactionConfig(config));
   }
 
-  public ClusterCompactionConfig getClusterConfig() throws Exception
+  public ClusterCompactionConfig getClusterConfig()
   {
-    String url = StringUtils.format("%s/compaction/config/cluster", 
getOverlordURL());
-    StatusResponseHolder response = httpClient().go(
-        new Request(HttpMethod.GET, new URL(url)), responseHandler
-    ).get();
-    if (!response.getStatus().equals(HttpResponseStatus.OK)) {
-      throw new ISE(
-          "Error while getting compaction config status[%s] content[%s]",
-          response.getStatus(),
-          response.getContent()
-      );
-    }
-    return jsonMapper.readValue(response.getContent(), new TypeReference<>() 
{});
+    return 
clients.onLeaderOverlord(OverlordClient::getClusterCompactionConfig);
   }
 
   /**
    * This API is currently only to force the coordinator to refresh its config.
    * For all other purposes, use {@link #updateClusterConfig}.
    */
   @Deprecated
-  private void updateCompactionTaskSlot(Double compactionTaskSlotRatio, 
Integer maxCompactionTaskSlots) throws Exception
+  private void updateCompactionTaskSlot(Double compactionTaskSlotRatio, 
Integer maxCompactionTaskSlots)
   {
     final String url = StringUtils.format(
-        "%sconfig/compaction/taskslots?ratio=%s&max=%s",
+        "%s/config/compaction/taskslots?ratio=%s&max=%s",
         getCoordinatorURL(),
         StringUtils.urlEncode(compactionTaskSlotRatio.toString()),
         StringUtils.urlEncode(maxCompactionTaskSlots.toString())
     );
-    StatusResponseHolder response = httpClient().go(new 
Request(HttpMethod.POST, new URL(url)), responseHandler).get();
-    if (!response.getStatus().equals(HttpResponseStatus.OK)) {
-      throw new ISE(
-          "Error while updating compaction task slot status[%s] content[%s]",
-          response.getStatus(),
-          response.getContent()
-      );
-    }
+    clients.onLeaderCoordinator(mapper -> new RequestBuilder(HttpMethod.POST, 
url), null);
   }
 
-  public Map<String, String> getCompactionProgress(String dataSource) throws 
Exception
+  public Map<String, String> getCompactionProgress(String dataSource)
   {
-    String url = StringUtils.format("%scompaction/progress?dataSource=%s", 
getCoordinatorURL(), StringUtils.urlEncode(dataSource));
-    StatusResponseHolder response = httpClient().go(
-        new Request(HttpMethod.GET, new URL(url)), responseHandler
-    ).get();
-    if (!response.getStatus().equals(HttpResponseStatus.OK)) {
-      throw new ISE(
-          "Error while getting compaction progress status[%s] content[%s]",
-          response.getStatus(),
-          response.getContent()
-      );
-    }
-    return jsonMapper.readValue(response.getContent(), new TypeReference<>() 
{});
+    String url = StringUtils.format(
+        "%s/compaction/progress?dataSource=%s",
+        getCoordinatorURL(),
+        StringUtils.urlEncode(dataSource)
+    );
+    return clients.onLeaderCoordinator(
+        mapper -> new RequestBuilder(HttpMethod.GET, url),
+        new TypeReference<>() {}
+    );
   }
 
-  public AutoCompactionSnapshot getCompactionStatus(String dataSource) throws 
Exception
+  public AutoCompactionSnapshot getCompactionStatus(String dataSource)
   {
-    String url = StringUtils.format("%scompaction/status?dataSource=%s", 
getCoordinatorURL(), StringUtils.urlEncode(dataSource));
-    StatusResponseHolder response = httpClient().go(
-        new Request(HttpMethod.GET, new URL(url)), responseHandler
-    ).get();
-    if (response.getStatus().equals(HttpResponseStatus.NOT_FOUND)) {
-      return null;
-    } else if (!response.getStatus().equals(HttpResponseStatus.OK)) {
-      throw new ISE(
-          "Error while getting compaction status status[%s] content[%s]",
-          response.getStatus(),
-          response.getContent()
+    String url = StringUtils.format(
+        "%s/compaction/status?dataSource=%s",
+        getCoordinatorURL(),
+        StringUtils.urlEncode(dataSource)
+    );
+
+    try {
+      final CompactionStatusResponse latestSnapshots = 
clients.onLeaderCoordinator(
+          mapper -> new RequestBuilder(HttpMethod.GET, url),
+          new TypeReference<>() {}
       );
+      return Objects.requireNonNull(latestSnapshots).getLatestStatus().get(0);
+    }
+    catch (Exception e) {

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [CompactionResourceTestClient.updateCompactionTaskSlot](1) should 
be avoided because it has been deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/9935)



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