public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
// Server targetServer = domain.getServerNamed(target);
//String configRef = targetServer.getConfigRef();
Cluster cluster =domain.getClusterNamed(clusterName);
if (cluster == null) {
report.setMessage(localStrings.getLocalString("configure.jms.cluster.invalidClusterName",
"No Cluster by this name has been configured"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
List instances = cluster.getInstances();
String warning = null;
if(instances.size() > 0) {
ActionReport listReport = habitat.getService(ActionReport.class);
ParameterMap parameters = new ParameterMap();
parameters.set("DEFAULT", clusterName);
commandRunner.getCommandInvocation("list-instances", listReport, context.getSubject()).parameters(parameters).execute();
if (ActionReport.ExitCode.FAILURE.equals(listReport.getActionExitCode())) {
warning = localStrings.getLocalString("configure.jms.cluster.clusterWithInstances",
"Warning: Please make sure running this command with all cluster instances stopped, otherwise it may lead to inconsistent JMS behavior and corruption of configuration and message stores.");
} else {
String result = listReport.getMessage();
String fixedResult = result.replaceAll("not running", "stopped");
if (fixedResult.indexOf("running") > -1) {
warning = localStrings.getLocalString("configure.jms.cluster.clusterWithInstances",
"Warning: Please make sure running this command with all cluster instances stopped, otherwise it may lead to inconsistent JMS behavior and corruption of configuration and message stores.");
warning = warning + "\r\n" + result + "\r\n";
}
}
}
Config config = domain.getConfigNamed(cluster.getConfigRef());
JmsService jmsService = config.getExtensionByType(JmsService.class);
if(jmsService == null) {
report.setMessage(localStrings.getLocalString("configure.jms.cluster.nojmsservice",
"No JMS Service element in config"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if(! CONVENTIONAL.equalsIgnoreCase(clusterType) && ! ENHANCED.equalsIgnoreCase(clusterType)){
report.setMessage(localStrings.getLocalString("configure.jms.cluster.wrongClusterType",
"Invalid option sepecified for clustertype. Valid options are conventional and enhanced"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (CONVENTIONAL.equalsIgnoreCase(clusterType) && ! MASTER_BROKER.equalsIgnoreCase(configStoreType) && ! SHARED_DB.equalsIgnoreCase(configStoreType)){
report.setMessage(localStrings.getLocalString("configure.jms.cluster.wrongConfigStoreType",
"Invalid option sepecified for configstoretype. Valid options are masterbroker and shareddb"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if(ENHANCED.equalsIgnoreCase(clusterType) && configStoreType != null){
report.setMessage(localStrings.getLocalString("configure.jms.cluster.wrongStoreType",
"configstoretype option is not configurable for Enhanced clusters."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (CONVENTIONAL.equalsIgnoreCase(clusterType) && ! MASTER_BROKER.equalsIgnoreCase(configStoreType) && ! FILE.equalsIgnoreCase(messageStoreType) && ! JDBC.equalsIgnoreCase(messageStoreType)){
report.setMessage(localStrings.getLocalString("configure.jms.cluster.wrongMessageStoreType",
"Invalid option sepecified for messagestoretype. Valid options are file and jdbc"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if(ENHANCED.equalsIgnoreCase(clusterType) && messageStoreType != null){
report.setMessage(localStrings.getLocalString("configure.jms.cluster.wrongmsgStoreType",
"messagestoretype option is not configurable for Enhanced clusters."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
String integrationMode = jmsService.getType();
if(REMOTE.equalsIgnoreCase(integrationMode)) {
report.setMessage(localStrings.getLocalString("configure.jms.cluster.remoteMode",
"JMS integration mode should be either EMBEDDED or LOCAL to run this command. Please use the asadmin.set command to change the integration mode"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
String changeIntegrationMode = null;
if(EMBEDDED.equalsIgnoreCase(integrationMode) && ENHANCED.equalsIgnoreCase(clusterType)) {
try {
ConfigSupport.apply(new SingleConfigCode<JmsService>() {
public Object run(JmsService param) throws PropertyVetoException, TransactionFailure {
param.setType(LOCAL);
return param;
}
}, jmsService);
changeIntegrationMode = localStrings.getLocalString("configure.jms.cluster.integrationModeChanged",
"WARNING: JMS integration mode has been changed from EMBEDDED to LOCAL automatically.");
} catch(TransactionFailure tfe) {
report.setMessage(localStrings.getLocalString("configure.jms.cluster.cannotChangeIntegrationMode",
"Unable to change the JMS integration mode to LOCAL for Enhanced cluster {0}.", clusterName) + " " + tfe.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(tfe);
return;
}
}
if (MASTER_BROKER.equalsIgnoreCase(configStoreType) && FILE.equals(messageStoreType)){
if(dbvendor != null || dburl != null || dbuser != null) {
report.setMessage(localStrings.getLocalString("configure.jms.cluster.invalidDboptions",
"Database options should not be specified for this configuration"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
if(! MASTER_BROKER.equalsIgnoreCase(configStoreType) || ENHANCED.equalsIgnoreCase(clusterType) || JDBC.equalsIgnoreCase(messageStoreType)){
if (dbvendor == null) {
report.setMessage(localStrings.getLocalString("configure.jms.cluster.nodbvendor",
"No DataBase vendor specified"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
else if (dburl == null) {
report.setMessage(localStrings.getLocalString("configure.jms.cluster.nojdbcurl",
"No JDBC URL specified"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
else if (! isSupportedDbVendor()){
report.setMessage(localStrings.getLocalString("configure.jms.cluster.invaliddbvendor",
"Invalid DB Vednor specified"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
if(CONVENTIONAL.equalsIgnoreCase(clusterType) && configStoreType == null){
report.setMessage(localStrings.getLocalString("configure.jms.cluster.noConfigStoreType",
"No configstoretype specified. Using the default value - masterbroker"));
configStoreType="masterbroker";
}
if(CONVENTIONAL.equalsIgnoreCase(clusterType) && messageStoreType == null){
report.setMessage(localStrings.getLocalString("configure.jms.cluster.noMessagetoreType",
"No messagestoretype specified. Using the default value - file"));
messageStoreType="file";
}
config = domain.getConfigNamed(cluster.getConfigRef());
JmsAvailability jmsAvailability = config.getAvailabilityService().getExtensionByType(JmsAvailability.class);
final Boolean availabilityEnabled = Boolean.valueOf(ENHANCED.equalsIgnoreCase(clusterType));
try {