Search in sources :

Example 6 with SubscriptionGroupWrapper

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();
    }
}
Also used : KVTable(org.apache.rocketmq.common.protocol.body.KVTable) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) HashMap(java.util.HashMap) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) Properties(java.util.Properties) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException) ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) HashMap(java.util.HashMap) Map(java.util.Map) SubscriptionGroupWrapper(org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper)

Example 7 with SubscriptionGroupWrapper

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);
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) SubscriptionGroupWrapper(org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper)

Example 8 with SubscriptionGroupWrapper

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());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) SubscriptionGroupWrapper(org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper)

Example 9 with SubscriptionGroupWrapper

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());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) SubscriptionGroupWrapper(org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper)

Example 10 with SubscriptionGroupWrapper

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();
}
Also used : SubscriptionGroupWrapper(org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper) Test(org.junit.Test)

Aggregations

SubscriptionGroupWrapper (org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper)17 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)8 Map (java.util.Map)7 SubscriptionGroupConfig (org.apache.rocketmq.common.subscription.SubscriptionGroupConfig)6 HashMap (java.util.HashMap)5 MQClientException (org.apache.rocketmq.client.exception.MQClientException)5 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)5 ArrayList (java.util.ArrayList)4 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)4 Set (java.util.Set)3 KVTable (org.apache.rocketmq.common.protocol.body.KVTable)3 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)3 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 HashSet (java.util.HashSet)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 TreeSet (java.util.TreeSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 SubscriptionGroupManager (org.apache.rocketmq.broker.subscription.SubscriptionGroupManager)2