* 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();
// 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();
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 {
ConfigSupport.apply(new SingleConfigCode<JmsAvailability>() {
public Object run(JmsAvailability param) throws PropertyVetoException, TransactionFailure {
param.setAvailabilityEnabled(availabilityEnabled.toString());
if(availabilityEnabled.booleanValue()){
param.setMessageStoreType(JDBC);
}
else{
param.setConfigStoreType(configStoreType.toLowerCase(Locale.ENGLISH));
param.setMessageStoreType(messageStoreType.toLowerCase(Locale.ENGLISH));
}
param.setDbVendor(dbvendor);
param.setDbUsername(dbuser);
param.setDbPassword(jmsDbPassword);
param.setDbUrl(dburl);
if(props != null)
{
for (Map.Entry e: props.entrySet()){
Property prop = param.createChild(Property.class);
prop.setName((String)e.getKey());
prop.setValue((String)e.getValue());
param.getProperty().add(prop);
}
}
return param;
}
}, jmsAvailability);
/* //update the useMasterBroker flag on the JmsService only if availabiltyEnabled is false
if(!availabilityEnabled.booleanValue()){
ConfigSupport.apply(new SingleConfigCode<JmsService>() {
public Object run(JmsService param) throws PropertyVetoException, TransactionFailure {
param.setUseMasterBroker(useMasterBroker.toString());
return param;
}
}, jmsservice);
}*/
} catch(TransactionFailure tfe) {
report.setMessage((changeIntegrationMode == null ? "" : changeIntegrationMode + "\n") +
localStrings.getLocalString("configure.jms.cluster.fail",
"Unable to Configure JMS Cluster for cluster {0}.", clusterName) +
" " + tfe.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(tfe);
}
String warning = null;
if(instances.size() > 0){
warning=localStrings.getLocalString("configure.jms.cluster.clusterWithInstances",
"Warning: make sure that you have followed the instructions specified in the documentation before running this command with this option. Running this command without the required precautions can lead to inconsistent JMS behavior and corruption of configuration and message stores.");
}
report.setMessage((warning == null ? "" : warning + "\n") + (changeIntegrationMode == null ? "" : changeIntegrationMode + "\n") +
localStrings.getLocalString("configure.jms.cluster.success", "JMS Cluster Configuration updated for Cluster {0}.", clusterName));
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}