Search in sources :

Example 31 with PoolInfo

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

the class ConnectorConnectionPoolAdminServiceImpl method updateMCFAndPoolAttributes.

private void updateMCFAndPoolAttributes(ConnectorConnectionPool ccp) throws ConnectorRuntimeException {
    PoolInfo poolInfo = ccp.getPoolInfo();
    try {
        ConnectorConnectionPool origCcp = getOriginalConnectorConnectionPool(poolInfo);
        // update properties
        origCcp.setSteadyPoolSize(ccp.getSteadyPoolSize());
        origCcp.setMaxPoolSize(ccp.getMaxPoolSize());
        origCcp.setMaxWaitTimeInMillis(ccp.getMaxWaitTimeInMillis());
        origCcp.setPoolResizeQuantity(ccp.getPoolResizeQuantity());
        origCcp.setIdleTimeoutInSeconds(ccp.getIdleTimeoutInSeconds());
        origCcp.setFailAllConnections(ccp.isFailAllConnections());
        // lazyEnlist, lazyAssoc and assocWithThread not required since they result
        // in a pool restart anyways, so they wouldn't have changed if we
        // came here
        origCcp.setMatchConnections(ccp.matchConnections());
        origCcp.setMaxConnectionUsage(ccp.getMaxConnectionUsage());
        origCcp.setNonComponent(ccp.isNonComponent());
        origCcp.setNonTransactional(ccp.isNonTransactional());
        origCcp.setConCreationRetryAttempts(ccp.getConCreationRetryAttempts());
        origCcp.setConCreationRetryInterval(ccp.getConCreationRetryInterval());
        origCcp.setValidateAtmostOncePeriod(ccp.getValidateAtmostOncePeriod());
        origCcp.setConnectionLeakTracingTimeout(ccp.getConnectionLeakTracingTimeout());
        origCcp.setConnectionReclaim(ccp.isConnectionReclaim());
        // now rebind the object in jndi
        String jndiNameForPool = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForPool(poolInfo);
        _runtime.getResourceNamingService().unpublishObject(poolInfo, jndiNameForPool);
        _runtime.getResourceNamingService().publishObject(poolInfo, jndiNameForPool, origCcp, true);
    } catch (NamingException ne) {
        throw new ConnectorRuntimeException(ne.getMessage());
    }
    // Check if this pool has been brought into memory
    // If its already in memory, just call reconfig on it
    PoolManager poolMgr = _runtime.getPoolManager();
    try {
        poolMgr.reconfigPoolProperties(ccp);
    } catch (PoolingException pe) {
        throw new ConnectorRuntimeException(pe.getMessage());
    }
    // Run setXXX methods on the copy of the MCF that we have
    // this is done to update the MCF to reflect changes in the
    // MCF properties for which we don't really need to recreate
    // the pool
    ConnectorRegistry registry = ConnectorRegistry.getInstance();
    ManagedConnectionFactory mcf = registry.getManagedConnectionFactory(poolInfo);
    SetMethodAction sma = new SetMethodAction(mcf, ccp.getConnectorDescriptorInfo().getMCFConfigProperties());
    try {
        sma.run();
    } catch (Exception e) {
        _logger.log(Level.WARNING, e.getMessage());
        ConnectorRuntimeException cre = new ConnectorRuntimeException(e.getMessage());
        cre.initCause(e);
        throw cre;
    }
    // update the properties "allow-non-component-callers" and
    // "non-transactional-connections" in the PoolMetaData
    PoolMetaData pmd = registry.getPoolMetaData(poolInfo);
    pmd.setIsPM(ccp.isNonComponent());
    pmd.setIsNonTx(ccp.isNonTransactional());
    pmd.setAuthCredentialsDefinedInPool(ccp.getAuthCredentialsDefinedInPool());
    logFine("Pool properties reconfiguration done");
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ManagedConnectionFactory(javax.resource.spi.ManagedConnectionFactory) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) NamingException(javax.naming.NamingException) PoolManager(com.sun.enterprise.resource.pool.PoolManager) 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 32 with PoolInfo

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

the class ConnectorConnectionPoolAdminServiceImpl method recreateConnectorConnectionPool.

/**
 * Recreate a connector connection pool. This method essentially does
 * the following things:
 * 1. Delete the said connector connection pool<br>
 * 2. Bind the pool to JNDI<br>
 * 3. Create an MCF for this pool and register with the connector registry<br>
 *
 * @param ccp - the ConnectorConnectionPool to publish
 */
public void recreateConnectorConnectionPool(ConnectorConnectionPool ccp) throws ConnectorRuntimeException {
    ConnectorRegistry registry = ConnectorRegistry.getInstance();
    if (registry == null) {
        throw new ConnectorRuntimeException("Cannot get ConnectorRegistry");
    }
    PoolInfo poolInfo = ccp.getPoolInfo();
    // First remove this pool from memory
    try {
        unloadAndKillPool(poolInfo);
    } catch (ConnectorRuntimeException cre) {
        throw cre;
    }
    // kill the pool
    // FIXME: deleteConnectorConnectionPool should do this
    // PoolManager poolManager = Switch.getSwitch().getPoolManager();
    // poolManager.killPool( poolName );
    // Now bind the updated pool and
    // obtain a new managed connection factory for this pool
    String jndiNameForPool = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForPool(poolInfo);
    ManagedConnectionFactory mcf = null;
    try {
        _runtime.getResourceNamingService().publishObject(poolInfo, jndiNameForPool, ccp, true);
        mcf = obtainManagedConnectionFactory(poolInfo);
    } catch (NamingException ne) {
        _logger.log(Level.SEVERE, "rardeployment.pool_jndi_bind_failure", poolInfo);
        String i18nMsg = localStrings.getString("ccp_adm.could_not_recreate_pool", poolInfo);
        ConnectorRuntimeException crex = new ConnectorRuntimeException(i18nMsg);
        crex.initCause(ne);
        throw crex;
    } finally {
        if (mcf == null) {
            try {
                _runtime.getResourceNamingService().unpublishObject(poolInfo, jndiNameForPool);
            } catch (NamingException e) {
                _logger.log(Level.WARNING, "Unable to unbind the pool configuration object " + "of pool [ " + poolInfo + " ] during MCF creation failure");
            }
            _logger.log(Level.WARNING, "rardeployment.mcf_creation_failure", poolInfo);
            String i18nMsg = localStrings.getString("ccp_adm.failed_to_create_mcf", poolInfo);
            throw new ConnectorRuntimeException(i18nMsg);
        }
    }
}
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)

Example 33 with PoolInfo

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

the class FlushConnectionPool method execute.

public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    Resources resources = domain.getResources();
    String scope = "";
    if (moduleName != null) {
        if (!poolUtil.isValidModule(applicationName, moduleName, poolName, report)) {
            return;
        }
        Application application = applications.getApplication(applicationName);
        Module module = application.getModule(moduleName);
        resources = module.getResources();
        scope = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX;
    } else if (applicationName != null) {
        if (!poolUtil.isValidApplication(applicationName, poolName, report)) {
            return;
        }
        Application application = applications.getApplication(applicationName);
        resources = application.getResources();
        scope = ConnectorConstants.JAVA_APP_SCOPE_PREFIX;
    }
    if (!poolUtil.isValidPool(resources, poolName, scope, report)) {
        return;
    }
    boolean poolingEnabled = false;
    ResourcePool pool = (ResourcePool) ConnectorsUtil.getResourceByName(resources, ResourcePool.class, poolName);
    if (pool instanceof ConnectorConnectionPool) {
        ConnectorConnectionPool ccp = (ConnectorConnectionPool) pool;
        poolingEnabled = Boolean.valueOf(ccp.getPooling());
    } else {
        JdbcConnectionPool ccp = (JdbcConnectionPool) pool;
        poolingEnabled = Boolean.valueOf(ccp.getPooling());
    }
    if (!poolingEnabled) {
        String i18nMsg = localStrings.getLocalString("flush.connection.pool.pooling.disabled", "Attempt to Flush Connection Pool failed because Pooling is disabled for pool : {0}", poolName);
        report.setMessage(i18nMsg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        PoolInfo poolInfo = new PoolInfo(poolName, applicationName, moduleName);
        _runtime.flushConnectionPool(poolInfo);
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (ConnectorRuntimeException e) {
        report.setMessage(localStrings.getLocalString("flush.connection.pool.fail", "Flush connection pool for {0} failed", poolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) ActionReport(org.glassfish.api.ActionReport)

Example 34 with PoolInfo

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

the class ConnectorResourceDeployer method deployResource.

/**
 * {@inheritDoc}
 */
public synchronized void deployResource(Object resource, String applicationName, String moduleName) throws Exception {
    // deployResource is not synchronized as there is only one caller
    // ResourceProxy which is synchronized
    ConnectorResource domainResource = (ConnectorResource) resource;
    ResourceInfo resourceInfo = new ResourceInfo(domainResource.getJndiName(), applicationName, moduleName);
    PoolInfo poolInfo = new PoolInfo(domainResource.getPoolName(), applicationName, moduleName);
    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)

Example 35 with PoolInfo

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

the class ConnectorResourceDeployer method checkAndDeletePool.

/**
 * Checks if no more resource-refs to resources exists for the
 * connector connection pool and then deletes the pool
 *
 * @param cr ConnectorResource
 * @throws Exception (ConfigException / undeploy exception)
 * @since 8.1 pe/se/ee
 */
private void checkAndDeletePool(ConnectorResource cr) throws Exception {
    String poolName = cr.getPoolName();
    ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(cr);
    PoolInfo poolInfo = new PoolInfo(poolName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
    Resources resources = (Resources) cr.getParent();
    // Its possible that the ConnectorResource here is a ConnectorResourceeDefinition. Ignore optimization.
    if (resources != null) {
        try {
            boolean poolReferred = ResourcesUtil.createInstance().isPoolReferredInServerInstance(poolInfo);
            if (!poolReferred) {
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.fine("Deleting connector connection pool [" + poolName + "] as there are no more " + "resource-refs to the pool in this server instance");
                }
                ConnectorConnectionPool ccp = (ConnectorConnectionPool) ConnectorsUtil.getResourceByName(resources, ConnectorConnectionPool.class, poolName);
                // Delete/Undeploy Pool
                runtime.getResourceDeployer(ccp).undeployResource(ccp);
            }
        } catch (Exception ce) {
            _logger.warning(ce.getMessage());
            if (_logger.isLoggable(Level.FINE)) {
                _logger.fine("Exception while deleting pool [ " + poolName + " ] : " + ce);
            }
            throw ce;
        }
    }
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) Resources(com.sun.enterprise.config.serverbeans.Resources) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)

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