Search in sources :

Example 1 with BindableResource

use of com.sun.enterprise.config.serverbeans.BindableResource in project Payara by payara.

the class JdbcConnectionPoolDeployer method handlePoolRecreation.

private void handlePoolRecreation(final ConnectorConnectionPool connConnPool) throws ConnectorRuntimeException {
    debug("[DRC] Pool recreation required");
    final long reconfigWaitTimeout = connConnPool.getDynamicReconfigWaitTimeout();
    PoolInfo poolInfo = new PoolInfo(connConnPool.getName(), connConnPool.getApplicationName(), connConnPool.getModuleName());
    final ResourcePool oldPool = runtime.getPoolManager().getPool(poolInfo);
    if (reconfigWaitTimeout > 0) {
        oldPool.blockRequests(reconfigWaitTimeout);
        if (oldPool.getPoolWaitQueue().getQueueLength() > 0 || oldPool.getPoolStatus().getNumConnUsed() > 0) {
            Runnable thread = new Runnable() {

                @Override
                public void run() {
                    try {
                        // poll every 5 seconds
                        long numSeconds = 5000L;
                        long steps = reconfigWaitTimeout / numSeconds;
                        if (steps == 0) {
                            waitForCompletion(steps, oldPool, reconfigWaitTimeout);
                        } else {
                            for (long i = 0; i < steps; i++) {
                                waitForCompletion(steps, oldPool, reconfigWaitTimeout);
                                if (oldPool.getPoolWaitQueue().getQueueLength() == 0 && oldPool.getPoolStatus().getNumConnUsed() == 0) {
                                    debug("wait-queue is empty and num-con-used is 0");
                                    break;
                                }
                            }
                        }
                        handlePoolRecreationForExistingProxies(connConnPool);
                        PoolWaitQueue reconfigWaitQueue = oldPool.getReconfigWaitQueue();
                        debug("checking reconfig-wait-queue for notification");
                        if (reconfigWaitQueue.getQueueContents().size() > 0) {
                            for (Object o : reconfigWaitQueue.getQueueContents()) {
                                debug("notifying reconfig-wait-queue object [ " + o + " ]");
                                synchronized (o) {
                                    o.notify();
                                }
                            }
                        }
                    } catch (InterruptedException ie) {
                        if (_logger.isLoggable(Level.FINEST)) {
                            _logger.log(Level.FINEST, "Interrupted while waiting for all existing clients to return connections to pool", ie);
                        }
                    }
                    if (_logger.isLoggable(Level.FINEST)) {
                        _logger.finest("woke-up after giving time for in-use connections to return, " + "WaitQueue-Length : [" + oldPool.getPoolWaitQueue().getQueueContents() + "], " + "Num-Conn-Used : [" + oldPool.getPoolStatus().getNumConnUsed() + "]");
                    }
                }
            };
            Callable c = Executors.callable(thread);
            ArrayList list = new ArrayList();
            list.add(c);
            try {
                execService.invokeAll(list);
            } catch (Exception e) {
                Object[] params = new Object[] { connConnPool.getName(), e };
                _logger.log(Level.WARNING, "exception.redeploying.pool.transparently", params);
            }
        } else {
            handlePoolRecreationForExistingProxies(connConnPool);
        }
    } else if (oldPool.getReconfigWaitTime() > 0) {
        // reconfig is being switched off, invalidate proxies
        Collection<BindableResource> resources = JdbcResourcesUtil.getResourcesOfPool(runtime.getResources(oldPool.getPoolInfo()), oldPool.getPoolInfo().getName());
        ConnectorRegistry registry = ConnectorRegistry.getInstance();
        for (BindableResource resource : resources) {
            ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(resource);
            registry.removeResourceFactories(resourceInfo);
        }
        // recreate the pool now.
        recreatePool(connConnPool);
    } else {
        recreatePool(connConnPool);
    }
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ArrayList(java.util.ArrayList) ResourcePool(com.sun.enterprise.resource.pool.ResourcePool) Callable(java.util.concurrent.Callable) MissingResourceException(java.util.MissingResourceException) ResourceConflictException(org.glassfish.resourcebase.resources.api.ResourceConflictException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) Collection(java.util.Collection) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) ConnectorRegistry(com.sun.enterprise.connectors.ConnectorRegistry) PoolWaitQueue(com.sun.enterprise.resource.pool.waitqueue.PoolWaitQueue)

Example 2 with BindableResource

use of com.sun.enterprise.config.serverbeans.BindableResource in project Payara by payara.

the class DeleteJndiResourceTest method testExecuteSuccessDefaultTarget.

/**
 * Test of execute method, of class DeleteJndiResource.
 * asadmin create-jndi-resource --restype=queue --factoryclass=sampleClass --jndilookupname=sample_jndi
 * sample_jndi_resource
 * delete-jndi-resource sample_jndi_resource
 */
@Test
public void testExecuteSuccessDefaultTarget() {
    parameters.set("restype", "topic");
    parameters.set("jndilookupname", "sample_jndi");
    parameters.set("factoryclass", "javax.naming.spi.ObjectFactory");
    parameters.set("jndi_name", "sample_jndi_resource");
    org.glassfish.resources.admin.cli.CreateJndiResource createCommand = habitat.getService(org.glassfish.resources.admin.cli.CreateJndiResource.class);
    cr.getCommandInvocation("create-jndi-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    parameters = new ParameterMap();
    parameters.set("jndi_name", "sample_jndi_resource");
    org.glassfish.resources.admin.cli.DeleteJndiResource deleteCommand = habitat.getService(org.glassfish.resources.admin.cli.DeleteJndiResource.class);
    cr.getCommandInvocation("delete-jndi-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    boolean isDeleted = true;
    for (Resource resource : resources.getResources()) {
        if (resource instanceof BindableResource) {
            BindableResource jr = (BindableResource) resource;
            if (jr.getJndiName().equals("sample_jndi_resource")) {
                isDeleted = false;
                logger.fine("Jndi Resource config bean sample_jndi_resource is created.");
                break;
            }
        }
    }
    assertTrue(isDeleted);
    logger.fine("msg: " + context.getActionReport().getMessage());
    Servers servers = habitat.getService(Servers.class);
    boolean isRefDeleted = true;
    for (Server server : servers.getServer()) {
        if (server.getName().equals(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)) {
            for (ResourceRef ref : server.getResourceRef()) {
                if (ref.getRef().equals("sample_jndi_resource")) {
                    isRefDeleted = false;
                    break;
                }
            }
        }
    }
    assertTrue(isRefDeleted);
}
Also used : BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) Resource(com.sun.enterprise.config.serverbeans.Resource) ParameterMap(org.glassfish.api.admin.ParameterMap) ResourceRef(com.sun.enterprise.config.serverbeans.ResourceRef) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 3 with BindableResource

use of com.sun.enterprise.config.serverbeans.BindableResource in project Payara by payara.

the class AppSpecificConnectorClassLoaderUtil method getModuleScopedResource.

private <T> Resource getModuleScopedResource(String name, String moduleName, Class<T> type, ApplicationInfo appInfo) {
    Resource foundRes = null;
    if (appInfo != null) {
        com.sun.enterprise.config.serverbeans.Application app = appInfo.getTransientAppMetaData(com.sun.enterprise.config.serverbeans.ServerTags.APPLICATION, com.sun.enterprise.config.serverbeans.Application.class);
        Resources resources = null;
        if (app != null) {
            Module module = null;
            List<Module> modules = app.getModule();
            for (Module m : modules) {
                if (ConnectorsUtil.getActualModuleName(m.getName()).equals(moduleName)) {
                    module = m;
                    break;
                }
            }
            if (module != null) {
                resources = appInfo.getTransientAppMetaData(module.getName() + "-resources", Resources.class);
            }
        }
        if (resources != null) {
            boolean bindableResource = BindableResource.class.isAssignableFrom(type);
            boolean poolResource = ResourcePool.class.isAssignableFrom(type);
            boolean workSecurityMap = WorkSecurityMap.class.isAssignableFrom(type);
            boolean rac = ResourceAdapterConfig.class.isAssignableFrom(type);
            Iterator itr = resources.getResources().iterator();
            while (itr.hasNext()) {
                String resourceName = null;
                Resource res = (Resource) itr.next();
                if (bindableResource && res instanceof BindableResource) {
                    resourceName = ((BindableResource) res).getJndiName();
                } else if (poolResource && res instanceof ResourcePool) {
                    resourceName = ((ResourcePool) res).getName();
                } else if (rac && res instanceof ResourceAdapterConfig) {
                    resourceName = ((ResourceAdapterConfig) res).getName();
                } else if (workSecurityMap && res instanceof WorkSecurityMap) {
                    resourceName = ((WorkSecurityMap) res).getName();
                }
                if (resourceName != null) {
                    if (!(resourceName.startsWith(ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX))) {
                        resourceName = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX + resourceName;
                    }
                    if (!(name.startsWith(ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX))) {
                        name = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX + name;
                    }
                    if (name.equals(resourceName)) {
                        foundRes = res;
                        break;
                    }
                }
            }
        }
    }
    return foundRes;
}
Also used : AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource) Resource(com.sun.enterprise.config.serverbeans.Resource) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) ConnectorResource(org.glassfish.connectors.config.ConnectorResource) ResourceAdapterConfig(org.glassfish.connectors.config.ResourceAdapterConfig) WorkSecurityMap(org.glassfish.connectors.config.WorkSecurityMap) ResourcePool(com.sun.enterprise.config.serverbeans.ResourcePool) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) Iterator(java.util.Iterator) Resources(com.sun.enterprise.config.serverbeans.Resources) Module(com.sun.enterprise.config.serverbeans.Module)

Example 4 with BindableResource

use of com.sun.enterprise.config.serverbeans.BindableResource in project Payara by payara.

the class AppSpecificConnectorClassLoaderUtil method getApplicationScopedResource.

private <T> Resource getApplicationScopedResource(String name, Class<T> type, ApplicationInfo appInfo) {
    Resource foundRes = null;
    if (appInfo != null) {
        com.sun.enterprise.config.serverbeans.Application app = appInfo.getTransientAppMetaData(com.sun.enterprise.config.serverbeans.ServerTags.APPLICATION, com.sun.enterprise.config.serverbeans.Application.class);
        Resources resources = null;
        if (app != null) {
            resources = appInfo.getTransientAppMetaData(app.getName() + "-resources", Resources.class);
        }
        if (resources != null) {
            boolean bindableResource = BindableResource.class.isAssignableFrom(type);
            boolean poolResource = ResourcePool.class.isAssignableFrom(type);
            boolean workSecurityMap = WorkSecurityMap.class.isAssignableFrom(type);
            boolean rac = ResourceAdapterConfig.class.isAssignableFrom(type);
            Iterator itr = resources.getResources().iterator();
            while (itr.hasNext()) {
                String resourceName = null;
                Resource res = (Resource) itr.next();
                if (bindableResource && res instanceof BindableResource) {
                    resourceName = ((BindableResource) res).getJndiName();
                } else if (poolResource && res instanceof ResourcePool) {
                    resourceName = ((ResourcePool) res).getName();
                } else if (rac && res instanceof ResourceAdapterConfig) {
                    resourceName = ((ResourceAdapterConfig) res).getName();
                } else if (workSecurityMap && res instanceof WorkSecurityMap) {
                    resourceName = ((WorkSecurityMap) res).getName();
                }
                if (resourceName != null) {
                    if (!(resourceName.startsWith(ConnectorConstants.JAVA_APP_SCOPE_PREFIX))) {
                        resourceName = ConnectorConstants.JAVA_APP_SCOPE_PREFIX + resourceName;
                    }
                    if (!(name.startsWith(ConnectorConstants.JAVA_APP_SCOPE_PREFIX))) {
                        name = ConnectorConstants.JAVA_APP_SCOPE_PREFIX + name;
                    }
                    if (name.equals(resourceName)) {
                        foundRes = res;
                        break;
                    }
                }
            }
        }
    }
    return foundRes;
}
Also used : AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource) Resource(com.sun.enterprise.config.serverbeans.Resource) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) ConnectorResource(org.glassfish.connectors.config.ConnectorResource) ResourceAdapterConfig(org.glassfish.connectors.config.ResourceAdapterConfig) WorkSecurityMap(org.glassfish.connectors.config.WorkSecurityMap) ResourcePool(com.sun.enterprise.config.serverbeans.ResourcePool) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) Iterator(java.util.Iterator) Resources(com.sun.enterprise.config.serverbeans.Resources)

Example 5 with BindableResource

use of com.sun.enterprise.config.serverbeans.BindableResource in project Payara by payara.

the class JdbcResourcesUtil method getResourcesOfPool.

public static Collection<BindableResource> getResourcesOfPool(Resources resources, String connectionPoolName) {
    Set<BindableResource> resourcesReferringPool = new HashSet<BindableResource>();
    ResourcePool pool = (ResourcePool) getResourceByName(resources, ResourcePool.class, connectionPoolName);
    if (pool != null) {
        Collection<BindableResource> bindableResources = resources.getResources(BindableResource.class);
        for (BindableResource resource : bindableResources) {
            if (JdbcResource.class.isAssignableFrom(resource.getClass())) {
                if ((((JdbcResource) resource).getPoolName()).equals(connectionPoolName)) {
                    resourcesReferringPool.add(resource);
                }
            }
        }
    }
    return resourcesReferringPool;
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) ResourcePool(com.sun.enterprise.config.serverbeans.ResourcePool) HashSet(java.util.HashSet)

Aggregations

BindableResource (com.sun.enterprise.config.serverbeans.BindableResource)9 Resource (com.sun.enterprise.config.serverbeans.Resource)6 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)4 Resources (com.sun.enterprise.config.serverbeans.Resources)3 Iterator (java.util.Iterator)2 ParameterMap (org.glassfish.api.admin.ParameterMap)2 AdminObjectResource (org.glassfish.connectors.config.AdminObjectResource)2 ConnectorResource (org.glassfish.connectors.config.ConnectorResource)2 ResourceAdapterConfig (org.glassfish.connectors.config.ResourceAdapterConfig)2 WorkSecurityMap (org.glassfish.connectors.config.WorkSecurityMap)2 PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)2 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)2 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)2 Test (org.junit.Test)2 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 Module (com.sun.enterprise.config.serverbeans.Module)1 ResourceRef (com.sun.enterprise.config.serverbeans.ResourceRef)1 Server (com.sun.enterprise.config.serverbeans.Server)1 ConnectorRegistry (com.sun.enterprise.connectors.ConnectorRegistry)1 ResourcePool (com.sun.enterprise.resource.pool.ResourcePool)1