use of org.apache.geode.management.ManagerMXBean in project geode by apache.
the class ManagementAdapter method handleManagerCreation.
/**
* Assumption is always cache and MemberMbean has been will be created first
*/
public void handleManagerCreation() throws ManagementException {
if (!isServiceInitialised("handleManagerCreation")) {
return;
}
ObjectName managerMBeanName = MBeanJMXAdapter.getManagerName();
ManagerMBeanBridge bridge = new ManagerMBeanBridge(service);
ManagerMXBean bean = new ManagerMBean(bridge);
service.registerInternalMBean(bean, managerMBeanName);
}
use of org.apache.geode.management.ManagerMXBean in project geode by apache.
the class ManagementAgent method startHttpService.
private void startHttpService(boolean isServer) {
final SystemManagementService managementService = (SystemManagementService) ManagementService.getManagementService(CacheFactory.getAnyInstance());
final ManagerMXBean managerBean = managementService.getManagerMXBean();
if (this.config.getHttpServicePort() != 0) {
if (logger.isDebugEnabled()) {
logger.debug("Attempting to start HTTP service on port ({}) at bind-address ({})...", this.config.getHttpServicePort(), this.config.getHttpServiceBindAddress());
}
// Find the Management WAR file
final String gemfireWar = agentUtil.findWarLocation("geode-web");
if (gemfireWar == null) {
if (logger.isDebugEnabled()) {
logger.debug("Unable to find GemFire Management REST API WAR file; the Management REST Interface for GemFire will not be accessible.");
}
}
// Find the Pulse WAR file
final String pulseWar = agentUtil.findWarLocation("geode-pulse");
if (pulseWar == null) {
final String message = "Unable to find Pulse web application WAR file; Pulse for GemFire will not be accessible";
setStatusMessage(managerBean, message);
if (logger.isDebugEnabled()) {
logger.debug(message);
}
} else if (securityService.isIntegratedSecurity()) {
System.setProperty("spring.profiles.active", "pulse.authentication.gemfire");
}
// Find developer REST WAR file
final String gemfireAPIWar = agentUtil.findWarLocation("geode-web-api");
if (gemfireAPIWar == null) {
final String message = "Unable to find GemFire Developer REST API WAR file; the Developer REST Interface for GemFire will not be accessible.";
setStatusMessage(managerBean, message);
if (logger.isDebugEnabled()) {
logger.debug(message);
}
}
try {
if (agentUtil.isWebApplicationAvailable(gemfireWar, pulseWar, gemfireAPIWar)) {
final String bindAddress = this.config.getHttpServiceBindAddress();
final int port = this.config.getHttpServicePort();
boolean isRestWebAppAdded = false;
this.httpServer = JettyHelper.initJetty(bindAddress, port, SSLConfigurationFactory.getSSLConfigForComponent(SecurableCommunicationChannel.WEB));
if (agentUtil.isWebApplicationAvailable(gemfireWar)) {
this.httpServer = JettyHelper.addWebApplication(this.httpServer, "/gemfire", gemfireWar);
this.httpServer = JettyHelper.addWebApplication(this.httpServer, "/geode-mgmt", gemfireWar);
}
if (agentUtil.isWebApplicationAvailable(pulseWar)) {
this.httpServer = JettyHelper.addWebApplication(this.httpServer, "/pulse", pulseWar);
}
if (isServer && this.config.getStartDevRestApi()) {
if (agentUtil.isWebApplicationAvailable(gemfireAPIWar)) {
this.httpServer = JettyHelper.addWebApplication(this.httpServer, "/geode", gemfireAPIWar);
this.httpServer = JettyHelper.addWebApplication(this.httpServer, "/gemfire-api", gemfireAPIWar);
isRestWebAppAdded = true;
}
} else {
final String message = "Developer REST API web application will not start when start-dev-rest-api is not set and node is not server";
setStatusMessage(managerBean, message);
if (logger.isDebugEnabled()) {
logger.debug(message);
}
}
if (logger.isDebugEnabled()) {
logger.debug("Starting HTTP embedded server on port ({}) at bind-address ({})...", ((ServerConnector) this.httpServer.getConnectors()[0]).getPort(), bindAddress);
}
System.setProperty(PULSE_EMBEDDED_PROP, "true");
System.setProperty(PULSE_PORT_PROP, "" + config.getJmxManagerPort());
final SocketCreator jmxSocketCreator = SocketCreatorFactory.getSocketCreatorForComponent(SecurableCommunicationChannel.JMX);
final SocketCreator locatorSocketCreator = SocketCreatorFactory.getSocketCreatorForComponent(SecurableCommunicationChannel.LOCATOR);
System.setProperty(PULSE_USESSL_MANAGER, jmxSocketCreator.useSSL() + "");
System.setProperty(PULSE_USESSL_LOCATOR, locatorSocketCreator.useSSL() + "");
this.httpServer = JettyHelper.startJetty(this.httpServer);
// clients to connect to Pulse
if (agentUtil.isWebApplicationAvailable(pulseWar)) {
managerBean.setPulseURL("http://".concat(getHost(bindAddress)).concat(":").concat(String.valueOf(port)).concat("/pulse/"));
}
// set cache property for developer REST service running
if (isRestWebAppAdded) {
InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
cache.setRESTServiceRunning(true);
// create region to hold query information (queryId, queryString).
// Added for the developer REST APIs
RestAgent.createParameterizedQueryRegion();
}
// set true for HTTP service running
setHttpServiceRunning(true);
}
} catch (Exception e) {
// Jetty needs to be stopped even if it has failed to
stopHttpService();
// start. Some of the threads are left behind even if
// server.start() fails due to an exception
setStatusMessage(managerBean, "HTTP service failed to start with " + e.getClass().getSimpleName() + " '" + e.getMessage() + "'");
throw new ManagementException("HTTP service failed to start", e);
}
} else {
setStatusMessage(managerBean, "Embedded HTTP server configured not to start (http-service-port=0) or (jmx-manager-http-port=0)");
}
}
use of org.apache.geode.management.ManagerMXBean in project geode by apache.
the class GemfireDataCommandsDUnitTest method waitForListClientMbean.
public void waitForListClientMbean(final String regionName) {
final VM manager = Host.getHost(0).getVM(0);
manager.invoke(new SerializableRunnable() {
@Override
public void run() {
Cache cache = getCache();
final ManagementService service = ManagementService.getManagementService(cache);
final WaitCriterion waitForMaangerMBean = new WaitCriterion() {
@Override
public boolean done() {
ManagerMXBean bean1 = service.getManagerMXBean();
DistributedRegionMXBean bean2 = service.getDistributedRegionMXBean(regionName);
if (bean1 == null) {
getLogWriter().info("waitForListClientMbean Still probing for ManagerMBean");
return false;
} else {
getLogWriter().info("waitForListClientMbean Still probing for DistributedRegionMXBean=" + bean2);
if (bean2 == null) {
bean2 = service.getDistributedRegionMXBean(Region.SEPARATOR + regionName);
}
if (bean2 == null) {
getLogWriter().info("waitForListClientMbean Still probing for DistributedRegionMXBean with separator = " + bean2);
return false;
} else {
getLogWriter().info("waitForListClientMbean Still probing for DistributedRegionMXBean with separator Not null " + bean2.getMembers().length);
return bean2.getMembers().length > 1;
}
}
}
@Override
public String description() {
return "waitForListClientMbean Probing for ManagerMBean";
}
};
waitForCriterion(waitForMaangerMBean, 30000, 2000, true);
DistributedRegionMXBean bean = service.getDistributedRegionMXBean(regionName);
if (bean == null) {
bean = service.getDistributedRegionMXBean(Region.SEPARATOR + regionName);
}
assertNotNull(bean);
}
});
}
use of org.apache.geode.management.ManagerMXBean in project geode by apache.
the class ManagerMBeanAuthorizationJUnitTest method beforeClassSetup.
@BeforeClass
public static void beforeClassSetup() throws Exception {
// Create a mock ManagerMBean that we will use to call against.
ObjectName managerMBeanName = ObjectName.getInstance("GemFire", "mock", "Manager");
ManagerMXBean bean = mock(ManagerMBean.class);
ManagementFactory.getPlatformMBeanServer().registerMBean(bean, managerMBeanName);
}
use of org.apache.geode.management.ManagerMXBean in project geode by apache.
the class LocatorLauncherAssemblyIntegrationTest method performTest.
private void performTest(Builder builder) {
assertFalse(builder.getForce());
this.launcher = builder.build();
assertFalse(this.launcher.isForcing());
LocatorLauncher dirLauncher = null;
int initialThreadCount = Thread.activeCount();
try {
this.launcher.start();
waitForLocatorToStart(this.launcher);
// validate the pid file and its contents
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.LOCATOR.getPidFileName());
assertTrue("Pid file " + this.pidFile.getCanonicalPath().toString() + " should exist", this.pidFile.exists());
final int pid = readPid(this.pidFile);
assertTrue(pid > 0);
assertEquals(ProcessUtils.identifyPid(), pid);
dirLauncher = new Builder().setWorkingDirectory(builder.getWorkingDirectory()).build();
assertNotNull(dirLauncher);
assertFalse(dirLauncher.isRunning());
// Stop the manager
Cache cache = CacheFactory.getAnyInstance();
ManagerMXBean managerBean = ManagementService.getManagementService(cache).getManagerMXBean();
managerBean.stop();
// stop the locator
final LocatorLauncher.LocatorState locatorState = dirLauncher.stop();
assertNotNull(locatorState);
assertEquals(Status.STOPPED, locatorState.getStatus());
} catch (Throwable e) {
this.errorCollector.addError(e);
}
try {
// verify the PID file was deleted
waitForFileToDelete(this.pidFile);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
int finalThreadCount = Integer.MAX_VALUE;
// Spin for up to 5 seconds waiting for threads to finish
for (int i = 0; i < 50 && finalThreadCount > initialThreadCount; i++) {
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
// ignored
}
finalThreadCount = Thread.activeCount();
}
assertEquals(initialThreadCount, finalThreadCount);
}
Aggregations