Search in sources :

Example 16 with JmsService

use of com.sun.enterprise.connectors.jms.config.JmsService in project Payara by payara.

the class ActiveJmsResourceAdapter method setClusterRABeanProperties.

// //@Siva: provide an API to read JMX information from RA and return it.
// private
/**
 * Sets the SE/EE specific MQ-RA bean properties
 * @throws ConnectorRuntimeException
 */
private void setClusterRABeanProperties() throws ConnectorRuntimeException {
    ConnectorDescriptor cd = super.getDescriptor();
    try {
        if (isClustered()) {
            JmsService jmsService = (JmsService) Globals.get(JmsService.class);
            /* ConfigContext ctx = ApplicationServer.getServerContext().
                    getConfigContext();
            JmsService jmsService = ServerBeansFactory.
                getConfigBean(ctx).getJmsService();    */
            String val = getGroupName();
            ConnectorConfigProperty envProp = new ConnectorConfigProperty(GROUPNAME, val, "Group Name", "java.lang.String");
            setProperty(cd, envProp);
            if (_logger.isLoggable(Level.FINE))
                logFine("CLUSTERED instance - setting groupname as" + val);
            boolean inClusteredContainer = false;
            if (jmsService.getType().equals(EMBEDDED) || jmsService.getType().equals(LOCAL))
                inClusteredContainer = true;
            ConnectorConfigProperty envProp1 = new ConnectorConfigProperty(CLUSTERCONTAINER, Boolean.toString(inClusteredContainer), "Cluster container flag", "java.lang.Boolean");
            setProperty(cd, envProp1);
            if (_logger.isLoggable(Level.FINE))
                logFine("CLUSTERED instance - setting inclusteredcontainer as" + inClusteredContainer);
            if (jmsService.getType().equals(REMOTE)) {
                /*
                * Do not set master broker for remote broker.
                * The RA might ignore it if we set, but we have to
                        * be certain from our end.
                */
                return;
            } else {
                if (!isDBEnabled()) {
                    String masterbrkr = getMasterBroker();
                    ConnectorConfigProperty envProp2 = new ConnectorConfigProperty(MASTERBROKER, masterbrkr, "Master  Broker", "java.lang.String");
                    setProperty(cd, envProp2);
                    if (_logger.isLoggable(Level.FINE))
                        logFine("MASTERBROKER - setting master broker val" + masterbrkr);
                }
            }
        } else {
            if (_logger.isLoggable(Level.FINE))
                logFine("Instance not Clustered and hence not setting " + "groupname");
        }
    } catch (Exception e) {
        ConnectorRuntimeException crex = new ConnectorRuntimeException(e.getMessage());
        throw (ConnectorRuntimeException) crex.initCause(e);
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) JmsService(com.sun.enterprise.connectors.jms.config.JmsService) 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 17 with JmsService

use of com.sun.enterprise.connectors.jms.config.JmsService in project Payara by payara.

the class ActiveJmsResourceAdapter method startResourceAdapter.

@Override
protected void startResourceAdapter(BootstrapContext bootstrapContext) throws ResourceAdapterInternalException {
    JmsService jmsService = getJmsService();
    if (jmsService != null && jmsService.getType().equals("DISABLED")) {
        return;
    }
    try {
        if (this.moduleName_.equals(ConnectorRuntime.DEFAULT_JMS_ADAPTER)) {
            if (connectorRuntime.isServer()) {
                Domain domain = Globals.get(Domain.class);
                ServerContext serverContext = Globals.get(ServerContext.class);
                Server server = domain.getServerNamed(serverContext.getInstanceName());
                try {
                    initializeLazyListener(jmsService);
                } catch (Throwable ex) {
                    Logger.getLogger(ActiveJmsResourceAdapter.class.getName()).log(Level.SEVERE, null, ex);
                    throw new ResourceAdapterInternalException(ex);
                }
            }
            // System.setProperty("imq.jmsra.direct.clustered", "true");
            AccessController.doPrivileged(new java.security.PrivilegedExceptionAction() {

                public Object run() throws ResourceAdapterInternalException {
                    // set the JMSRA system property to enable XA JOINS
                    // disabling this due to issue - 8727
                    // System.setProperty(XA_JOIN_ALLOWED, "true");
                    // to prevent classloader leaks in new threads clear invocation manager before bootstrapping JMS
                    resourceadapter_.start(bootStrapContextImpl);
                    return null;
                }
            });
        // setResourceAdapter(resourceadapter_);
        } else {
            resourceadapter_.start(bootStrapContextImpl);
        }
    } catch (PrivilegedActionException ex) {
        throw new ResourceAdapterInternalException(ex);
    }
}
Also used : JmsService(com.sun.enterprise.connectors.jms.config.JmsService) ServerContext(org.glassfish.internal.api.ServerContext) Server(com.sun.enterprise.config.serverbeans.Server) PrivilegedActionException(java.security.PrivilegedActionException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) Domain(com.sun.enterprise.config.serverbeans.Domain) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction)

Example 18 with JmsService

use of com.sun.enterprise.connectors.jms.config.JmsService in project Payara by payara.

the class ActiveJmsResourceAdapter method setAddressList.

private void setAddressList() throws ConnectorRuntimeException {
    // constructing addresslist]
    try {
        // ConfigContext ctx = ApplicationServer.getServerContext().getConfigContext();
        JmsService jmsService = (JmsService) Globals.get(JmsService.class);
        // ServerBeansFactory.getJmsServiceBean(ctx);
        setConnectionURL(jmsService, urlList);
    } catch (Exception e) {
        e.printStackTrace();
    }
    super.loadRAConfiguration();
}
Also used : JmsService(com.sun.enterprise.connectors.jms.config.JmsService) 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 19 with JmsService

use of com.sun.enterprise.connectors.jms.config.JmsService in project Payara by payara.

the class ConfigureJMSCluster 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();
    // Server targetServer = domain.getServerNamed(target);
    // String configRef = targetServer.getConfigRef();
    Cluster cluster = domain.getClusterNamed(clusterName);
    if (cluster == null) {
        report.setMessage(localStrings.getLocalString("configure.jms.cluster.invalidClusterName", "No Cluster by this name has been configured"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    List instances = cluster.getInstances();
    String warning = null;
    if (instances.size() > 0) {
        ActionReport listReport = habitat.getService(ActionReport.class);
        ParameterMap parameters = new ParameterMap();
        parameters.set("DEFAULT", clusterName);
        commandRunner.getCommandInvocation("list-instances", listReport, context.getSubject()).parameters(parameters).execute();
        if (ActionReport.ExitCode.FAILURE.equals(listReport.getActionExitCode())) {
            warning = localStrings.getLocalString("configure.jms.cluster.clusterWithInstances", "Warning: Please make sure running this command with all cluster instances stopped, otherwise it may lead to inconsistent JMS behavior and corruption of configuration and message stores.");
        } else {
            String result = listReport.getMessage();
            String fixedResult = result.replaceAll("not running", "stopped");
            if (fixedResult.indexOf("running") > -1) {
                warning = localStrings.getLocalString("configure.jms.cluster.clusterWithInstances", "Warning: Please make sure running this command with all cluster instances stopped, otherwise it may lead to inconsistent JMS behavior and corruption of configuration and message stores.");
                warning = warning + "\r\n" + result + "\r\n";
            }
        }
    }
    Config config = domain.getConfigNamed(cluster.getConfigRef());
    JmsService jmsService = config.getExtensionByType(JmsService.class);
    if (jmsService == null) {
        report.setMessage(localStrings.getLocalString("configure.jms.cluster.nojmsservice", "No JMS Service element in config"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (!CONVENTIONAL.equalsIgnoreCase(clusterType) && !ENHANCED.equalsIgnoreCase(clusterType)) {
        report.setMessage(localStrings.getLocalString("configure.jms.cluster.wrongClusterType", "Invalid option sepecified for clustertype. Valid options are conventional and enhanced"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (CONVENTIONAL.equalsIgnoreCase(clusterType) && !MASTER_BROKER.equalsIgnoreCase(configStoreType) && !SHARED_DB.equalsIgnoreCase(configStoreType)) {
        report.setMessage(localStrings.getLocalString("configure.jms.cluster.wrongConfigStoreType", "Invalid option sepecified for configstoretype. Valid options are masterbroker and shareddb"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (ENHANCED.equalsIgnoreCase(clusterType) && configStoreType != null) {
        report.setMessage(localStrings.getLocalString("configure.jms.cluster.wrongStoreType", "configstoretype option is not configurable for Enhanced clusters."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (CONVENTIONAL.equalsIgnoreCase(clusterType) && !MASTER_BROKER.equalsIgnoreCase(configStoreType) && !FILE.equalsIgnoreCase(messageStoreType) && !JDBC.equalsIgnoreCase(messageStoreType)) {
        report.setMessage(localStrings.getLocalString("configure.jms.cluster.wrongMessageStoreType", "Invalid option sepecified for messagestoretype. Valid options are file and jdbc"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (ENHANCED.equalsIgnoreCase(clusterType) && messageStoreType != null) {
        report.setMessage(localStrings.getLocalString("configure.jms.cluster.wrongmsgStoreType", "messagestoretype option is not configurable for Enhanced clusters."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    String integrationMode = jmsService.getType();
    if (REMOTE.equalsIgnoreCase(integrationMode)) {
        report.setMessage(localStrings.getLocalString("configure.jms.cluster.remoteMode", "JMS integration mode should be either EMBEDDED or LOCAL to run this command. Please use the asadmin.set command to change the integration mode"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    String changeIntegrationMode = null;
    if (EMBEDDED.equalsIgnoreCase(integrationMode) && ENHANCED.equalsIgnoreCase(clusterType)) {
        try {
            ConfigSupport.apply(new SingleConfigCode<JmsService>() {

                public Object run(JmsService param) throws PropertyVetoException, TransactionFailure {
                    param.setType(LOCAL);
                    return param;
                }
            }, jmsService);
            changeIntegrationMode = localStrings.getLocalString("configure.jms.cluster.integrationModeChanged", "WARNING: JMS integration mode has been changed from EMBEDDED to LOCAL automatically.");
        } catch (TransactionFailure tfe) {
            report.setMessage(localStrings.getLocalString("configure.jms.cluster.cannotChangeIntegrationMode", "Unable to change the JMS integration mode to LOCAL for Enhanced cluster {0}.", clusterName) + " " + tfe.getLocalizedMessage());
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setFailureCause(tfe);
            return;
        }
    }
    if (MASTER_BROKER.equalsIgnoreCase(configStoreType) && FILE.equals(messageStoreType)) {
        if (dbvendor != null || dburl != null || dbuser != null) {
            report.setMessage(localStrings.getLocalString("configure.jms.cluster.invalidDboptions", "Database options should not be specified for this configuration"));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    if (!MASTER_BROKER.equalsIgnoreCase(configStoreType) || ENHANCED.equalsIgnoreCase(clusterType) || JDBC.equalsIgnoreCase(messageStoreType)) {
        if (dbvendor == null) {
            report.setMessage(localStrings.getLocalString("configure.jms.cluster.nodbvendor", "No DataBase vendor specified"));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        } else if (dburl == null) {
            report.setMessage(localStrings.getLocalString("configure.jms.cluster.nojdbcurl", "No JDBC URL specified"));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        } else if (!isSupportedDbVendor()) {
            report.setMessage(localStrings.getLocalString("configure.jms.cluster.invaliddbvendor", "Invalid DB Vednor specified"));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    if (CONVENTIONAL.equalsIgnoreCase(clusterType) && configStoreType == null) {
        report.setMessage(localStrings.getLocalString("configure.jms.cluster.noConfigStoreType", "No configstoretype specified. Using the default value - masterbroker"));
        configStoreType = "masterbroker";
    }
    if (CONVENTIONAL.equalsIgnoreCase(clusterType) && messageStoreType == null) {
        report.setMessage(localStrings.getLocalString("configure.jms.cluster.noMessagetoreType", "No messagestoretype specified. Using the default value - file"));
        messageStoreType = "file";
    }
    config = domain.getConfigNamed(cluster.getConfigRef());
    JmsAvailability jmsAvailability = config.getAvailabilityService().getExtensionByType(JmsAvailability.class);
    final Boolean availabilityEnabled = Boolean.valueOf(ENHANCED.equalsIgnoreCase(clusterType));
    try {
        ConfigSupport.apply(new SingleConfigCode<JmsAvailability>() {

            public Object run(JmsAvailability param) throws PropertyVetoException, TransactionFailure {
                param.setAvailabilityEnabled(availabilityEnabled.toString());
                if (availabilityEnabled.booleanValue()) {
                    param.setMessageStoreType(JDBC);
                } else {
                    param.setConfigStoreType(configStoreType.toLowerCase(Locale.ENGLISH));
                    param.setMessageStoreType(messageStoreType.toLowerCase(Locale.ENGLISH));
                }
                param.setDbVendor(dbvendor);
                param.setDbUsername(dbuser);
                param.setDbPassword(jmsDbPassword);
                param.setDbUrl(dburl);
                if (props != null) {
                    for (Map.Entry e : props.entrySet()) {
                        Property prop = param.createChild(Property.class);
                        prop.setName((String) e.getKey());
                        prop.setValue((String) e.getValue());
                        param.getProperty().add(prop);
                    }
                }
                return param;
            }
        }, jmsAvailability);
    /* //update the useMasterBroker flag on the JmsService only if availabiltyEnabled is false
            if(!availabilityEnabled.booleanValue()){
              ConfigSupport.apply(new SingleConfigCode<JmsService>() {
                public Object run(JmsService param) throws PropertyVetoException, TransactionFailure {

                    param.setUseMasterBroker(useMasterBroker.toString());
                    return param;
                }
            }, jmsservice);
            }*/
    } catch (TransactionFailure tfe) {
        report.setMessage((changeIntegrationMode == null ? "" : changeIntegrationMode + "\n") + localStrings.getLocalString("configure.jms.cluster.fail", "Unable to Configure JMS Cluster for cluster {0}.", clusterName) + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
    }
    report.setMessage((warning == null ? "" : warning + "\n") + (changeIntegrationMode == null ? "" : changeIntegrationMode + "\n") + localStrings.getLocalString("configure.jms.cluster.success", "JMS Cluster Configuration updated for Cluster {0}.", clusterName));
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JmsService(com.sun.enterprise.connectors.jms.config.JmsService) Cluster(com.sun.enterprise.config.serverbeans.Cluster) ActionReport(org.glassfish.api.ActionReport) PropertyVetoException(java.beans.PropertyVetoException) JmsAvailability(com.sun.enterprise.connectors.jms.config.JmsAvailability) List(java.util.List) Property(org.jvnet.hk2.config.types.Property)

Example 20 with JmsService

use of com.sun.enterprise.connectors.jms.config.JmsService in project Payara by payara.

the class JMSDestination method getJmsServiceOfStandaloneServerInstance.

private JmsService getJmsServiceOfStandaloneServerInstance(String target, Config cfg, Domain domain) throws Exception {
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "getJMSServiceOfSI LL " + target);
        // ConfigContext con = com.sun.enterprise.admin.server.core.AdminService.getAdminService().getAdminContext().getAdminConfigContext();
        logger.log(Level.FINE, "cfg " + cfg);
    }
    JmsService jmsService = cfg.getExtensionByType(JmsService.class);
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "jmsservice " + jmsService);
    }
    return jmsService;
}
Also used : JmsService(com.sun.enterprise.connectors.jms.config.JmsService)

Aggregations

JmsService (com.sun.enterprise.connectors.jms.config.JmsService)22 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)10 JmsHost (com.sun.enterprise.connectors.jms.config.JmsHost)10 PrivilegedActionException (java.security.PrivilegedActionException)6 ResourceAdapterInternalException (javax.resource.spi.ResourceAdapterInternalException)6 ActionReport (org.glassfish.api.ActionReport)6 PropertyVetoException (java.beans.PropertyVetoException)5 URISyntaxException (java.net.URISyntaxException)5 ExecutionException (java.util.concurrent.ExecutionException)5 MultiException (org.glassfish.hk2.api.MultiException)5 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)4 com.sun.enterprise.config.serverbeans (com.sun.enterprise.config.serverbeans)3 Cluster (com.sun.enterprise.config.serverbeans.Cluster)3 Server (com.sun.enterprise.config.serverbeans.Server)3 ServerContext (org.glassfish.internal.api.ServerContext)3 Domain (com.sun.enterprise.config.serverbeans.Domain)2 JmsAvailability (com.sun.enterprise.connectors.jms.config.JmsAvailability)2 ActiveJmsResourceAdapter (com.sun.enterprise.connectors.jms.system.ActiveJmsResourceAdapter)2 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)2 ConnectorDescriptor (com.sun.enterprise.deployment.ConnectorDescriptor)2