Search in sources :

Example 1 with JdbcConnectionPool

use of org.glassfish.jdbc.config.JdbcConnectionPool 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 2 with JdbcConnectionPool

use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.

the class JdbcConnectionPoolValidator method isValid.

@Override
public boolean isValid(final ResourcePool pool, final ConstraintValidatorContext constraintValidatorContext) {
    if (poolFaults == ConnectionPoolErrorMessages.MAX_STEADY_INVALID) {
        if (pool instanceof JdbcConnectionPool) {
            JdbcConnectionPool jdbcPool = (JdbcConnectionPool) pool;
            String maxPoolSize = jdbcPool.getMaxPoolSize();
            String steadyPoolSize = jdbcPool.getSteadyPoolSize();
            if (steadyPoolSize == null) {
                steadyPoolSize = Constants.DEFAULT_STEADY_POOL_SIZE;
            }
            if (maxPoolSize == null) {
                maxPoolSize = Constants.DEFAULT_MAX_POOL_SIZE;
            }
            if (Integer.parseInt(maxPoolSize) < (Integer.parseInt(steadyPoolSize))) {
                // max pool size fault
                return false;
            }
        }
    }
    if (poolFaults == ConnectionPoolErrorMessages.STMT_WRAPPING_DISABLED) {
        if (pool instanceof JdbcConnectionPool) {
            JdbcConnectionPool jdbcPool = (JdbcConnectionPool) pool;
            String stmtCacheSize = jdbcPool.getStatementCacheSize();
            String stmtLeakTimeout = jdbcPool.getStatementLeakTimeoutInSeconds();
            // PAYARA-661 allow empty "" sql trace listeners
            if (jdbcPool.getSqlTraceListeners() != null && !jdbcPool.getSqlTraceListeners().isEmpty()) {
                if (!Boolean.valueOf(jdbcPool.getWrapJdbcObjects())) {
                    return false;
                }
            }
            if (stmtCacheSize != null && Integer.parseInt(stmtCacheSize) != 0) {
                if (!Boolean.valueOf(jdbcPool.getWrapJdbcObjects())) {
                    return false;
                }
            }
            if (stmtLeakTimeout != null && Integer.parseInt(stmtLeakTimeout) != 0) {
                if (!Boolean.parseBoolean(jdbcPool.getWrapJdbcObjects())) {
                    return false;
                }
            }
            if (Boolean.valueOf(jdbcPool.getStatementLeakReclaim())) {
                if (!Boolean.valueOf(jdbcPool.getWrapJdbcObjects())) {
                    return false;
                }
            }
        }
    }
    if (poolFaults == ConnectionPoolErrorMessages.TABLE_NAME_MANDATORY) {
        if (pool instanceof JdbcConnectionPool) {
            JdbcConnectionPool jdbcPool = (JdbcConnectionPool) pool;
            if (Boolean.valueOf(jdbcPool.getIsConnectionValidationRequired())) {
                if ("table".equals(jdbcPool.getConnectionValidationMethod())) {
                    if (jdbcPool.getValidationTableName() == null || jdbcPool.getValidationTableName().equals("")) {
                        return false;
                    }
                }
            }
        }
    }
    if (poolFaults == ConnectionPoolErrorMessages.CUSTOM_VALIDATION_CLASS_NAME_MANDATORY) {
        if (pool instanceof JdbcConnectionPool) {
            JdbcConnectionPool jdbcPool = (JdbcConnectionPool) pool;
            if (Boolean.valueOf(jdbcPool.getIsConnectionValidationRequired())) {
                if ("custom-validation".equals(jdbcPool.getConnectionValidationMethod())) {
                    if (jdbcPool.getValidationClassname() == null || jdbcPool.getValidationClassname().equals("")) {
                        return false;
                    }
                }
            }
        }
    }
    if (poolFaults == ConnectionPoolErrorMessages.RES_TYPE_MANDATORY) {
        if (pool instanceof JdbcConnectionPool) {
            JdbcConnectionPool jdbcPool = (JdbcConnectionPool) pool;
            String resType = jdbcPool.getResType();
            String dsClassName = jdbcPool.getDatasourceClassname();
            String driverClassName = jdbcPool.getDriverClassname();
            if (resType == null) {
                // One of datasource/driver classnames must be provided.
                if ((dsClassName == null || dsClassName.equals("")) && (driverClassName == null || driverClassName.equals(""))) {
                    return false;
                } else {
                    // Check if both are provided and if so, return false
                    if (dsClassName != null && driverClassName != null) {
                        return false;
                    }
                }
            } else if (resType.equals("javax.sql.DataSource") || resType.equals("javax.sql.ConnectionPoolDataSource") || resType.equals("javax.sql.XADataSource")) {
                // Then datasourceclassname cannot be empty
                if (dsClassName == null || dsClassName.equals("")) {
                    return false;
                }
            } else if (resType.equals("java.sql.Driver")) {
                // Then driver classname cannot be empty
                if (driverClassName == null || driverClassName.equals("")) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool)

Example 3 with JdbcConnectionPool

use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.

the class SQLTraceStoreImpl method collect.

@Override
public void collect(MonitoringWatchCollector collector) {
    for (Entry<String, JdbcConnectionPool> poolEntry : connectionPoolByName.entrySet()) {
        JdbcConnectionPool pool = poolEntry.getValue();
        if (pool != null) {
            String poolName = poolEntry.getKey();
            long thresholdInMillis = thresholdInMillis(pool);
            if (thresholdInMillis > 0) {
                collector.watch("ns:sql @:" + poolName + " MaxExecutionTime", poolName + " Slow Query", "ms").red(thresholdInMillis, 0, false, null, null, false);
            }
        }
    }
}
Also used : JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool)

Example 4 with JdbcConnectionPool

use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.

the class JdbcConnectionPoolDeployer method undeployResource.

/**
 * {@inheritDoc}
 */
@Override
public synchronized void undeployResource(Object resource) throws Exception {
    JdbcConnectionPool jdbcConnPool = (JdbcConnectionPool) resource;
    PoolInfo poolInfo = ConnectorsUtil.getPoolInfo(jdbcConnPool);
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine(" JdbcConnectionPoolDeployer - unDeployResource : " + "calling actualUndeploy of " + poolInfo);
    }
    actualUndeployResource(poolInfo);
}
Also used : JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo)

Example 5 with JdbcConnectionPool

use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.

the class JdbcConnectionPoolDeployer method deployResource.

/**
 * {@inheritDoc}
 */
@Override
public void deployResource(Object resource, String applicationName, String moduleName) throws Exception {
    // deployResource is not synchronized as there is only one caller
    // ResourceProxy which is synchronized
    // intentional no-op
    // From 8.1 PE/SE/EE, JDBC connection pools are no more resources and
    // they would be available only to server instances that have a resoruce-ref
    // that maps to a pool. So deploy resource would not be called during
    // JDBC connection pool creation. The actualDeployResource method
    // below is invoked by JdbcResourceDeployer when a resource-ref for a
    // resource that is pointed to this pool is added to a server instance
    JdbcConnectionPool jcp = (JdbcConnectionPool) resource;
    PoolInfo poolInfo = new PoolInfo(jcp.getName(), applicationName, moduleName);
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine(" JdbcConnectionPoolDeployer - deployResource : " + poolInfo + " calling actualDeploy");
    }
    actualDeployResource(resource, poolInfo);
}
Also used : JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo)

Aggregations

JdbcConnectionPool (org.glassfish.jdbc.config.JdbcConnectionPool)32 PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)10 JdbcResource (org.glassfish.jdbc.config.JdbcResource)7 Test (org.junit.Test)7 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)5 Resources (com.sun.enterprise.config.serverbeans.Resources)4 Resource (com.sun.enterprise.config.serverbeans.Resource)3 ActionReport (org.glassfish.api.ActionReport)3 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)3 Domain (com.sun.enterprise.config.serverbeans.Domain)2 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)2 ConnectorConnectionPool (com.sun.enterprise.connectors.ConnectorConnectionPool)2 DataSourceDefinitionDescriptor (com.sun.enterprise.deployment.DataSourceDefinitionDescriptor)2 ArrayList (java.util.ArrayList)2 ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)2 DataSource (javax.sql.DataSource)2 XADataSource (javax.sql.XADataSource)2 ConnectorConnectionPool (org.glassfish.connectors.config.ConnectorConnectionPool)2 ResourceConflictException (org.glassfish.resourcebase.resources.api.ResourceConflictException)2 Property (org.jvnet.hk2.config.types.Property)2