Search in sources :

Example 26 with PoolInfo

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

the class ConnectionPoolHealthCheck method doCheck.

@Override
public HealthCheckResult doCheck() {
    HealthCheckResult result = new HealthCheckResult();
    Collection<JdbcResource> allJdbcResources = getAllJdbcResources();
    for (JdbcResource resource : allJdbcResources) {
        ResourceInfo resourceInfo = ResourceUtil.getResourceInfo(resource);
        JdbcConnectionPool pool = JdbcResourcesUtil.createInstance().getJdbcConnectionPoolOfResource(resourceInfo);
        PoolInfo poolInfo = ResourceUtil.getPoolInfo(pool);
        if (getOptions().getPoolName() != null) {
            if (getOptions().getPoolName().equals(poolInfo.getName())) {
                evaluatePoolUsage(result, poolInfo);
            }
        } else {
            evaluatePoolUsage(result, poolInfo);
        }
    }
    return result;
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) JdbcResource(org.glassfish.jdbc.config.JdbcResource) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) HealthCheckResult(fish.payara.nucleus.healthcheck.HealthCheckResult) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo)

Example 27 with PoolInfo

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

the class ActiveResourceAdapterImpl method createDefaultConnectorConnectionPools.

/**
 * Creates default connector connection pool
 *
 * @param useSunRA whether to use default pool settings or settings in sun-ra.xml
 * @throws ConnectorRuntimeException when unable to create connector connection pools
 */
protected void createDefaultConnectorConnectionPools(boolean useSunRA) throws ConnectorRuntimeException {
    for (ConnectionDefDescriptor descriptor : connectionDefs_) {
        String poolName = connectorRuntime_.getDefaultPoolName(moduleName_, descriptor.getConnectionFactoryIntf());
        PoolInfo poolInfo = new PoolInfo(poolName);
        ConnectorDescriptorInfo connectorDescriptorInfo = ConnectorDDTransformUtils.getConnectorDescriptorInfo(descriptor);
        connectorDescriptorInfo.setRarName(moduleName_);
        connectorDescriptorInfo.setResourceAdapterClassName(desc_.getResourceAdapterClass());
        ConnectorConnectionPool connectorPoolObj;
        // from sunRAXML
        if (useSunRA) {
            connectorPoolObj = ConnectionPoolObjectsUtils.createSunRaConnectorPoolObject(poolInfo, desc_, moduleName_);
        } else {
            connectorPoolObj = ConnectionPoolObjectsUtils.createDefaultConnectorPoolObject(poolInfo, moduleName_);
        }
        connectorPoolObj.setConnectorDescriptorInfo(connectorDescriptorInfo);
        connectorRuntime_.createConnectorConnectionPool(connectorPoolObj);
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "Created default connection pool [ " + poolInfo + " ] ");
        }
    }
}
Also used : ConnectionDefDescriptor(com.sun.enterprise.deployment.ConnectionDefDescriptor) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo)

Example 28 with PoolInfo

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

the class ActiveResourceAdapterImpl method deleteSunRAConnectionPool.

/**
 * Added to clean up the connector connection pool pertaining to sun-ra.xml. This is
 * only for 1.0 complient rars.
 */
private void deleteSunRAConnectionPool() {
    String defaultPoolName = connectorRuntime_.getDefaultPoolName(moduleName_, connectionDefs_[0].getConnectionFactoryIntf());
    String sunRAPoolName = defaultPoolName + ConnectorConstants.SUN_RA_POOL;
    PoolInfo poolInfo = new PoolInfo(sunRAPoolName);
    try {
        connectorRuntime_.deleteConnectorConnectionPool(poolInfo);
    } catch (ConnectorRuntimeException cre) {
        _logger.log(Level.WARNING, "rar.undeployment.sun_ra_pool_delete_fail", poolInfo);
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo)

Example 29 with PoolInfo

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

the class ConnectorConnectionPoolAdminServiceImpl method getConnection.

/**
 * Get a sql connection from the DataSource specified by the jdbcJndiName.
 * This API is intended to be used in the DAS. The motivation for having this
 * API is to provide the CMP backend a means of acquiring a connection during
 * the codegen phase. If a user is trying to deploy an app on a remote server,
 * without this API, a resource reference has to be present both in the DAS
 * and the server instance. This makes the deployment more complex for the
 * user since a resource needs to be forcibly created in the DAS Too.
 * This API will mitigate this need.
 *
 * @param resourceInfo the jndi name of the resource being used to get Connection from
 *                 This resource can either be a pmf resource or a jdbc resource
 * @param user     the user used to authenticate this request
 * @param password the password used to authenticate this request
 * @return a java.sql.Connection
 * @throws java.sql.SQLException in case of errors
 */
public Connection getConnection(ResourceInfo resourceInfo, String user, String password) throws SQLException {
    java.sql.Connection con = null;
    try {
        // DASResourcesUtil.setAdminConfigContext();
        PoolInfo poolInfo = getPoolNameFromResourceJndiName(resourceInfo);
        if (poolInfo == null) {
            throw new SQLException("No pool by name exists ");
        }
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("ConnectorRuntime.getConnection :: poolName : " + poolInfo);
        }
        // Maintain consitency with the ConnectionManagerImpl change to be checked in later
        String passwd = (password == null) ? "" : password;
        // From what we have seen so far, the user cannot be null
        // but password can be
        // if user is null we will use default authentication
        // TODO: Discuss if this is the right thing to do
        ResourcePrincipal prin = (user == null) ? null : new ResourcePrincipal(user, passwd);
        con = (java.sql.Connection) getUnpooledConnection(poolInfo, prin, true);
        if (con == null) {
            String i18nMsg = localStrings.getString("ccp_adm.null_unpooled_connection");
            throw new SQLException(i18nMsg);
        }
    } catch (ResourceException re) {
        SQLException sqle = new SQLException(re.getMessage());
        sqle.initCause(re);
        _logger.log(Level.WARNING, "jdbc.exc_get_conn", re.getMessage());
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine(" getConnection in ConnectorRuntime failed : " + re);
        }
        throw sqle;
    } catch (Exception ex) {
        SQLException sqle = new SQLException(ex.getMessage());
        sqle.initCause(ex);
        _logger.log(Level.WARNING, "jdbc.exc_get_conn", ex.getMessage());
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine(" getConnection in ConnectorRuntime failed : " + ex);
        }
        throw sqle;
    }
    return con;
}
Also used : Connection(java.sql.Connection) SQLException(java.sql.SQLException) ResourcePrincipal(com.sun.enterprise.deployment.ResourcePrincipal) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) ResourceException(javax.resource.ResourceException) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceException(javax.resource.ResourceException) NamingException(javax.naming.NamingException) SQLException(java.sql.SQLException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)

Example 30 with PoolInfo

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

the class ConnectorConnectionPoolAdminServiceImpl method createConnectorConnectionPool.

/**
 * Creates connector connection pool in the connector container.
 *
 * @param ccp     ConnectorConnectionPool instance to be bound to JNDI. This
 *                object contains the pool properties.
 * @param cdd     ConnectorDescriptor obejct which abstracts the ra.xml
 * @param rarName Name of the resource adapter
 * @throws ConnectorRuntimeException When creation of pool fails.
 */
/*
    public void createConnectorConnectionPool(ConnectorConnectionPool ccp,
                                              ConnectionDefDescriptor cdd, String rarName)
            throws ConnectorRuntimeException {

        if ((ccp == null) || (cdd == null) || (rarName == null)) {

            if(_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "Wrong parameters for pool creation ");
            }
            String i18nMsg = localStrings.getString("ccp_adm.wrong_params_for_create");
            throw new ConnectorRuntimeException(i18nMsg);
        }
        ConnectorDescriptorInfo cdi = new ConnectorDescriptorInfo();

        ConnectorDescriptor connectorDescriptor = _registry.getDescriptor(rarName);

        if (connectorDescriptor == null) {
            String i18nMsg = localStrings.getString("ccp_adm.no_conn_pool_obj", rarName);
            ConnectorRuntimeException cre = new ConnectorRuntimeException(i18nMsg);
            _logger.log(Level.SEVERE, "rardeployment.connector_descriptor_notfound_registry", rarName);
            _logger.log(Level.SEVERE, "", cre);
            throw cre;
        }
        cdi.setRarName(rarName);
        cdi.setResourceAdapterClassName(
                connectorDescriptor.getResourceAdapterClass());
        cdi.setConnectionDefinitionName(cdd.getConnectionFactoryIntf());
        cdi.setManagedConnectionFactoryClass(
                cdd.getManagedConnectionFactoryImpl());
        cdi.setConnectionFactoryClass(cdd.getConnectionFactoryImpl());
        cdi.setConnectionFactoryInterface(cdd.getConnectionFactoryIntf());
        cdi.setConnectionClass(cdd.getConnectionImpl());
        cdi.setConnectionInterface(cdd.getConnectionIntf());
        cdi.setMCFConfigProperties(cdd.getConfigProperties());
        cdi.setResourceAdapterConfigProperties(
                connectorDescriptor.getConfigProperties());
        createConnectorConnectionPool(ccp, cdi);
    }
*/
/**
 * Creates connector connection pool in the connector container.
 *
 * @param connectorPoolObj  ConnectorConnectionPool instance to be bound to JNDI. This
 *                          object contains the pool properties.
 * @param connectorDescInfo ConnectorDescriptorInfo object which
 *                          abstracts the connection definition values
 *                          present in ra.xml
 * @throws ConnectorRuntimeException When creation of pool fails.
 */
/*
    private void createConnectorConnectionPool(
            ConnectorConnectionPool connectorPoolObj,
            ConnectorDescriptorInfo connectorDescInfo)
            throws ConnectorRuntimeException {

        connectorPoolObj.setConnectorDescriptorInfo(connectorDescInfo);
        createConnectorConnectionPool(connectorPoolObj);
    }
*/
/**
 * Creates connector connection pool in the connector container.
 *
 * @param connectorPoolObj ConnectorConnectionPool instance to be bound to JNDI. This
 *                         object contains the pool properties.
 * @throws ConnectorRuntimeException When creation of pool fails.
 */
public void createConnectorConnectionPool(ConnectorConnectionPool connectorPoolObj) throws ConnectorRuntimeException {
    if (connectorPoolObj == null) {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "Wrong parameters for pool creation ");
        }
        String i18nMsg = localStrings.getString("ccp_adm.wrong_params_for_create");
        throw new ConnectorRuntimeException(i18nMsg);
    }
    PoolInfo poolInfo = connectorPoolObj.getPoolInfo();
    String jndiNameForPool = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForPool(poolInfo);
    try {
        _runtime.getResourceNamingService().publishObject(poolInfo, jndiNameForPool, connectorPoolObj, true);
        ManagedConnectionFactory mcf = createManagedConnectionFactory(connectorPoolObj);
        if (mcf == null) {
            _runtime.getResourceNamingService().unpublishObject(poolInfo, jndiNameForPool);
            String i18nMsg = localStrings.getString("ccp_adm.failed_to_create_mcf", poolInfo);
            ConnectorRuntimeException cre = new ConnectorRuntimeException(i18nMsg);
            _logger.log(Level.SEVERE, "rardeployment.mcf_creation_failure", poolInfo);
            _logger.log(Level.SEVERE, "", cre);
            throw cre;
        }
    } catch (NamingException ex) {
        String i18nMsg = localStrings.getString("ccp_adm.failed_to_publish_in_jndi", poolInfo);
        ConnectorRuntimeException cre = new ConnectorRuntimeException(i18nMsg);
        cre.initCause(ex);
        _logger.log(Level.SEVERE, "rardeployment.pool_jndi_bind_failure", poolInfo);
        _logger.log(Level.SEVERE, "", cre);
        throw cre;
    } catch (NullPointerException ex) {
        try {
            _runtime.getResourceNamingService().unpublishObject(poolInfo, jndiNameForPool);
        } catch (NamingException ne) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "Failed to unbind connection pool object  ", poolInfo);
            }
        }
        String i18nMsg = localStrings.getString("ccp_adm.failed_to_register_mcf", poolInfo);
        ConnectorRuntimeException cre = new ConnectorRuntimeException(i18nMsg);
        cre.initCause(ex);
        _logger.log(Level.SEVERE, "rardeployment.mcf_registration_failure", poolInfo);
        _logger.log(Level.SEVERE, "", cre);
        throw cre;
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ManagedConnectionFactory(javax.resource.spi.ManagedConnectionFactory) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) NamingException(javax.naming.NamingException)

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