use of org.glassfish.internal.api.ServerContext in project Payara by payara.
the class TransactionServiceProperties method getJTSProperties.
public static synchronized Properties getJTSProperties(ServiceLocator serviceLocator, boolean isORBAvailable) {
if (orbAvailable == isORBAvailable && properties != null) {
// We will need to update the properties if ORB availability changed
return properties;
}
Properties jtsProperties = new Properties();
if (serviceLocator != null) {
jtsProperties.put(HABITAT, serviceLocator);
ProcessEnvironment processEnv = serviceLocator.getService(ProcessEnvironment.class);
if (processEnv.getProcessType().isServer()) {
TransactionService txnService = serviceLocator.getService(TransactionService.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
if (txnService != null) {
jtsProperties.put(Configuration.HEURISTIC_DIRECTION, txnService.getHeuristicDecision());
jtsProperties.put(Configuration.KEYPOINT_COUNT, txnService.getKeypointInterval());
String automaticRecovery = txnService.getAutomaticRecovery();
boolean isAutomaticRecovery = (isValueSet(automaticRecovery) && "true".equals(automaticRecovery));
if (isAutomaticRecovery) {
_logger.log(Level.FINE, "Recoverable J2EE Server");
jtsProperties.put(Configuration.MANUAL_RECOVERY, "true");
}
boolean disable_distributed_transaction_logging = false;
String dbLoggingResource = null;
for (Property prop : txnService.getProperty()) {
String name = prop.getName();
String value = prop.getValue();
if (name.equals("disable-distributed-transaction-logging")) {
if (isValueSet(value) && "true".equals(value)) {
disable_distributed_transaction_logging = true;
}
} else if (name.equals("xaresource-txn-timeout")) {
if (isValueSet(value)) {
_logger.log(Level.FINE, "XAResource transaction timeout is" + value);
TransactionManagerImpl.setXAResourceTimeOut(Integer.parseInt(value));
}
} else if (name.equals("db-logging-resource")) {
dbLoggingResource = value;
_logger.log(Level.FINE, "Transaction DB Logging Resource Name" + dbLoggingResource);
if (dbLoggingResource != null && (" ".equals(dbLoggingResource) || "".equals(dbLoggingResource))) {
dbLoggingResource = "jdbc/TxnDS";
}
} else if (name.equals("xa-servername")) {
if (isValueSet(value)) {
jtsProperties.put(JTS_XA_SERVER_NAME, value);
}
} else if (name.equals("pending-txn-cleanup-interval")) {
if (isValueSet(value)) {
jtsProperties.put("pending-txn-cleanup-interval", value);
}
} else if (name.equals(Configuration.COMMIT_ONE_PHASE_DURING_RECOVERY)) {
if (isValueSet(value)) {
jtsProperties.put(Configuration.COMMIT_ONE_PHASE_DURING_RECOVERY, value);
}
} else if (name.equals("add-wait-point-during-recovery")) {
if (isValueSet(value)) {
try {
FailureInducer.setWaitPointRecovery(Integer.parseInt(value));
} catch (Exception e) {
_logger.log(Level.WARNING, e.getMessage());
}
}
}
}
if (dbLoggingResource != null) {
disable_distributed_transaction_logging = true;
jtsProperties.put(Configuration.DB_LOG_RESOURCE, dbLoggingResource);
}
/**
* JTS_SERVER_ID needs to be unique for each for server instance.
* This will be used as recovery identifier along with the hostname
* for example: if the hostname is 'tulsa' and iiop-listener-port is 3700
* recovery identifier will be tulsa,P3700
*/
// default value
int jtsServerId = DEFAULT_SERVER_ID;
if (isORBAvailable) {
jtsServerId = serviceLocator.<GlassFishORBHelper>getService(GlassFishORBHelper.class).getORBInitialPort();
if (jtsServerId == 0) {
// XXX Can this ever happen?
// default value
jtsServerId = DEFAULT_SERVER_ID;
}
}
jtsProperties.put(JTS_SERVER_ID, String.valueOf(jtsServerId));
/* ServerId is an J2SE persistent server activation
API. ServerId is scoped at the ORBD. Since
There is no ORBD present in J2EE the value of
ServerId is meaningless - except it must have
SOME value if persistent POAs are created.
*/
// For clusters - all servers in the cluster MUST
// have the same ServerId so when failover happens
// and requests are delivered to a new server, the
// ServerId in the request will match the new server.
String serverId = String.valueOf(DEFAULT_SERVER_ID);
System.setProperty(J2EE_SERVER_ID_PROP, serverId);
ServerContext ctx = serviceLocator.getService(ServerContext.class);
String instanceName = ctx.getInstanceName();
/**
* if the auto recovery is true, always transaction logs will be written irrespective of
* disable_distributed_transaction_logging.
* if the auto recovery is false, then disable_distributed_transaction_logging will be used
* to write transaction logs are not.If disable_distributed_transaction_logging is set to
* false(by default false) logs will be written, set to true logs won't be written.
*/
if (!isAutomaticRecovery && disable_distributed_transaction_logging) {
Configuration.disableFileLogging();
} else {
// if (dbLoggingResource == null) {
Domain domain = serviceLocator.getService(Domain.class);
Server server = domain.getServerNamed(instanceName);
// Check if the server system property is set
String logdir = getTXLogDir(server);
// if not, check if the cluster system property is set
if (logdir == null) {
Cluster cluster = server.getCluster();
if (cluster != null) {
logdir = getTXLogDir(cluster);
}
}
// No system properties are set - get tx log dir from transaction service
if (logdir == null) {
logdir = txnService.getTxLogDir();
}
if (logdir == null) {
logdir = domain.getLogRoot();
if (logdir == null) {
// logdir = FileUtil.getAbsolutePath(".." + File.separator + "logs");
logdir = ".." + File.separator + "logs";
}
} else if (!(new File(logdir)).isAbsolute()) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Relative pathname specified for transaction log directory : " + logdir);
}
String logroot = domain.getLogRoot();
if (logroot != null) {
logdir = logroot + File.separator + logdir;
} else {
// logdir = FileUtil.getAbsolutePath(".." + File.separator + "logs"
// + File.separator + logdir);
logdir = ".." + File.separator + "logs" + File.separator + logdir;
}
}
logdir += File.separator + instanceName + File.separator + "tx";
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "JTS log directory: " + logdir);
_logger.log(Level.FINE, "JTS Server id " + jtsServerId);
}
jtsProperties.put(Configuration.LOG_DIRECTORY, logdir);
}
jtsProperties.put(Configuration.COMMIT_RETRY, txnService.getRetryTimeoutInSeconds());
jtsProperties.put(Configuration.INSTANCE_NAME, instanceName);
}
}
}
properties = jtsProperties;
orbAvailable = isORBAvailable;
return properties;
}
use of org.glassfish.internal.api.ServerContext in project Payara by payara.
the class MEJBNamingObjectProxy method deployMEJB.
private void deployMEJB() throws IOException {
_logger.info("Loading MEJB app on JNDI look up");
ServerContext serverContext = habitat.getService(ServerContext.class);
File mejbArchive = new File(serverContext.getInstallRoot(), "lib/install/applications/mejb.jar");
DeployCommandParameters deployParams = new DeployCommandParameters(mejbArchive);
String targetName = habitat.<Server>getService(Server.class, ServerEnvironment.DEFAULT_INSTANCE_NAME).getName();
deployParams.target = targetName;
deployParams.name = "mejb";
ActionReport report = habitat.getService(ActionReport.class, "plain");
Deployment deployment = habitat.getService(Deployment.class);
ExtendedDeploymentContext dc = deployment.getBuilder(_logger, deployParams, report).source(mejbArchive).build();
deployment.deploy(dc);
if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
throw new RuntimeException("Failed to deploy MEJB app: " + report.getFailureCause());
}
}
use of org.glassfish.internal.api.ServerContext in project Payara by payara.
the class DomainDiscoveryService method discoverNodes.
@Override
public Iterable<DiscoveryNode> discoverNodes() {
logger.fine("Starting Domain Node Discovery");
List<DiscoveryNode> nodes = new LinkedList<>();
Domain domain = Globals.getDefaultHabitat().getService(Domain.class);
ServerContext ctxt = Globals.getDefaultHabitat().getService(ServerContext.class);
ServerEnvironment env = Globals.getDefaultHabitat().getService(ServerEnvironment.class);
// add the DAS
HazelcastRuntimeConfiguration hzConfig = domain.getExtensionByType(HazelcastRuntimeConfiguration.class);
if (!env.isDas()) {
try {
// first get hold of the DAS host
logger.fine("This is a Standalone Instance");
String dasHost = hzConfig.getDASPublicAddress();
if (dasHost == null || dasHost.isEmpty()) {
dasHost = hzConfig.getDASBindAddress();
}
dasHost = Optional.ofNullable(initAddress(dasHost, 0)).map(InetSocketAddress::getHostString).orElse("");
if (dasHost.isEmpty()) {
// ok drag it off the properties file
logger.fine("Neither DAS Public Address or Bind Address is set in the configuration");
InstanceDirs instance = new InstanceDirs(env.getInstanceRoot());
Properties dasProps = new Properties();
dasProps.load(new FileInputStream(instance.getDasPropertiesFile()));
logger.fine("Loaded the das.properties file from the agent directory");
dasHost = dasProps.getProperty("agent.das.host");
// then do an IP lookup
dasHost = InetAddress.getByName(dasHost).getHostAddress();
logger.log(Level.FINE, "Loaded the das.properties file from the agent directory and found DAS IP {0}", dasHost);
}
if (dasHost.isEmpty() || dasHost.equals("127.0.0.1") || dasHost.equals("localhost")) {
logger.fine("Looks like the DAS IP is loopback or empty let's find the actual IP of this machine as that is where the DAS is");
nodes.add(new SimpleDiscoveryNode(new Address(chosenAddress.get(), Integer.parseInt(hzConfig.getDasPort()))));
} else {
logger.log(Level.FINE, "DAS should be listening on {0}", dasHost);
nodes.add(new SimpleDiscoveryNode(new Address(dasHost, Integer.valueOf(hzConfig.getDasPort()))));
}
// also add all nodes we are aware of in the domain to see if we can get in using start port
logger.fine("Also adding all known domain nodes and start ports in case the DAS is down");
for (Node node : domain.getNodes().getNode()) {
InetAddress address = InetAddress.getByName(node.getNodeHost());
if (!address.isLoopbackAddress()) {
logger.log(Level.FINE, "Adding Node {0}", address);
nodes.add(new SimpleDiscoveryNode(new Address(address.getHostAddress(), Integer.valueOf(hzConfig.getStartPort()))));
}
}
} catch (IOException ex) {
Logger.getLogger(DomainDiscoveryService.class.getName()).log(Level.SEVERE, null, ex);
}
} else if (env.isMicro()) {
try {
logger.log(Level.FINE, "We are Payara Micro therefore adding DAS {0}", hzConfig.getDASPublicAddress());
// check if user has added locahost as unlikely to work
String dasHost = Optional.ofNullable(initAddress(hzConfig.getDASPublicAddress(), 0)).map(InetSocketAddress::getHostString).orElse("");
if (hzConfig.getDasPort().equals("4848")) {
logger.log(Level.WARNING, "You have specified 4848 as the datagrid domain port however this is the default DAS admin port, the default domain datagrid port is 4900");
}
if (dasHost.isEmpty() || dasHost.equals("127.0.0.1") || dasHost.equals("localhost")) {
nodes.add(new SimpleDiscoveryNode(new Address(chosenAddress.get(), Integer.parseInt(hzConfig.getDasPort()))));
} else {
nodes.add(new SimpleDiscoveryNode(new Address(InetAddress.getByName(dasHost), Integer.valueOf(hzConfig.getDasPort()))));
}
} catch (UnknownHostException | NumberFormatException ex) {
Logger.getLogger(DomainDiscoveryService.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
// ok this is the DAS
logger.fine("We are the DAS therefore we will add all known nodes with start port as IP addresses to connect to");
// Embedded runtimese don't have nodes
if (domain.getNodes() == null) {
nodes.add(new SimpleDiscoveryNode(new Address(chosenAddress.get(), Integer.parseInt(hzConfig.getStartPort()))));
} else {
for (Node node : domain.getNodes().getNode()) {
try {
InetAddress address = InetAddress.getByName(node.getNodeHost());
if (!address.isLoopbackAddress()) {
logger.log(Level.FINE, "Adding Node {0}", address);
nodes.add(new SimpleDiscoveryNode(new Address(address.getHostAddress(), Integer.valueOf(hzConfig.getStartPort()))));
} else {
// we need to add our IP address so add each interface address with the start port
nodes.add(new SimpleDiscoveryNode(new Address(chosenAddress.get(), Integer.parseInt(hzConfig.getStartPort()))));
}
} catch (IOException ex) {
Logger.getLogger(DomainDiscoveryService.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
return nodes;
}
use of org.glassfish.internal.api.ServerContext in project Payara by payara.
the class MQAddressList method setupClusterViewFromRepository.
private void setupClusterViewFromRepository() throws Exception {
ServerContext context = Globals.get(ServerContext.class);
Domain domain = Globals.get(Domain.class);
String serverName = context.getInstanceName();
// context.getConfigBean();
Server server = domain.getServerNamed(serverName);
// rep = new AppserverClusterViewFromCacheRepository(domainurl);
try {
nodeHost = getNodeHostName(server);
logFine("na host" + nodeHost);
} catch (Exception e) {
if (logger.isLoggable(Level.FINE))
logger.log(Level.FINE, "Exception while attempting to get nodeagentHost : " + e.getMessage());
if (logger.isLoggable(Level.FINER))
logger.log(Level.FINER, e.getMessage(), e);
}
}
use of org.glassfish.internal.api.ServerContext 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);
}
}
Aggregations