use of org.jvnet.hk2.config.ConfigModel.Property in project Payara by payara.
the class JdbcRecoveryResourceHandler method loadXAResourcesAndItsConnections.
/**
* {@inheritDoc}
*/
@Override
public void loadXAResourcesAndItsConnections(List xaresList, List connList) {
// Done so as to initialize connectors-runtime before loading jdbc-resources. need a better way ?
ConnectorRuntime crt = connectorRuntimeProvider.get();
Collection<JdbcResource> jdbcResources = getAllJdbcResources();
if (jdbcResources == null || jdbcResources.size() == 0) {
if (_logger.isLoggable(Level.FINEST)) {
_logger.finest("loadXAResourcesAndItsConnections : no resources");
}
return;
}
List<JdbcConnectionPool> jdbcPools = new ArrayList<JdbcConnectionPool>();
for (Resource resource : jdbcResources) {
JdbcResource jdbcResource = (JdbcResource) resource;
if (getResourcesUtil().isEnabled(jdbcResource)) {
ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(jdbcResource);
JdbcConnectionPool pool = JdbcResourcesUtil.createInstance().getJdbcConnectionPoolOfResource(resourceInfo);
if (pool != null && "javax.sql.XADataSource".equals(pool.getResType())) {
jdbcPools.add(pool);
}
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("JdbcRecoveryResourceHandler:: loadXAResourcesAndItsConnections :: " + "adding : " + (jdbcResource.getPoolName()));
}
}
}
loadAllJdbcResources();
// Read from the transaction-service , if the replacement of
// Vendor XAResource class with our version required.
// If yes, put the mapping in the xaresourcewrappers properties.
Properties XAResourceWrappers = new Properties();
XAResourceWrappers.put("oracle.jdbc.xa.client.OracleXADataSource", "com.sun.enterprise.transaction.jts.recovery.OracleXAResource");
Config c = habitat.getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
txService = c.getExtensionByType(TransactionService.class);
List<Property> properties = txService.getProperty();
if (properties != null) {
for (Property property : properties) {
String name = property.getName();
String value = property.getValue();
if (name.equals("oracle-xa-recovery-workaround")) {
if ("false".equals(value)) {
XAResourceWrappers.remove("oracle.jdbc.xa.client.OracleXADataSource");
}
} else if (name.equals("sybase-xa-recovery-workaround")) {
if (value.equals("true")) {
XAResourceWrappers.put("com.sybase.jdbc2.jdbc.SybXADataSource", "com.sun.enterprise.transaction.jts.recovery.SybaseXAResource");
}
}
}
}
for (JdbcConnectionPool jdbcConnectionPool : jdbcPools) {
if (jdbcConnectionPool.getResType() == null || jdbcConnectionPool.getName() == null || !jdbcConnectionPool.getResType().equals("javax.sql.XADataSource")) {
if (_logger.isLoggable(Level.FINEST)) {
_logger.finest("skipping pool : " + jdbcConnectionPool.getName());
}
continue;
}
if (_logger.isLoggable(Level.FINEST)) {
_logger.finest(" using pool : " + jdbcConnectionPool.getName());
}
PoolInfo poolInfo = ConnectorsUtil.getPoolInfo(jdbcConnectionPool);
try {
String[] dbUserPassword = getdbUserPasswordOfJdbcConnectionPool(jdbcConnectionPool);
String dbUser = dbUserPassword[0];
String dbPassword = dbUserPassword[1];
if (dbPassword == null) {
dbPassword = "";
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, "datasource.xadatasource_nullpassword_error", poolInfo);
}
}
if (dbUser == null) {
dbUser = "";
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, "datasource.xadatasource_nulluser_error", poolInfo);
}
}
ManagedConnectionFactory fac = crt.obtainManagedConnectionFactory(poolInfo);
Subject subject = new Subject();
PasswordCredential pc = new PasswordCredential(dbUser, dbPassword.toCharArray());
pc.setManagedConnectionFactory(fac);
Principal prin = new ResourcePrincipal(dbUser, dbPassword);
subject.getPrincipals().add(prin);
subject.getPrivateCredentials().add(pc);
ManagedConnection mc = fac.createManagedConnection(subject, null);
connList.add(mc);
try {
XAResource xares = mc.getXAResource();
if (xares != null) {
// See if a wrapper class for the vendor XADataSource is
// specified if yes, replace the XAResouce class of database
// vendor with our own version
String datasourceClassname = jdbcConnectionPool.getDatasourceClassname();
String wrapperclass = (String) XAResourceWrappers.get(datasourceClassname);
if (wrapperclass != null) {
// need to load wrapper class provided by "transactions" module.
// Using connector-class-loader so as to get access to "transaction" module.
XAResourceWrapper xaresWrapper = null;
xaresWrapper = (XAResourceWrapper) crt.getConnectorClassLoader().loadClass(wrapperclass).newInstance();
xaresWrapper.init(mc, subject);
if (_logger.isLoggable(Level.FINEST)) {
_logger.finest("adding resource " + poolInfo + " -- " + xaresWrapper);
}
xaresList.add(xaresWrapper);
} else {
if (_logger.isLoggable(Level.FINEST)) {
_logger.finest("adding resource " + poolInfo + " -- " + xares);
}
xaresList.add(xares);
}
}
} catch (ResourceException ex) {
_logger.log(Level.WARNING, "datasource.xadatasource_error", poolInfo);
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "datasource.xadatasource_error_excp", ex);
}
// ignored. Not at XA_TRANSACTION level
}
} catch (Exception ex) {
_logger.log(Level.WARNING, "datasource.xadatasource_error", poolInfo);
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "datasource.xadatasource_error_excp", ex);
}
}
}
}
use of org.jvnet.hk2.config.ConfigModel.Property in project Payara by payara.
the class CreateJMSHost 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();
Config targetConfig = domain.getConfigNamed(target);
if (targetConfig != null)
config = targetConfig;
Server targetServer = domain.getServerNamed(target);
// String configRef = targetServer.getConfigRef();
if (targetServer != null) {
config = domain.getConfigNamed(targetServer.getConfigRef());
}
com.sun.enterprise.config.serverbeans.Cluster cluster = domain.getClusterNamed(target);
if (cluster != null) {
config = domain.getConfigNamed(cluster.getConfigRef());
}
if (jmsHostName == null) {
report.setMessage(localStrings.getLocalString("create.jms.host.noJmsHost", "No JMS Host name specified."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
JmsService jmsservice = config.getExtensionByType(JmsService.class);
// ensure we don't already have one of this name before creating it.
for (JmsHost jmsHost : jmsservice.getJmsHost()) {
if (jmsHostName.equals(jmsHost.getName())) {
if (force) {
ActionReport deleteReport = report.addSubActionsReport();
ParameterMap parameters = new ParameterMap();
parameters.set("DEFAULT", jmsHostName);
parameters.set("target", target);
commandRunner.getCommandInvocation("delete-jms-host", deleteReport, context.getSubject()).parameters(parameters).execute();
if (ActionReport.ExitCode.FAILURE.equals(deleteReport.getActionExitCode())) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
break;
} else {
report.setMessage(localStrings.getLocalString("create.jms.host.duplicate", "A JMS Host named {0} already exists.", jmsHostName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
try {
ConfigSupport.apply(new SingleConfigCode<JmsService>() {
public Object run(JmsService param) throws PropertyVetoException, TransactionFailure {
// TODO: need a way to create a JmsHost instance
JmsHost jmsHost = param.createChild(JmsHost.class);
jmsHost.setAdminPassword(mqpassword);
jmsHost.setAdminUserName(mquser);
jmsHost.setName(jmsHostName);
jmsHost.setHost(mqhost);
jmsHost.setPort(mqport);
if (props != null) {
for (Map.Entry e : props.entrySet()) {
Property prop = jmsHost.createChild(Property.class);
prop.setName((String) e.getKey());
prop.setValue((String) e.getValue());
jmsHost.getProperty().add(prop);
}
}
param.getJmsHost().add(jmsHost);
return jmsHost;
}
}, jmsservice);
} catch (TransactionFailure tfe) {
report.setMessage(localStrings.getLocalString("create.jms.host.fail", "Unable to create jms host {0}.", jmsHostName) + " " + tfe.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(tfe);
}
report.setMessage(localStrings.getLocalString("create.jms.host.success", "Jms Host {0} created.", jmsHostName));
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.jvnet.hk2.config.ConfigModel.Property in project Payara by payara.
the class ConnectorResourceManager method createConfigBean.
private ConnectorResource createConfigBean(Resources param, Properties properties) throws PropertyVetoException, TransactionFailure {
ConnectorResource newResource = param.createChild(ConnectorResource.class);
newResource.setJndiName(jndiName);
if (description != null) {
newResource.setDescription(description);
}
newResource.setPoolName(poolName);
newResource.setEnabled(enabled);
newResource.setObjectType(objectType);
if (properties != null) {
for (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.jvnet.hk2.config.ConfigModel.Property 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.jvnet.hk2.config.ConfigModel.Property in project Payara by payara.
the class JndiResourceManager method createConfigBean.
private ExternalJndiResource createConfigBean(Resources param, Properties properties) throws PropertyVetoException, TransactionFailure {
ExternalJndiResource newResource = param.createChild(ExternalJndiResource.class);
newResource.setJndiName(jndiName);
newResource.setFactoryClass(factoryClass);
newResource.setJndiLookupName(jndiLookupName);
newResource.setResType(resType);
newResource.setEnabled(enabled);
if (description != null) {
newResource.setDescription(description);
}
if (properties != null) {
for (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;
}
Aggregations