Search in sources :

Example 71 with SubCommandException

use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class UpdateTopicPermSubCommand method execute.

@Override
public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        defaultMQAdminExt.start();
        TopicConfig topicConfig = new TopicConfig();
        String topic = commandLine.getOptionValue('t').trim();
        TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);
        assert topicRouteData != null;
        List<QueueData> queueDatas = topicRouteData.getQueueDatas();
        assert queueDatas != null && queueDatas.size() > 0;
        QueueData queueData = queueDatas.get(0);
        topicConfig.setTopicName(topic);
        topicConfig.setWriteQueueNums(queueData.getWriteQueueNums());
        topicConfig.setReadQueueNums(queueData.getReadQueueNums());
        topicConfig.setPerm(queueData.getPerm());
        topicConfig.setTopicSysFlag(queueData.getTopicSynFlag());
        // new perm
        int perm = Integer.parseInt(commandLine.getOptionValue('p').trim());
        int oldPerm = topicConfig.getPerm();
        if (perm == oldPerm) {
            System.out.printf("new perm equals to the old one!%n");
            return;
        }
        topicConfig.setPerm(perm);
        if (commandLine.hasOption('b')) {
            String addr = commandLine.getOptionValue('b').trim();
            defaultMQAdminExt.createAndUpdateTopicConfig(addr, topicConfig);
            System.out.printf("update topic perm from %s to %s in %s success.%n", oldPerm, perm, addr);
            System.out.printf("%s%n", topicConfig);
            return;
        } else if (commandLine.hasOption('c')) {
            String clusterName = commandLine.getOptionValue('c').trim();
            Set<String> masterSet = CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName);
            for (String addr : masterSet) {
                defaultMQAdminExt.createAndUpdateTopicConfig(addr, topicConfig);
                System.out.printf("update topic perm from %s to %s in %s success.%n", oldPerm, perm, addr);
            }
            return;
        }
        ServerUtil.printCommandLineHelp("mqadmin " + this.commandName(), options);
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
Also used : Set(java.util.Set) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) QueueData(org.apache.rocketmq.common.protocol.route.QueueData) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) TopicConfig(org.apache.rocketmq.common.TopicConfig) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 72 with SubCommandException

use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq by apache.

the class UpdateBrokerConfigSubCommand 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 key = commandLine.getOptionValue('k').trim();
        String value = commandLine.getOptionValue('v').trim();
        Properties properties = new Properties();
        properties.put(key, value);
        if (commandLine.hasOption('b')) {
            String brokerAddr = commandLine.getOptionValue('b').trim();
            defaultMQAdminExt.start();
            defaultMQAdminExt.updateBrokerConfig(brokerAddr, properties);
            System.out.printf("update broker config success, %s\n", brokerAddr);
            return;
        } else if (commandLine.hasOption('c')) {
            String clusterName = commandLine.getOptionValue('c').trim();
            defaultMQAdminExt.start();
            Set<String> masterSet = CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName);
            for (String brokerAddr : masterSet) {
                try {
                    defaultMQAdminExt.updateBrokerConfig(brokerAddr, properties);
                    System.out.printf("update broker config success, %s\n", brokerAddr);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return;
        }
        ServerUtil.printCommandLineHelp("mqadmin " + this.commandName(), options);
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
Also used : Set(java.util.Set) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) Properties(java.util.Properties) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException)

Example 73 with SubCommandException

use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq by apache.

the class ClusterListSubCommand method execute.

@Override
public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    long printInterval = 1;
    boolean enableInterval = commandLine.hasOption('i');
    if (enableInterval) {
        printInterval = Long.parseLong(commandLine.getOptionValue('i')) * 1000;
    }
    try {
        defaultMQAdminExt.start();
        long i = 0;
        do {
            if (i++ > 0) {
                Thread.sleep(printInterval);
            }
            if (commandLine.hasOption('m')) {
                this.printClusterMoreStats(defaultMQAdminExt);
            } else {
                this.printClusterBaseInfo(defaultMQAdminExt);
            }
        } while (enableInterval);
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
Also used : SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) RemotingTimeoutException(org.apache.rocketmq.remoting.exception.RemotingTimeoutException) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) RemotingConnectException(org.apache.rocketmq.remoting.exception.RemotingConnectException) RemotingSendRequestException(org.apache.rocketmq.remoting.exception.RemotingSendRequestException)

Example 74 with SubCommandException

use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq by apache.

the class ConsumerConnectionSubCommand 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 {
        defaultMQAdminExt.start();
        String group = commandLine.getOptionValue('g').trim();
        ConsumerConnection cc = defaultMQAdminExt.examineConsumerConnectionInfo(group);
        int i = 1;
        for (Connection conn : cc.getConnectionSet()) {
            System.out.printf("%03d  %-32s %-22s %-8s %s%n", i++, conn.getClientId(), conn.getClientAddr(), conn.getLanguage(), MQVersion.getVersionDesc(conn.getVersion()));
        }
        System.out.printf("%nBelow is subscription:");
        Iterator<Entry<String, SubscriptionData>> it = cc.getSubscriptionTable().entrySet().iterator();
        i = 1;
        while (it.hasNext()) {
            Entry<String, SubscriptionData> entry = it.next();
            SubscriptionData sd = entry.getValue();
            System.out.printf("%03d  Topic: %-40s SubExpression: %s%n", i++, sd.getTopic(), sd.getSubString());
        }
        System.out.printf("");
        System.out.printf("ConsumeType: %s%n", cc.getConsumeType());
        System.out.printf("MessageModel: %s%n", cc.getMessageModel());
        System.out.printf("ConsumeFromWhere: %s%n", cc.getConsumeFromWhere());
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
Also used : Entry(java.util.Map.Entry) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) Connection(org.apache.rocketmq.common.protocol.body.Connection) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException)

Example 75 with SubCommandException

use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq by apache.

the class StatsAllSubCommand 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 {
        defaultMQAdminExt.start();
        TopicList topicList = defaultMQAdminExt.fetchAllTopicList();
        System.out.printf("%-32s  %-32s %12s %11s %11s %14s %14s%n", "#Topic", "#Consumer Group", "#Accumulation", "#InTPS", "#OutTPS", "#InMsg24Hour", "#OutMsg24Hour");
        boolean activeTopic = commandLine.hasOption('a');
        String selectTopic = commandLine.getOptionValue('t');
        for (String topic : topicList.getTopicList()) {
            if (topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX) || topic.startsWith(MixAll.DLQ_GROUP_TOPIC_PREFIX)) {
                continue;
            }
            if (selectTopic != null && !selectTopic.isEmpty() && !topic.equals(selectTopic)) {
                continue;
            }
            try {
                printTopicDetail(defaultMQAdminExt, topic, activeTopic);
            } catch (Exception e) {
            }
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
Also used : SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) 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)

Aggregations

SubCommandException (org.apache.rocketmq.tools.command.SubCommandException)88 DefaultMQAdminExt (org.apache.rocketmq.tools.admin.DefaultMQAdminExt)76 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)22 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)16 MQClientException (org.apache.rocketmq.client.exception.MQClientException)16 Set (java.util.Set)14 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)12 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 LinkedList (java.util.LinkedList)8 Map (java.util.Map)8 DefaultMQProducer (org.apache.rocketmq.client.producer.DefaultMQProducer)8 Connection (org.apache.rocketmq.common.protocol.body.Connection)8 ConsumerConnection (org.apache.rocketmq.common.protocol.body.ConsumerConnection)8 TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)8 Date (java.util.Date)6 Entry (java.util.Map.Entry)6 Properties (java.util.Properties)6 DefaultMQPullConsumer (org.apache.rocketmq.client.consumer.DefaultMQPullConsumer)6 PullResult (org.apache.rocketmq.client.consumer.PullResult)6 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)6