This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new f42586290 fix(instance): bound the batch delete like every other batch
input (#6102)
f42586290 is described below
commit f4258629056fdf9c667b5ab157f785d4d7a0881d
Author: Apulupie <[email protected]>
AuthorDate: Fri Nov 27 12:53:06 2026 +0800
fix(instance): bound the batch delete like every other batch input (#6102)
---
.../studio/instance/BatchDeleteInstancesDTO.java | 2 ++
.../rocketmq/studio/instance/InstanceService.java | 11 +++++++++++
.../studio/instance/InstanceControllerTest.java | 15 ++++++++++++++
.../studio/instance/InstanceServiceTest.java | 23 ++++++++++++++++++++++
4 files changed, 51 insertions(+)
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/instance/BatchDeleteInstancesDTO.java
b/server/src/main/java/org/apache/rocketmq/studio/instance/BatchDeleteInstancesDTO.java
index 8d5c9e907..ced87b067 100644
---
a/server/src/main/java/org/apache/rocketmq/studio/instance/BatchDeleteInstancesDTO.java
+++
b/server/src/main/java/org/apache/rocketmq/studio/instance/BatchDeleteInstancesDTO.java
@@ -18,6 +18,7 @@
package org.apache.rocketmq.studio.instance;
import jakarta.validation.constraints.NotEmpty;
+import jakarta.validation.constraints.Size;
import lombok.Data;
import java.util.List;
@@ -26,5 +27,6 @@ import java.util.List;
public class BatchDeleteInstancesDTO {
@NotEmpty
+ @Size(max = 100, message = "At most 100 instances are allowed per batch")
private List<String> ids;
}
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/instance/InstanceService.java
b/server/src/main/java/org/apache/rocketmq/studio/instance/InstanceService.java
index 1289a7918..4378bef02 100644
---
a/server/src/main/java/org/apache/rocketmq/studio/instance/InstanceService.java
+++
b/server/src/main/java/org/apache/rocketmq/studio/instance/InstanceService.java
@@ -633,6 +633,13 @@ public class InstanceService {
}
/** Free-text fields of rmq_instance, capped at the width of their column.
*/
+ /**
+ * Upper bound of one batch delete. Every other batch input in the
repository is bounded the
+ * same way (import topics / consumer groups, selected DLQ resends)
because each entry costs a
+ * lookup and a transaction of its own.
+ */
+ static final int MAX_BATCH_DELETE_INSTANCES = 100;
+
static final int MAX_INSTANCE_ENDPOINT_LENGTH = 512;
static final int MAX_INSTANCE_REMARK_LENGTH = 255;
static final int MAX_INSTANCE_CREDENTIAL_REF_LENGTH = 128;
@@ -808,6 +815,10 @@ public class InstanceService {
if (normalizedIds.isEmpty()) {
throw new BusinessException(400, "Instance IDs are required");
}
+ if (normalizedIds.size() > MAX_BATCH_DELETE_INSTANCES) {
+ throw new BusinessException(400,
+ "At most " + MAX_BATCH_DELETE_INSTANCES + " instances are
allowed per batch");
+ }
int deleted = 0;
List<String> failed = new ArrayList<>();
for (String instanceId : normalizedIds) {
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/instance/InstanceControllerTest.java
b/server/src/test/java/org/apache/rocketmq/studio/instance/InstanceControllerTest.java
index 6d53176a2..d56285999 100644
---
a/server/src/test/java/org/apache/rocketmq/studio/instance/InstanceControllerTest.java
+++
b/server/src/test/java/org/apache/rocketmq/studio/instance/InstanceControllerTest.java
@@ -280,6 +280,21 @@ class InstanceControllerTest extends WebMvcAuthTestSupport
{
verifyNoInteractions(instanceService);
}
+ @Test
+ void deleteInstancesShouldRejectABatchAboveTheLimitTest() throws Exception
{
+ List<String> ids = java.util.stream.IntStream.rangeClosed(1, 101)
+ .mapToObj(index -> "inst-" + index).toList();
+
+ mockMvc.perform(post("/api/instances/delete-batch")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(Map.of("ids",
ids))))
+ .andExpect(status().isBadRequest())
+ .andExpect(jsonPath("$.code").value(400))
+ .andExpect(jsonPath("$.message").value("At most 100 instances
are allowed per batch"));
+
+ verifyNoInteractions(instanceService);
+ }
+
@Test
void deleteInstanceShouldRejectMissingId() throws Exception {
mockMvc.perform(post("/api/instances/delete")
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/instance/InstanceServiceTest.java
b/server/src/test/java/org/apache/rocketmq/studio/instance/InstanceServiceTest.java
index 9561c0616..7a47007ec 100644
---
a/server/src/test/java/org/apache/rocketmq/studio/instance/InstanceServiceTest.java
+++
b/server/src/test/java/org/apache/rocketmq/studio/instance/InstanceServiceTest.java
@@ -1153,6 +1153,29 @@ class InstanceServiceTest {
assertThat(result.getFailed()).containsExactly("missing: Instance not
found: missing");
}
+ @Test
+ void deleteInstancesShouldRejectABatchAboveTheBatchLimitTest() {
+ List<String> ids = java.util.stream.IntStream.rangeClosed(1, 101)
+ .mapToObj(index -> "inst-" + index).toList();
+
+ assertThatThrownBy(() -> instanceService.deleteInstances(ids))
+ .isInstanceOf(BusinessException.class)
+ .hasMessageContaining("At most 100 instances are allowed per
batch");
+ }
+
+ @Test
+ void deleteInstancesShouldAcceptABatchAtTheBatchLimitTest() {
+
when(instanceRepository.findByIdentifier(anyString())).thenReturn(Optional.empty());
+ ReflectionTestUtils.setField(instanceService, "self", instanceService);
+ List<String> ids = java.util.stream.IntStream.rangeClosed(1, 100)
+ .mapToObj(index -> "inst-" + index).toList();
+
+ BatchDeleteResultVO result = instanceService.deleteInstances(ids);
+
+ assertThat(result.getDeleted()).isZero();
+ assertThat(result.getFailed()).hasSize(100);
+ }
+
@Test
void deleteInstancesShouldContinueAfterProviderRuntimeFailureTest() {
InstanceVO failedInstance =
InstanceVO.builder().name("inst-a").build();