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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
