use of org.glassfish.internal.api.ServerContext 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 org.glassfish.internal.api.ServerContext 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;
}
use of org.glassfish.internal.api.ServerContext in project Payara by payara.
the class ExtSharedServiceEnableDisableTest method test.
@Test
public void test() throws Exception {
// 1. Bootstrap GlassFish DAS in embedded mode.
GlassFishProperties glassFishProperties = new GlassFishProperties();
glassFishProperties.setInstanceRoot(System.getenv("S1AS_HOME") + "/domains/domain1");
glassFishProperties.setConfigFileReadOnly(false);
GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassFishProperties);
PrintStream sysout = System.out;
glassfish.start();
System.setOut(sysout);
// 2. Deploy the PaaS-bookstore application.
File archive = new File(System.getProperty("basedir") + // TODO :: use mvn apis to get the
"/target/ext-shared-service-enable-disable-test.war");
// archive location.
Assert.assertTrue(archive.exists());
// Obtaining the IP address of the DAS
String ip_address = "127.0.0.1";
try {
Enumeration netint_enum = NetworkInterface.getNetworkInterfaces();
for (Iterator it = Collections.list(netint_enum).iterator(); it.hasNext(); ) {
NetworkInterface netint = (NetworkInterface) it.next();
if (netint.getName().equals("virbr0")) {
Enumeration inetAddresses = netint.getInetAddresses();
if (inetAddresses.hasMoreElements()) {
InetAddress inetAddress = (InetAddress) inetAddresses.nextElement();
ip_address = inetAddress.toString();
ip_address = ip_address.substring(1, ip_address.length());
break;
}
}
}
} catch (SocketException socketException) {
socketException.printStackTrace();
}
Deployer deployer = null;
String appName = null;
try {
{
// start-database
ServiceLocator habitat = Globals.getDefaultHabitat();
ServerContext serverContext = habitat.getService(ServerContext.class);
String[] startdbArgs = { serverContext.getInstallRoot().getAbsolutePath() + File.separator + "bin" + File.separator + "asadmin" + (OS.isWindows() ? ".bat" : ""), "start-database", "--dbhome", serverContext.getInstallRoot().getAbsolutePath() + File.separator + "databases", "--dbhost", ip_address };
ProcessExecutor startDatabase = new ProcessExecutor(startdbArgs);
try {
startDatabase.execute();
} catch (ExecException e) {
e.printStackTrace();
}
}
// Create the shared & external services first, as these services will be referenced by the application
createSharedAndExternalServices(ip_address);
deployer = glassfish.getDeployer();
appName = deployer.deploy(archive);
System.err.println("Deployed [" + appName + "]");
Assert.assertNotNull(appName);
CommandRunner commandRunner = glassfish.getCommandRunner();
CommandResult result = commandRunner.run("list-services");
System.out.println("\nlist-services command output [ " + result.getOutput() + "]");
// 3. Access the app to make sure PaaS-ext-shared-service-enable-disable-test app is correctly
// provisioned.
String HTTP_PORT = (System.getProperty("http.port") != null) ? System.getProperty("http.port") : "28080";
String instanceIP = getLBIPAddress(glassfish);
get("http://" + instanceIP + ":" + HTTP_PORT + "/ext-shared-service-enable-disable-test/list", "Here is a list of animals in the zoo.");
testSharedAndExternalService();
// 4. Access the app to make sure PaaS-ext-shared-service-enable-disable-test app is correctly
// provisioned after running Shared-Services test
get("http://" + instanceIP + ":" + HTTP_PORT + "/ext-shared-service-enable-disable-test/list", "Here is a list of animals in the zoo.");
// 5. Undeploy the Zoo catalogue application .
} finally {
if (appName != null) {
deployer.undeploy(appName);
System.err.println("Undeployed [" + appName + "]");
deleteSharedAndExternalService();
{
// stop-database
ServiceLocator habitat = Globals.getDefaultHabitat();
ServerContext serverContext = habitat.getService(ServerContext.class);
String[] stopDbArgs = { serverContext.getInstallRoot().getAbsolutePath() + File.separator + "bin" + File.separator + "asadmin" + (OS.isWindows() ? ".bat" : ""), "stop-database", "--dbhost", ip_address };
ProcessExecutor stopDatabase = new ProcessExecutor(stopDbArgs);
try {
stopDatabase.execute();
} catch (ExecException e) {
e.printStackTrace();
}
}
try {
boolean undeployClean = false;
CommandResult commandResult = glassfish.getCommandRunner().run("list-services");
System.out.println(commandResult.getOutput().toString());
if (commandResult.getOutput().contains("Nothing to list")) {
undeployClean = true;
}
Assert.assertTrue(undeployClean);
} catch (Exception e) {
System.err.println("Couldn't varify whether undeploy succeeded");
}
}
}
}
use of org.glassfish.internal.api.ServerContext in project Payara by payara.
the class SharedAndExternalServiceTest method test.
@Test
public void test() throws Exception {
// 1. Bootstrap GlassFish DAS in embedded mode.
GlassFishProperties glassFishProperties = new GlassFishProperties();
glassFishProperties.setInstanceRoot(System.getenv("S1AS_HOME") + "/domains/domain1");
glassFishProperties.setConfigFileReadOnly(false);
GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassFishProperties);
PrintStream sysout = System.out;
glassfish.start();
System.setOut(sysout);
// 2. Deploy the PaaS-bookstore application.
File archive = new File(System.getProperty("basedir") + // TODO :: use mvn apis to get the
"/target/external-and-shared-service-test.war");
// archive location.
org.junit.Assert.assertTrue(archive.exists());
// Obtaining the IP address of the DAS
String ip_address = "127.0.0.1";
try {
Enumeration netint_enum = NetworkInterface.getNetworkInterfaces();
for (Iterator it = Collections.list(netint_enum).iterator(); it.hasNext(); ) {
NetworkInterface netint = (NetworkInterface) it.next();
if (netint.getName().equals("virbr0")) {
Enumeration inetAddresses = netint.getInetAddresses();
if (inetAddresses.hasMoreElements()) {
InetAddress inetAddress = (InetAddress) inetAddresses.nextElement();
ip_address = inetAddress.toString();
ip_address = ip_address.substring(1, ip_address.length());
break;
}
}
}
} catch (SocketException socketException) {
socketException.printStackTrace();
}
Deployer deployer = null;
String appName = null;
try {
{
// start-database
ServiceLocator habitat = Globals.getDefaultHabitat();
ServerContext serverContext = habitat.getService(ServerContext.class);
String[] startdbArgs = { serverContext.getInstallRoot().getAbsolutePath() + File.separator + "bin" + File.separator + "asadmin" + (OS.isWindows() ? ".bat" : ""), "start-database", "--dbhome", serverContext.getInstallRoot().getAbsolutePath() + File.separator + "databases", "--dbhost", ip_address };
ProcessExecutor startDatabase = new ProcessExecutor(startdbArgs);
try {
startDatabase.execute();
} catch (ExecException e) {
e.printStackTrace();
}
}
// Create the shared & external services first, as these services will be referenced by the application
createSharedAndExternalServices(ip_address);
deployer = glassfish.getDeployer();
appName = deployer.deploy(archive);
System.err.println("Deployed [" + appName + "]");
Assert.assertNotNull(appName);
CommandRunner commandRunner = glassfish.getCommandRunner();
CommandResult result = commandRunner.run("list-services");
System.out.println("\nlist-services command output [ " + result.getOutput() + "]");
// 3. Access the app to make sure PaaS-external-and-shared-service-test app is correctly
// provisioned.
String HTTP_PORT = (System.getProperty("http.port") != null) ? System.getProperty("http.port") : "28080";
String instanceIP = getLBIPAddress(glassfish);
get("http://" + instanceIP + ":" + HTTP_PORT + "/external-and-shared-service-test/list", "Here is a list of animals in the zoo.");
testSharedAndExternalService();
// 4. Access the app to make sure PaaS-external-and-shared-service-test app is correctly
// provisioned after running Shared-Services test
get("http://" + instanceIP + ":" + HTTP_PORT + "/external-and-shared-service-test/list", "Here is a list of animals in the zoo.");
// 5. Undeploy the Zoo catalogue application .
} finally {
if (appName != null) {
deployer.undeploy(appName);
System.err.println("Undeployed [" + appName + "]");
deleteSharedAndExternalService();
{
// stop-database
ServiceLocator habitat = Globals.getDefaultHabitat();
ServerContext serverContext = habitat.getService(ServerContext.class);
String[] stopDbArgs = { serverContext.getInstallRoot().getAbsolutePath() + File.separator + "bin" + File.separator + "asadmin" + (OS.isWindows() ? ".bat" : ""), "stop-database", "--dbhost", ip_address };
ProcessExecutor stopDatabase = new ProcessExecutor(stopDbArgs);
try {
stopDatabase.execute();
} catch (ExecException e) {
e.printStackTrace();
}
}
try {
boolean undeployClean = false;
CommandResult commandResult = glassfish.getCommandRunner().run("list-services");
System.out.println(commandResult.getOutput().toString());
if (commandResult.getOutput().contains("Nothing to list")) {
undeployClean = true;
}
Assert.assertTrue(undeployClean);
} catch (Exception e) {
System.err.println("Couldn't varify whether undeploy succeeded");
}
}
}
}
use of org.glassfish.internal.api.ServerContext in project Payara by payara.
the class J2EEInstanceListener method init.
private synchronized void init(WebModule wm) {
if (initialized) {
return;
}
ServerContext serverContext = wm.getServerContext();
if (serverContext == null) {
String msg = _rb.getString(LogFacade.NO_SERVER_CONTEXT);
msg = MessageFormat.format(msg, wm.getName());
throw new IllegalStateException(msg);
}
ServiceLocator services = serverContext.getDefaultServices();
im = services.getService(InvocationManager.class);
tm = getJavaEETransactionManager(services);
injectionMgr = services.getService(InjectionManager.class);
initialized = true;
securityContext = serverContext.getDefaultServices().getService(AppServSecurityContext.class);
if (securityContext != null) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, LogFacade.SECURITY_CONTEXT_OBTAINED, securityContext);
}
} else {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, LogFacade.SECURITY_CONTEXT_FAILED);
}
}
}
Aggregations