Search in sources :

Example 1 with AdminObjectResource

use of org.glassfish.connectors.config.AdminObjectResource 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 AdminObjectResource

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

the class ActiveJmsResourceAdapter method getPhysicalDestinationFromConfiguration.

private String getPhysicalDestinationFromConfiguration(String logicalDest, String appName, String moduleName) throws ConnectorRuntimeException {
    Property ep = null;
    try {
        // ServerContext sc = ApplicationServer.getServerContext();
        // ConfigContext ctx = sc.getConfigContext();
        // Resources rbeans =                           ServerBeansFactory.getDomainBean(ctx).getResources();
        AdminObjectResource res = null;
        res = (AdminObjectResource) ResourcesUtil.createInstance().getResource(logicalDest, appName, moduleName, AdminObjectResource.class);
        // AdminObjectResource res = (AdminObjectResource)   allResources.getAdminObjectResourceByJndiName(logicalDest);
        if (res == null) {
            String msg = sm.getString("ajra.err_getting_dest", logicalDest);
            throw new ConnectorRuntimeException(msg);
        }
        // getElementPropertyByName(PHYSICAL_DESTINATION);
        ep = res.getProperty(PHYSICAL_DESTINATION);
    } catch (Exception ce) {
        String msg = sm.getString("ajra.err_getting_dest", logicalDest);
        ConnectorRuntimeException cre = new ConnectorRuntimeException(msg);
        cre.initCause(ce);
        throw cre;
    }
    if (ep == null) {
        String msg = sm.getString("ajra.cannot_find_phy_dest", null);
        throw new ConnectorRuntimeException(msg);
    }
    return ep.getValue();
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource) Property(org.jvnet.hk2.config.types.Property) EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) ConnectorConfigProperty(com.sun.enterprise.deployment.ConnectorConfigProperty) 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 3 with AdminObjectResource

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

the class ActiveJmsResourceAdapter method updateMDBRuntimeInfo.

/**
 * This is the most appropriate time (??) to update the runtime
 * info of a 1.3 MDB into 1.4 MDB.  <p>
 *
 * Assumptions : <p>
 * 0. Assume it is a 1.3 MDB if no RA mid is specified.
 * 1. Use the default system JMS resource adapter. <p>
 * 2. The ActivationSpec of the default JMS RA will provide the
 *    setDestination, setDestinationType, setSubscriptionName methods.
 * 3. The jndi-name of the 1.3 MDB is the value for the Destination
 *    property for the ActivationSpec.
 * 4. The ActivationSpec provides setter methods for the properties
 *    defined in the CF that corresponds to the mdb-connection-factory
 *    JNDI name.
 *
 * @param descriptor_
 * @param poolDescriptor
 * @throws com.sun.appserv.connectors.internal.api.ConnectorRuntimeException
 */
@Override
public void updateMDBRuntimeInfo(EjbMessageBeanDescriptor descriptor_, BeanPoolDescriptor poolDescriptor) throws ConnectorRuntimeException {
    String jndiName = descriptor_.getJndiName();
    if (jndiName == null || "".equals(jndiName)) {
        MessageDestinationDescriptor destDescriptor = descriptor_.getMessageDestination();
        if (destDescriptor != null)
            jndiName = destDescriptor.getJndiName();
    }
    String destinationLookup = descriptor_.getActivationConfigValue("destinationLookup");
    String destinationProp = descriptor_.getActivationConfigValue("destination");
    if (destinationLookup == null && destinationProp == null && (jndiName == null || "".equals(jndiName))) {
        if (_logger.isLoggable(Level.SEVERE)) {
            _logger.log(Level.SEVERE, JMSLoggerInfo.ERROR_IN_DD);
        }
        String msg = sm.getString("ajra.error_in_dd");
        throw new ConnectorRuntimeException(msg);
    }
    String resourceAdapterMid = ConnectorRuntime.DEFAULT_JMS_ADAPTER;
    descriptor_.setResourceAdapterMid(resourceAdapterMid);
    if (destinationLookup == null && destinationProp == null) {
        String appName = descriptor_.getApplication().getAppName();
        String moduleName = ConnectorsUtil.getModuleName(descriptor_);
        JMSDestinationDefinitionDescriptor destination = getJMSDestinationFromDescriptor(jndiName, descriptor_);
        String destName = null;
        if (isValidDestination(destination)) {
            destName = destination.getDestinationName();
        } else {
            destName = getPhysicalDestinationFromConfiguration(jndiName, appName, moduleName);
        }
        // 1.3 jndi-name ==> 1.4 setDestination
        descriptor_.putRuntimeActivationConfigProperty(new EnvironmentProperty(DESTINATION, destName, null));
        // XXX Do we really need this???
        if (descriptor_.getDestinationType() != null && !"".equals(descriptor_.getDestinationType())) {
            descriptor_.putRuntimeActivationConfigProperty(new EnvironmentProperty(DESTINATION_TYPE, descriptor_.getDestinationType(), null));
            if (_logger.isLoggable(Level.INFO)) {
                _logger.log(Level.INFO, JMSLoggerInfo.ENDPOINT_DEST_NAME, new Object[] { descriptor_.getDestinationType(), jndiName, descriptor_.getName() });
            }
        } else if (isValidDestination(destination) && ConnectorConstants.DEFAULT_JMS_ADAPTER.equals(destination.getResourceAdapter())) {
            descriptor_.putRuntimeActivationConfigProperty(new EnvironmentProperty(DESTINATION_TYPE, destination.getInterfaceName(), null));
            if (_logger.isLoggable(Level.INFO)) {
                _logger.log(Level.INFO, JMSLoggerInfo.ENDPOINT_DEST_NAME, new Object[] { destination.getInterfaceName(), destination.getName(), descriptor_.getName() });
            }
        } else {
            /*
                 * If destination type is not provided by the MDB component
                 * [typically used by EJB3.0 styled MDBs which create MDBs without
                 * a destination type activation-config property] and the MDB is for
                 * the default JMS RA, attempt to infer the destination type by trying
                 * to find out if there has been any JMS destination resource already
                 * defined for default JMS RA. This is a best attempt guess and if there
                 * are no JMS destination resources/admin-objects defined, AS would pass
                 * the properties as defined by the MDB.
                 */
            try {
                AdminObjectResource aor = (AdminObjectResource) ResourcesUtil.createInstance().getResource(jndiName, appName, moduleName, AdminObjectResource.class);
                if (aor != null && ConnectorConstants.DEFAULT_JMS_ADAPTER.equals(aor.getResAdapter())) {
                    descriptor_.putRuntimeActivationConfigProperty(new EnvironmentProperty(DESTINATION_TYPE, aor.getResType(), null));
                    if (_logger.isLoggable(Level.INFO)) {
                        _logger.log(Level.INFO, JMSLoggerInfo.ENDPOINT_DEST_NAME, new Object[] { aor.getResType(), aor.getJndiName(), descriptor_.getName() });
                    }
                }
            } catch (Exception e) {
            }
        }
    }
    // 1.3 durable-subscription-name == 1.4 setSubscriptionName
    descriptor_.putRuntimeActivationConfigProperty(new EnvironmentProperty(SUBSCRIPTION_NAME, descriptor_.getDurableSubscriptionName(), null));
    String mdbCF = null;
    try {
        mdbCF = descriptor_.getMdbConnectionFactoryJndiName();
    } catch (NullPointerException ne) {
    // Dont process connection factory.
    }
    if (mdbCF != null && !"".equals(mdbCF)) {
        setValuesFromConfiguration(mdbCF, descriptor_);
    }
    if (poolDescriptor != null) {
        descriptor_.putRuntimeActivationConfigProperty(new EnvironmentProperty(MAXPOOLSIZE, "" + poolDescriptor.getMaxPoolSize(), "", "java.lang.Integer"));
        descriptor_.putRuntimeActivationConfigProperty(new EnvironmentProperty(MINPOOLSIZE, "" + poolDescriptor.getSteadyPoolSize(), "", "java.lang.Integer"));
        descriptor_.putRuntimeActivationConfigProperty(new EnvironmentProperty(RESIZECOUNT, "" + poolDescriptor.getPoolResizeQuantity(), "", "java.lang.Integer"));
        descriptor_.putRuntimeActivationConfigProperty(new EnvironmentProperty(RESIZETIMEOUT, "" + poolDescriptor.getPoolIdleTimeoutInSeconds(), "", "java.lang.Integer"));
        /**
         * The runtime activation config property holds all the
         * vendor specific properties, unfortunately the vendor
         * specific way of configuring exception count and the
         * standard way of configuring redelivery attempts is
         * through the same property REDELIVERYCOUNT . So, we first
         * check if the user (MDB assember) has configured a value
         * if not we set the one from mdb-container props
         * We have to check for both cases here because it has been
         * documented as "endpointExceptionRedeliveryAttempts" but
         * used in the code as "EndpointExceptionRedeliveryAttempts"
         */
        if ((descriptor_.getActivationConfigValue(REDELIVERYCOUNT) == null) && (descriptor_.getActivationConfigValue(LOWERCASE_REDELIVERYCOUNT) == null)) {
            descriptor_.putRuntimeActivationConfigProperty(new EnvironmentProperty(REDELIVERYCOUNT, "" + MdbContainerProps.getMaxRuntimeExceptions(), "", "java.lang.Integer"));
        }
    }
    // Set SE/EE specific MQ-RA ActivationSpec properties
    try {
        boolean clustered = isClustered();
        if (_logger.isLoggable(Level.FINE))
            logFine("Are we in a Clustered contained ? " + clustered);
        if (clustered)
            setClusterActivationSpecProperties(descriptor_);
    } catch (Exception e) {
        ConnectorRuntimeException crex = new ConnectorRuntimeException(e.getMessage());
        throw (ConnectorRuntimeException) crex.initCause(e);
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) MessageDestinationDescriptor(com.sun.enterprise.deployment.MessageDestinationDescriptor) JMSDestinationDefinitionDescriptor(com.sun.enterprise.deployment.JMSDestinationDefinitionDescriptor) EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource) 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 4 with AdminObjectResource

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

the class AdminObjectManager method createResource.

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

Example 5 with AdminObjectResource

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

the class AdminObjectResourceDeployer method deployResource.

/**
 * {@inheritDoc}
 */
public synchronized void deployResource(Object resource) throws Exception {
    final AdminObjectResource aor = (AdminObjectResource) resource;
    ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(aor);
    createAdminObjectResource(aor, resourceInfo);
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource)

Aggregations

AdminObjectResource (org.glassfish.connectors.config.AdminObjectResource)11 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)4 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)2 EnvironmentProperty (com.sun.enterprise.deployment.EnvironmentProperty)2 URISyntaxException (java.net.URISyntaxException)2 PrivilegedActionException (java.security.PrivilegedActionException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ExecutionException (java.util.concurrent.ExecutionException)2 ResourceAdapterInternalException (javax.resource.spi.ResourceAdapterInternalException)2 ActionReport (org.glassfish.api.ActionReport)2 ConnectorConnectionPool (org.glassfish.connectors.config.ConnectorConnectionPool)2 ConnectorResource (org.glassfish.connectors.config.ConnectorResource)2 MultiException (org.glassfish.hk2.api.MultiException)2 Property (org.jvnet.hk2.config.types.Property)2 BindableResource (com.sun.enterprise.config.serverbeans.BindableResource)1 Resource (com.sun.enterprise.config.serverbeans.Resource)1 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)1 Application (com.sun.enterprise.deployment.Application)1