Search in sources :

Example 1 with ManagerMXBean

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);
}
Also used : ManagerMXBean(org.apache.geode.management.ManagerMXBean) ObjectName(javax.management.ObjectName)

Example 2 with ManagerMXBean

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)");
    }
}
Also used : ManagementException(org.apache.geode.management.ManagementException) InternalCache(org.apache.geode.internal.cache.InternalCache) ManagerMXBean(org.apache.geode.management.ManagerMXBean) SocketCreator(org.apache.geode.internal.net.SocketCreator) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) ManagementException(org.apache.geode.management.ManagementException) MalformedObjectNameException(javax.management.MalformedObjectNameException) GemFireConfigException(org.apache.geode.GemFireConfigException) MBeanRegistrationException(javax.management.MBeanRegistrationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) AlreadyBoundException(java.rmi.AlreadyBoundException)

Example 3 with ManagerMXBean

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);
        }
    });
}
Also used : ManagementService(org.apache.geode.management.ManagementService) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) ManagerMXBean(org.apache.geode.management.ManagerMXBean) DistributedRegionMXBean(org.apache.geode.management.DistributedRegionMXBean) Cache(org.apache.geode.cache.Cache) InternalCache(org.apache.geode.internal.cache.InternalCache)

Example 4 with ManagerMXBean

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);
}
Also used : ManagerMXBean(org.apache.geode.management.ManagerMXBean) ObjectName(javax.management.ObjectName) BeforeClass(org.junit.BeforeClass)

Example 5 with ManagerMXBean

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);
}
Also used : Builder(org.apache.geode.distributed.LocatorLauncher.Builder) ManagerMXBean(org.apache.geode.management.ManagerMXBean) File(java.io.File) Cache(org.apache.geode.cache.Cache)

Aggregations

ManagerMXBean (org.apache.geode.management.ManagerMXBean)6 InternalCache (org.apache.geode.internal.cache.InternalCache)3 ObjectName (javax.management.ObjectName)2 Cache (org.apache.geode.cache.Cache)2 DistributedRegionMXBean (org.apache.geode.management.DistributedRegionMXBean)2 ManagementService (org.apache.geode.management.ManagementService)2 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)2 VM (org.apache.geode.test.dunit.VM)2 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)2 File (java.io.File)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 AlreadyBoundException (java.rmi.AlreadyBoundException)1 Properties (java.util.Properties)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 GemFireConfigException (org.apache.geode.GemFireConfigException)1 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)1