Search in sources :

Example 11 with PoolInfo

use of org.glassfish.resourcebase.resources.api.PoolInfo in project Payara by payara.

the class PoolManagerImpl method resourceEnlisted.

public void resourceEnlisted(Transaction tran, com.sun.appserv.connectors.internal.api.ResourceHandle h) throws IllegalStateException {
    ResourceHandle res = (ResourceHandle) h;
    PoolInfo poolInfo = res.getResourceSpec().getPoolInfo();
    try {
        JavaEETransaction j2eeTran = (JavaEETransaction) tran;
        if (poolInfo != null && j2eeTran.getResources(poolInfo) == null) {
            addSyncListener(tran);
        }
    } catch (ClassCastException e) {
        addSyncListener(tran);
    }
    if (poolInfo != null) {
        ResourcePool pool = getPool(poolInfo);
        if (pool != null) {
            pool.resourceEnlisted(tran, res);
        }
    }
}
Also used : JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) ResourceHandle(com.sun.enterprise.resource.ResourceHandle) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo)

Example 12 with PoolInfo

use of org.glassfish.resourcebase.resources.api.PoolInfo in project Payara by payara.

the class ConnectorsRecoveryResourceHandler method loadXAResourcesAndItsConnections.

/**
 * {@inheritDoc}
 */
public void loadXAResourcesAndItsConnections(List xaresList, List connList) {
    // Done so as to initialize connectors-runtime before loading connector-resources. need a better way ?
    ConnectorRuntime crt = connectorRuntimeProvider.get();
    // ApplicationLoaderService already guarantees that connectors are loaded before any other applications.
    // Recovery will not start sooner than transaction is first needed on EE application startup, therefore
    // it is safe to continue here without waiting for startupProvider, as that ultimately creates a deadlock
    // between ApplicationLoaderService needed a transaction manager, and recovery wainting for applications
    // to finish loading.
    Collection<ConnectorResource> connectorResources = getAllConnectorResources();
    if (connectorResources == null || connectorResources.size() == 0) {
        return;
    }
    List<ConnectorConnectionPool> connPools = new ArrayList<ConnectorConnectionPool>();
    for (Resource resource : connectorResources) {
        ConnectorResource connResource = (ConnectorResource) resource;
        if (getResourcesUtil().isEnabled(connResource)) {
            ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(connResource);
            ConnectorConnectionPool pool = ResourcesUtil.createInstance().getConnectorConnectionPoolOfResource(resourceInfo);
            if (pool != null && ConnectorConstants.XA_TRANSACTION_TX_SUPPORT_STRING.equals(getTransactionSupport(pool))) {
                connPools.add(pool);
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.fine("ConnectorsRecoveryResourceHandler loadXAResourcesAndItsConnections :: " + "adding : " + connResource.getPoolName());
                }
            }
        }
    }
    loadAllConnectorResources();
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Recovering pools : " + connPools.size());
    }
    for (ConnectorConnectionPool connPool : connPools) {
        PoolInfo poolInfo = ConnectorsUtil.getPoolInfo(connPool);
        try {
            String[] dbUserPassword = getdbUserPasswordOfConnectorConnectionPool(connPool);
            if (dbUserPassword == null) {
                continue;
            }
            String dbUser = dbUserPassword[0];
            String dbPassword = dbUserPassword[1];
            Subject subject = new Subject();
            // username [pointbase interprets this as "root"]/password.
            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);
                }
            }
            String rarName = connPool.getResourceAdapterName();
            // TODO V3 JMS-RA ??
            if (ConnectorAdminServiceUtils.isJMSRA(rarName)) {
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "Performing recovery for JMS RA, poolName  " + poolInfo);
                }
                ManagedConnectionFactory[] mcfs = crt.obtainManagedConnectionFactories(poolInfo);
                _logger.log(Level.INFO, "JMS resource recovery has created CFs = " + mcfs.length);
                for (int i = 0; i < mcfs.length; i++) {
                    PasswordCredential pc = new PasswordCredential(dbUser, dbPassword.toCharArray());
                    pc.setManagedConnectionFactory(mcfs[i]);
                    Principal prin = new ResourcePrincipal(dbUser, dbPassword);
                    subject.getPrincipals().add(prin);
                    subject.getPrivateCredentials().add(pc);
                    ManagedConnection mc = mcfs[i].createManagedConnection(subject, null);
                    connList.add(mc);
                    try {
                        XAResource xares = mc.getXAResource();
                        if (xares != null) {
                            xaresList.add(xares);
                        }
                    } catch (ResourceException ex) {
                    // ignored. Not at XA_TRANSACTION level
                    }
                }
            } else {
                ManagedConnectionFactory mcf = crt.obtainManagedConnectionFactory(poolInfo);
                PasswordCredential pc = new PasswordCredential(dbUser, dbPassword.toCharArray());
                pc.setManagedConnectionFactory(mcf);
                Principal prin = new ResourcePrincipal(dbUser, dbPassword);
                subject.getPrincipals().add(prin);
                subject.getPrivateCredentials().add(pc);
                ManagedConnection mc = mcf.createManagedConnection(subject, null);
                connList.add(mc);
                try {
                    XAResource xares = mc.getXAResource();
                    if (xares != null) {
                        xaresList.add(xares);
                    }
                } catch (ResourceException 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);
            }
        }
    }
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Total XAResources identified for recovery is " + xaresList.size());
        _logger.log(Level.FINE, "Total connections identified for recovery is " + connList.size());
    }
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) XAResource(javax.transaction.xa.XAResource) ConnectorResource(org.glassfish.connectors.config.ConnectorResource) PasswordCredential(javax.resource.spi.security.PasswordCredential) ResourcePrincipal(com.sun.enterprise.deployment.ResourcePrincipal) Subject(javax.security.auth.Subject) ResourceException(javax.resource.ResourceException) NamingException(javax.naming.NamingException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ManagedConnectionFactory(javax.resource.spi.ManagedConnectionFactory) XAResource(javax.transaction.xa.XAResource) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) ManagedConnection(javax.resource.spi.ManagedConnection) ResourceException(javax.resource.ResourceException) ConnectorResource(org.glassfish.connectors.config.ConnectorResource) ResourcePrincipal(com.sun.enterprise.deployment.ResourcePrincipal) Principal(java.security.Principal) ConnectorRuntime(com.sun.enterprise.connectors.ConnectorRuntime)

Example 13 with PoolInfo

use of org.glassfish.resourcebase.resources.api.PoolInfo in project Payara by payara.

the class ActiveResourceAdapterImpl method createSunRAConnectionPool.

/**
 * Creates connector connection pool pertaining to sun-ra.xml. This is
 * only for 1.0 complient rars.
 *
 * @throws ConnectorRuntimeException Thrown when pool creation fails.
 */
private void createSunRAConnectionPool() throws ConnectorRuntimeException {
    String defaultPoolName = connectorRuntime_.getDefaultPoolName(moduleName_, connectionDefs_[0].getConnectionFactoryIntf());
    String sunRAPoolName = defaultPoolName + ConnectorConstants.SUN_RA_POOL;
    PoolInfo poolInfo = new PoolInfo(sunRAPoolName);
    ConnectorDescriptorInfo connectorDescriptorInfo = ConnectorDDTransformUtils.getConnectorDescriptorInfo(connectionDefs_[0]);
    connectorDescriptorInfo.setRarName(moduleName_);
    connectorDescriptorInfo.setResourceAdapterClassName(desc_.getResourceAdapterClass());
    ConnectorConnectionPool connectorPoolObj = ConnectionPoolObjectsUtils.createSunRaConnectorPoolObject(poolInfo, desc_, moduleName_);
    connectorPoolObj.setConnectorDescriptorInfo(connectorDescriptorInfo);
    connectorRuntime_.createConnectorConnectionPool(connectorPoolObj);
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Created SUN-RA connection pool:", poolInfo);
    }
    String jndiName = (String) desc_.getSunDescriptor().getResourceAdapter().getValue(ResourceAdapter.JNDI_NAME);
    ResourceInfo resourceInfo = new ResourceInfo(jndiName);
    connectorRuntime_.createConnectorResource(resourceInfo, poolInfo, null);
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Created SUN-RA connector resource : ", resourceInfo);
    }
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo)

Example 14 with PoolInfo

use of org.glassfish.resourcebase.resources.api.PoolInfo in project Payara by payara.

the class ActiveResourceAdapterImpl method deleteDefaultConnectorConnectionPools.

/**
 * Deletes the default connector connection pools.
 */
protected void deleteDefaultConnectorConnectionPools() {
    for (ConnectionDefDescriptor aConnectionDefs_ : connectionDefs_) {
        String connectionDefName = aConnectionDefs_.getConnectionFactoryIntf();
        String resourceJndiName = connectorRuntime_.getDefaultPoolName(moduleName_, connectionDefName);
        try {
            PoolInfo poolInfo = new PoolInfo(resourceJndiName);
            connectorRuntime_.deleteConnectorConnectionPool(poolInfo);
        } catch (ConnectorRuntimeException cre) {
            _logger.log(Level.WARNING, "rar.undeployment.default_pool_delete_fail", resourceJndiName);
        }
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectionDefDescriptor(com.sun.enterprise.deployment.ConnectionDefDescriptor) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo)

Example 15 with PoolInfo

use of org.glassfish.resourcebase.resources.api.PoolInfo in project Payara by payara.

the class ActiveResourceAdapterImpl method createDefaultConnectorResources.

/**
 * Creates default connector resource
 *
 * @throws ConnectorRuntimeException when unable to create connector resources
 */
protected void createDefaultConnectorResources() throws ConnectorRuntimeException {
    for (ConnectionDefDescriptor descriptor : connectionDefs_) {
        String connectionDefName = descriptor.getConnectionFactoryIntf();
        String resourceName = connectorRuntime_.getDefaultResourceName(moduleName_, connectionDefName);
        String poolName = connectorRuntime_.getDefaultPoolName(moduleName_, connectionDefName);
        PoolInfo poolInfo = new PoolInfo(poolName);
        ResourceInfo resourceInfo = new ResourceInfo(resourceName);
        connectorRuntime_.createConnectorResource(resourceInfo, poolInfo, null);
        desc_.addDefaultResourceName(resourceName);
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "Created default connector resource [ " + resourceName + " ] ");
        }
    }
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ConnectionDefDescriptor(com.sun.enterprise.deployment.ConnectionDefDescriptor) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo)

Aggregations

PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)52 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)17 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)15 NamingException (javax.naming.NamingException)10 JdbcConnectionPool (org.glassfish.jdbc.config.JdbcConnectionPool)9 ConnectorConnectionPool (com.sun.enterprise.connectors.ConnectorConnectionPool)7 ManagedConnectionFactory (javax.resource.spi.ManagedConnectionFactory)7 ProbeListener (org.glassfish.external.probe.provider.annotations.ProbeListener)7 ResourceException (javax.resource.ResourceException)6 Property (org.jvnet.hk2.config.types.Property)5 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)4 Resources (com.sun.enterprise.config.serverbeans.Resources)4 ConnectionDefDescriptor (com.sun.enterprise.deployment.ConnectionDefDescriptor)4 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)4 ArrayList (java.util.ArrayList)4 JdbcResource (org.glassfish.jdbc.config.JdbcResource)4 ConnectorRegistry (com.sun.enterprise.connectors.ConnectorRegistry)3 ConnectorRuntime (com.sun.enterprise.connectors.ConnectorRuntime)3 ResourcePrincipal (com.sun.enterprise.deployment.ResourcePrincipal)3 ActionReport (org.glassfish.api.ActionReport)3