Search in sources :

Example 11 with JmsHost

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

the class JMSConfigListener method changed.

/**
 * Implementation of org.jvnet.hk2.config.ConfigListener
 */
public UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
    // Events that we can't process now because they require server restart.
    jmsService = serverConfig.getExtensionByType(JmsService.class);
    List<UnprocessedChangeEvent> unprocessedEvents = new ArrayList<UnprocessedChangeEvent>();
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "In JMSConfigListener - received config event");
    }
    Domain domain = Globals.get(Domain.class);
    String jmsProviderPort = null;
    ServerContext serverContext = Globals.get(ServerContext.class);
    Server thisServer = domain.getServerNamed(serverContext.getInstanceName());
    // if(thisServer.isDas() || thisServer.getCluster() == null)
    {
    // _logger.log(Level.FINE,"JMSConfigListerner server is either das or a stand-alone instance - hence ignoring");
    // return null;
    }
    for (int i = 0; i < events.length; i++) {
        // for (PropertyChangeEvent event : events) {
        PropertyChangeEvent event = events[i];
        String eventName = event.getPropertyName();
        Object oldValue = event.getOldValue();
        Object newValue = event.getNewValue();
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "In JMSConfigListener " + eventName + oldValue + newValue);
        }
        if (oldValue != null && oldValue.equals(newValue)) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "Event " + eventName + " did not change existing value of " + oldValue);
            }
            continue;
        }
        if (event.getSource().toString().indexOf("connectors.jms.config.JmsService") != -1) {
            boolean notifyFlag = true;
            if (oldValue != null && newValue == null && "jms-host".equals(event.getPropertyName())) {
                JmsHost jmsHost = (JmsHost) oldValue;
                String name = ActiveJmsResourceAdapter.GRIZZLY_PROXY_PREFIX + jmsHost.getName();
                ActiveJmsResourceAdapter adapter = Globals.get(ActiveJmsResourceAdapter.class);
                if (adapter.getGrizzlyListeners().contains(name)) {
                    GrizzlyService grizzlyService = Globals.get(GrizzlyService.class);
                    synchronized (adapter.getGrizzlyListeners()) {
                        if (_logger.isLoggable(Level.FINE)) {
                            _logger.log(Level.FINE, "Stopping Grizzly proxy " + name);
                        }
                        grizzlyService.removeNetworkProxy(name);
                        adapter.getGrizzlyListeners().remove(name);
                    }
                    notifyFlag = false;
                }
            }
            if (notifyFlag) {
                UnprocessedChangeEvent uchangeEvent = new UnprocessedChangeEvent(event, "restart required");
                unprocessedEvents.add(uchangeEvent);
            }
        } else if (event.getSource().toString().indexOf("connectors.jms.config.JmsHost") != -1) {
            if (oldValue == null && newValue != null && "name".equals(event.getPropertyName())) {
                JmsProviderLifecycle lifecycle = Globals.get(JmsProviderLifecycle.class);
                JmsHost jmsHost = (JmsHost) event.getSource();
                if (ActiveJmsResourceAdapter.EMBEDDED.equalsIgnoreCase(jmsService.getType())) {
                    ActiveJmsResourceAdapter adapter = Globals.get(ActiveJmsResourceAdapter.class);
                    if (!adapter.getDoBind()) {
                        if (Boolean.valueOf(jmsHost.getLazyInit())) {
                            String host = null;
                            if (jmsHost.getHost() != null && "localhost".equals(jmsHost.getHost())) {
                                host = "0.0.0.0";
                            } else {
                                host = jmsHost.getHost();
                            }
                            try {
                                GrizzlyService grizzlyService = Globals.get(GrizzlyService.class);
                                NetworkListener dummy = new DummyNetworkListener();
                                dummy.setPort(jmsHost.getPort());
                                dummy.setAddress(host);
                                dummy.setType("proxy");
                                dummy.setProtocol(ActiveJmsResourceAdapter.JMS_SERVICE);
                                dummy.setTransport("tcp");
                                String name = ActiveJmsResourceAdapter.GRIZZLY_PROXY_PREFIX + jmsHost.getName();
                                dummy.setName(name);
                                synchronized (adapter.getGrizzlyListeners()) {
                                    if (_logger.isLoggable(Level.FINE)) {
                                        _logger.log(Level.FINE, "Starting Grizzly proxy " + name + " on port " + jmsHost.getPort());
                                    }
                                    grizzlyService.createNetworkProxy(dummy);
                                    adapter.getGrizzlyListeners().add(name);
                                }
                                return unprocessedEvents.size() > 0 ? new UnprocessedChangeEvents(unprocessedEvents) : null;
                            } catch (Exception e) {
                                LogHelper.log(_logger, Level.WARNING, JMSLoggerInfo.GRIZZLY_START_FAILURE, e);
                            }
                        }
                    }
                }
            }
        }
        if ("JMS_PROVIDER_PORT".equals(newValue)) {
            // The value is in the next event
            PropertyChangeEvent nextevent = events[i + 1];
            jmsProviderPort = (String) nextevent.getNewValue();
        }
        if (event.getSource() instanceof JmsService) {
            if (eventName.equals(ServerTags.MASTER_BROKER)) {
                String oldMB = oldValue != null ? oldValue.toString() : null;
                String newMB = newValue != null ? newValue.toString() : null;
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "Got JmsService Master Broker change event " + event.getSource() + " " + eventName + " " + oldMB + " " + newMB);
                }
                if (newMB != null) {
                    Server newMBServer = domain.getServerNamed(newMB);
                    if (newMBServer != null) {
                        Node node = domain.getNodeNamed(newMBServer.getNodeRef());
                        String newMasterBrokerPort = JmsRaUtil.getJMSPropertyValue(newMBServer);
                        if (newMasterBrokerPort == null)
                            newMasterBrokerPort = getDefaultJmsHost(jmsService).getPort();
                        String newMasterBrokerHost = node.getNodeHost();
                        aresourceAdapter.setMasterBroker(newMasterBrokerHost + ":" + newMasterBrokerPort);
                    }
                }
            }
        }
        if (eventName.equals(ServerTags.SERVER_REF)) {
            // if(event instanceof ServerRef){
            String oldServerRef = oldValue != null ? oldValue.toString() : null;
            String newServerRef = newValue != null ? newValue.toString() : null;
            if (oldServerRef != null && newServerRef == null && !thisServer.isDas()) {
                // instance has been deleted
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "Got Cluster change event for server_ref" + event.getSource() + " " + eventName + " " + oldServerRef + " " + null);
                }
                String url = getBrokerList();
                aresourceAdapter.setClusterBrokerList(url);
                break;
            }
        // 
        }
        // else skip
        if (event.getSource() instanceof Server) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "In JMSConfigListener - recieved cluster event " + event.getSource());
            }
            Server changedServer = (Server) event.getSource();
            if (thisServer.isDas())
                return null;
            if (jmsProviderPort != null) {
                String nodeName = changedServer.getNodeRef();
                String nodeHost = null;
                if (nodeName != null)
                    nodeHost = domain.getNodeNamed(nodeName).getNodeHost();
                String url = getBrokerList();
                url = url + ",mq://" + nodeHost + ":" + jmsProviderPort;
                aresourceAdapter.setClusterBrokerList(url);
                break;
            }
        }
    }
    return unprocessedEvents.size() > 0 ? new UnprocessedChangeEvents(unprocessedEvents) : null;
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) DummyNetworkListener(com.sun.enterprise.v3.services.impl.DummyNetworkListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) JmsService(com.sun.enterprise.connectors.jms.config.JmsService) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) ServerContext(org.glassfish.internal.api.ServerContext) GrizzlyService(com.sun.enterprise.v3.services.impl.GrizzlyService) JmsHost(com.sun.enterprise.connectors.jms.config.JmsHost) DummyNetworkListener(com.sun.enterprise.v3.services.impl.DummyNetworkListener) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 12 with JmsHost

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

the class ChangeMasterBrokerCommand method getDefaultJmsHost.

private JmsHost getDefaultJmsHost(JmsService jmsService) {
    JmsHost jmsHost = null;
    String defaultJmsHostName = jmsService.getDefaultJmsHost();
    List jmsHostsList = jmsService.getJmsHost();
    for (int i = 0; i < jmsHostsList.size(); i++) {
        JmsHost tmpJmsHost = (JmsHost) jmsHostsList.get(i);
        if (tmpJmsHost != null && tmpJmsHost.getName().equals(defaultJmsHostName))
            jmsHost = tmpJmsHost;
    }
    return jmsHost;
}
Also used : List(java.util.List) JmsHost(com.sun.enterprise.connectors.jms.config.JmsHost)

Example 13 with JmsHost

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

the class JMSDestination method _getMQJMXConnectorInfoForCluster.

/**
 *  Gets the <code>MQJMXConnector</code> object for a cluster. Since this code is
 *  executed in DAS, an admin API is used to resolve hostnames and ports of
 *  cluster instances for LOCAL type brokers while creating the connectionURL.
 */
protected MQJMXConnectorInfo _getMQJMXConnectorInfoForCluster(String target, JmsService jmsService, Class mqRAClassName, ServerContext serverContext) throws ConnectorRuntimeException {
    // Create a new RA instance.
    ResourceAdapter raInstance = null;
    // Set the ConnectionURL
    MQAddressList list = null;
    try {
        if (jmsService.getType().equalsIgnoreCase(ActiveJmsResourceAdapter.REMOTE)) {
            list = getDefaultAddressList(jmsService);
        } else {
            list = new MQAddressList();
            CommandTarget ctarget = this.getTypeForTarget(target);
            if (ctarget == CommandTarget.CLUSTER) {
                Server[] servers = list.getServersInCluster(target);
                if (servers != null && servers.length > 0)
                    list.setInstanceName(servers[0].getName());
            } else if (ctarget == CommandTarget.CLUSTERED_INSTANCE) {
                list.setInstanceName(target);
            }
            java.util.Map<String, JmsHost> hostMap = list.getResolvedLocalJmsHostsInMyCluster(true);
            if (hostMap.size() == 0) {
                String msg = localStrings.getLocalString("mqjmx.no_jms_hosts", "No JMS Hosts Configured");
                throw new ConnectorRuntimeException(msg);
            }
            for (JmsHost host : hostMap.values()) {
                list.addMQUrl(host);
            }
        }
        String connectionUrl = list.toString();
        String adminUserName = null;
        String adminPassword = null;
        JmsHost jmsHost = list.getDefaultJmsHost(jmsService);
        if (jmsHost != null) {
            // && jmsHost.isEnabled()) {
            adminUserName = jmsHost.getAdminUserName();
            adminPassword = JmsRaUtil.getUnAliasedPwd(jmsHost.getAdminPassword());
        } else {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, " _getMQJMXConnectorInfo, using default jms admin user and password ");
            }
        }
        raInstance = getConfiguredRA(mqRAClassName, connectionUrl, adminUserName, adminPassword);
    } catch (Exception e) {
        e.printStackTrace();
        ConnectorRuntimeException cre = new ConnectorRuntimeException(e.getMessage());
        cre.initCause(e);
        throw cre;
    }
    try {
        String jmxServiceURL = null, jmxServiceURLList = null;
        Map<String, ?> jmxConnectorEnv = null;
        Method[] methds = raInstance.getClass().getMethods();
        for (int i = 0; i < methds.length; i++) {
            Method m = methds[i];
            if (m.getName().equalsIgnoreCase("get" + JMXSERVICEURLLIST)) {
                jmxServiceURLList = (String) m.invoke(raInstance, new Object[] {});
                if (jmxServiceURLList != null && !jmxServiceURLList.trim().equals("")) {
                    jmxServiceURL = getFirstJMXServiceURL(jmxServiceURLList);
                }
            } else if (m.getName().equalsIgnoreCase("get" + JMXCONNECTORENV)) {
                jmxConnectorEnv = (Map<String, ?>) m.invoke(raInstance, new Object[] {});
            }
        }
        MQJMXConnectorInfo mqInfo = new MQJMXConnectorInfo(target, ActiveJmsResourceAdapter.getBrokerInstanceName(jmsService), jmsService.getType(), jmxServiceURL, jmxConnectorEnv);
        return mqInfo;
    } catch (Exception e) {
        e.printStackTrace();
        ConnectorRuntimeException cre = new ConnectorRuntimeException(e.getMessage());
        cre.initCause(e);
        throw cre;
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) MQAddressList(com.sun.enterprise.connectors.jms.system.MQAddressList) CommandTarget(org.glassfish.config.support.CommandTarget) Method(java.lang.reflect.Method) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) java.util(java.util) ActiveJmsResourceAdapter(com.sun.enterprise.connectors.jms.system.ActiveJmsResourceAdapter) ResourceAdapter(javax.resource.spi.ResourceAdapter) JmsHost(com.sun.enterprise.connectors.jms.config.JmsHost)

Example 14 with JmsHost

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

the class JMSPing 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();
    if (targetServer != null) {
        config = domain.getConfigNamed(targetServer.getConfigRef());
    }
    com.sun.enterprise.config.serverbeans.Cluster cluster = domain.getClusterNamed(target);
    if (cluster != null) {
        config = domain.getConfigNamed(cluster.getConfigRef());
    }
    JmsService jmsservice = config.getExtensionByType(JmsService.class);
    /* for (Config c : configs.getConfig()) {

                      if(configRef.equals(c.getName()))
                            jmsservice = c.getJmsService();
                   } */
    String defaultJmshostStr = jmsservice.getDefaultJmsHost();
    JmsHost defaultJmsHost = null;
    for (JmsHost jmshost : jmsservice.getJmsHost()) {
        if (jmshost.getName().equals(defaultJmshostStr)) {
            defaultJmsHost = jmshost;
        }
    }
    if (defaultJmsHost == null) {
        report.setMessage(localStrings.getLocalString("jms-ping.noDefaultJMSHost", "Unable to PING the JMS Broker as no Default JMS Host is configured on the DAS"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    String tmpJMSResource = "test_jms_adapter";
    ActionReport subReport = report.addSubActionsReport();
    createJMSResource(defaultJmsHost, subReport, tmpJMSResource, context.getSubject());
    if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
        report.setMessage(localStrings.getLocalString("jms-ping.cannotCreateJMSResource", "Unable to create a temporary Connection Factory to the JMS Host"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        boolean value = pingConnectionPool(tmpJMSResource + JNDINAME_APPENDER);
        if (!value) {
            report.setMessage(localStrings.getLocalString("jms-ping.pingConnectionPoolFailed", "Pinging to the JMS Host failed."));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        } else {
            report.setMessage(localStrings.getLocalString("jms-ping.pingConnectionPoolSuccess", "JMS-ping command executed successfully"));
            report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        }
    } catch (ResourceException e) {
        report.setMessage(localStrings.getLocalString("jms-ping.pingConnectionPoolException", "An exception occured while trying to ping the JMS Host.", e.getMessage()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
    deleteJMSResource(subReport, tmpJMSResource, context.getSubject());
    if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
        report.setMessage(localStrings.getLocalString("jms-ping.cannotdeleteJMSResource", "Unable to delete the temporary JMS Resource " + tmpJMSResource + ". Please delete this manually.", tmpJMSResource));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) JmsService(com.sun.enterprise.connectors.jms.config.JmsService) ResourceException(javax.resource.ResourceException) ActionReport(org.glassfish.api.ActionReport) JmsHost(com.sun.enterprise.connectors.jms.config.JmsHost) Cluster(com.sun.enterprise.config.serverbeans.Cluster)

Example 15 with JmsHost

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

the class DeleteJMSHost 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();
    Config targetConfig = domain.getConfigNamed(target);
    if (targetConfig != null)
        config = targetConfig;
    Server targetServer = domain.getServerNamed(target);
    if (targetServer != null) {
        config = domain.getConfigNamed(targetServer.getConfigRef());
    }
    com.sun.enterprise.config.serverbeans.Cluster cluster = domain.getClusterNamed(target);
    if (cluster != null) {
        config = domain.getConfigNamed(cluster.getConfigRef());
    }
    if (jmsHostName == null) {
        report.setMessage(localStrings.getLocalString("delete.jms.host.noHostName", "No JMS Host Name specified for JMS Host."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    JmsService jmsService = config.getExtensionByType(JmsService.class);
    if (jmsService == null) {
        report.setMessage(localStrings.getLocalString("list.jms.host.invalidTarget", "Invalid Target specified."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    JmsHost jmsHost = null;
    for (JmsHost r : jmsService.getJmsHost()) {
        if (jmsHostName.equals(r.getName())) {
            jmsHost = r;
            break;
        }
    }
    if (jmsHost == null) {
        report.setMessage(localStrings.getLocalString("list.jms.host.noJmsHostFound", "JMS Host {0} does not exist.", jmsHostName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    final JmsHost jHost = jmsHost;
    try {
        ConfigSupport.apply(new SingleConfigCode<JmsService>() {

            public Object run(JmsService param) throws PropertyVetoException, TransactionFailure {
                return param.getJmsHost().remove(jHost);
            }
        }, jmsService);
    } catch (TransactionFailure tfe) {
        report.setMessage(localStrings.getLocalString("delete.jms.host.fail", "Unable to delete jms host {0}.", jmsHostName) + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JmsService(com.sun.enterprise.connectors.jms.config.JmsService) ActionReport(org.glassfish.api.ActionReport) com.sun.enterprise.config.serverbeans(com.sun.enterprise.config.serverbeans) PropertyVetoException(java.beans.PropertyVetoException) JmsHost(com.sun.enterprise.connectors.jms.config.JmsHost)

Aggregations

JmsHost (com.sun.enterprise.connectors.jms.config.JmsHost)24 JmsService (com.sun.enterprise.connectors.jms.config.JmsService)10 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)6 PropertyVetoException (java.beans.PropertyVetoException)6 ActionReport (org.glassfish.api.ActionReport)4 com.sun.enterprise.config.serverbeans (com.sun.enterprise.config.serverbeans)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ActiveJmsResourceAdapter (com.sun.enterprise.connectors.jms.system.ActiveJmsResourceAdapter)2 MQAddressList (com.sun.enterprise.connectors.jms.system.MQAddressList)2 DummyNetworkListener (com.sun.enterprise.v3.services.impl.DummyNetworkListener)2 GrizzlyService (com.sun.enterprise.v3.services.impl.GrizzlyService)2 Method (java.lang.reflect.Method)2 java.util (java.util)2 ResourceAdapter (javax.resource.spi.ResourceAdapter)2 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)2 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)2 Property (org.jvnet.hk2.config.types.Property)2 Cluster (com.sun.enterprise.config.serverbeans.Cluster)1