-
Notifications
You must be signed in to change notification settings - Fork 11.9k
[ISSUE #3148]Support metadata export #3149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
b42acdd
[ISSUE #3148]Support metadata export
a729957
[ISSUE #3148]Support metadata export
bc6b433
[ISSUE #3148]Support metadata export
18251c1
[ISSUE #3148]Support metadata export
9f0b5cc
[ISSUE #3148]Support metadata export
c9a647d
[ISSUE #3148]Support metadata export
248f1a0
[ISSUE #3199]two timed task for RequestFutureTable
panzhi33 a643a50
[ISSUE #3148]Support metadata export
panzhi33 8d01b47
[ISSUE #3148]Support metadata export
panzhi33 3800f23
[ISSUE #3148]Support metadata export
panzhi33 5da18ea
[ISSUE #3148]Support metadata export
panzhi33 d0111c5
[ISSUE #3148]Support metadata export
panzhi33 f646fcc
[ISSUE #3148]Support metadata export
panzhi33 064a3b8
[ISSUE #3148]Support metadata export
panzhi33 b610091
[ISSUE #3148]Support metadata export
panzhi33 d47f051
[ISSUE #3148]Support metadata export
panzhi33 6013bfb
[ISSUE #3148]Support metadata export
panzhi33 d904d91
[ISSUE #3148]Support metadata export
panzhi33 6fdc201
[ISSUE #3148]Support metadata export
panzhi33 303500b
[ISSUE #3148]Support metadata export
panzhi33 2bff096
[ISSUE #3148]Support metadata export
panzhi33 107ba89
[ISSUE #3148]Support metadata export
panzhi33 da4f873
[ISSUE #3148]Support metadata export
panzhi33 27b0cfe
[ISSUE #3148]Support metadata export
panzhi33 7b2c1f6
[ISSUE #3148]Support metadata export
panzhi33 bc35d5c
[ISSUE #3148]Support metadata export
panzhi33 6de3ce7
[ISSUE #3148]Support metadata export
panzhi33 55bdbfe
[ISSUE #3148]Support metadata export
panzhi33 14be0bf
[ISSUE #3148]Support metadata export
panzhi33 75271df
[ISSUE #3148]Support metadata export
panzhi33 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/bin/bash | ||
|
||
# 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. | ||
|
||
if [ -z "$ROCKETMQ_HOME" ]; then | ||
## resolve links - $0 may be a link to maven's home | ||
PRG="$0" | ||
|
||
# need this for relative symlinks | ||
while [ -h "$PRG" ]; do | ||
ls=$(ls -ld "$PRG") | ||
link=$(expr "$ls" : '.*-> \(.*\)$') | ||
if expr "$link" : '/.*' >/dev/null; then | ||
PRG="$link" | ||
else | ||
PRG="$(dirname "$PRG")/$link" | ||
fi | ||
done | ||
|
||
saveddir=$(pwd) | ||
|
||
ROCKETMQ_HOME=$(dirname "$PRG")/.. | ||
|
||
# make it fully qualified | ||
ROCKETMQ_HOME=$(cd "$ROCKETMQ_HOME" && pwd) | ||
|
||
cd "$saveddir" | ||
fi | ||
|
||
export ROCKETMQ_HOME | ||
|
||
namesrvAddr= | ||
while [ -z "${namesrvAddr}" ]; do | ||
read -p "Enter name server address list:" namesrvAddr | ||
done | ||
|
||
clusterName= | ||
while [ -z "${clusterName}" ]; do | ||
read -p "Choose a cluster to export:" clusterName | ||
done | ||
|
||
read -p "Enter file path to export [default /tmp/rocketmq/export]:" filePath | ||
if [ -z "${filePath}" ]; then | ||
filePath="/tmp/rocketmq/config" | ||
fi | ||
|
||
if [[ -e ${filePath} ]]; then | ||
rm -rf ${filePath} | ||
fi | ||
|
||
sh ${ROCKETMQ_HOME}/bin/mqadmin exportMetrics -c ${clusterName} -n ${namesrvAddr} -f ${filePath} | ||
sh ${ROCKETMQ_HOME}/bin/mqadmin exportConfigs -c ${clusterName} -n ${namesrvAddr} -f ${filePath} | ||
sh ${ROCKETMQ_HOME}/bin/mqadmin exportMetadata -c ${clusterName} -n ${namesrvAddr} -f ${filePath} | ||
|
||
cd ${filePath} || exit | ||
|
||
configs=$(cat ./configs.json) | ||
if [ -z "$configs" ]; then | ||
configs="{}" | ||
fi | ||
metadata=$(cat ./metadata.json) | ||
if [ -z "$metadata" ]; then | ||
metadata="{}" | ||
fi | ||
metrics=$(cat ./metrics.json) | ||
if [ -z "$metrics" ]; then | ||
metrics="{}" | ||
fi | ||
|
||
echo "{ | ||
\"configs\": ${configs}, | ||
\"metadata\": ${metadata}, | ||
\"metrics\": ${metrics} | ||
}" >rocketmq-metadata-export.json | ||
|
||
echo -e "[INFO] The RocketMQ metadata has been exported to the file:${filePath}/rocketmq-metadata-export.json" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
tools/src/main/java/org/apache/rocketmq/tools/command/export/ExportConfigsCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
* 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 org.apache.rocketmq.tools.command.export; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
|
||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.Option; | ||
import org.apache.commons.cli.Options; | ||
import org.apache.rocketmq.common.MixAll; | ||
import org.apache.rocketmq.remoting.RPCHook; | ||
import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; | ||
import org.apache.rocketmq.tools.command.CommandUtil; | ||
import org.apache.rocketmq.tools.command.SubCommand; | ||
import org.apache.rocketmq.tools.command.SubCommandException; | ||
|
||
public class ExportConfigsCommand implements SubCommand { | ||
@Override | ||
public String commandName() { | ||
return "exportConfigs"; | ||
} | ||
|
||
@Override | ||
public String commandDesc() { | ||
return "export configs"; | ||
} | ||
|
||
@Override | ||
public Options buildCommandlineOptions(Options options) { | ||
Option opt = new Option("c", "clusterName", true, "choose a cluster to export"); | ||
opt.setRequired(true); | ||
options.addOption(opt); | ||
|
||
opt = new Option("f", "filePath", true, | ||
"export configs.json path | default /tmp/rocketmq/export"); | ||
opt.setRequired(false); | ||
options.addOption(opt); | ||
return options; | ||
} | ||
|
||
@Override | ||
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) | ||
throws SubCommandException { | ||
DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); | ||
defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); | ||
|
||
try { | ||
String clusterName = commandLine.getOptionValue('c').trim(); | ||
String filePath = !commandLine.hasOption('f') ? "/tmp/rocketmq/export" : commandLine.getOptionValue('f') | ||
.trim(); | ||
|
||
defaultMQAdminExt.start(); | ||
Map<String, Object> result = new HashMap<>(); | ||
// name servers | ||
List<String> nameServerAddressList = defaultMQAdminExt.getNameServerAddressList(); | ||
|
||
//broker | ||
int masterBrokerSize = 0; | ||
int slaveBrokerSize = 0; | ||
Map<String, Properties> brokerConfigs = new HashMap<>(); | ||
Map<String, List<String>> masterAndSlaveMap | ||
= CommandUtil.fetchMasterAndSlaveDistinguish(defaultMQAdminExt, clusterName); | ||
for (String masterAddr : masterAndSlaveMap.keySet()) { | ||
Properties masterProperties = defaultMQAdminExt.getBrokerConfig(masterAddr); | ||
masterBrokerSize++; | ||
slaveBrokerSize += masterAndSlaveMap.get(masterAddr).size(); | ||
|
||
brokerConfigs.put(masterProperties.getProperty("brokerName"), needBrokerProprties(masterProperties)); | ||
} | ||
|
||
Map<String, Integer> clusterScaleMap = new HashMap<>(); | ||
clusterScaleMap.put("namesrvSize", nameServerAddressList.size()); | ||
clusterScaleMap.put("masterBrokerSize", masterBrokerSize); | ||
clusterScaleMap.put("slaveBrokerSize", slaveBrokerSize); | ||
|
||
result.put("brokerConfigs", brokerConfigs); | ||
result.put("clusterScale", clusterScaleMap); | ||
|
||
String path = filePath + "/configs.json"; | ||
MixAll.string2FileNotSafe(JSON.toJSONString(result, true), path); | ||
System.out.printf("export %s success", path); | ||
} catch (Exception e) { | ||
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); | ||
} finally { | ||
defaultMQAdminExt.shutdown(); | ||
} | ||
} | ||
|
||
private Properties needBrokerProprties(Properties properties) { | ||
Properties newProperties = new Properties(); | ||
newProperties.setProperty("brokerClusterName", properties.getProperty("brokerClusterName")); | ||
newProperties.setProperty("brokerId", properties.getProperty("brokerId")); | ||
newProperties.setProperty("brokerName", properties.getProperty("brokerName")); | ||
newProperties.setProperty("brokerRole", properties.getProperty("brokerRole")); | ||
newProperties.setProperty("fileReservedTime", properties.getProperty("fileReservedTime")); | ||
newProperties.setProperty("filterServerNums", properties.getProperty("filterServerNums")); | ||
newProperties.setProperty("flushDiskType", properties.getProperty("flushDiskType")); | ||
newProperties.setProperty("maxMessageSize", properties.getProperty("maxMessageSize")); | ||
newProperties.setProperty("messageDelayLevel", properties.getProperty("messageDelayLevel")); | ||
newProperties.setProperty("msgTraceTopicName", properties.getProperty("msgTraceTopicName")); | ||
newProperties.setProperty("slaveReadEnable", properties.getProperty("slaveReadEnable")); | ||
newProperties.setProperty("traceOn", properties.getProperty("traceOn")); | ||
newProperties.setProperty("traceTopicEnable", properties.getProperty("traceTopicEnable")); | ||
newProperties.setProperty("useTLS", properties.getProperty("useTLS")); | ||
newProperties.setProperty("autoCreateTopicEnable", properties.getProperty("autoCreateTopicEnable")); | ||
newProperties.setProperty("autoCreateSubscriptionGroup", properties.getProperty("autoCreateSubscriptionGroup")); | ||
return newProperties; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Define a constant for
"/tmp/rocketmq/export"