use of org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper in project rocketmq by apache.
the class ExportMetricsCommand method execute.
@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, Map<String, Map<String, Object>>> evaluateReportMap = new HashMap<>();
Map<String, Double> totalTpsMap = new HashMap<>();
Map<String, Long> totalOneDayNumMap = new HashMap<>();
initTotalMap(totalTpsMap, totalOneDayNumMap);
ClusterInfo clusterInfoSerializeWrapper = defaultMQAdminExt.examineBrokerClusterInfo();
Set<String> brokerNameSet = clusterInfoSerializeWrapper.getClusterAddrTable().get(clusterName);
for (String brokerName : brokerNameSet) {
BrokerData brokerData = clusterInfoSerializeWrapper.getBrokerAddrTable().get(brokerName);
if (brokerData != null) {
String addr = brokerData.getBrokerAddrs().get(0L);
KVTable kvTable = defaultMQAdminExt.fetchBrokerRuntimeStats(addr);
Properties properties = defaultMQAdminExt.getBrokerConfig(addr);
SubscriptionGroupWrapper subscriptionGroupWrapper = defaultMQAdminExt.getUserSubscriptionGroup(addr, 10000);
Map<String, Map<String, Object>> brokerInfo = new HashMap<>();
// broker environment,machine configuration
brokerInfo.put("runtimeEnv", getRuntimeEnv(kvTable, properties));
brokerInfo.put("runtimeQuota", getRuntimeQuota(kvTable, defaultMQAdminExt, addr, totalTpsMap, totalOneDayNumMap, subscriptionGroupWrapper));
// runtime version
brokerInfo.put("runtimeVersion", getRuntimeVersion(defaultMQAdminExt, subscriptionGroupWrapper));
evaluateReportMap.put(brokerName, brokerInfo);
}
}
String path = filePath + "/metrics.json";
Map<String, Object> totalData = new HashMap<>();
totalData.put("totalTps", totalTpsMap);
totalData.put("totalOneDayNum", totalOneDayNumMap);
Map<String, Object> result = new HashMap<>();
result.put("evaluateReport", evaluateReportMap);
result.put("totalData", totalData);
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();
}
}
use of org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper in project rocketmq by apache.
the class BrokerOuterAPI method getAllSubscriptionGroupConfig.
public SubscriptionGroupWrapper getAllSubscriptionGroupConfig(final String addr) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException {
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_SUBSCRIPTIONGROUP_CONFIG, null);
RemotingCommand response = this.remotingClient.invokeSync(addr, request, 3000);
assert response != null;
switch(response.getCode()) {
case ResponseCode.SUCCESS:
{
return SubscriptionGroupWrapper.decode(response.getBody(), SubscriptionGroupWrapper.class);
}
default:
break;
}
throw new MQBrokerException(response.getCode(), response.getRemark(), addr);
}
use of org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class MQClientAPIImpl method getAllSubscriptionGroup.
public SubscriptionGroupWrapper getAllSubscriptionGroup(final String brokerAddr, long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException {
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_SUBSCRIPTIONGROUP_CONFIG, null);
RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), brokerAddr), request, timeoutMillis);
assert response != null;
switch(response.getCode()) {
case ResponseCode.SUCCESS:
{
return SubscriptionGroupWrapper.decode(response.getBody(), SubscriptionGroupWrapper.class);
}
default:
break;
}
throw new MQBrokerException(response.getCode(), response.getRemark());
}
use of org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class BrokerOuterAPI method getAllSubscriptionGroupConfig.
public SubscriptionGroupWrapper getAllSubscriptionGroupConfig(final String addr) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException {
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_SUBSCRIPTIONGROUP_CONFIG, null);
RemotingCommand response = this.remotingClient.invokeSync(addr, request, 3000);
assert response != null;
switch(response.getCode()) {
case ResponseCode.SUCCESS:
{
return SubscriptionGroupWrapper.decode(response.getBody(), SubscriptionGroupWrapper.class);
}
default:
break;
}
throw new MQBrokerException(response.getCode(), response.getRemark());
}
use of org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class DefaultMQAdminExtTest method testGetAllSubscriptionGroup.
@Test
public void testGetAllSubscriptionGroup() throws InterruptedException, MQBrokerException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException {
SubscriptionGroupWrapper subscriptionGroupWrapper = defaultMQAdminExt.getAllSubscriptionGroup("127.0.0.1:10911", 10000);
assertThat(subscriptionGroupWrapper.getSubscriptionGroupTable().get("Consumer-group-one").getBrokerId()).isEqualTo(1234);
assertThat(subscriptionGroupWrapper.getSubscriptionGroupTable().get("Consumer-group-one").getGroupName()).isEqualTo("Consumer-group-one");
assertThat(subscriptionGroupWrapper.getSubscriptionGroupTable().get("Consumer-group-one").isConsumeBroadcastEnable()).isTrue();
}
Aggregations