EMsnap commented on a change in pull request #374:
URL: https://github.com/apache/incubator-tubemq/pull/374#discussion_r549552283
##########
File path:
tubemq-manager/src/main/java/org/apache/tubemq/manager/service/NodeService.java
##########
@@ -120,6 +123,106 @@ private TubeHttpTopicInfoList
requestTopicConfigInfo(NodeEntry nodeEntry, String
}
+ public TubeMQResult cloneBrokersWithTopic(CloneBrokersReq req, int
clusterId) throws Exception {
+
+ // 1. query source broker config
+ QueryBrokerCfgReq queryReq =
QueryBrokerCfgReq.getReq(req.getSourceBrokerId());
+ NodeEntry masterEntry =
nodeRepository.findNodeEntryByClusterIdIsAndMasterIsTrue(
+ clusterId);
+ BrokerStatusInfo brokerStatusInfo = getBrokerStatusInfo(queryReq,
masterEntry);
+
+ // 2. use source broker config to clone brokers
+ BrokerConf sourceBrokerConf = brokerStatusInfo.getData().get(0);
+ AddBrokersReq addBrokersReq = getBatchAddBrokersReq(req, clusterId,
sourceBrokerConf);
+
+ // 3. request master, return broker ids generated by master
+ AddBrokerResult addBrokerResult =
addBrokersToClusterWithId(addBrokersReq, masterEntry);
+
+ // might have duplicate brokers
+ if (addBrokerResult.getErrCode() != 0) {
+ return TubeMQResult.getErrorResult(addBrokerResult.getErrMsg());
+ }
+ List<Integer> brokerIds = getBrokerIds(addBrokerResult);
+ List<AddTopicReq> addTopicReqs = req.getAddTopicReqs();
+
+ // 4. add topic to brokers
+ return addTopicToBrokers(masterEntry, brokerIds, addTopicReqs);
+ }
+
+ private TubeMQResult addTopicToBrokers(NodeEntry masterEntry,
List<Integer> brokerIds, List<AddTopicReq> addTopicReqs) {
+ TubeMQResult tubeResult = new TubeMQResult();
+ AddTopicsResult addTopicsResult = new AddTopicsResult();
+
+ if (CollectionUtils.isEmpty(addTopicReqs)) {
+ return tubeResult;
+ }
+ addTopicReqs.forEach(addTopicReq -> {
+ try {
+ String brokerStr = StringUtils.join(brokerIds, ",");
Review comment:
roger
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]