Search in sources :

Example 11 with ConnectorResource

use of org.glassfish.connectors.config.ConnectorResource in project Payara by payara.

the class AppSpecificConnectorClassLoaderUtil method detectResourceInRA.

private void detectResourceInRA(Application app, String moduleName, String jndiName) {
    // domain.xml
    Resource res = null;
    if (jndiName.startsWith(ConnectorConstants.JAVA_APP_SCOPE_PREFIX)) /*|| jndiName.startsWith("java:global/")*/
    {
        ApplicationInfo appInfo = appRegistry.get(app.getName());
        res = getApplicationScopedResource(jndiName, BindableResource.class, appInfo);
    } else if (jndiName.startsWith(ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX)) {
        ApplicationInfo appInfo = appRegistry.get(app.getName());
        res = getModuleScopedResource(jndiName, moduleName, BindableResource.class, appInfo);
    } else {
        res = ConnectorsUtil.getResourceByName(getResources(), BindableResource.class, jndiName);
    }
    // (and .ear may refer to these resources in DD)
    if (res != null) {
        if (ConnectorResource.class.isAssignableFrom(res.getClass())) {
            ConnectorResource connResource = (ConnectorResource) res;
            String poolName = connResource.getPoolName();
            Resource pool;
            ApplicationInfo appInfo = appRegistry.get(app.getName());
            if (jndiName.startsWith(ConnectorConstants.JAVA_APP_SCOPE_PREFIX)) /*|| jndiName.startsWith("java:global/")*/
            {
                pool = getApplicationScopedResource(poolName, ResourcePool.class, appInfo);
            } else if (jndiName.startsWith(ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX)) {
                pool = getModuleScopedResource(poolName, moduleName, ResourcePool.class, appInfo);
            } else {
                pool = ConnectorsUtil.getResourceByName(getResources(), ResourcePool.class, poolName);
            }
            if (ConnectorConnectionPool.class.isAssignableFrom(pool.getClass())) {
                String raName = ((ConnectorConnectionPool) pool).getResourceAdapterName();
                app.addResourceAdapter(raName);
            }
        } else if (AdminObjectResource.class.isAssignableFrom(res.getClass())) {
            String raName = ((AdminObjectResource) res).getResAdapter();
            app.addResourceAdapter(raName);
        }
    } else {
        boolean found = false;
        // detect sun-ra.xml
        // find all the standalone connector modules
        List<com.sun.enterprise.config.serverbeans.Application> applications = getApplications().getApplicationsWithSnifferType(com.sun.enterprise.config.serverbeans.ServerTags.CONNECTOR, true);
        Iterator itr = applications.iterator();
        while (itr.hasNext()) {
            com.sun.enterprise.config.serverbeans.Application application = (com.sun.enterprise.config.serverbeans.Application) itr.next();
            String appName = application.getName();
            ApplicationInfo appInfo = appRegistry.get(appName);
            if (appInfo == null) {
                // the app is not deployed on this node
                continue;
            }
            Application dolApp = appInfo.getMetaData(Application.class);
            Collection<ConnectorDescriptor> rarDescriptors = dolApp.getBundleDescriptors(ConnectorDescriptor.class);
            for (ConnectorDescriptor desc : rarDescriptors) {
                SunConnector sunraDesc = desc.getSunDescriptor();
                if (sunraDesc != null) {
                    String sunRAJndiName = (String) sunraDesc.getResourceAdapter().getValue(ResourceAdapter.JNDI_NAME);
                    if (jndiName.equals(sunRAJndiName)) {
                        app.addResourceAdapter(desc.getName());
                        found = true;
                        break;
                    }
                } else {
                    // check whether it is default resource in the connector
                    if (desc.getDefaultResourcesNames().contains(jndiName)) {
                        app.addResourceAdapter(desc.getName());
                        found = true;
                        break;
                    }
                }
            }
        }
        if (!found) {
            if (DOLUtils.getDefaultLogger().isLoggable(Level.FINEST)) {
                DOLUtils.getDefaultLogger().log(Level.FINEST, "could not find resource by name : " + jndiName);
            }
        }
    }
}
Also used : ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) 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) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ResourcePool(com.sun.enterprise.config.serverbeans.ResourcePool) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) Iterator(java.util.Iterator) SunConnector(com.sun.enterprise.deployment.runtime.connector.SunConnector) AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource) Application(com.sun.enterprise.deployment.Application) ConnectorResource(org.glassfish.connectors.config.ConnectorResource)

Example 12 with ConnectorResource

use of org.glassfish.connectors.config.ConnectorResource in project Payara by payara.

the class DeleteConnectorResource method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the parameter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    if (jndiName == null) {
        report.setMessage(localStrings.getLocalString("delete.connector.resource.noJndiName", "No JNDI name defined for connector resource."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // ensure we already have this resource
    Resource r = ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorResource.class, jndiName);
    if (r == null) {
        report.setMessage(localStrings.getLocalString("delete.connector.resource.notfound", "A connector resource named {0} does not exist.", jndiName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if ("system-all-req".equals(r.getObjectType())) {
        report.setMessage(localStrings.getLocalString("delete.connector.resource.notAllowed", "The {0} resource cannot be deleted as it is required to be configured in the system.", jndiName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (environment.isDas()) {
        if ("domain".equals(target)) {
            if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) {
                report.setMessage(localStrings.getLocalString("delete.connector.resource.resource-ref.exist", "connector-resource [ {0} ] is referenced in an" + "instance/cluster target, Use delete-resource-ref on appropriate target", jndiName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        } else {
            if (!resourceUtil.isResourceRefInTarget(jndiName, target)) {
                report.setMessage(localStrings.getLocalString("delete.connector.resource.no.resource-ref", "connector-resource [ {0} ] is not referenced in target [ {1} ]", jndiName, target));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
            if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 1) {
                report.setMessage(localStrings.getLocalString("delete.connector.resource.multiple.resource-refs", "connector resource [ {0} ] is referenced in multiple " + "instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
    }
    try {
        // delete resource-ref
        resourceUtil.deleteResourceRef(jndiName, target);
        // delete connector-resource
        if (ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                ConnectorResource resource = (ConnectorResource) ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorResource.class, jndiName);
                return param.getResources().remove(resource);
            }
        }, domain.getResources()) == null) {
            report.setMessage(localStrings.getLocalString("delete.connector.resource.fail", "Connector resource {0} delete failed ", jndiName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    } catch (TransactionFailure tfe) {
        report.setMessage(localStrings.getLocalString("delete.connector.resource.fail", "Connector resource {0} delete failed ", jndiName) + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
    }
    report.setMessage(localStrings.getLocalString("delete.connector.resource.success", "Connector resource {0} deleted successfully", jndiName));
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) ConnectorResource(org.glassfish.connectors.config.ConnectorResource) Resource(com.sun.enterprise.config.serverbeans.Resource) Resources(com.sun.enterprise.config.serverbeans.Resources) ActionReport(org.glassfish.api.ActionReport) ConnectorResource(org.glassfish.connectors.config.ConnectorResource)

Example 13 with ConnectorResource

use of org.glassfish.connectors.config.ConnectorResource 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 14 with ConnectorResource

use of org.glassfish.connectors.config.ConnectorResource in project Payara by payara.

the class JMSConnectionFactoryDefinitionDeployer method deployResource.

public void deployResource(Object resource) throws Exception {
    final JMSConnectionFactoryDefinitionDescriptor desc = (JMSConnectionFactoryDefinitionDescriptor) resource;
    String poolName = ConnectorsUtil.deriveResourceName(desc.getResourceId(), desc.getName(), JMSCFDDPOOL);
    String resourceName = ConnectorsUtil.deriveResourceName(desc.getResourceId(), desc.getName(), desc.getResourceType());
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "JMSConnectionFactoryDefinitionDeployer.deployResource() : pool-name [" + poolName + "], " + " resource-name [" + resourceName + "]");
    }
    ConnectorConnectionPool connectorCp = new MyJMSConnectionFactoryConnectionPool(desc, poolName);
    // deploy pool
    getDeployer(connectorCp).deployResource(connectorCp);
    // deploy resource
    ConnectorResource connectorResource = new MyJMSConnectionFactoryResource(poolName, resourceName);
    getDeployer(connectorResource).deployResource(connectorResource);
}
Also used : JMSConnectionFactoryDefinitionDescriptor(com.sun.enterprise.deployment.JMSConnectionFactoryDefinitionDescriptor) ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) ConnectorResource(org.glassfish.connectors.config.ConnectorResource)

Example 15 with ConnectorResource

use of org.glassfish.connectors.config.ConnectorResource in project Payara by payara.

the class ConnectorsRecoveryResourceHandler method loadAllConnectorResources.

/**
 * does a lookup of resources so that they are loaded for sure.
 */
private void loadAllConnectorResources() {
    try {
        Collection<ConnectorResource> connResources = getAllConnectorResources();
        InitialContext ic = new InitialContext();
        for (ConnectorResource connResource : connResources) {
            if (getResourcesUtil().isEnabled(connResource)) {
                try {
                    ic.lookup(connResource.getJndiName());
                // } catch (NameNotFoundException ne) {
                } catch (NamingException ne) {
                    // So we need to explicitly load that rar and create the resources
                    try {
                        ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(connResource);
                        ConnectorConnectionPool connConnectionPool = ResourcesUtil.createInstance().getConnectorConnectionPoolOfResource(resourceInfo);
                        if (connConnectionPool != null) {
                            // TODO V3 ideally this should not happen if connector modules (and embedded rars)
                            // TODO  are loaded before recovery
                            createActiveResourceAdapter(connConnectionPool.getResourceAdapterName());
                            getConnectorResourceDeployer().deployResource(connResource);
                        }
                    } catch (Exception ex) {
                        _logger.log(Level.SEVERE, "error.loading.connector.resources.during.recovery", connResource.getJndiName());
                        if (_logger.isLoggable(Level.FINE)) {
                            _logger.log(Level.FINE, ne.toString(), ne);
                        }
                        _logger.log(Level.SEVERE, "error.loading.connector.resources.during.recovery", connResource.getJndiName());
                        if (_logger.isLoggable(Level.FINE)) {
                            _logger.log(Level.FINE, ex.toString(), ex);
                        }
                    }
                } catch (Exception ex) {
                    _logger.log(Level.SEVERE, "error.loading.connector.resources.during.recovery", connResource.getJndiName());
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.log(Level.FINE, ex.toString(), ex);
                    }
                }
            }
        }
    } catch (NamingException ne) {
        _logger.log(Level.SEVERE, "error.loading.connector.resources.during.recovery", ne.getMessage());
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, ne.toString(), ne);
        }
    }
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) NamingException(javax.naming.NamingException) ConnectorResource(org.glassfish.connectors.config.ConnectorResource) InitialContext(javax.naming.InitialContext) ResourceException(javax.resource.ResourceException) NamingException(javax.naming.NamingException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)

Aggregations

ConnectorResource (org.glassfish.connectors.config.ConnectorResource)18 ConnectorConnectionPool (org.glassfish.connectors.config.ConnectorConnectionPool)9 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)6 ActionReport (org.glassfish.api.ActionReport)4 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)3 Resource (com.sun.enterprise.config.serverbeans.Resource)3 Map (java.util.Map)3 PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)3 ConnectionFactoryDefinitionDescriptor (com.sun.enterprise.deployment.ConnectionFactoryDefinitionDescriptor)2 JMSConnectionFactoryDefinitionDescriptor (com.sun.enterprise.deployment.JMSConnectionFactoryDefinitionDescriptor)2 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 NamingException (javax.naming.NamingException)2 ResourceException (javax.resource.ResourceException)2 AdminObjectResource (org.glassfish.connectors.config.AdminObjectResource)2 Property (org.jvnet.hk2.config.types.Property)2 BindableResource (com.sun.enterprise.config.serverbeans.BindableResource)1 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)1 Resources (com.sun.enterprise.config.serverbeans.Resources)1 ConnectorRuntime (com.sun.enterprise.connectors.ConnectorRuntime)1