use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq by apache.
the class ResetOffsetByTimeOldCommand 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 consumerGroup = commandLine.getOptionValue("g").trim();
String topic = commandLine.getOptionValue("t").trim();
String timeStampStr = commandLine.getOptionValue("s").trim();
long timestamp = 0;
try {
timestamp = Long.parseLong(timeStampStr);
} catch (NumberFormatException e) {
Date date = UtilAll.parseDate(timeStampStr, UtilAll.YYYY_MM_DD_HH_MM_SS_SSS);
if (date != null) {
timestamp = UtilAll.parseDate(timeStampStr, UtilAll.YYYY_MM_DD_HH_MM_SS_SSS).getTime();
} else {
System.out.printf("specified timestamp invalid.%n");
return;
}
boolean force = true;
if (commandLine.hasOption('f')) {
force = Boolean.valueOf(commandLine.getOptionValue("f").trim());
}
defaultMQAdminExt.start();
resetOffset(defaultMQAdminExt, consumerGroup, topic, timestamp, force, timeStampStr);
}
} catch (Exception e) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
} finally {
defaultMQAdminExt.shutdown();
}
}
use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq by apache.
the class AllocateMQSubCommand method execute.
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook);
adminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
try {
adminExt.start();
String topic = commandLine.getOptionValue('t').trim();
String ips = commandLine.getOptionValue('i').trim();
final String[] split = ips.split(",");
final List<String> ipList = new LinkedList<String>();
for (String ip : split) {
ipList.add(ip);
}
final TopicRouteData topicRouteData = adminExt.examineTopicRouteInfo(topic);
final Set<MessageQueue> mqs = MQClientInstance.topicRouteData2TopicSubscribeInfo(topic, topicRouteData);
final AllocateMessageQueueAveragely averagely = new AllocateMessageQueueAveragely();
RebalanceResult rr = new RebalanceResult();
for (String i : ipList) {
final List<MessageQueue> mqResult = averagely.allocate("aa", i, new ArrayList<MessageQueue>(mqs), ipList);
rr.getResult().put(i, mqResult);
}
final String json = RemotingSerializable.toJson(rr, false);
System.out.printf("%s%n", json);
} catch (Exception e) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
} finally {
adminExt.shutdown();
}
}
use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq by apache.
the class TopicClusterSubCommand 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()));
String topic = commandLine.getOptionValue('t').trim();
try {
defaultMQAdminExt.start();
Set<String> clusters = defaultMQAdminExt.getTopicClusterList(topic);
for (String value : clusters) {
System.out.printf("%s%n", value);
}
} catch (Exception e) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
} finally {
defaultMQAdminExt.shutdown();
}
}
use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq by apache.
the class TopicStatusSubCommand 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();
String topic = commandLine.getOptionValue('t').trim();
TopicStatsTable topicStatsTable = defaultMQAdminExt.examineTopicStats(topic);
List<MessageQueue> mqList = new LinkedList<MessageQueue>();
mqList.addAll(topicStatsTable.getOffsetTable().keySet());
Collections.sort(mqList);
System.out.printf("%-32s %-4s %-20s %-20s %s%n", "#Broker Name", "#QID", "#Min Offset", "#Max Offset", "#Last Updated");
for (MessageQueue mq : mqList) {
TopicOffset topicOffset = topicStatsTable.getOffsetTable().get(mq);
String humanTimestamp = "";
if (topicOffset.getLastUpdateTimestamp() > 0) {
humanTimestamp = UtilAll.timeMillisToHumanString2(topicOffset.getLastUpdateTimestamp());
}
System.out.printf("%-32s %-4d %-20d %-20d %s%n", UtilAll.frontStringAtLeast(mq.getBrokerName(), 32), mq.getQueueId(), topicOffset.getMinOffset(), topicOffset.getMaxOffset(), humanTimestamp);
}
} catch (Exception e) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
} finally {
defaultMQAdminExt.shutdown();
}
}
use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq by apache.
the class UpdateOrderConfCommand 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 {
String topic = commandLine.getOptionValue('t').trim();
String type = commandLine.getOptionValue('m').trim();
if ("get".equals(type)) {
defaultMQAdminExt.start();
String orderConf = defaultMQAdminExt.getKVConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, topic);
System.out.printf("get orderConf success. topic=[%s], orderConf=[%s] ", topic, orderConf);
return;
} else if ("put".equals(type)) {
defaultMQAdminExt.start();
String orderConf = "";
if (commandLine.hasOption('v')) {
orderConf = commandLine.getOptionValue('v').trim();
}
if (UtilAll.isBlank(orderConf)) {
throw new Exception("please set orderConf with option -v.");
}
defaultMQAdminExt.createOrUpdateOrderConf(topic, orderConf, true);
System.out.printf("update orderConf success. topic=[%s], orderConf=[%s]", topic, orderConf.toString());
return;
} else if ("delete".equals(type)) {
defaultMQAdminExt.start();
defaultMQAdminExt.deleteKvConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, topic);
System.out.printf("delete orderConf success. topic=[%s]", topic);
return;
}
ServerUtil.printCommandLineHelp("mqadmin " + this.commandName(), options);
} catch (Exception e) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
} finally {
defaultMQAdminExt.shutdown();
}
}
Aggregations