You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "zhaohai666 (via GitHub)" <gi...@apache.org> on 2026/07/18 05:20:49 UTC

[PR] [Studio] feat: add cluster broker overview page [rocketmq-dashboard]

zhaohai666 opened a new pull request, #457:
URL: https://github.com/apache/rocketmq-dashboard/pull/457

   ## Summary
   Implement cluster and broker management module, providing core APIs including cluster list query, cluster detail retrieval, cluster configuration update, and broker restart. The module adopts a layered architecture (Controller → Service → Repository/Provider), with in-memory stub data implementation and full unit test coverage.
   
   ## Files Changed
   12 files modified, total 1141 line insertions
   
   ### Controller Layer
   #### ClusterController.java
   Annotated with `@RestController` and `@RequestMapping("/api/clusters")`, exposes 4 API endpoints:
   - `GET /api/clusters`: Query cluster list
   - `GET /api/clusters/{id}`: Get single cluster details
   - `POST /api/clusters/config/update`: Update cluster configurations
   - `POST /api/clusters/{clusterId}/brokers/{name}/restart`: Trigger broker restart
   
   ### Service Layer
   #### ClusterService.java
   Annotated with `@Service`, contains core business logic:
   1. Query methods: `listClusters()`, `getCluster(id)`
      - Throws `BusinessException` with 404 code when target cluster cannot be found
   2. `updateClusterConfig(UpdateConfigDTO)`
      - Supports incremental update of 8 configuration fields
      - Automatically creates empty config record if incoming config is null
   3. `restartBroker(clusterId, brokerName)`
      - Validates target cluster existence before execution
   4. Reserved methods for NameServer & Proxy operations:
      `createNameServer`, `updateNameServer`, `restartNameServer`, `upgradeNameServer`, `deleteNameServer`, `restartProxy`
      - References DTOs from nameserver and proxy packages for future extension
   
   ### Repository Layer
   #### ClusterRepository.java
   Repository interface with methods:
   `findAll()`, `findById(id)`, `updateConfig(id, config)`
   
   #### ClusterRepositoryImpl.java
   Annotated with `@Repository`
   - Uses `ConcurrentHashMap` for in-memory data storage
   - Preloads 2 stub clusters (prod & staging) with complete embedded Broker, Proxy, NameServer and configuration data
   
   ### Provider Layer
   #### ClusterProvider.java
   Provider interface with methods:
   `discoverClusters()`, `refreshClusterDetail(id)`
   
   #### ClusterProviderStub.java
   Annotated with `@Component`
   - Returns static single-cluster stub mock data
   
   ### VO & DTO Model Files
   1. `ClusterVO.java`
      - Extends `BaseEntity`
      - Fields: name, type, endpoint, status, brokers, proxies, nameServers, config, topicCount, groupCount, tpsHistory
   2. `BrokerVO.java`
      - Fields: name, addr, version, status, diskUsage, tpsIn, tpsOut
   3. `ClusterConfigVO.java`
      - Contains 10 configuration entries: writeQueueNums, readQueueNums, maxMessageSize, flushDiskType, etc.
   4. `UpdateConfigDTO.java`
      - Command object for partial config update
      - All fields use wrapped types (Boolean / Integer), optional to support incremental patch
   
   ### Test Files
   #### ClusterControllerTest.java
   - Annotated with `@WebMvcTest`
   - 5 test cases: 2 for cluster list query, 1 for cluster detail query, 1 for config update, 1 for broker restart
   
   #### ClusterServiceTest.java
   - Annotated with `@ExtendWith(MockitoExtension)`
   - 11 test cases: 2 list queries, 2 detail queries, 5 incremental config updates, 2 broker restart logics
   - Uses AssertJ for fluent assertion
   
   ## Key Design
   1. Clear layered architecture: Controller → Service → Repository + Provider with separated responsibilities
   2. Incremental configuration update
      All fields in `UpdateConfigDTO` are nullable wrapped types; null fields will not overwrite existing values to support partial patch
   3. Stub mock data strategy
      `ClusterRepositoryImpl` and `ClusterProviderStub` provide in-memory mock data to facilitate front-end local development and debugging
   4. Unified global exception handling
      Relies on common foundation module: throws `BusinessException` (404 Not Found), captured uniformly by `GlobalExceptionHandler`
   5. Cross-module forward compatibility
      `ClusterService` references VO/DTO from nameserver and proxy modules, reserving interfaces for follow-up PR development
   
   ## Dependencies
   Depends on branch `feature/studio-common-foundation`:
   Reuses `BaseEntity`, unified response `Result`, `BusinessException`, `GlobalExceptionHandler` and business enums (ClusterStatus, ClusterType, BrokerStatus, FlushDiskType)
   
   Cross-module reference:
   This module imports VO/DTO classes from nameserver and proxy submodules
   
   ## Test Coverage
   - Controller layer: 5 test cases covering all 4 API endpoints (including empty list boundary case)
   - Service layer: 11 test cases covering normal flow, 404 exception flow, incremental config patch and empty config creation logic
   - Total: 16 test methods, 417 lines of test code
   
   ## PR Title Specification Reminder
   All PR and Issue titles of this project must start with `[studio]` to help community quickly filter and track related work items.
   Example:
   `[studio] feat: implement cluster and broker management module with stub data`


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Studio] feat: add cluster broker overview page [rocketmq-dashboard]

Posted by "lizhimins (via GitHub)" <gi...@apache.org>.
lizhimins commented on PR #457:
URL: https://github.com/apache/rocketmq-dashboard/pull/457#issuecomment-5045281655

   Closing as superseded: the cluster/broker backend (ClusterController/Service/Provider/Repository, BrokerVO, cluster config DTO/VO) is already present on the rocketmq-studio branch, introduced by commit b773716a ("feat: implement backend cluster management module"). The files are identical, so this PR is a no-op. Thanks for the contribution!


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Studio] feat: add cluster broker overview page [rocketmq-dashboard]

Posted by "RockteMQ-AI (via GitHub)" <gi...@apache.org>.
RockteMQ-AI commented on code in PR #457:
URL: https://github.com/apache/rocketmq-dashboard/pull/457#discussion_r4001308715


##########
server/src/main/java/com/rocketmq/studio/cluster/broker/ClusterController.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.rocketmq.studio.cluster.broker;
+
+import com.rocketmq.studio.cluster.config.UpdateConfigDTO;
+
+import com.rocketmq.studio.common.domain.Result;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/api/clusters")
+@RequiredArgsConstructor
+public class ClusterController {
+
+    private final ClusterService clusterService;

Review Comment:
   **[Warning]** Consider adding `@Valid` annotation on request body parameters and input validation (e.g., null checks for `clusterId`). Without validation, malformed requests could cause NPEs in the service layer.



##########
server/src/main/java/com/rocketmq/studio/cluster/broker/ClusterRepositoryImpl.java:
##########
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.rocketmq.studio.cluster.broker;
+
+import com.rocketmq.studio.cluster.config.ClusterConfigVO;
+import com.rocketmq.studio.cluster.nameserver.NameServerVO;
+import com.rocketmq.studio.cluster.proxy.ProxyVO;
+
+import com.rocketmq.studio.common.domain.enums.BrokerStatus;
+import com.rocketmq.studio.common.domain.enums.ClusterStatus;
+import com.rocketmq.studio.common.domain.enums.ClusterType;
+import com.rocketmq.studio.common.domain.enums.FlushDiskType;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Repository;
+
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+
+@Slf4j
+@Repository
+public class ClusterRepositoryImpl implements ClusterRepository {
+
+    private final Map<String, ClusterVO> store = new ConcurrentHashMap<>();
+
+    public ClusterRepositoryImpl() {
+        initStubData();
+    }
+
+    @Override
+    public List<ClusterVO> findAll() {
+        return new ArrayList<>(store.values());
+    }
+
+    @Override
+    public Optional<ClusterVO> findById(String id) {

Review Comment:
   **[Info]** The `updateClusterConfig` method in the service calls `findById` then `updateConfig`, but `updateConfig` internally does another `store.get()`. Consider passing the cluster object directly to avoid the double lookup, or use `computeIfPresent` for atomic update.



-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Studio] feat: add cluster broker overview page [rocketmq-dashboard]

Posted by "lizhimins (via GitHub)" <gi...@apache.org>.
lizhimins closed pull request #457: [Studio] feat: add cluster broker overview page
URL: https://github.com/apache/rocketmq-dashboard/pull/457


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org