* 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();
//Collection connPools = domain.getResources().getResources(ConnectorConnectionPool.class);
if (resourceType == null) {
report.setMessage(localStrings.getLocalString("create.jms.resource.noResourceType",
"No Resoruce Type specified for JMS Resource."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (jndiName == null) {
report.setMessage(localStrings.getLocalString("create.jms.resource.noJndiName",
"No JNDI name specified for JMS Resource."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (!(resourceType.equals(TOPIC_CF) || resourceType.equals(QUEUE_CF) || resourceType.equals(UNIFIED_CF) || resourceType.equals(TOPIC) || resourceType.equals(QUEUE))) {
report.setMessage(localStrings.getLocalString("create.jms.resource.InvalidResourceType",
"Invalid Resource Type specified for JMS Resource."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
jndiNameForConnectionPool = jndiName + JNDINAME_APPENDER;
if (force) {
Resource res = null;
if (resourceType.equals(TOPIC) || resourceType.equals(QUEUE))
res = ConnectorsUtil.getResourceByName(domain.getResources(), AdminObjectResource.class, jndiName);
else
res = ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorResource.class, jndiName);
if (res != null) {
ActionReport deleteReport = report.addSubActionsReport();
ParameterMap parameters = new ParameterMap();
parameters.set(DEFAULT_OPERAND, jndiName);
parameters.set("target", target);
commandRunner.getCommandInvocation("delete-jms-resource", deleteReport, context.getSubject()).parameters(parameters).execute();
if (ActionReport.ExitCode.FAILURE.equals(deleteReport.getActionExitCode())) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
//Populate the JMS RA map
populateJmsRAMap();
/* Map MQ properties to Resource adapter properties */
if (props != null) {
Enumeration en = props.keys();
while (en.hasMoreElements()) {
String key = (String) en.nextElement();
String raKey = getMappedName(key);
if (raKey == null) raKey = key;
props.put(raKey, (String) props.get(key));
if(! raKey.equals(key))
props.remove(key);
}
}
ActionReport subReport = report.addSubActionsReport();
if (resourceType.equals(TOPIC_CF) || resourceType.equals(QUEUE_CF) || resourceType.equals(UNIFIED_CF)) {
ConnectorConnectionPool cpool = (ConnectorConnectionPool) ConnectorsUtil.getResourceByName(
domain.getResources(), ConnectorConnectionPool.class, jndiNameForConnectionPool);
boolean createdPool = false;
// If pool is already existing, do not try to create it again
if (cpool == null || ! filterForTarget (jndiNameForConnectionPool)) {
// Add connector-connection-pool.
ParameterMap parameters = populateConnectionPoolParameters();
commandRunner.getCommandInvocation("create-connector-connection-pool", subReport, context.getSubject()).parameters(parameters).execute();
createdPool= true;
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;
}
}
ParameterMap params = populateConnectionResourceParameters();
commandRunner.getCommandInvocation("create-connector-resource", subReport, context.getSubject()).parameters(params).execute();
if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())){
report.setMessage(localStrings.getLocalString("create.jms.resource.cannotCreateConnectorResource",
"Unable to create connection resource."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
//rollback the connection pool ONLY if we created it...
if (createdPool)
commandRunner.getCommandInvocation("delete-connector-connection-pool", subReport, context.getSubject()).parameters(populateConnectionPoolParameters()).execute();
return;
}
} else if (resourceType.equals(TOPIC) ||
resourceType.equals(QUEUE))
{
ParameterMap aoAttrList = new ParameterMap();
try{
//validate the provided properties and modify it if required.
Properties properties = validateDestinationResourceProps(props, jndiName);
//aoAttrList.put("property", properties);
StringBuilder builder = new StringBuilder();
for (java.util.Map.Entry<Object, Object>prop : properties.entrySet()) {
builder.append(prop.getKey()).append("=").append(prop.getValue()).append(":");
}
String propString = builder.toString();
int lastColonIndex = propString.lastIndexOf(":");
if (lastColonIndex >= 0) {
propString = propString.substring(0, lastColonIndex);
}
aoAttrList.set("property", propString);
}catch (Exception e)
{
report.setMessage(localStrings.getLocalString("create.jms.resource.cannotCreateAdminObjectWithRootCause",
"Unable to create admin object. Reason: " + e.getMessage(), e.getMessage()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// create admin object
aoAttrList.set(DEFAULT_OPERAND, jndiName);
aoAttrList.set("restype", resourceType);
aoAttrList.set("raname", DEFAULT_JMS_ADAPTER);
aoAttrList.set("target", target);
if(enabled!=null)
aoAttrList.set("enabled", Boolean.toString(enabled));
commandRunner.getCommandInvocation("create-admin-object", subReport, context.getSubject()).parameters(aoAttrList).execute();
if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())){
report.setMessage(localStrings.getLocalString("create.jms.resource.cannotCreateAdminObject",
"Unable to create admin object."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}