use of com.sun.enterprise.config.serverbeans.Domain in project Payara by payara.
the class AllModelsImplementingTest method checkResources.
@Test
public void checkResources() throws ClassNotFoundException {
ServiceLocator habitat = getHabitat();
Resources resources = habitat.<Domain>getService(Domain.class).getResources();
Dom dom = Dom.unwrap(resources);
List<ConfigModel> models = dom.document.getAllModelsImplementing(Resource.class);
for (ConfigModel model : models) {
Logger.getAnonymousLogger().fine(model.targetTypeName);
}
assertTrue(models.size() > 0);
}
use of com.sun.enterprise.config.serverbeans.Domain 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.config.serverbeans.Domain in project Payara by payara.
the class ActiveJmsResourceAdapter method isClustered.
private static boolean isClustered() {
Domain domain = Globals.get(Domain.class);
Clusters clusters = domain.getClusters();
if (clusters == null)
return false;
List clusterList = clusters.getCluster();
ServerContext serverctx = Globals.get(ServerContext.class);
return JmsRaUtil.isClustered(clusterList, serverctx.getInstanceName());
}
use of com.sun.enterprise.config.serverbeans.Domain in project Payara by payara.
the class JdbcRuntimeExtension method getAllSystemRAResourcesAndPools.
@Override
public Collection<Resource> getAllSystemRAResourcesAndPools() {
List<Resource> resources = new ArrayList<Resource>();
Domain domain = domainProvider.get();
if (domain != null) {
Resources allResources = domain.getResources();
for (Resource resource : allResources.getResources()) {
if (resource instanceof JdbcConnectionPool) {
resources.add(resource);
} else if (resource instanceof JdbcResource) {
resources.add(resource);
}
}
}
System.out.println("JdbcRuntimeExtension, getAllSystemRAResourcesAndPools = " + resources);
return resources;
}
use of com.sun.enterprise.config.serverbeans.Domain in project Payara by payara.
the class ReferenceConstrainTest method doChangeToInValidPool.
@Test
public void doChangeToInValidPool() throws TransactionFailure {
Domain domain = habitat.getService(Domain.class);
// Find JdbcResource to chenge its values
Iterator<JdbcResource> iterator = domain.getResources().getResources(JdbcResource.class).iterator();
JdbcResource jdbc = null;
while (iterator.hasNext()) {
JdbcResource res = iterator.next();
if ("H2Pool".equals(res.getPoolName())) {
jdbc = res;
break;
}
}
assertNotNull(jdbc);
ConfigBean poolConfig = (ConfigBean) ConfigBean.unwrap(jdbc);
Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
Map<String, String> configChanges = new HashMap<String, String>();
configChanges.put("pool-name", "WrongPointer");
changes.put(poolConfig, configChanges);
try {
ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
cs.apply(changes);
fail("Can not reach this point");
} catch (TransactionFailure tf) {
ConstraintViolationException cv = findConstrViolation(tf);
// cv.printStackTrace(System.out);
assertNotNull(cv);
}
}
Aggregations