@Ignore @Test public void testExecute() throws SubCommandException { UpdateBrokerConfigSubCommand cmd = new UpdateBrokerConfigSubCommand(); Options options = ServerUtil.buildCommandlineOptions(new Options()); String[] subargs = new String[] {"-b 127.0.0.1:10911", "-c default-cluster", "-k topicname", "-v unit_test"}; final CommandLine commandLine = ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser()); cmd.execute(commandLine, options, null); }
@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(); } }
UpdateBrokerConfigSubCommand implements SubCommand { @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(); } } }
UpdateBrokerConfigSubCommand implements SubCommand { @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(); } }  }
UpdateBrokerConfigSubCommand implements SubCommand { @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(); } }  @Override String commandName(); @Override String commandDesc(); @Override Options buildCommandlineOptions(Options options); @Override void execute(CommandLine commandLine, Options options, RPCHook rpcHook); }
UpdateBrokerConfigSubCommand implements SubCommand { @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(); } }  @Override String commandName(); @Override String commandDesc(); @Override Options buildCommandlineOptions(Options options); @Override void execute(CommandLine commandLine, Options options, RPCHook rpcHook);  }