Search in sources :

Example 16 with PoolInfo

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

the class ConnectorConnectionPoolAdminServiceImpl method getPoolNameFromResourceJndiName.

/**
 * Gets the Pool name that this JDBC resource points to. In case of a PMF resource
 * gets the pool name of the pool pointed to by jdbc resource being pointed to by
 * the PMF resource
 *
 * @param jndiName the jndi name of the resource being used to get Connection from
 *                 This resource can either be a pmf resource or a jdbc resource
 * @return poolName of the pool that this resource directly/indirectly points to
 */
private PoolInfo getPoolNameFromResourceJndiName(ResourceInfo resourceInfo) {
    PoolInfo poolInfo = null;
    Collection<ConnectorRuntimeExtension> extensions = Globals.getDefaultHabitat().getAllServices(ConnectorRuntimeExtension.class);
    for (ConnectorRuntimeExtension extension : extensions) {
        poolInfo = extension.getPoolNameFromResourceJndiName(resourceInfo);
    }
    return poolInfo;
}
Also used : PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo)

Example 17 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
 * @return a java.sql.Connection
 * @throws java.sql.SQLException in case of errors
 */
public Connection getConnection(ResourceInfo resourceInfo) 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);
        }
        con = (java.sql.Connection) getUnpooledConnection(poolInfo, null, 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("Exception : " + 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) 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 18 with PoolInfo

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

the class ConnectorConnectionPoolAdminServiceImpl method reconfigureConnectorConnectionPool.

/**
 * Reconfigure a connection pool.
 * This method compares the passed connector connection pool with the one
 * in memory. If the pools are unequal and the MCF properties are changed
 * a pool recreate is required. However if the pools are unequal and the
 * MCF properties are not changed a recreate is not required
 *
 * @param ccp           - the Updated connector connection pool object that admin
 *                      hands over
 * @param excludedProps - A set of excluded property names that we want
 *                      to be excluded in the comparison check while
 *                      comparing MCF properties
 * @return true - if a pool restart is required, false otherwise
 * @throws ConnectorRuntimeException
 */
public boolean reconfigureConnectorConnectionPool(ConnectorConnectionPool ccp, Set excludedProps) throws ConnectorRuntimeException {
    if (ccp == null) {
        throw new ConnectorRuntimeException("No pool to reconfigure, new pool object is null");
    }
    logFine("new ccp :\n" + ccp.toString());
    // see if the new ConnectorConnectionPool is different from
    // the original one and update relevant properties
    PoolInfo poolInfo = ccp.getPoolInfo();
    ConnectorConnectionPool origCcp = null;
    try {
        origCcp = getOriginalConnectorConnectionPool(poolInfo);
    } catch (NamingException ne) {
        throw new ConnectorRuntimeException(ne.getMessage());
    }
    if (origCcp == null) {
        throw new ConnectorRuntimeException("No pool to reconfigure, original pool object is null");
    }
    logFine("original ccp :\n" + origCcp.toString());
    ConnectionPoolReconfigHelper.ReconfigAction action = ConnectionPoolReconfigHelper.compare(origCcp, ccp, excludedProps);
    logFine("pool reconfig action == " + action);
    if (action == ConnectionPoolReconfigHelper.ReconfigAction.UPDATE_MCF_AND_ATTRIBUTES) {
        updateMCFAndPoolAttributes(ccp);
    } else if (action == ConnectionPoolReconfigHelper.ReconfigAction.RECREATE_POOL) {
        return true;
    }
    return false;
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) NamingException(javax.naming.NamingException)

Example 19 with PoolInfo

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

the class ConnectorResourceAdminServiceImpl method createConnectorResource.

/**
 * Creates the connector resource on a given connection pool
 *
 * @param resourceInfo     JNDI name of the resource to be created
 * @param poolInfo     PoolName to which the connector resource belongs.
 * @param resourceType Resource type Unused.
 * @throws ConnectorRuntimeException If the resouce creation fails.
 */
public void createConnectorResource(ResourceInfo resourceInfo, PoolInfo poolInfo, String resourceType) throws ConnectorRuntimeException {
    try {
        ConnectorConnectionPool ccp = null;
        String jndiNameForPool = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForPool(poolInfo);
        try {
            ccp = (ConnectorConnectionPool) namingService.lookup(poolInfo, jndiNameForPool);
        } catch (NamingException ne) {
            // Probably the pool is not yet initialized (lazy-loading), try doing a lookup
            try {
                checkAndLoadPool(poolInfo);
                ccp = (ConnectorConnectionPool) namingService.lookup(poolInfo, jndiNameForPool);
            } catch (NamingException e) {
                Object[] params = new Object[] { poolInfo, e };
                _logger.log(Level.SEVERE, "unable.to.lookup.pool", params);
            }
        }
        if (ccp == null) {
            ccp = (ConnectorConnectionPool) namingService.lookup(poolInfo, jndiNameForPool);
        }
        ConnectorDescriptorInfo cdi = ccp.getConnectorDescriptorInfo();
        javax.naming.Reference ref = new javax.naming.Reference(cdi.getConnectionFactoryClass(), "com.sun.enterprise.resource.naming.ConnectorObjectFactory", null);
        RefAddr addr = new SerializableObjectRefAddr(PoolInfo.class.getName(), poolInfo);
        ref.add(addr);
        addr = new StringRefAddr("rarName", cdi.getRarName());
        ref.add(addr);
        RefAddr resAddr = new SerializableObjectRefAddr(ResourceInfo.class.getName(), resourceInfo);
        ref.add(resAddr);
        try {
            namingService.publishObject(resourceInfo, ref, true);
            _registry.addResourceInfo(resourceInfo);
        } catch (NamingException ne) {
            ConnectorRuntimeException cre = new ConnectorRuntimeException(ne.getMessage());
            cre.initCause(ne);
            Object[] params = new Object[] { resourceInfo, cre };
            _logger.log(Level.SEVERE, "rardeployment.resource_jndi_bind_failure", params);
            throw cre;
        }
        /*

            ConnectorObjectFactory cof = new ConnectorObjectFactory(jndiName, ccp.getConnectorDescriptorInfo().
                    getConnectionFactoryClass(), cdi.getRarName(), poolName);

            _runtime.getNamingManager().publishObject(jndiName, cof, true);
*/
        // To notify that a connector resource rebind has happened.
        ConnectorResourceNamingEventNotifier.getInstance().notifyListeners(new ConnectorNamingEvent(resourceInfo.toString(), ConnectorNamingEvent.EVENT_OBJECT_REBIND));
    } catch (NamingException ne) {
        ConnectorRuntimeException cre = new ConnectorRuntimeException(ne.getMessage());
        cre.initCause(ne);
        Object[] params = new Object[] { resourceInfo, cre };
        _logger.log(Level.SEVERE, "rardeployment.jndi_lookup_failed", params);
        throw cre;
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ConnectorConnectionPool(com.sun.enterprise.connectors.ConnectorConnectionPool) SerializableObjectRefAddr(org.glassfish.resources.naming.SerializableObjectRefAddr) ConnectorNamingEvent(com.sun.appserv.connectors.internal.spi.ConnectorNamingEvent) RefAddr(javax.naming.RefAddr) SerializableObjectRefAddr(org.glassfish.resources.naming.SerializableObjectRefAddr) StringRefAddr(javax.naming.StringRefAddr) StringRefAddr(javax.naming.StringRefAddr) ConnectorDescriptorInfo(com.sun.enterprise.connectors.ConnectorDescriptorInfo) NamingException(javax.naming.NamingException) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo)

Example 20 with PoolInfo

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

the class ConnectorResourceDeployer method deployResource.

/**
 * {@inheritDoc}
 */
public void deployResource(Object resource) throws Exception {
    // deployResource is not synchronized as there is only one caller
    // ResourceProxy which is synchronized
    ConnectorResource domainResource = (ConnectorResource) resource;
    String poolName = domainResource.getPoolName();
    ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(domainResource);
    PoolInfo poolInfo = new PoolInfo(poolName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
    createConnectorResource(domainResource, resourceInfo, poolInfo);
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) ConnectorResource(org.glassfish.connectors.config.ConnectorResource)

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