use of com.sun.enterprise.connectors.jms.config.JmsAvailability in project Payara by payara.
the class ActiveJmsResourceAdapter method isJMSAvailabilityOn.
// todo: enable this method
/* private String getPropertyFromPool(JdbcConnectionPool jdbcConPool,
String poolPropertyName) {
String poolPropertyValue = null;
if(jdbcConPool == null) {
return null;
}
ElementProperty[] props = jdbcConPool.getElementProperty();
for (int i = 0; i < props.length; i++) {
String name = props[i].getAttributeValue("name");
String value = props[i].getAttributeValue("value");
if (name.equalsIgnoreCase(poolPropertyName)) {
//if (name.equalsIgnoreCase("username")) {
poolPropertyValue = value;
}
}
logFine("ActiveJMSResourceAdapter :: got property " + poolPropertyName
+ "="+ poolPropertyValue);
return poolPropertyValue;
} */
private boolean isJMSAvailabilityOn(AvailabilityService as) {
if (as == null) {
return false;
}
JmsAvailability ja = as.getExtensionByType(JmsAvailability.class);
boolean jmsAvailability = false;
/* JMS Availability should be false if its not present in
* domain.xml,
*/
if (ja != null) {
jmsAvailability = Boolean.parseBoolean(ja.getAvailabilityEnabled());
}
_logger.log(Level.FINE, "JMS availability :: " + jmsAvailability);
return jmsAvailability;
}
use of com.sun.enterprise.connectors.jms.config.JmsAvailability 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);
}
}
use of com.sun.enterprise.connectors.jms.config.JmsAvailability 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;
}
use of com.sun.enterprise.connectors.jms.config.JmsAvailability 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);
}
Aggregations