* where the keys are the paramter names and the values the parameter values
*
* @param context information
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
final String newMB = newMasterBroker;
Server newMBServer = domain.getServerNamed(newMasterBroker);
if (newMBServer == null) {
report.setMessage(localStrings.getLocalString("change.master.broker.invalidServerName",
"Invalid server name specified. There is no server by this name"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
Cluster cluster = newMBServer.getCluster();//domain.getClusterNamed(clusterName);
if (cluster == null) {
report.setMessage(localStrings.getLocalString("change.master.broker.invalidClusterName",
"The server specified is not associated with a cluster. The server assocaited with the master broker has to be a part of the cluster"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
/*if(!cluster.getName().equals(newMBServer.getCluster().getName()))
{
report.setMessage(localStrings.getLocalString("configure.jms.cluster.invalidClusterName",
"{0} does not belong to the specified cluster", newMasterBroker));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
} */
Nodes nodes = domain.getNodes();
config = domain.getConfigNamed(cluster.getConfigRef());
JmsService jmsservice = config.getExtensionByType(JmsService.class);
Server oldMBServer = null;
//If Master broker has been set previously using this command, use that master broker as the old MB instance
//Else use the first configured instance in the cluster list
if(jmsservice.getMasterBroker() != null){
oldMBServer = domain.getServerNamed(jmsservice.getMasterBroker());
}else
{
List<Server> serverList = cluster.getInstances();
//if(serverList == null || serverList.size() == 0){
//report.setMessage(localStrings.getLocalString("change.master.broker.invalidCluster",
// "No servers configured in cluster {0}", clusterName));
//report.setActionExitCode(ActionReport.ExitCode.FAILURE);
//return;
//}
oldMBServer = serverList.get(0);
}
String oldMasterBrokerPort = JmsRaUtil.getJMSPropertyValue(oldMBServer);
if(oldMasterBrokerPort == null) {
SystemProperty sp = config.getSystemProperty("JMS_PROVIDER_PORT");
if(sp != null) oldMasterBrokerPort = sp.getValue();
}
if(oldMasterBrokerPort == null) oldMasterBrokerPort = getDefaultJmsHost(jmsservice).getPort();
String oldMasterBrokerHost = nodes.getNode(oldMBServer.getNodeRef()).getNodeHost();
String newMasterBrokerPort = JmsRaUtil.getJMSPropertyValue(newMBServer);
if(newMasterBrokerPort == null) newMasterBrokerPort = getDefaultJmsHost(jmsservice).getPort();
String newMasterBrokerHost = nodes.getNode(newMBServer.getNodeRef()).getNodeHost();
String oldMasterBroker = oldMasterBrokerHost + ":" + oldMasterBrokerPort;
String newMasterBroker = newMasterBrokerHost + ":" + newMasterBrokerPort;
// System.out.println("1: IN deleteinstanceCheck supplimental oldMasterBroker = " + oldMasterBroker + " newmasterBroker " + newMasterBroker);
try{
CompositeData result = updateMasterBroker(oldMBServer.getName(), oldMasterBroker, newMasterBroker);
boolean success = ((Boolean) result.get("Success")).booleanValue();
if (!success) {
int statusCode = ((Integer) result.get("StatusCode")).intValue();
String detailMessage = (String) result.get("DetailMessage");
String msg = " " + detailMessage;
if (BrokerStatusCode.BAD_REQUEST.getCode() == statusCode || BrokerStatusCode.NOT_ALLOWED.getCode() == statusCode ||
BrokerStatusCode.UNAVAILABLE.getCode() == statusCode || BrokerStatusCode.PRECONDITION_FAILED.getCode() == statusCode) {
msg = localStrings.getLocalString("change.master.broker.errorMsg",
"{0}. But it didn't affect current master broker configuration.", msg);
} else {
msg = msg + ". " + localStrings.getLocalString("change.master.broker.otherErrorMsg",
"The cluster should be shutdown and configured with the new master broker then restarts.");
}
report.setMessage(localStrings.getLocalString("change.master.broker.CannotChangeMB",
"Unable to change master broker.{0}", msg));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}catch(Exception e){
report.setMessage(localStrings.getLocalString("change.master.broker.CannotChangeMB",
"Unable to change master broker.{0}", ""));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
/*String setCommandStr = cluster.getConfigRef() + "." + "jms-service" + "." +"master-Broker";
ParameterMap parameters = new ParameterMap();
parameters.set(setCommandStr, newMB );
ActionReport subReport = report.addSubActionsReport();
commandRunner.getCommandInvocation("set", subReport, context.getSubject()).parameters(parameters).execute();
if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())){
report.setMessage(localStrings.getLocalString("create.jms.resource.cannotCreateConnectionPool",
"Unable to create connection pool."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}*/
ConfigSupport.apply(new SingleConfigCode<JmsService>() {
public Object run(JmsService param) throws PropertyVetoException, TransactionFailure {
param.setMasterBroker(newMB);
return param;
}
}, jmsservice);
} catch(Exception tfe) {
report.setMessage(localStrings.getLocalString("change.master.broker.fail",
"Unable to update the domain.xml with the new master broker") +
" " + tfe.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(tfe);
}
report.setMessage(localStrings.getLocalString("change.master.broker.success",
"Master broker change has executed successfully for Cluster {0}.", cluster.getName()));
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}