use of com.sun.messaging.jmq.admin.bkrutil.BrokerAdmin in project openmq by eclipse-ee4j.
the class CmdRunner method runMetrics.
private int runMetrics(BrokerCmdProperties brokerCmdProps) {
BrokerAdmin broker;
BrokerCmdPrinter bcp;
String commandArg;
long sleepTime;
int metricType, metricSamples;
broker = init();
commandArg = brokerCmdProps.getCommandArg();
sleepTime = brokerCmdProps.getMetricInterval();
metricType = getMetricType(brokerCmdProps);
metricSamples = brokerCmdProps.getMetricSamples();
if (CMDARG_SERVICE.equals(commandArg)) {
bcp = setupMetricTitle(commandArg, metricType);
if (broker == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_METRICS_SVC_FAIL));
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
String svcName = brokerCmdProps.getTargetName();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_METRICS_SVC));
printServiceInfo();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_SPECIFY_BKR));
printBrokerInfo(broker);
try {
MetricCounters previousMetrics = null;
int rowsPrinted = 0;
connectToBroker(broker);
while (true) {
broker.sendGetMetricsMessage(svcName);
MetricCounters mc = (MetricCounters) broker.receiveGetMetricsReplyMessage();
if (mc == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_METRICS_SVC_FAIL));
return (1);
}
addOneMetricRow(metricType, bcp, mc, previousMetrics);
if ((rowsPrinted % 20) == 0) {
bcp.print();
} else {
bcp.print(false);
}
bcp.clear();
previousMetrics = mc;
rowsPrinted++;
if (metricSamples > 0) {
if (metricSamples == rowsPrinted) {
break;
}
}
try {
Thread.sleep(sleepTime * 1000);
} catch (InterruptedException ie) {
Globals.stdErrPrintln(ie.toString());
}
}
Globals.stdOutPrintln("");
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_METRICS_SVC_SUC));
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_METRICS_SVC_FAIL));
return (1);
}
} else if (CMDARG_BROKER.equals(commandArg)) {
if (broker == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_METRICS_BKR_FAIL));
return (1);
}
bcp = setupMetricTitle(commandArg, metricType);
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_METRICS_BKR));
printBrokerInfo(broker);
try {
MetricCounters previousMetrics = null;
int rowsPrinted = 0;
connectToBroker(broker);
while (true) {
broker.sendGetMetricsMessage(null);
MetricCounters mc = (MetricCounters) broker.receiveGetMetricsReplyMessage();
if (mc == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_METRICS_BKR_FAIL));
return (1);
}
addOneMetricRow(metricType, bcp, mc, previousMetrics);
if ((rowsPrinted % 20) == 0) {
bcp.print();
} else {
bcp.print(false);
}
bcp.clear();
previousMetrics = mc;
rowsPrinted++;
if (metricSamples > 0) {
if (metricSamples == rowsPrinted) {
break;
}
}
try {
Thread.sleep(sleepTime * 1000);
} catch (InterruptedException ie) {
Globals.stdErrPrintln(ie.toString());
}
}
Globals.stdOutPrintln("");
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_METRICS_BKR_SUC));
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_METRICS_BKR_FAIL));
return (1);
}
} else if (CMDARG_DESTINATION.equals(commandArg)) {
String destName;
int destTypeMask;
destName = brokerCmdProps.getTargetName();
destTypeMask = getDestTypeMask(brokerCmdProps);
bcp = setupDestMetricTitle(commandArg, metricType, destTypeMask);
if (broker == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_METRICS_DST_FAIL));
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_METRICS_DST));
printDestinationInfo();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_SPECIFY_BKR));
printBrokerInfo(broker);
try {
DestMetricsCounters previousMetrics = null;
int rowsPrinted = 0;
connectToBroker(broker);
while (true) {
broker.sendGetMetricsMessage(destName, destTypeMask);
DestMetricsCounters mc = (DestMetricsCounters) broker.receiveGetMetricsReplyMessage();
if (mc == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_METRICS_DST_FAIL));
return (1);
}
addOneDestMetricRow(metricType, destTypeMask, bcp, mc, previousMetrics);
if ((rowsPrinted % 20) == 0) {
bcp.print();
} else {
bcp.print(false);
}
bcp.clear();
previousMetrics = mc;
rowsPrinted++;
if (metricSamples > 0) {
if (metricSamples == rowsPrinted) {
break;
}
}
try {
Thread.sleep(sleepTime * 1000);
} catch (InterruptedException ie) {
Globals.stdErrPrintln(ie.toString());
}
}
Globals.stdOutPrintln("");
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_METRICS_DST_SUC));
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_METRICS_DST_FAIL));
return (1);
}
}
if (broker.isConnected()) {
broker.close();
}
return (0);
}
use of com.sun.messaging.jmq.admin.bkrutil.BrokerAdmin in project openmq by eclipse-ee4j.
the class CmdRunner method runTakeover.
private int runTakeover(BrokerCmdProperties brokerCmdProps) {
BrokerAdmin broker;
String input = null;
String yes, yesShort, no, noShort;
yes = ar.getString(ar.Q_RESPONSE_YES);
yesShort = ar.getString(ar.Q_RESPONSE_YES_SHORT);
no = ar.getString(ar.Q_RESPONSE_NO);
noShort = ar.getString(ar.Q_RESPONSE_NO_SHORT);
broker = init();
boolean force = brokerCmdProps.forceModeSet();
// Check for the target argument
String commandArg = brokerCmdProps.getCommandArg();
if (CMDARG_BROKER.equals(commandArg)) {
String brokerID = brokerCmdProps.getTargetName();
if (broker == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_TAKEOVER_BKR_FAIL));
return (1);
}
if (!force)
broker = promptForAuthentication(broker);
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_TAKEOVER_BKR));
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_BKR_PERFORMING_TAKEOVER));
printBrokerInfo(broker);
try {
connectToBroker(broker);
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_TAKEOVER_BKR_FAIL));
return (1);
}
try {
/*
* Get broker props to find out if broker is in HA cluster and broker cluster ID
*/
broker.sendGetBrokerPropsMessage();
Properties bkrProps = broker.receiveGetBrokerPropsReplyMessage();
/*
* Check if cluster is HA or not
*/
String value1 = bkrProps.getProperty(PROP_NAME_BKR_CLS_HA);
String value2 = bkrProps.getProperty(PROP_NAME_BKR_STORE_MIGRATABLE);
if (!Boolean.parseBoolean(value1) && !Boolean.parseBoolean(value2)) {
Globals.stdErrPrintln(ar.getString(ar.E_BROKER_NO_TAKEOVER_SUPPORT));
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_TAKEOVER_BKR_FAIL));
return (1);
}
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_BKR_FAIL));
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_TAKEOVER_BKR_FAIL));
return (1);
}
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_BKR_STORE_TAKEOVER));
BrokerCmdPrinter bcp = new BrokerCmdPrinter(5, 3, "-");
String[] row = new String[5];
bcp.setSortNeeded(false);
bcp.setTitleAlign(BrokerCmdPrinter.CENTER);
int i = 0;
row[i++] = "";
row[i++] = "";
row[i++] = "";
row[i++] = "";
row[i++] = ar.getString(ar.I_JMQCMD_CLS_TIME_SINCE_TIMESTAMP1);
bcp.addTitle(row);
i = 0;
row[i++] = ar.getString(ar.I_JMQCMD_CLS_BROKER_ID);
row[i++] = ar.getString(ar.I_JMQCMD_CLS_ADDRESS);
row[i++] = ar.getString(ar.I_JMQCMD_CLS_BROKER_STATE);
row[i++] = ar.getString(ar.I_JMQCMD_CLS_NUM_MSGS);
row[i++] = ar.getString(ar.I_JMQCMD_CLS_TIME_SINCE_TIMESTAMP2);
bcp.addTitle(row);
/*
* Get state of each broker in cluster
*/
Vector bkrList = null;
try {
broker.sendGetClusterMessage(true);
bkrList = broker.receiveGetClusterReplyMessage();
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.E_FAILED_TO_OBTAIN_CLUSTER_INFO));
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_TAKEOVER_BKR_FAIL));
return (1);
}
String brokerIDFromList = null;
boolean found = false;
Enumeration thisEnum = bkrList.elements();
while (thisEnum.hasMoreElements()) {
Hashtable bkrClsInfo = (Hashtable) thisEnum.nextElement();
Long tmpLong;
Integer tmpInt;
long idle;
brokerIDFromList = (String) bkrClsInfo.get(BrokerClusterInfo.ID);
if ((brokerIDFromList == null) || (!brokerIDFromList.equals(brokerID))) {
continue;
}
found = true;
i = 0;
row[i++] = checkNullAndPrint(brokerIDFromList);
row[i++] = checkNullAndPrint(bkrClsInfo.get(BrokerClusterInfo.ADDRESS));
tmpInt = (Integer) bkrClsInfo.get(BrokerClusterInfo.STATE);
if (tmpInt != null) {
row[i++] = BrokerState.toString(tmpInt.intValue());
} else {
row[i++] = "";
}
tmpLong = (Long) bkrClsInfo.get(BrokerClusterInfo.NUM_MSGS);
row[i++] = checkNullAndPrint(tmpLong);
tmpLong = (Long) bkrClsInfo.get(BrokerClusterInfo.STATUS_TIMESTAMP);
if (tmpLong != null) {
idle = System.currentTimeMillis() - tmpLong.longValue();
row[i++] = CommonCmdRunnerUtil.getTimeString(idle);
} else {
row[i++] = "";
}
bcp.add(row);
/*
* Only need to display info on the one desired broker
*/
break;
}
if (!found) {
Globals.stdErrPrintln(ar.getString(ar.E_CANNOT_FIND_BROKERID, brokerID));
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_TAKEOVER_BKR_FAIL));
return (1);
}
bcp.println();
if (!force) {
input = CommonCmdRunnerUtil.getUserInput(ar.getString(ar.Q_TAKEOVER_BKR_OK), noShort);
Globals.stdOutPrintln("");
}
if (yesShort.equalsIgnoreCase(input) || yes.equalsIgnoreCase(input) || force) {
try {
broker.sendTakeoverMessage(brokerID);
broker.receiveTakeoverReplyMessage();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_TAKEOVER_BKR_SUC));
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_TAKEOVER_BKR_FAIL));
return (1);
}
} else if (noShort.equalsIgnoreCase(input) || no.equalsIgnoreCase(input)) {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_TAKEOVER_BKR_NOOP));
return (0);
} else {
Globals.stdOutPrintln(ar.getString(ar.I_UNRECOGNIZED_RES, input));
Globals.stdOutPrintln("");
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_TAKEOVER_BKR_NOOP));
return (1);
}
}
broker.close();
return (0);
}
use of com.sun.messaging.jmq.admin.bkrutil.BrokerAdmin in project openmq by eclipse-ee4j.
the class CmdRunner method runMigrateStore.
private int runMigrateStore(BrokerCmdProperties brokerCmdProps) {
BrokerAdmin broker;
String input = null;
String yes, yesShort, no, noShort;
yes = ar.getString(ar.Q_RESPONSE_YES);
yesShort = ar.getString(ar.Q_RESPONSE_YES_SHORT);
no = ar.getString(ar.Q_RESPONSE_NO);
noShort = ar.getString(ar.Q_RESPONSE_NO_SHORT);
broker = init();
boolean force = brokerCmdProps.forceModeSet();
// Check for the target argument
String commandArg = brokerCmdProps.getCommandArg();
Properties targetAttrs = brokerCmdProps.getTargetAttrs();
String partition = targetAttrs.getProperty(BrokerCmdOptions.PROP_NAME_OPTION_PARTITION);
if (CMDARG_BROKER.equals(commandArg)) {
String brokerID = brokerCmdProps.getTargetName();
if (brokerID == null && partition != null) {
Globals.stdErrPrintln(ar.getString(ar.E_MIGRATE_PARTITION_NO_TARGET_BROKER, partition));
return (1);
}
if (broker == null) {
if (partition == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_MIGRATESTORE_BKR_FAIL_NOT_MIGRATED));
} else {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_MIGRATE_PARTITION_FAIL_NOT_MIGRATED, partition, brokerID));
}
return (1);
}
if (!force) {
broker = promptForAuthentication(broker);
}
if (partition == null) {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_MIGRATESTORE_BKR));
} else {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_MIGRATE_PARTITION, partition));
}
printBrokerInfo(broker);
try {
connectToBroker(broker);
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
if (partition == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_MIGRATESTORE_BKR_FAIL_NOT_MIGRATED));
} else {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_MIGRATE_PARTITION_FAIL_NOT_MIGRATED, partition, brokerID));
}
return (1);
}
// boolean isHA = false;
try {
/*
* Get broker props to find out if broker is in HA/BDBREP cluster and broker cluster ID
*/
broker.sendGetBrokerPropsMessage();
Properties bkrProps = broker.receiveGetBrokerPropsReplyMessage();
/*
* Check if cluster is HA or not
*/
// String value1 = bkrProps.getProperty(PROP_NAME_BKR_CLS_HA);
String value2 = bkrProps.getProperty(PROP_NAME_BKR_STORE_MIGRATABLE);
String value3 = bkrProps.getProperty(PROP_NAME_BKR_PARTITION_MIGRATABLE);
// isHA = Boolean.valueOf(value1).booleanValue();
if (partition == null && !Boolean.parseBoolean(value2)) {
Globals.stdErrPrintln(ar.getString(ar.E_BROKER_NO_STORE_MIGRATION_SUPPORT));
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_MIGRATESTORE_BKR_FAIL_NOT_MIGRATED));
return (1);
}
if (partition != null && !Boolean.parseBoolean(value3)) {
Globals.stdErrPrintln(ar.getString(ar.E_MIGRATE_PARTITION_NO_SUPPORT));
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_MIGRATE_PARTITION_FAIL_NOT_MIGRATED, partition, brokerID));
return (1);
}
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_BKR_FAIL));
if (partition == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_MIGRATESTORE_BKR_FAIL_NOT_MIGRATED));
} else {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_MIGRATE_PARTITION_FAIL_NOT_MIGRATED, partition, brokerID));
}
return (1);
}
if (brokerID != null) {
if (partition == null) {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_MIGRATESTORE_BKR_TO));
} else {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_MIGRATE_PARTITION_TO, partition));
}
int numcolums = 4;
if (partition != null) {
numcolums = 5;
}
BrokerCmdPrinter bcp = new BrokerCmdPrinter(numcolums, 3, "-");
String[] row = new String[numcolums];
bcp.setSortNeeded(false);
bcp.setTitleAlign(BrokerCmdPrinter.CENTER);
int i = 0;
row[i++] = "";
row[i++] = "";
row[i++] = "";
row[i++] = ar.getString(ar.I_JMQCMD_CLS_TIME_SINCE_TIMESTAMP1);
if (partition != null) {
row[i++] = "";
}
bcp.addTitle(row);
i = 0;
row[i++] = ar.getString(ar.I_JMQCMD_CLS_BROKER_ID);
row[i++] = ar.getString(ar.I_JMQCMD_CLS_ADDRESS);
row[i++] = ar.getString(ar.I_JMQCMD_CLS_BROKER_STATE);
row[i++] = ar.getString(ar.I_JMQCMD_CLS_TIME_SINCE_TIMESTAMP2);
if (partition != null) {
row[i++] = ar.getString(ar.I_JMQCMD_NUM_PARTITION);
}
bcp.addTitle(row);
/*
* Get state of each broker in cluster
*/
Vector bkrList = null;
try {
broker.sendGetClusterMessage(true);
bkrList = broker.receiveGetClusterReplyMessage();
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.E_FAILED_TO_OBTAIN_CLUSTER_INFO));
if (partition == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_MIGRATESTORE_BKR_FAIL_NOT_MIGRATED));
} else {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_MIGRATE_PARTITION_FAIL_NOT_MIGRATED, partition, brokerID));
}
return (1);
}
String brokerIDFromList = null;
boolean found = false;
Enumeration thisEnum = bkrList.elements();
while (thisEnum.hasMoreElements()) {
Hashtable bkrClsInfo = (Hashtable) thisEnum.nextElement();
Long tmpLong;
Integer tmpInt;
long idle;
brokerIDFromList = (String) bkrClsInfo.get(BrokerClusterInfo.ID);
if ((brokerIDFromList == null)) {
continue;
}
if ((!brokerIDFromList.equals(brokerID))) {
continue;
}
found = true;
i = 0;
row[i++] = checkNullAndPrint(brokerIDFromList);
row[i++] = checkNullAndPrint(bkrClsInfo.get(BrokerClusterInfo.ADDRESS));
tmpInt = (Integer) bkrClsInfo.get(BrokerClusterInfo.STATE);
if (tmpInt != null) {
row[i++] = BrokerState.toString(tmpInt.intValue());
} else {
row[i++] = "";
}
// tmpLong = (Long)bkrClsInfo.get(BrokerClusterInfo.NUM_MSGS);
// row[i++] = checkNullAndPrint(tmpLong);
tmpLong = (Long) bkrClsInfo.get(BrokerClusterInfo.STATUS_TIMESTAMP);
if (tmpLong != null) {
idle = System.currentTimeMillis() - tmpLong.longValue();
row[i++] = CommonCmdRunnerUtil.getTimeString(idle);
} else {
row[i++] = "";
}
if (partition != null) {
tmpInt = (Integer) bkrClsInfo.get(MessageType.JMQ_NUM_PARTITIONS);
if (tmpInt != null) {
row[i++] = String.valueOf(tmpInt.intValue());
} else {
row[i++] = "";
}
}
bcp.add(row);
break;
}
if (!found) {
Globals.stdErrPrintln(ar.getString(ar.E_CANNOT_FIND_BROKERID, brokerID));
if (partition == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_MIGRATESTORE_BKR_FAIL_NOT_MIGRATED));
} else {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_MIGRATE_PARTITION_FAIL_NOT_MIGRATED, partition, brokerID));
}
return (1);
}
bcp.println();
}
if (!force) {
if (partition == null) {
input = CommonCmdRunnerUtil.getUserInput(ar.getString(ar.Q_MIGRATESTORE_BKR_OK), noShort);
} else {
input = CommonCmdRunnerUtil.getUserInput(ar.getString(ar.Q_MIGRATE_PARTITION_OK, partition, brokerID), noShort);
}
Globals.stdOutPrintln("");
}
if (yesShort.equalsIgnoreCase(input) || yes.equalsIgnoreCase(input) || force) {
try {
broker.sendMigrateStoreMessage(brokerID, partition);
String tobroker = broker.receiveMigrateStoreReplyMessage();
if (partition == null) {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_MIGRATESTORE_BKR_SUC, tobroker));
} else {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_MIGRATE_PARTITION_SUC, partition, tobroker));
}
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
int status = bae.getReplyStatus();
Message msg = bae.getReplyMsg();
String bk = null, hp = null;
try {
bk = msg.getStringProperty(MessageType.JMQ_BROKER_ID);
hp = msg.getStringProperty(MessageType.JMQ_MQ_ADDRESS);
} catch (Exception e) {
}
if (bk != null) {
bk = bk + (hp == null ? "" : "[" + hp + "]");
} else {
bk = "";
}
String st = null;
if (status >= 0) {
st = Status.getString(status);
}
if (st == null) {
if (partition == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_MIGRATESTORE_BKR_FAIL, bk));
} else {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_MIGRATE_PARTITION_FAIL, partition, brokerID));
}
} else {
if (partition == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_MIGRATESTORE_BKR_FAIL_STATUS, bk, st));
} else {
Object[] args = { partition, brokerID, st };
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_MIGRATE_PARTITION_FAIL_STATUS, args));
}
}
return (1);
}
} else if (noShort.equalsIgnoreCase(input) || no.equalsIgnoreCase(input)) {
if (partition == null) {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_MIGRATESTORE_BKR_NOOP));
} else {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_MIGRATE_PARTITION_NOOP, partition, brokerID));
}
return (0);
} else {
Globals.stdOutPrintln(ar.getString(ar.I_UNRECOGNIZED_RES, input));
Globals.stdOutPrintln("");
if (partition == null) {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_MIGRATESTORE_BKR_NOOP));
} else {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_MIGRATE_PARTITION_NOOP, partition, brokerID));
}
return (1);
}
}
/**
* broker will shutdown itself broker.close();
*/
return (0);
}
use of com.sun.messaging.jmq.admin.bkrutil.BrokerAdmin in project openmq by eclipse-ee4j.
the class CmdRunner method runDebug.
private int runDebug(BrokerCmdProperties brokerCmdProps) {
BrokerAdmin broker;
BrokerCmdPrinter bcp;
Hashtable debugHash = null;
String cmd, cmdarg, target;
String targetType;
Properties optionalProps = null;
broker = init();
if (broker == null) {
Globals.stdOutPrintln("Problems connecting to the broker.");
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
cmd = brokerCmdProps.getCommand();
cmdarg = brokerCmdProps.getCommandArg();
target = brokerCmdProps.getTargetName();
/*
* The -t option is used to specify target type
*/
targetType = brokerCmdProps.getDestType();
optionalProps = brokerCmdProps.getTargetAttrs();
Globals.stdOutPrintln("Sending the following DEBUG message:");
bcp = new BrokerCmdPrinter(2, 4, "-", BrokerCmdPrinter.LEFT, false);
String[] row = new String[2];
row[0] = "Header Property Name";
row[1] = "Value";
bcp.addTitle(row);
row[0] = MessageType.JMQ_CMD;
row[1] = cmd;
bcp.add(row);
row[0] = MessageType.JMQ_CMDARG;
row[1] = cmdarg;
bcp.add(row);
if (target != null) {
row[0] = MessageType.JMQ_TARGET;
row[1] = target;
bcp.add(row);
}
if (targetType != null) {
row[0] = MessageType.JMQ_TARGET_TYPE;
row[1] = targetType;
bcp.add(row);
}
bcp.println();
if ((optionalProps != null) && (optionalProps.size() > 0)) {
Globals.stdOutPrintln("Optional properties:");
printAttrs(optionalProps, true);
}
Globals.stdOutPrintln("To the broker specified by:");
printBrokerInfo(broker);
try {
connectToBroker(broker);
broker.sendDebugMessage(cmd, cmdarg, target, targetType, optionalProps);
debugHash = broker.receiveDebugReplyMessage();
if (debugHash != null && !debugHash.isEmpty()) {
Globals.stdOutPrintln("Data received back from broker:");
CommonCmdRunnerUtil.printDebugHash(debugHash);
} else {
Globals.stdOutPrintln("No additional data received back from broker.\n");
}
Globals.stdOutPrintln("DEBUG message sent successfully.");
return (0);
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
return (1);
}
}
use of com.sun.messaging.jmq.admin.bkrutil.BrokerAdmin in project openmq by eclipse-ee4j.
the class CmdRunner method runChangeMaster.
private int runChangeMaster(BrokerCmdProperties brokerCmdProps) {
BrokerAdmin broker;
String yes = ar.getString(ar.Q_RESPONSE_YES);
String yesShort = ar.getString(ar.Q_RESPONSE_YES_SHORT);
String no = ar.getString(ar.Q_RESPONSE_NO);
String noShort = ar.getString(ar.Q_RESPONSE_NO_SHORT);
broker = init();
if (broker == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_CHANGEMASTER_CLS_FAIL));
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force) {
broker = promptForAuthentication(broker);
}
Properties targetAttrs = brokerCmdProps.getTargetAttrs();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_CHANGEMASTER_CLS));
Globals.stdOutPrintln("");
printAttrs(targetAttrs);
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_SPECIFY_BKR));
printBrokerInfo(broker);
if (!force) {
String input = CommonCmdRunnerUtil.getUserInput(ar.getString(ar.Q_CHANGEMASTER_OK), noShort);
Globals.stdOutPrintln("");
if (noShort.equalsIgnoreCase(input) || no.equalsIgnoreCase(input)) {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_CHANGEMASTER_NOOP));
return (0);
} else if (!(yesShort.equalsIgnoreCase(input) || yes.equalsIgnoreCase(input))) {
Globals.stdOutPrintln(ar.getString(ar.I_UNRECOGNIZED_RES, input));
Globals.stdOutPrintln("");
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_CHANGEMASTER_NOOP));
return (1);
}
}
try {
connectToBroker(broker);
broker.sendClusterChangeMasterMessage(targetAttrs);
broker.receiveClusterChangeMasterReplyMessage();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_CHANGEMASTER_CLS_SUC));
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_CHANGEMASTER_CLS_FAIL));
return (1);
}
broker.close();
return (0);
}
Aggregations