yuz10 commented on a change in pull request #3710:
URL: https://github.com/apache/rocketmq/pull/3710#discussion_r780072521
##########
File path:
tools/src/main/java/org/apache/rocketmq/tools/command/export/ExportMetadataCommand.java
##########
@@ -127,49 +129,51 @@ public void execute(CommandLine commandLine, Options
options, RPCHook rpcHook)
SubscriptionGroupWrapper subscriptionGroupWrapper =
defaultMQAdminExt.getUserSubscriptionGroup(
addr, 10000);
- if (commandLine.hasOption('t')) {
- filePath = filePath + "/topic.json";
-
MixAll.string2FileNotSafe(JSON.toJSONString(topicConfigSerializeWrapper, true),
filePath);
- System.out.printf("export %s success", filePath);
- return;
- } else if (commandLine.hasOption('g')) {
- filePath = filePath + "/subscriptionGroup.json";
-
MixAll.string2FileNotSafe(JSON.toJSONString(subscriptionGroupWrapper, true),
filePath);
- System.out.printf("export %s success", filePath);
- return;
- } else {
- for (Map.Entry<String, TopicConfig> entry :
topicConfigSerializeWrapper.getTopicConfigTable().entrySet()) {
- TopicConfig topicConfig =
topicConfigMap.get(entry.getKey());
- if (null != topicConfig) {
- entry.getValue().setWriteQueueNums(
- topicConfig.getWriteQueueNums() +
entry.getValue().getWriteQueueNums());
- entry.getValue().setReadQueueNums(
- topicConfig.getReadQueueNums() +
entry.getValue().getReadQueueNums());
- }
- topicConfigMap.put(entry.getKey(),
entry.getValue());
+ for (Map.Entry<String, TopicConfig> entry :
topicConfigSerializeWrapper.getTopicConfigTable()
+ .entrySet()) {
+ TopicConfig topicConfig =
topicConfigMap.get(entry.getKey());
+ if (null != topicConfig) {
+ entry.getValue().setWriteQueueNums(
+ topicConfig.getWriteQueueNums() +
entry.getValue().getWriteQueueNums());
+ entry.getValue().setReadQueueNums(
+ topicConfig.getReadQueueNums() +
entry.getValue().getReadQueueNums());
}
+ topicConfigMap.put(entry.getKey(), entry.getValue());
+ }
- for (Map.Entry<String, SubscriptionGroupConfig> entry
: subscriptionGroupWrapper.getSubscriptionGroupTable().entrySet()) {
+ for (Map.Entry<String, SubscriptionGroupConfig> entry :
subscriptionGroupWrapper.getSubscriptionGroupTable()
+ .entrySet()) {
- SubscriptionGroupConfig subscriptionGroupConfig =
subGroupConfigMap.get(entry.getKey());
- if (null != subscriptionGroupConfig) {
- entry.getValue().setRetryQueueNums(
-
subscriptionGroupConfig.getRetryQueueNums() +
entry.getValue().getRetryQueueNums());
- }
- subGroupConfigMap.put(entry.getKey(),
entry.getValue());
+ SubscriptionGroupConfig subscriptionGroupConfig =
subGroupConfigMap.get(entry.getKey());
+ if (null != subscriptionGroupConfig) {
+ entry.getValue().setRetryQueueNums(
+ subscriptionGroupConfig.getRetryQueueNums() +
entry.getValue().getRetryQueueNums());
}
+ subGroupConfigMap.put(entry.getKey(),
entry.getValue());
+ }
- Map<String, Object> result = new HashMap<>();
- result.put("topicConfigTable", topicConfigMap);
- result.put("subscriptionGroupTable",
subGroupConfigMap);
- result.put("rocketmqVersion",
MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION));
- result.put("exportTime", System.currentTimeMillis());
+ }
- filePath = filePath + "/metadata.json";
- MixAll.string2FileNotSafe(JSON.toJSONString(result,
true), filePath);
- System.out.printf("export %s success", filePath);
- }
+ if (commandLine.hasOption('t')) {
Review comment:
could extract duplication like:
```java
String exportPath;
if (commandLine.hasOption('t')) {
result.put("topicConfigTable", topicConfigMap);
exportPath = filePath + "/topic.json";
} else if (commandLine.hasOption('g')) {
result.put("subscriptionGroupTable", subGroupConfigMap);
exportPath = filePath + "/topic.json";
} else {
result.put("topicConfigTable", topicConfigMap);
result.put("subscriptionGroupTable", subGroupConfigMap);
exportPath = filePath + "/metadata.json";
}
result.put("exportTime", System.currentTimeMillis());
MixAll.string2FileNotSafe(JSON.toJSONString(result, true),
exportPath);
System.out.printf("export %s success%n", exportPath);
```
--
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]