Search in sources :

Example 1 with ConnectorRuntime

use of com.sun.enterprise.connectors.ConnectorRuntime in project Payara by payara.

the class ConnectorsRecoveryResourceHandler method loadXAResourcesAndItsConnections.

/**
 * {@inheritDoc}
 */
public void loadXAResourcesAndItsConnections(List xaresList, List connList) {
    // Done so as to initialize connectors-runtime before loading connector-resources. need a better way ?
    ConnectorRuntime crt = connectorRuntimeProvider.get();
    // ApplicationLoaderService already guarantees that connectors are loaded before any other applications.
    // Recovery will not start sooner than transaction is first needed on EE application startup, therefore
    // it is safe to continue here without waiting for startupProvider, as that ultimately creates a deadlock
    // between ApplicationLoaderService needed a transaction manager, and recovery wainting for applications
    // to finish loading.
    Collection<ConnectorResource> connectorResources = getAllConnectorResources();
    if (connectorResources == null || connectorResources.size() == 0) {
        return;
    }
    List<ConnectorConnectionPool> connPools = new ArrayList<ConnectorConnectionPool>();
    for (Resource resource : connectorResources) {
        ConnectorResource connResource = (ConnectorResource) resource;
        if (getResourcesUtil().isEnabled(connResource)) {
            ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(connResource);
            ConnectorConnectionPool pool = ResourcesUtil.createInstance().getConnectorConnectionPoolOfResource(resourceInfo);
            if (pool != null && ConnectorConstants.XA_TRANSACTION_TX_SUPPORT_STRING.equals(getTransactionSupport(pool))) {
                connPools.add(pool);
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.fine("ConnectorsRecoveryResourceHandler loadXAResourcesAndItsConnections :: " + "adding : " + connResource.getPoolName());
                }
            }
        }
    }
    loadAllConnectorResources();
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Recovering pools : " + connPools.size());
    }
    for (ConnectorConnectionPool connPool : connPools) {
        PoolInfo poolInfo = ConnectorsUtil.getPoolInfo(connPool);
        try {
            String[] dbUserPassword = getdbUserPasswordOfConnectorConnectionPool(connPool);
            if (dbUserPassword == null) {
                continue;
            }
            String dbUser = dbUserPassword[0];
            String dbPassword = dbUserPassword[1];
            Subject subject = new Subject();
            // username [pointbase interprets this as "root"]/password.
            if (dbPassword == null) {
                dbPassword = "";
                if (_logger.isLoggable(Level.FINEST)) {
                    _logger.log(Level.FINEST, "datasource.xadatasource_nullpassword_error", poolInfo);
                }
            }
            if (dbUser == null) {
                dbUser = "";
                if (_logger.isLoggable(Level.FINEST)) {
                    _logger.log(Level.FINEST, "datasource.xadatasource_nulluser_error", poolInfo);
                }
            }
            String rarName = connPool.getResourceAdapterName();
            // TODO V3 JMS-RA ??
            if (ConnectorAdminServiceUtils.isJMSRA(rarName)) {
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "Performing recovery for JMS RA, poolName  " + poolInfo);
                }
                ManagedConnectionFactory[] mcfs = crt.obtainManagedConnectionFactories(poolInfo);
                _logger.log(Level.INFO, "JMS resource recovery has created CFs = " + mcfs.length);
                for (int i = 0; i < mcfs.length; i++) {
                    PasswordCredential pc = new PasswordCredential(dbUser, dbPassword.toCharArray());
                    pc.setManagedConnectionFactory(mcfs[i]);
                    Principal prin = new ResourcePrincipal(dbUser, dbPassword);
                    subject.getPrincipals().add(prin);
                    subject.getPrivateCredentials().add(pc);
                    ManagedConnection mc = mcfs[i].createManagedConnection(subject, null);
                    connList.add(mc);
                    try {
                        XAResource xares = mc.getXAResource();
                        if (xares != null) {
                            xaresList.add(xares);
                        }
                    } catch (ResourceException ex) {
                    // ignored. Not at XA_TRANSACTION level
                    }
                }
            } else {
                ManagedConnectionFactory mcf = crt.obtainManagedConnectionFactory(poolInfo);
                PasswordCredential pc = new PasswordCredential(dbUser, dbPassword.toCharArray());
                pc.setManagedConnectionFactory(mcf);
                Principal prin = new ResourcePrincipal(dbUser, dbPassword);
                subject.getPrincipals().add(prin);
                subject.getPrivateCredentials().add(pc);
                ManagedConnection mc = mcf.createManagedConnection(subject, null);
                connList.add(mc);
                try {
                    XAResource xares = mc.getXAResource();
                    if (xares != null) {
                        xaresList.add(xares);
                    }
                } catch (ResourceException ex) {
                // ignored. Not at XA_TRANSACTION level
                }
            }
        } catch (Exception ex) {
            _logger.log(Level.WARNING, "datasource.xadatasource_error", poolInfo);
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "datasource.xadatasource_error_excp", ex);
            }
        }
    }
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Total XAResources identified for recovery is " + xaresList.size());
        _logger.log(Level.FINE, "Total connections identified for recovery is " + connList.size());
    }
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) XAResource(javax.transaction.xa.XAResource) ConnectorResource(org.glassfish.connectors.config.ConnectorResource) PasswordCredential(javax.resource.spi.security.PasswordCredential) ResourcePrincipal(com.sun.enterprise.deployment.ResourcePrincipal) Subject(javax.security.auth.Subject) ResourceException(javax.resource.ResourceException) NamingException(javax.naming.NamingException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ManagedConnectionFactory(javax.resource.spi.ManagedConnectionFactory) XAResource(javax.transaction.xa.XAResource) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) ManagedConnection(javax.resource.spi.ManagedConnection) ResourceException(javax.resource.ResourceException) ConnectorResource(org.glassfish.connectors.config.ConnectorResource) ResourcePrincipal(com.sun.enterprise.deployment.ResourcePrincipal) Principal(java.security.Principal) ConnectorRuntime(com.sun.enterprise.connectors.ConnectorRuntime)

Example 2 with ConnectorRuntime

use of com.sun.enterprise.connectors.ConnectorRuntime in project Payara by payara.

the class ResourceAdapterAdminServiceImpl method createActiveResourceAdapter.

/**
 * Creates Active resource Adapter which abstracts the rar module. During
 * the creation of ActiveResourceAdapter, default pools and resources also
 * are created.
 *
 * @param connectorDescriptor object which abstracts the connector deployment descriptor
 *                            i.e rar.xml and sun-ra.xml.
 * @param moduleName          Name of the module
 * @param moduleDir           Directory where rar module is exploded.
 * @param loader              Classloader to use
 * @throws ConnectorRuntimeException if creation fails.
 */
public void createActiveResourceAdapter(ConnectorDescriptor connectorDescriptor, String moduleName, String moduleDir, ClassLoader loader) throws ConnectorRuntimeException {
    synchronized (_registry.getLockObject(moduleName)) {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("ResourceAdapterAdminServiceImpl :: createActiveRA " + moduleName + " at " + moduleDir);
        }
        ActiveResourceAdapter activeResourceAdapter = _registry.getActiveResourceAdapter(moduleName);
        if (activeResourceAdapter != null) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "rardeployment.resourceadapter.already.started", moduleName);
            }
            return;
        }
        // TODO V3 works fine ?
        if (loader == null) {
            try {
                loader = connectorDescriptor.getClassLoader();
            } catch (Exception ex) {
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "No classloader available with connector descriptor");
                }
                loader = null;
            }
        }
        ConnectorRuntime connectorRuntime = ConnectorRuntime.getRuntime();
        ModuleDescriptor moduleDescriptor = null;
        Application application = null;
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("ResourceAdapterAdminServiceImpl :: createActiveRA " + moduleName + " at " + moduleDir + " loader :: " + loader);
        }
        // (standalone + embedded)
        if (loader == null && ConnectorsUtil.belongsToSystemRA(moduleName)) {
            if (connectorRuntime.isServer()) {
                loader = connectorRuntime.getSystemRARClassLoader(moduleName);
            }
        } else {
            connectorDescriptor.setClassLoader(null);
            moduleDescriptor = connectorDescriptor.getModuleDescriptor();
            application = connectorDescriptor.getApplication();
            connectorDescriptor.setModuleDescriptor(null);
            connectorDescriptor.setApplication(null);
        }
        try {
            activeResourceAdapter = connectorRuntime.getActiveRAFactory().createActiveResourceAdapter(connectorDescriptor, moduleName, loader);
            if (_logger.isLoggable(Level.FINE)) {
                _logger.fine("ResourceAdapterAdminServiceImpl :: createActiveRA " + moduleName + " at " + moduleDir + " adding to registry " + activeResourceAdapter);
            }
            _registry.addActiveResourceAdapter(moduleName, activeResourceAdapter);
            if (_logger.isLoggable(Level.FINE)) {
                _logger.fine("ResourceAdapterAdminServiceImpl:: createActiveRA " + moduleName + " at " + moduleDir + " env =server ? " + (connectorRuntime.isServer()));
            }
            if (connectorRuntime.isServer()) {
                // Update RAConfig in Connector Descriptor and bind in JNDI
                // so that ACC clients could use RAConfig
                updateRAConfigInDescriptor(connectorDescriptor, moduleName);
                String descriptorJNDIName = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForDescriptor(moduleName);
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.fine("ResourceAdapterAdminServiceImpl :: createActiveRA " + moduleName + " at " + moduleDir + " publishing descriptor " + descriptorJNDIName);
                }
                _runtime.getNamingManager().publishObject(descriptorJNDIName, connectorDescriptor, true);
                activeResourceAdapter.setup();
                if (System.getSecurityManager() != null) {
                    String securityWarningMessage = connectorRuntime.getSecurityPermissionSpec(moduleName);
                    // To i18N.
                    if (securityWarningMessage != null) {
                        _logger.log(Level.WARNING, securityWarningMessage);
                    }
                }
            }
        } catch (NullPointerException npEx) {
            ConnectorRuntimeException cre = new ConnectorRuntimeException("Error in creating active RAR");
            cre.initCause(npEx);
            _logger.log(Level.SEVERE, "rardeployment.nullPointerException", moduleName);
            _logger.log(Level.SEVERE, "", cre);
            throw cre;
        } catch (NamingException ne) {
            ConnectorRuntimeException cre = new ConnectorRuntimeException("Error in creating active RAR");
            cre.initCause(ne);
            _logger.log(Level.SEVERE, "rardeployment.jndi_publish_failure");
            _logger.log(Level.SEVERE, "", cre);
            throw cre;
        } finally {
            if (moduleDescriptor != null) {
                connectorDescriptor.setModuleDescriptor(moduleDescriptor);
                connectorDescriptor.setApplication(application);
                connectorDescriptor.setClassLoader(loader);
            }
        }
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) NamingException(javax.naming.NamingException) ActiveResourceAdapter(com.sun.enterprise.connectors.ActiveResourceAdapter) ConnectorApplication(com.sun.enterprise.connectors.module.ConnectorApplication) Application(com.sun.enterprise.deployment.Application) ResourceException(javax.resource.ResourceException) NamingException(javax.naming.NamingException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorRuntime(com.sun.enterprise.connectors.ConnectorRuntime)

Example 3 with ConnectorRuntime

use of com.sun.enterprise.connectors.ConnectorRuntime in project Payara by payara.

the class ConnectorMessageBeanClient method setup.

/**
 * Gets executed as part of message bean deployment. Creates the
 * <code>ActivationSpec</code> javabean and does endpointfactory
 * activation with the resource adapter. This code also converts
 * all J2EE 1.3 MDB properties to MQ resource adapter activation
 * spec properties, if user doesnt specifies resource adapter
 * module name in sun-ejb-jar.xml of the MDB. This is done using
 * <code>com.sun.enterprise.connector.system.ActiveJmsResourceAdapter
 * </code>
 *
 * @param messageBeanPM <code>MessageBeanProtocolManager</code> object.
 */
public void setup(MessageBeanProtocolManager messageBeanPM) throws Exception {
    ClassLoader loader = descriptor_.getEjbBundleDescriptor().getClassLoader();
    if (loader == null) {
        loader = Thread.currentThread().getContextClassLoader();
    }
    beanClass_ = loader.loadClass(descriptor_.getEjbClassName());
    messageBeanPM_ = messageBeanPM;
    String resourceAdapterMid = getResourceAdapterMid(descriptor_);
    ActiveInboundResourceAdapter aira = getActiveResourceAdapter(resourceAdapterMid);
    aira.updateMDBRuntimeInfo(descriptor_, messageBeanPM_.getPoolDescriptor());
    // the resource adapter this MDB client is deployed to
    ResourceAdapter ra = aira.getResourceAdapter();
    if (ra == null) {
        String i18nMsg = localStrings.getString("msg-bean-client.ra.class.not.specified", resourceAdapterMid);
        throw new ConnectorRuntimeException(i18nMsg);
    }
    ConnectorDescriptor desc = aira.getDescriptor();
    MessageListener msgListener = getMessageListener(desc);
    String activationSpecClassName = null;
    if (msgListener != null) {
        activationSpecClassName = msgListener.getActivationSpecClass();
    }
    if (activationSpecClassName != null) {
        if (logger.isLoggable(Level.FINEST)) {
            String msg = "ActivationSpecClassName = " + activationSpecClassName;
            logger.log(Level.FINEST, msg);
        }
        try {
            ActivationSpec activationSpec = getActivationSpec(aira, activationSpecClassName);
            activationSpec.setResourceAdapter(ra);
            // at this stage, activation-spec is created, config properties merged with ejb-descriptor.
            // validate activation-spec now
            ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
            runtime.getConnectorBeanValidator().validateJavaBean(activationSpec, resourceAdapterMid);
            aira.validateActivationSpec(activationSpec);
            myState = BLOCKED;
            ra.endpointActivation(this, activationSpec);
            aira.addEndpointFactoryInfo(beanID_, new MessageEndpointFactoryInfo(this, activationSpec));
        } catch (Exception ex) {
            Object[] args = new Object[] { resourceAdapterMid, activationSpecClassName, ex };
            logger.log(Level.WARNING, "endpoint.activation.failure", args);
            throw (Exception) (new Exception()).initCause(ex);
        }
    } else {
        // FIXME  throw some exception here.
        throw new Exception("Unsupported message listener type");
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) ActivationSpec(javax.resource.spi.ActivationSpec) MessageListener(com.sun.enterprise.deployment.MessageListener) ActiveResourceAdapter(com.sun.enterprise.connectors.ActiveResourceAdapter) ResourceAdapter(javax.resource.spi.ResourceAdapter) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) UnavailableException(javax.resource.spi.UnavailableException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConnectorRuntime(com.sun.enterprise.connectors.ConnectorRuntime)

Example 4 with ConnectorRuntime

use of com.sun.enterprise.connectors.ConnectorRuntime in project Payara by payara.

the class ResourceAdapterAdminServiceImpl method reCreateActiveResourceAdapter.

/**
 * The ActiveResourceAdapter object which abstract the rar module is
 * recreated in the connector container/registry. All the pools and
 * resources are killed. But the infrastructure to create the pools and and
 * resources is untouched. Only the actual pool is killed.
 *
 * @param moduleName
 *                     rar module Name.
 * @throws ConnectorRuntimeException
 *                      if recreation fails.
 */
public void reCreateActiveResourceAdapter(String moduleName) throws ConnectorRuntimeException {
    ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
    if (isRarDeployed(moduleName)) {
        if (!ConnectorsUtil.belongsToSystemRA(moduleName)) {
            ConnectorApplication app = _registry.getConnectorApplication(moduleName);
            app.undeployResources();
            stopAndRemoveActiveResourceAdapter(moduleName);
            String moduleDir = ConnectorsUtil.getLocation(moduleName);
            createActiveResourceAdapter(moduleDir, moduleName, app.getClassLoader());
            _registry.getConnectorApplication(moduleName).deployResources();
        } else {
            Collection<Resource> resources = getResourcesUtil().filterConnectorResources(getResourcesUtil().getGlobalResources(), moduleName, true);
            runtime.getGlobalResourceManager().undeployResources(resources);
            stopAndRemoveActiveResourceAdapter(moduleName);
            String moduleDir = ConnectorsUtil.getLocation(moduleName);
            createActiveResourceAdapter(moduleDir, moduleName, runtime.getSystemRARClassLoader(moduleName));
            runtime.getGlobalResourceManager().deployResources(resources);
        }
    }
/*   //No need to deploy the .rar, it may be a case where rar is not deployed yet
        //Also, when the rar is started, RA-Config is anyway used
        else {
            ConnectorApplication app = _registry.getConnectorApplication(moduleName);
            createActiveResourceAdapter(moduleDir, moduleName, app.getClassLoader());
            _registry.getConnectorApplication(moduleName).deployResources();
        }*/
}
Also used : ConnectorApplication(com.sun.enterprise.connectors.module.ConnectorApplication) Resource(com.sun.enterprise.config.serverbeans.Resource) ConnectorRuntime(com.sun.enterprise.connectors.ConnectorRuntime)

Example 5 with ConnectorRuntime

use of com.sun.enterprise.connectors.ConnectorRuntime in project Payara by payara.

the class ConnectorMessageBeanClient method getActiveResourceAdapter.

private ActiveInboundResourceAdapter getActiveResourceAdapter(String resourceAdapterMid) throws Exception {
    Object activeRar = registry_.getActiveResourceAdapter(resourceAdapterMid);
    // (as of now, jms-ra is the only inbound system-rar)
    if (activeRar == null && ConnectorsUtil.belongsToSystemRA(resourceAdapterMid)) {
        ConnectorRuntime crt = ConnectorRuntime.getRuntime();
        crt.loadDeferredResourceAdapter(resourceAdapterMid);
        activeRar = registry_.getActiveResourceAdapter(resourceAdapterMid);
    }
    if (activeRar == null) {
        String msg = "Resource adapter " + resourceAdapterMid + " is not deployed";
        throw new ConnectorRuntimeException(msg);
    }
    if (!(activeRar instanceof ActiveInboundResourceAdapter)) {
        throw new Exception("Resource Adapter selected doesn't support Inbound");
    }
    return (ActiveInboundResourceAdapter) activeRar;
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) UnavailableException(javax.resource.spi.UnavailableException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConnectorRuntime(com.sun.enterprise.connectors.ConnectorRuntime)

Aggregations

ConnectorRuntime (com.sun.enterprise.connectors.ConnectorRuntime)13 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)7 PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)3 ActiveResourceAdapter (com.sun.enterprise.connectors.ActiveResourceAdapter)2 ConnectorApplication (com.sun.enterprise.connectors.module.ConnectorApplication)2 ConnectorDescriptor (com.sun.enterprise.deployment.ConnectorDescriptor)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 NamingException (javax.naming.NamingException)2 ResourceException (javax.resource.ResourceException)2 UnavailableException (javax.resource.spi.UnavailableException)2 ResourceAdapterConfig (org.glassfish.connectors.config.ResourceAdapterConfig)2 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)2 Resource (com.sun.enterprise.config.serverbeans.Resource)1 ConnectorRegistry (com.sun.enterprise.connectors.ConnectorRegistry)1 ConnectorArchivist (com.sun.enterprise.connectors.deployment.util.ConnectorArchivist)1 FileArchive (com.sun.enterprise.deploy.shared.FileArchive)1 Application (com.sun.enterprise.deployment.Application)1 MessageListener (com.sun.enterprise.deployment.MessageListener)1 ResourcePrincipal (com.sun.enterprise.deployment.ResourcePrincipal)1 AdministeredObjectResource (com.sun.enterprise.resource.beans.AdministeredObjectResource)1