Search in sources :

Example 41 with ResourceInfo

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

the class ConnectionManagerImpl method validateResourceAndPool.

private void validateResourceAndPool() throws ResourceException {
    ResourceInfo resourceInfo = this.resourceInfo;
    ResourcesUtil resourcesUtil = ResourcesUtil.createInstance();
    ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
    ConnectorRegistry registry = ConnectorRegistry.getInstance();
    // are disabled.
    if (!registry.isResourceDeployed(resourceInfo)) {
        if (logger.isLoggable(Level.FINEST)) {
            logger.log(Level.FINEST, "resourceInfo not found in connector-registry : " + resourceInfo);
        }
        boolean isDefaultResource = false;
        boolean isSunRAResource = false;
        ConnectorDescriptor descriptor = registry.getDescriptor(rarName);
        if (descriptor != null) {
            isDefaultResource = descriptor.getDefaultResourcesNames().contains(resourceInfo.getName());
            if (descriptor.getSunDescriptor() != null) {
                com.sun.enterprise.deployment.runtime.connector.ResourceAdapter rar = descriptor.getSunDescriptor().getResourceAdapter();
                if (rar != null) {
                    String sunRAJndiName = (String) rar.getValue(com.sun.enterprise.deployment.runtime.connector.ResourceAdapter.JNDI_NAME);
                    isSunRAResource = resourceInfo.getName().equals(sunRAJndiName);
                }
            }
        }
        if ((runtime.isServer() || runtime.isEmbedded()) && (!resourceInfo.getName().contains(ConnectorConstants.DATASOURCE_DEFINITION_JNDINAME_PREFIX) && (!isDefaultResource) && (!isSunRAResource))) {
            // resources config bean each time.
            if (resourceConfiguration == null) {
                resourceConfiguration = (BindableResource) resourcesUtil.getResource(resourceInfo, BindableResource.class);
                if (resourceConfiguration == null) {
                    String suffix = ConnectorsUtil.getValidSuffix(resourceInfo.getName());
                    // check for the enabled status and existence using non-prefixed resource-name
                    if (suffix != null) {
                        String nonPrefixedName = resourceInfo.getName().substring(0, resourceInfo.getName().lastIndexOf(suffix));
                        resourceInfo = new ResourceInfo(nonPrefixedName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
                        resourceConfiguration = (BindableResource) resourcesUtil.getResource(resourceInfo, BindableResource.class);
                    }
                }
            } else {
                // we cache the resourceConfiguration for performance optimization.
                // make sure that appropriate (actual) resourceInfo is used for validation.
                String suffix = ConnectorsUtil.getValidSuffix(resourceInfo.getName());
                // check for the enabled status and existence using non-prefixed resource-name
                if (suffix != null) {
                    String nonPrefixedName = resourceInfo.getName().substring(0, resourceInfo.getName().lastIndexOf(suffix));
                    resourceInfo = new ResourceInfo(nonPrefixedName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
                }
            }
            if (resourceConfiguration == null) {
                throw new ResourceException("No such resource : " + resourceInfo);
            }
            if (!resourcesUtil.isEnabled(resourceConfiguration, resourceInfo)) {
                throw new ResourceException(resourceInfo + " is not enabled");
            }
        }
    }
    if (registry.getPoolMetaData(poolInfo) == null) {
        String msg = getLocalStrings().getString("con_mgr.no_pool_meta_data", poolInfo);
        throw new ResourceException(poolInfo + ": " + msg);
    }
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) ResourcesUtil(com.sun.enterprise.connectors.util.ResourcesUtil) ResourceException(javax.resource.ResourceException)

Example 42 with ResourceInfo

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

the class ConnectorRuntime method lookupNonTxResource.

/**
 * {@inheritDoc}
 */
public Object lookupNonTxResource(ResourceInfo resourceInfo, boolean force) throws NamingException {
    Object result;
    try {
        if (!resourceInfo.getName().endsWith(NON_TX_JNDI_SUFFIX)) {
            ResourceInfo tmpInfo = new ResourceInfo(resourceInfo.getName() + NON_TX_JNDI_SUFFIX, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
            resourceInfo = tmpInfo;
        }
        result = connectorResourceAdmService.lookup(resourceInfo);
    } catch (NamingException ne) {
        if (force && isDAS()) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "jdbc.unable_to_lookup_resource", new Object[] { resourceInfo });
            }
            result = lookupDataSourceInDAS(resourceInfo);
        } else {
            throw ne;
        }
    }
    return result;
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) NamingException(javax.naming.NamingException)

Example 43 with ResourceInfo

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

the class ConnectorRuntime method lookupPMResource.

/**
 * {@inheritDoc}
 */
public Object lookupPMResource(ResourceInfo resourceInfo, boolean force) throws NamingException {
    Object result;
    try {
        if (!resourceInfo.getName().endsWith(PM_JNDI_SUFFIX)) {
            ResourceInfo tmpInfo = new ResourceInfo(resourceInfo.getName() + PM_JNDI_SUFFIX, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
            resourceInfo = tmpInfo;
        }
        result = connectorResourceAdmService.lookup(resourceInfo);
    } catch (NamingException ne) {
        if (force && isDAS()) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "jdbc.unable_to_lookup_resource", new Object[] { resourceInfo });
            }
            result = lookupDataSourceInDAS(resourceInfo);
        } else {
            throw ne;
        }
    }
    return result;
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) NamingException(javax.naming.NamingException)

Example 44 with ResourceInfo

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

the class ConnectorResourceAdminServiceImpl method lookup.

/**
 * Look up the JNDI name with appropriate suffix.
 * Suffix can be either __pm or __nontx.
 *
 * @param resourceInfo resource-name
 * @return Object - from jndi
 * @throws NamingException - when unable to get the object form jndi
 */
public Object lookup(ResourceInfo resourceInfo) throws NamingException {
    Hashtable env = null;
    String jndiName = resourceInfo.getName();
    String suffix = ConnectorsUtil.getValidSuffix(jndiName);
    // To pass suffix that will be used by connector runtime during lookup
    if (suffix != null) {
        env = new Hashtable();
        env.put(ConnectorConstants.JNDI_SUFFIX_PROPERTY, suffix);
        jndiName = jndiName.substring(0, jndiName.lastIndexOf(suffix));
    }
    ResourceInfo actualResourceInfo = new ResourceInfo(jndiName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
    return namingService.lookup(actualResourceInfo, actualResourceInfo.getName(), env);
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) Hashtable(java.util.Hashtable)

Example 45 with ResourceInfo

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

the class AdminObjectResourceDeployer method undeployResource.

/**
 * {@inheritDoc}
 */
public synchronized void undeployResource(Object resource) throws Exception {
    final AdminObjectResource aor = (AdminObjectResource) resource;
    ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(aor);
    deleteAdminObjectResource(aor, resourceInfo);
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource)

Aggregations

ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)81 PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)15 NamingException (javax.naming.NamingException)14 JdbcResource (org.glassfish.jdbc.config.JdbcResource)9 Test (org.junit.Test)9 ContextServiceImpl (org.glassfish.enterprise.concurrent.ContextServiceImpl)8 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)7 ConnectorResource (org.glassfish.connectors.config.ConnectorResource)6 RefAddr (javax.naming.RefAddr)5 SerializableObjectRefAddr (org.glassfish.resources.naming.SerializableObjectRefAddr)5 Resources (com.sun.enterprise.config.serverbeans.Resources)4 ResourceException (javax.resource.ResourceException)4 ContextService (org.glassfish.concurrent.config.ContextService)4 ManagedThreadFactory (org.glassfish.concurrent.config.ManagedThreadFactory)4 AdminObjectResource (org.glassfish.connectors.config.AdminObjectResource)4 CustomResource (org.glassfish.resources.config.CustomResource)4 MailResource (org.glassfish.resources.javamail.config.MailResource)4 ManagedConnectionFactory (javax.resource.spi.ManagedConnectionFactory)3 ManagedExecutorService (org.glassfish.concurrent.config.ManagedExecutorService)3 ManagedScheduledExecutorService (org.glassfish.concurrent.config.ManagedScheduledExecutorService)3