use of org.glassfish.connectors.config.ConnectorConnectionPool in project Payara by payara.
the class CreateJMSResource method execute.
/**
* Executes the command with the command parameters passed as Properties
* 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) {
ParameterMap paramsForRollback = new ParameterMap();
paramsForRollback.set(DEFAULT_OPERAND, jndiNameForConnectionPool);
commandRunner.getCommandInvocation("delete-connector-connection-pool", subReport, context.getSubject()).parameters(paramsForRollback).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;
}
}
ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
report.setActionExitCode(ec);
}
use of org.glassfish.connectors.config.ConnectorConnectionPool in project Payara by payara.
the class ListJMSResources method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the paramter names and the values the parameter values
*
* @param context information
*/
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
ArrayList<Map<String, String>> list = new ArrayList<>();
Properties extraProperties = new Properties();
Collection adminObjectResourceList = domain.getResources().getResources(AdminObjectResource.class);
Collection connectorResourcesList = domain.getResources().getResources(ConnectorResource.class);
Object[] connectorResources = connectorResourcesList.toArray();
Object[] adminObjectResources = adminObjectResourceList.toArray();
if (resourceType == null) {
try {
// list all JMS resources
for (Object r : adminObjectResources) {
AdminObjectResource adminObject = (AdminObjectResource) r;
if (JMSRA.equals(adminObject.getResAdapter())) {
Map<String, String> m = new HashMap<>();
m.put("name", adminObject.getJndiName());
list.add(m);
}
}
for (Object c : connectorResources) {
ConnectorResource cr = (ConnectorResource) c;
ConnectorConnectionPool cp = (ConnectorConnectionPool) ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorConnectionPool.class, cr.getPoolName());
if (cp != null && JMSRA.equals(cp.getResourceAdapterName())) {
Map<String, String> m = new HashMap<>();
m.put("name", cr.getJndiName());
list.add(m);
}
}
} catch (Exception e) {
report.setMessage(localStrings.getLocalString("list.jms.resources.fail", "Unable to list JMS Resources") + " " + e.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
} else {
switch(resourceType) {
case TOPIC_CF:
case QUEUE_CF:
case UNIFIED_CF:
for (Object c : connectorResources) {
ConnectorResource cr = (ConnectorResource) c;
ConnectorConnectionPool cp = (ConnectorConnectionPool) ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorConnectionPool.class, cr.getPoolName());
if (cp != null && resourceType.equals(cp.getConnectionDefinitionName()) && JMSRA.equals(cp.getResourceAdapterName())) {
Map<String, String> m = new HashMap<>();
m.put("name", cr.getJndiName());
list.add(m);
}
}
break;
case TOPIC:
case QUEUE:
for (Object r : adminObjectResources) {
AdminObjectResource res = (AdminObjectResource) r;
if (resourceType.equals(res.getResType()) && JMSRA.equals(res.getResAdapter())) {
Map<String, String> m = new HashMap<>();
m.put("name", res.getJndiName());
list.add(m);
}
}
break;
}
}
if (!list.isEmpty()) {
List<Map<String, String>> resourceList = CommandTarget.DOMAIN.isValid(habitat, target) ? list : filterListForTarget(list);
List<DefaultResourceProxy> drps = habitat.getAllServices(DefaultResourceProxy.class);
for (Map<String, String> m : resourceList) {
String jndiName = m.get("name");
final ActionReport.MessagePart part = report.getTopMessagePart().addChild();
part.setMessage(jndiName);
String logicalName = DefaultResourceProxy.Util.getLogicalName(drps, jndiName);
if (logicalName != null) {
m.put("logical-jndi-name", logicalName);
}
}
extraProperties.put("jmsResources", resourceList);
}
report.setExtraProperties(extraProperties);
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.connectors.config.ConnectorConnectionPool in project Payara by payara.
the class CreateConnectorSecurityMap method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the parameter names and the values the parameter values
*
* @param context information
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
if (securityMapName == null) {
report.setMessage(localStrings.getLocalString("create.connector.security.map.noSecurityMapName", "No security map name specified"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (principals == null && userGroups == null) {
report.setMessage(localStrings.getLocalString("create.connector.security.map.noPrincipalsOrGroupsMap", "Either the principal or the user group has to be specified while creating a security map." + " Both cannot be null."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (principals != null && userGroups != null) {
report.setMessage(localStrings.getLocalString("create.connector.security.map.specifyPrincipalsOrGroupsMap", "A work-security-map can have either (any number of) group mapping or (any number of) principals" + " mapping but not both. Specify --principals or --usergroups."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
Collection<ConnectorConnectionPool> ccPools = domain.getResources().getResources(ConnectorConnectionPool.class);
if (!doesPoolNameExist(poolName, ccPools)) {
report.setMessage(localStrings.getLocalString("create.connector.security.map.noSuchPoolFound", "Connector connection pool {0} does not exist. Please specify a valid pool name.", poolName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (doesMapNameExist(poolName, securityMapName, ccPools)) {
report.setMessage(localStrings.getLocalString("create.connector.security.map.duplicate", "A security map named {0} already exists for connector connection pool {1}. Please give a" + " different map name.", securityMapName, poolName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// get all the security maps for this pool.....
List<SecurityMap> maps = getAllSecurityMapsForPool(poolName, ccPools);
if (principals != null) {
for (String principal : principals) {
if (isPrincipalExisting(principal, maps)) {
report.setMessage(localStrings.getLocalString("create.connector.security.map.principal_exists", "The principal {0} already exists in connector connection pool {1}. Please give a " + "different principal name.", principal, poolName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
if (userGroups != null) {
for (String userGroup : userGroups) {
if (isUserGroupExisting(userGroup, maps)) {
report.setMessage(localStrings.getLocalString("create.connector.security.map.usergroup_exists", "The user-group {0} already exists in connector connection pool {1}. Please give a" + " different user-group name.", userGroup, poolName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
ConnectorConnectionPool connPool = null;
for (ConnectorConnectionPool ccp : ccPools) {
if (ccp.getName().equals(poolName)) {
connPool = ccp;
}
}
try {
ConfigSupport.apply(new SingleConfigCode<ConnectorConnectionPool>() {
public Object run(ConnectorConnectionPool ccp) throws PropertyVetoException, TransactionFailure {
List<SecurityMap> securityMaps = ccp.getSecurityMap();
SecurityMap newResource = ccp.createChild(SecurityMap.class);
newResource.setName(securityMapName);
if (principals != null) {
for (String p : principals) {
newResource.getPrincipal().add(p);
}
}
if (userGroups != null) {
for (String u : userGroups) {
newResource.getUserGroup().add(u);
}
}
BackendPrincipal backendPrincipal = newResource.createChild(BackendPrincipal.class);
backendPrincipal.setUserName(mappedusername);
if (mappedpassword != null && !mappedpassword.isEmpty()) {
backendPrincipal.setPassword(mappedpassword);
}
newResource.setBackendPrincipal(backendPrincipal);
securityMaps.add(newResource);
return newResource;
}
}, connPool);
} catch (TransactionFailure tfe) {
Object[] params = { securityMapName, poolName };
report.setMessage(localStrings.getLocalString("create.connector.security.map.fail", "Unable to create connector security map {0} for connector connection pool {1} ", params) + " " + tfe.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(tfe);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.connectors.config.ConnectorConnectionPool in project Payara by payara.
the class ConnectorConnectionPoolManager method createConfigBean.
private ConnectorConnectionPool createConfigBean(Resources param, Properties properties) throws PropertyVetoException, TransactionFailure {
ConnectorConnectionPool newResource = param.createChild(ConnectorConnectionPool.class);
newResource.setResourceAdapterName(raname);
newResource.setConnectionDefinitionName(connectiondefinition);
if (validateAtmostOncePeriod != null) {
newResource.setValidateAtmostOncePeriodInSeconds(validateAtmostOncePeriod);
}
newResource.setSteadyPoolSize(steadypoolsize);
newResource.setPoolResizeQuantity(poolresize);
newResource.setMaxWaitTimeInMillis(maxwait);
newResource.setMaxPoolSize(maxpoolsize);
if (maxConnectionUsageCount != null) {
newResource.setMaxConnectionUsageCount(maxConnectionUsageCount);
}
newResource.setMatchConnections(matchConnections);
if (lazyConnectionEnlistment != null) {
newResource.setLazyConnectionEnlistment(lazyConnectionEnlistment);
}
if (lazyConnectionAssociation != null) {
newResource.setLazyConnectionAssociation(lazyConnectionAssociation);
}
if (isconnectvalidatereq != null) {
newResource.setIsConnectionValidationRequired(isconnectvalidatereq);
}
newResource.setIdleTimeoutInSeconds(idletimeout);
newResource.setFailAllConnections(failconnection);
if (connectionLeakTimeout != null) {
newResource.setConnectionLeakTimeoutInSeconds(connectionLeakTimeout);
}
if (connectionLeakReclaim != null) {
newResource.setConnectionLeakReclaim(connectionLeakReclaim);
}
if (connectionCreationRetryInterval != null) {
newResource.setConnectionCreationRetryIntervalInSeconds(connectionCreationRetryInterval);
}
if (connectionCreationRetryAttempts != null) {
newResource.setConnectionCreationRetryAttempts(connectionCreationRetryAttempts);
}
if (associateWithThread != null) {
newResource.setAssociateWithThread(associateWithThread);
}
if (pooling != null) {
newResource.setPooling(pooling);
}
if (ping != null) {
newResource.setPing(ping);
}
if (transactionSupport != null) {
newResource.setTransactionSupport(transactionSupport);
}
if (description != null) {
newResource.setDescription(description);
}
newResource.setName(poolname);
if (properties != null) {
for (java.util.Map.Entry e : properties.entrySet()) {
Property prop = newResource.createChild(Property.class);
prop.setName((String) e.getKey());
prop.setValue((String) e.getValue());
newResource.getProperty().add(prop);
}
}
return newResource;
}
use of org.glassfish.connectors.config.ConnectorConnectionPool in project Payara by payara.
the class ConnectionPoolStatsProviderBootstrap method poolCreated.
/**
* When a pool is created (or initialized) the pool should be registered
* to the StatsProviderManager. Also, the pool lifecycle
* listener needs to be registered for this pool to track events on change
* of any monitoring attributes.
* @param poolInfo
*/
public void poolCreated(PoolInfo poolInfo) {
if (logger.isLoggable(Level.FINEST)) {
logger.finest("Pool created : " + poolInfo);
}
if (runtime.isServer()) {
ResourcePool pool = runtime.getConnectionPoolConfig(poolInfo);
Collection<ConnectionPoolMonitoringExtension> extensions = habitat.getAllServices(ConnectionPoolMonitoringExtension.class);
for (ConnectionPoolMonitoringExtension extension : extensions) {
extension.registerPool(poolInfo);
}
if (pool instanceof ConnectorConnectionPool) {
registerCcPool(poolInfo);
}
/*else if (poolInfo.getName().contains(ConnectorConstants.DATASOURCE_DEFINITION_JNDINAME_PREFIX)){
registerJdbcPool(poolInfo);
}*/
}
}
Aggregations