Search in sources :

Example 1 with AvailabilityService

use of com.sun.enterprise.config.serverbeans.AvailabilityService in project Payara by payara.

the class ActiveJmsResourceAdapter method setAvailabilityProperties.

/*

     * Set Availability related properties
     * If JMS availability true set availability properties
     * read configured pool information and set.
     */
private void setAvailabilityProperties() throws ConnectorRuntimeException {
    if (!isClustered())
        return;
    try {
        Domain domain = Globals.get(Domain.class);
        ServerContext serverContext = Globals.get(ServerContext.class);
        Server server = domain.getServerNamed(serverContext.getInstanceName());
        JmsService jmsService = server.getConfig().getExtensionByType(JmsService.class);
        if (jmsService.getType().equals(REMOTE)) {
            // been configured with the right properties.
            return;
        }
        AvailabilityService as = server.getConfig().getAvailabilityService();
        if (as == null) {
            if (_logger.isLoggable(Level.FINE))
                logFine("Availability Service is null. Not setting AvailabilityProperties.");
            return;
        }
        boolean useMasterBroker = true;
        if (as.getExtensionByType(JmsAvailability.class) != null && !MASTERBROKER.equalsIgnoreCase(as.getExtensionByType(JmsAvailability.class).getConfigStoreType()))
            useMasterBroker = false;
        // jmsService.getUseMasterBroker() != null ? Boolean.valueOf(jmsService.getUseMasterBroker()) :true;
        boolean isJmsAvailabilityEnabled = this.isJMSAvailabilityOn(as);
        if (_logger.isLoggable(Level.FINE))
            logFine("Setting AvailabilityProperties .. ");
        if (!useMasterBroker || isJmsAvailabilityEnabled) {
            // For conventional cluster of peer brokers and Enhanced Broker Cluster.
            ConnectorDescriptor cd = getDescriptor();
            String clusterName = getMQClusterName();
            ConnectorConfigProperty envProp1 = new ConnectorConfigProperty(CLUSTERID, clusterName, "Cluster Id", "java.lang.String");
            setProperty(cd, envProp1);
            if (brokerInstanceName == null) {
                brokerInstanceName = getBrokerInstanceName(jmsService);
            }
            ConnectorConfigProperty envProp2 = new ConnectorConfigProperty(BROKERID, brokerInstanceName, "Broker Id", "java.lang.String");
            setProperty(cd, envProp2);
            // Only if JMS availability is true - Enhanced Broker Cluster only.
            if (isJmsAvailabilityEnabled) {
                // Set HARequired as true - irrespective of whether it is REMOTE or
                // LOCAL
                ConnectorConfigProperty envProp3 = new ConnectorConfigProperty(HAREQUIRED, "true", "HA Required", "java.lang.String");
                setProperty(cd, envProp3);
                /* The broker has a property to control whether
               * it starts in HA mode or not and that's represented on
               * the RA by BrokerEnableHA.
               * On the MQ Client connection side it is HARequired -
               * this does not control the broker, it just is a client
               * side requirement.
               * So for AS EE, if BrokerType is LOCAL or EMBEDDED,
               * and AS HA is enabled for JMS then both these must be
               * set to true. */
                ConnectorConfigProperty envProp4 = new ConnectorConfigProperty(BROKERENABLEHA, "true", "BrokerEnableHA flag", "java.lang.Boolean");
                setProperty(cd, envProp4);
                String nodeHostName = domain.getNodeNamed(server.getNodeRef()).getNodeHost();
                if (nodeHostName != null) {
                    ConnectorConfigProperty envProp5 = new ConnectorConfigProperty(BROKERBINDADDRESS, nodeHostName, "Broker Bind Address", "java.lang.String");
                    setProperty(cd, envProp5);
                }
                loadDBProperties(as.getExtensionByType(JmsAvailability.class), ClusterMode.ENHANCED);
            } else {
                // Conventional cluster of peer brokers
                JmsAvailability jmsAvailability = as.getExtensionByType(JmsAvailability.class);
                if ("jdbc".equals(jmsAvailability.getMessageStoreType()))
                    loadDBProperties(jmsAvailability, ClusterMode.ENHANCED);
                loadDBProperties(jmsAvailability, ClusterMode.CONVENTIONAL_OF_PEER_BROKERS);
            }
        /*
            ConnectorConfigProperty  envProp4 = new ConnectorConfigProperty  (
                            DBTYPE , DBTYPE_HADB,"DBType",
                            "java.lang.String");
            setProperty(cd, envProp4);



            * The broker has a property to control whether
            * it starts in HA mode or not and that's represented on
            * the RA by BrokerEnableHA.
            * On the MQ Client connection side it is HARequired -
            * this does not control the broker, it just is a client
            * side requirement.
            * So for AS EE, if BrokerType is LOCAL or EMBEDDED,
            * and AS HA is enabled for JMS then both these must be
            * set to true.

            ConnectorConfigProperty  envProp5 = new ConnectorConfigProperty  (
                        BROKERENABLEHA , "true",
                        "BrokerEnableHA flag","java.lang.Boolean");
            setProperty(cd, envProp5);

            String nodeHostName = domain.getNodeNamed(server.getNode()).getNodeHost();
            if (nodeHostName != null)  {
              ConnectorConfigProperty  envProp6 = new ConnectorConfigProperty  (
                          BROKERBINDADDRESS , nodeHostName,
                          "Broker Bind Address","java.lang.String");
              setProperty(cd, envProp6);
            }
            //get pool name
            String poolJNDIName = as.getJmsAvailability().getMqStorePoolName();
            //If no MQ store pool name is specified, use default poolname
            //XXX: default pool name is jdbc/hastore but asadmin
            //configure-ha-cluster creates a resource called
            //"jdbc/<asclustername>-hastore" which needs to be used.
            if (poolJNDIName == null || poolJNDIName =="" ) {
              //get Web container's HA store's pool name
              poolJNDIName = as.getWebContainerAvailability().
                                getHttpSessionStorePoolName();
              logFine("HTTP Session store pool jndi name " +
                         "is " + poolJNDIName);
            }
            //XXX: request HADB team mq-store-pool name to be
            //populated as part of configure-ha-cluster

            JdbcConnectionPool jdbcConPool = getJDBCConnectionPoolInfo(
                                                poolJNDIName);
            //DBProps: compute values from pool object
            String userName = getPropertyFromPool(jdbcConPool, DUSERNAME);
            logFine("HA username is " + userName);

            String password = getPropertyFromPool(jdbcConPool, DPASSWORD);
            logFine("HA Password is " + password);

            String driverClass = jdbcConPool.getDatasourceClassname();
            logFine("HA driverclass" + driverClass);

            dbProps = new Properties();
            dbProps.setProperty(DB_HADB_USER, userName);
            dbProps.setProperty(DB_HADB_PASSWORD, password);
            dbProps.setProperty(DB_HADB_DRIVERCLASS, driverClass);

            //DSProps: compute values from pool object
            String serverList = getPropertyFromPool(jdbcConPool, DSERVERLIST);
            logFine("HADB server list is " + serverList);
            dsProps = new Properties();

            if (serverList != null) {
                dsProps.setProperty(DS_HADB_SERVERLIST, serverList);
            } else {
                _logger.warning("ajra.incorrect_hadb_server_list");
            }

            //set all other properties in dsProps as well.
            Properties p = getDSPropertiesFromThePool(jdbcConPool);
            Iterator iterator = p.keySet().iterator();
            while (iterator.hasNext()) {
                String key = (String) iterator.next();
                String val = (String)p.get(key);
                dsProps.setProperty(key, val);
            }*/
        } else {
            // Conventional cluster with master broker.
            if ("jdbc".equals(as.getExtensionByType(JmsAvailability.class).getMessageStoreType()))
                loadDBProperties(as.getExtensionByType(JmsAvailability.class), ClusterMode.CONVENTIONAL_WITH_MASTER_BROKER);
        }
    } 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) AvailabilityService(com.sun.enterprise.config.serverbeans.AvailabilityService) ServerContext(org.glassfish.internal.api.ServerContext) Server(com.sun.enterprise.config.serverbeans.Server) JmsService(com.sun.enterprise.connectors.jms.config.JmsService) JmsAvailability(com.sun.enterprise.connectors.jms.config.JmsAvailability) Domain(com.sun.enterprise.config.serverbeans.Domain) 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 2 with AvailabilityService

use of com.sun.enterprise.config.serverbeans.AvailabilityService in project Payara by payara.

the class ActiveJmsResourceAdapter method isDBEnabled.

private boolean isDBEnabled() {
    Domain domain = Globals.get(Domain.class);
    ServerContext serverContext = Globals.get(ServerContext.class);
    Server server = domain.getServerNamed(serverContext.getInstanceName());
    AvailabilityService as = server.getConfig().getAvailabilityService();
    if (as != null) {
        JmsAvailability jmsAvailability = as.getExtensionByType(JmsAvailability.class);
        if (jmsAvailability.getAvailabilityEnabled() != null && Boolean.parseBoolean(jmsAvailability.getAvailabilityEnabled())) {
            return true;
        } else if (jmsAvailability.getConfigStoreType() != null && !"MASTERBROKER".equalsIgnoreCase(jmsAvailability.getConfigStoreType()))
            return true;
    }
    return false;
}
Also used : AvailabilityService(com.sun.enterprise.config.serverbeans.AvailabilityService) ServerContext(org.glassfish.internal.api.ServerContext) Server(com.sun.enterprise.config.serverbeans.Server) JmsAvailability(com.sun.enterprise.connectors.jms.config.JmsAvailability) Domain(com.sun.enterprise.config.serverbeans.Domain)

Aggregations

AvailabilityService (com.sun.enterprise.config.serverbeans.AvailabilityService)2 Domain (com.sun.enterprise.config.serverbeans.Domain)2 Server (com.sun.enterprise.config.serverbeans.Server)2 JmsAvailability (com.sun.enterprise.connectors.jms.config.JmsAvailability)2 ServerContext (org.glassfish.internal.api.ServerContext)2 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 JmsService (com.sun.enterprise.connectors.jms.config.JmsService)1 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)1 ConnectorDescriptor (com.sun.enterprise.deployment.ConnectorDescriptor)1 URISyntaxException (java.net.URISyntaxException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ResourceAdapterInternalException (javax.resource.spi.ResourceAdapterInternalException)1 MultiException (org.glassfish.hk2.api.MultiException)1