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


##########
server/src/test/java/org/apache/druid/server/http/CoordinatorCompactionConfigsResourceTest.java:
##########
@@ -543,4 +555,68 @@
     Assert.assertEquals(Response.Status.OK.getStatusCode(), 
response.getStatus());
     Assert.assertTrue(((Collection) response.getEntity()).isEmpty());
   }
+
+  @Test
+  public void testSimulateCompactionDynamicConfig()
+  {
+    final TestSegmentsMetadataManager segmentsMetadataManager = new 
TestSegmentsMetadataManager();
+    final CoordinatorConfigManager mockConfigManager = 
Mockito.mock(CoordinatorConfigManager.class);
+    Mockito.when(mockConfigManager.getCurrentCompactionConfig()).thenReturn(
+        new CoordinatorCompactionConfig(
+            Collections.singletonList(createDatasourceConfig("wiki")),
+            null, null, null, null, null
+        )
+    );
+
+    final MetadataManager metadataManager = new MetadataManager(
+        mockAuditManager,
+        mockConfigManager, segmentsMetadataManager, null, null, null, null
+    );
+
+    // Add some segments to the timeline
+    final List<DataSegment> wikiSegments
+        = CreateDataSegments.ofDatasource("wiki")
+                            .forIntervals(10, Granularities.DAY)
+                            .withNumPartitions(10)
+                            .startingAt("2013-01-01")
+                            .eachOfSizeInMb(100);
+    wikiSegments.forEach(segmentsMetadataManager::addSegment);
+
+    coordinatorCompactionConfigsResource = new 
CoordinatorCompactionConfigsResource(
+        null,
+        new CompactionDutySimulator(metadataManager, OBJECT_MAPPER),
+        null
+    );
+    Response response = 
coordinatorCompactionConfigsResource.simulateCompactionDynamicConfig(
+        new CompactionConfigUpdateRequest(null, null, null, null, null),
+        mockHttpServletRequest
+    );
+    Assert.assertEquals(Response.Status.OK.getStatusCode(), 
response.getStatus());
+    Assert.assertTrue(response.getEntity() instanceof 
CompactionSimulateResult);
+
+    CompactionSimulateResult simulateResult = (CompactionSimulateResult) 
response.getEntity();
+    Assert.assertEquals(
+        Arrays.asList(
+            Arrays.asList("dataSource", "interval", "numSegments", "bytes", 
"reasonToCompact"),
+            Arrays.asList("wiki", Intervals.of("2013-01-09/P1D"), 10, 
1_000_000_000L, 2, ""),
+            Arrays.asList("wiki", Intervals.of("2013-01-08/P1D"), 10, 
1_000_000_000L, 2, ""),
+            Arrays.asList("wiki", Intervals.of("2013-01-07/P1D"), 10, 
1_000_000_000L, 2, ""),
+            Arrays.asList("wiki", Intervals.of("2013-01-06/P1D"), 10, 
1_000_000_000L, 2, ""),
+            Arrays.asList("wiki", Intervals.of("2013-01-05/P1D"), 10, 
1_000_000_000L, 2, ""),
+            Arrays.asList("wiki", Intervals.of("2013-01-04/P1D"), 10, 
1_000_000_000L, 2, ""),
+            Arrays.asList("wiki", Intervals.of("2013-01-03/P1D"), 10, 
1_000_000_000L, 2, ""),
+            Arrays.asList("wiki", Intervals.of("2013-01-02/P1D"), 10, 
1_000_000_000L, 2, ""),
+            Arrays.asList("wiki", Intervals.of("2013-01-01/P1D"), 10, 
1_000_000_000L, 2, "")
+        ),
+        simulateResult.getSubmittedTasks()
+    );
+  }
+
+  private static DataSourceCompactionConfig createDatasourceConfig(String 
datasource)

Review Comment:
   ## Useless parameter
   
   The parameter 'datasource' is never used.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/7589)



##########
server/src/main/java/org/apache/druid/server/http/CoordinatorCompactionConfigsResource.java:
##########
@@ -91,6 +95,30 @@
     return Response.ok(configManager.getCurrentCompactionConfig()).build();
   }
 
+  @POST
+  @Path("/dynamic")
+  @Consumes(MediaType.APPLICATION_JSON)
+  public Response updateCompactionDynamicConfig(
+      CompactionConfigUpdateRequest updatePayload,
+      @Context HttpServletRequest req
+  )
+  {
+    UnaryOperator<CoordinatorCompactionConfig> operator =
+        current -> CoordinatorCompactionConfig.from(current, updatePayload);
+    return updateConfigHelper(operator, 
AuthorizationUtils.buildAuditInfo(req));
+  }
+
+  @POST
+  @Path("/simulate")
+  @Consumes(MediaType.APPLICATION_JSON)
+  public Response simulateCompactionDynamicConfig(
+      CompactionConfigUpdateRequest updatePayload,
+      @Context HttpServletRequest req

Review Comment:
   ## Useless parameter
   
   The parameter 'req' is never used.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/7588)



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