Search in sources :

Example 16 with ConnectorResource

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

the class ConnectorResourceManager method createResource.

private ConnectorResource createResource(Resources param, Properties props) throws PropertyVetoException, TransactionFailure {
    ConnectorResource newResource = createConfigBean(param, props);
    param.getResources().add(newResource);
    return newResource;
}
Also used : ConnectorResource(org.glassfish.connectors.config.ConnectorResource)

Example 17 with ConnectorResource

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

the class ActiveJmsResourceAdapter method setValuesFromConfiguration.

private void setValuesFromConfiguration(String cfName, EjbMessageBeanDescriptor descriptor_) throws ConnectorRuntimeException {
    // todo: need to enable
    List<Property> ep = null;
    try {
        /*Resources rbeans = getAllResources();//ServerBeansFactory.getDomainBean(ctx).getResources();
            ConnectorResource res = (ConnectorResource)
                             rbeans.getResourceByName(ConnectorResource.class, cfName);*/
        String appName = descriptor_.getApplication().getAppName();
        String moduleName = ConnectorsUtil.getModuleName(descriptor_);
        ConnectorResource res = (ConnectorResource) ResourcesUtil.createInstance().getResource(cfName, appName, moduleName, ConnectorResource.class);
        if (res == null) {
            String msg = sm.getString("ajra.mdb_cf_not_created", cfName);
            throw new ConnectorRuntimeException(msg);
        }
        ConnectorConnectionPool ccp = (ConnectorConnectionPool) ResourcesUtil.createInstance().getResource(res.getPoolName(), appName, moduleName, ConnectorConnectionPool.class);
        // rbeans.getResourceByName(ConnectorConnectionPool.class, res.getPoolName());
        ep = ccp.getProperty();
    } catch (Exception ce) {
        String msg = sm.getString("ajra.mdb_cf_not_created", cfName);
        ConnectorRuntimeException cre = new ConnectorRuntimeException(msg);
        cre.initCause(ce);
        throw cre;
    }
    if (ep == null) {
        String msg = sm.getString("ajra.cannot_find_phy_dest");
        throw new ConnectorRuntimeException(msg);
    }
    for (int i = 0; i < ep.size(); i++) {
        Property prop = ep.get(i);
        String name = prop.getName();
        if (name.equals(MCFADDRESSLIST)) {
            name = ADDRESSLIST;
        }
        String val = prop.getValue();
        if (val == null || val.equals("")) {
            continue;
        }
        descriptor_.putRuntimeActivationConfigProperty(new EnvironmentProperty(name, val, null));
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) Property(org.jvnet.hk2.config.types.Property) EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) ConnectorConfigProperty(com.sun.enterprise.deployment.ConnectorConfigProperty) ConnectorResource(org.glassfish.connectors.config.ConnectorResource) MultiException(org.glassfish.hk2.api.MultiException) PrivilegedActionException(java.security.PrivilegedActionException) ExecutionException(java.util.concurrent.ExecutionException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) URISyntaxException(java.net.URISyntaxException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)

Example 18 with ConnectorResource

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

the class DeleteJMSResource 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
 */
@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    if (jndiName == null) {
        report.setMessage(localStrings.getLocalString("delete.jms.resource.noJndiName", "No JNDI name defined for JMS Resource."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    jndiNameForConnectionPool = jndiName + JNDINAME_APPENDER;
    ActionReport subReport = report.addSubActionsReport();
    ConnectorResource cresource = null;
    Resource res = ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorResource.class, jndiName);
    if (res instanceof ConnectorResource) {
        cresource = (ConnectorResource) res;
    }
    /* for (ConnectorResource cr : connResources) {
         if (cr.getJndiName().equals(jndiName))
         cresource = cr;
         } */
    if (cresource == null) {
        ParameterMap params = new ParameterMap();
        params.set("jndi_name", jndiName);
        params.set("DEFAULT", jndiName);
        params.set("target", target);
        commandRunner.getCommandInvocation("delete-admin-object", subReport, context.getSubject()).parameters(params).execute();
        if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
            report.setMessage(localStrings.getLocalString("delete.jms.resource.cannotDeleteJMSAdminObject", "Unable to Delete Admin Object."));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    } else {
        if (!cascade) {
            Collection<ConnectorResource> connectorResources = domain.getResources().getResources(ConnectorResource.class);
            String connPoolName = jndiName + JNDINAME_APPENDER;
            int count = 0;
            for (ConnectorResource resource : connectorResources) {
                if (connPoolName.equals(resource.getPoolName())) {
                    count++;
                    if (count > 1)
                        break;
                }
            }
            if (count > 1) {
                report.setMessage(localStrings.getLocalString("found.more.connector.resources", "Some connector resources are referencing connection pool {0}. Use 'cascade' option to delete them", connPoolName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
        ActionReport listReport = habitat.getService(ActionReport.class);
        ParameterMap listParams = new ParameterMap();
        listParams.set("target", target);
        commandRunner.getCommandInvocation("list-jms-resources", listReport, context.getSubject()).parameters(listParams).execute();
        if (ActionReport.ExitCode.FAILURE.equals(listReport.getActionExitCode())) {
            report.setMessage(localStrings.getLocalString("list.jms.resources.fail", "Unable to list JMS Resources"));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        Properties extraProps = listReport.getExtraProperties();
        if (extraProps != null && extraProps.size() > 0) {
            boolean resourceExist = false;
            for (int i = 0; i < extraProps.size(); i++) {
                List<Map<String, String>> nameList = (List) extraProps.get("jmsResources");
                for (Map<String, String> m : nameList) {
                    String jndi = (String) m.get("name");
                    if (jndiName.equals(jndi)) {
                        resourceExist = true;
                        break;
                    }
                }
                if (resourceExist)
                    break;
            }
            if (!resourceExist) {
                report.setMessage(localStrings.getLocalString("jms.resources.not.found", "JMS Resource {0} not found", jndiName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
        // Delete the connector resource and connector connection pool
        String defPoolName = jndiNameForConnectionPool;
        String poolName = cresource.getPoolName();
        if (poolName != null && poolName.equals(defPoolName)) {
            ParameterMap params = new ParameterMap();
            params.set("DEFAULT", jndiName);
            params.set("connector_resource_name", jndiName);
            params.set("target", target);
            commandRunner.getCommandInvocation("delete-connector-resource", subReport, context.getSubject()).parameters(params).execute();
            if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
                report.setMessage(localStrings.getLocalString("delete.jms.resource.cannotDeleteJMSResource", "Unable to Delete Connector Resource."));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
            params = new ParameterMap();
            params.set("poolname", jndiName);
            params.set("cascade", cascade.toString());
            params.set("DEFAULT", jndiNameForConnectionPool);
            commandRunner.getCommandInvocation("delete-connector-connection-pool", subReport, context.getSubject()).parameters(params).execute();
            if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
                report.setMessage(localStrings.getLocalString("delete.jms.resource.cannotDeleteJMSPool", "Unable to Delete Connector Connection Pool."));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
            // clear the message set by the delete-connector-connection-pool command this is to prevent the 'connection pool deleted' message from displaying
            subReport.setMessage("");
        } else {
            // There is no connector pool with the default poolName.
            // However, no need to throw exception as the connector
            // resource might still be there. Try to delete the
            // connector-resource without touching the ref. as
            // ref. might have been deleted while deleting connector-connection-pool
            // as the ref. is the same.
            ParameterMap params = new ParameterMap();
            params.set("DEFAULT", jndiName);
            params.set("connector_resource_name", jndiName);
            params.set("target", target);
            commandRunner.getCommandInvocation("delete-connector-resource", subReport, context.getSubject()).parameters(params).execute();
            if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
                report.setMessage(localStrings.getLocalString("delete.jms.resource.cannotDeleteJMSResource", "Unable to Delete Connector Resource."));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
    }
    ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
    report.setActionExitCode(ec);
}
Also used : ConnectorResource(org.glassfish.connectors.config.ConnectorResource) Resource(com.sun.enterprise.config.serverbeans.Resource) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) List(java.util.List) Map(java.util.Map) 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