Search in sources :

Example 1 with ConnectorResource

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

the class ListJMSResources method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the paramter names and the values the parameter values
 *
 * @param context information
 */
@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    ArrayList<Map<String, String>> list = new ArrayList<>();
    Properties extraProperties = new Properties();
    Collection adminObjectResourceList = domain.getResources().getResources(AdminObjectResource.class);
    Collection connectorResourcesList = domain.getResources().getResources(ConnectorResource.class);
    Object[] connectorResources = connectorResourcesList.toArray();
    Object[] adminObjectResources = adminObjectResourceList.toArray();
    if (resourceType == null) {
        try {
            // list all JMS resources
            for (Object r : adminObjectResources) {
                AdminObjectResource adminObject = (AdminObjectResource) r;
                if (JMSRA.equals(adminObject.getResAdapter())) {
                    Map<String, String> m = new HashMap<>();
                    m.put("name", adminObject.getJndiName());
                    list.add(m);
                }
            }
            for (Object c : connectorResources) {
                ConnectorResource cr = (ConnectorResource) c;
                ConnectorConnectionPool cp = (ConnectorConnectionPool) ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorConnectionPool.class, cr.getPoolName());
                if (cp != null && JMSRA.equals(cp.getResourceAdapterName())) {
                    Map<String, String> m = new HashMap<>();
                    m.put("name", cr.getJndiName());
                    list.add(m);
                }
            }
        } catch (Exception e) {
            report.setMessage(localStrings.getLocalString("list.jms.resources.fail", "Unable to list JMS Resources") + " " + e.getLocalizedMessage());
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setFailureCause(e);
            return;
        }
    } else {
        switch(resourceType) {
            case TOPIC_CF:
            case QUEUE_CF:
            case UNIFIED_CF:
                for (Object c : connectorResources) {
                    ConnectorResource cr = (ConnectorResource) c;
                    ConnectorConnectionPool cp = (ConnectorConnectionPool) ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorConnectionPool.class, cr.getPoolName());
                    if (cp != null && resourceType.equals(cp.getConnectionDefinitionName()) && JMSRA.equals(cp.getResourceAdapterName())) {
                        Map<String, String> m = new HashMap<>();
                        m.put("name", cr.getJndiName());
                        list.add(m);
                    }
                }
                break;
            case TOPIC:
            case QUEUE:
                for (Object r : adminObjectResources) {
                    AdminObjectResource res = (AdminObjectResource) r;
                    if (resourceType.equals(res.getResType()) && JMSRA.equals(res.getResAdapter())) {
                        Map<String, String> m = new HashMap<>();
                        m.put("name", res.getJndiName());
                        list.add(m);
                    }
                }
                break;
        }
    }
    if (!list.isEmpty()) {
        List<Map<String, String>> resourceList = CommandTarget.DOMAIN.isValid(habitat, target) ? list : filterListForTarget(list);
        List<DefaultResourceProxy> drps = habitat.getAllServices(DefaultResourceProxy.class);
        for (Map<String, String> m : resourceList) {
            String jndiName = m.get("name");
            final ActionReport.MessagePart part = report.getTopMessagePart().addChild();
            part.setMessage(jndiName);
            String logicalName = DefaultResourceProxy.Util.getLogicalName(drps, jndiName);
            if (logicalName != null) {
                m.put("logical-jndi-name", logicalName);
            }
        }
        extraProperties.put("jmsResources", resourceList);
    }
    report.setExtraProperties(extraProperties);
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) DefaultResourceProxy(org.glassfish.api.naming.DefaultResourceProxy) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) Collection(java.util.Collection) AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource) HashMap(java.util.HashMap) Map(java.util.Map) ConnectorResource(org.glassfish.connectors.config.ConnectorResource)

Example 2 with ConnectorResource

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

the class ConnectorResourceManager method createConfigBean.

private ConnectorResource createConfigBean(Resources param, Properties properties) throws PropertyVetoException, TransactionFailure {
    ConnectorResource newResource = param.createChild(ConnectorResource.class);
    newResource.setJndiName(jndiName);
    if (description != null) {
        newResource.setDescription(description);
    }
    newResource.setPoolName(poolName);
    newResource.setEnabled(enabled);
    newResource.setObjectType(objectType);
    if (properties != null) {
        for (Map.Entry e : properties.entrySet()) {
            Property prop = newResource.createChild(Property.class);
            prop.setName((String) e.getKey());
            prop.setValue((String) e.getValue());
            newResource.getProperty().add(prop);
        }
    }
    return newResource;
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) Property(org.jvnet.hk2.config.types.Property) ConnectorResource(org.glassfish.connectors.config.ConnectorResource)

Example 3 with ConnectorResource

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

the class ListConnectorResources method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the paramter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    try {
        Collection<ConnectorResource> connectorResources = domain.getResources().getResources(ConnectorResource.class);
        for (ConnectorResource resource : connectorResources) {
            if (bindableResourcesHelper.resourceExists(resource.getJndiName(), target)) {
                ActionReport.MessagePart part = report.getTopMessagePart().addChild();
                part.setMessage(resource.getJndiName());
            }
        }
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("list.connector.resources.fail", "List connector resources failed") + " " + e.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : ActionReport(org.glassfish.api.ActionReport) ConnectorResource(org.glassfish.connectors.config.ConnectorResource)

Example 4 with ConnectorResource

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

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

the class ConnectionFactoryDefinitionDeployer method undeployResource.

public void undeployResource(Object resource) throws Exception {
    final ConnectionFactoryDefinitionDescriptor desc = (ConnectionFactoryDefinitionDescriptor) resource;
    String poolName = ConnectorsUtil.deriveResourceName(desc.getResourceId(), desc.getName(), CFDPOOL);
    String resourceName = ConnectorsUtil.deriveResourceName(desc.getResourceId(), desc.getName(), desc.getResourceType());
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "ConnectionFactoryDefinitionDeployer.undeployResource() : pool-name [" + poolName + "], " + " resource-name [" + resourceName + "]");
    }
    // undeploy resource
    ConnectorResource connectorResource = new MyConnectorResource(poolName, resourceName);
    getDeployer(connectorResource).undeployResource(connectorResource);
    // undeploy pool
    ConnectorConnectionPool connectorCp = new MyConnectorConnectionPool(desc, poolName);
    getDeployer(connectorCp).undeployResource(connectorCp);
}
Also used : ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) ConnectionFactoryDefinitionDescriptor(com.sun.enterprise.deployment.ConnectionFactoryDefinitionDescriptor) ConnectorResource(org.glassfish.connectors.config.ConnectorResource)

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