Search in sources :

Example 6 with ManagerMXBean

use of org.apache.geode.management.ManagerMXBean in project geode by apache.

the class GemfireDataCommandsDUnitTest method setupForGetPutRemoveLocateEntry.

void setupForGetPutRemoveLocateEntry(String testName) {
    final VM vm1 = Host.getHost(0).getVM(1);
    final VM vm2 = Host.getHost(0).getVM(2);
    Properties props = new Properties();
    props.setProperty(NAME, testName + "Manager");
    HeadlessGfsh gfsh = setUpJmxManagerOnVm0ThenConnect(props);
    assertNotNull(gfsh);
    assertEquals(true, gfsh.isConnectedAndReady());
    vm1.invoke(new SerializableRunnable() {

        public void run() {
            InternalCache cache = getCache();
            RegionFactory regionFactory = cache.createRegionFactory(RegionShortcut.REPLICATE);
            Region dataRegion = regionFactory.create(DATA_REGION_NAME);
            assertNotNull(dataRegion);
            getLogWriter().info("Created Region " + dataRegion);
            dataRegion = dataRegion.createSubregion(DATA_REGION_NAME_CHILD_1, dataRegion.getAttributes());
            assertNotNull(dataRegion);
            getLogWriter().info("Created Region " + dataRegion);
            dataRegion = dataRegion.createSubregion(DATA_REGION_NAME_CHILD_1_2, dataRegion.getAttributes());
            assertNotNull(dataRegion);
            getLogWriter().info("Created Region " + dataRegion);
            dataRegion = regionFactory.create(DATA_REGION_NAME_VM1);
            assertNotNull(dataRegion);
            getLogWriter().info("Created Region " + dataRegion);
            PartitionAttributes partitionAttrs = new PartitionAttributesFactory().setRedundantCopies(2).create();
            RegionFactory<Object, Object> partitionRegionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
            partitionRegionFactory.setPartitionAttributes(partitionAttrs);
            Region dataParRegion = partitionRegionFactory.create(DATA_PAR_REGION_NAME);
            assertNotNull(dataParRegion);
            getLogWriter().info("Created Region " + dataParRegion);
            dataParRegion = partitionRegionFactory.create(DATA_PAR_REGION_NAME_VM1);
            assertNotNull(dataParRegion);
            getLogWriter().info("Created Region " + dataParRegion);
        }
    });
    vm2.invoke(new SerializableRunnable() {

        public void run() {
            InternalCache cache = getCache();
            RegionFactory regionFactory = cache.createRegionFactory(RegionShortcut.REPLICATE);
            Region dataRegion = regionFactory.create(DATA_REGION_NAME);
            assertNotNull(dataRegion);
            getLogWriter().info("Created Region " + dataRegion);
            dataRegion = dataRegion.createSubregion(DATA_REGION_NAME_CHILD_1, dataRegion.getAttributes());
            assertNotNull(dataRegion);
            getLogWriter().info("Created Region " + dataRegion);
            dataRegion = dataRegion.createSubregion(DATA_REGION_NAME_CHILD_1_2, dataRegion.getAttributes());
            assertNotNull(dataRegion);
            getLogWriter().info("Created Region " + dataRegion);
            dataRegion = regionFactory.create(DATA_REGION_NAME_VM2);
            assertNotNull(dataRegion);
            getLogWriter().info("Created Region " + dataRegion);
            PartitionAttributes partitionAttrs = new PartitionAttributesFactory().setRedundantCopies(2).create();
            RegionFactory<Object, Object> partitionRegionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
            partitionRegionFactory.setPartitionAttributes(partitionAttrs);
            Region dataParRegion = partitionRegionFactory.create(DATA_PAR_REGION_NAME);
            assertNotNull(dataParRegion);
            getLogWriter().info("Created Region " + dataParRegion);
            dataParRegion = partitionRegionFactory.create(DATA_PAR_REGION_NAME_VM2);
            assertNotNull(dataParRegion);
            getLogWriter().info("Created Region " + dataParRegion);
        }
    });
    final String vm1MemberId = vm1.invoke(() -> getMemberId());
    final String vm2MemberId = vm2.invoke(() -> getMemberId());
    getLogWriter().info("Vm1 ID : " + vm1MemberId);
    getLogWriter().info("Vm2 ID : " + vm2MemberId);
    final VM manager = Host.getHost(0).getVM(0);
    SerializableRunnable checkRegionMBeans = new SerializableRunnable() {

        @Override
        public void run() {
            InternalCache 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(DATA_REGION_NAME_PATH);
                    if (bean1 == null) {
                        getLogWriter().info("Still probing for ManagerMBean");
                        return false;
                    } else {
                        getLogWriter().info("Still probing for DistributedRegionMXBean=" + bean2);
                        return (bean2 != null);
                    }
                }

                @Override
                public String description() {
                    return "Probing for ManagerMBean";
                }
            };
            waitForCriterion(waitForMaangerMBean, 30000, 2000, true);
            assertNotNull(service.getMemberMXBean());
            assertNotNull(service.getManagerMXBean());
            DistributedRegionMXBean bean = service.getDistributedRegionMXBean(DATA_REGION_NAME_PATH);
            assertNotNull(bean);
            WaitCriterion waitForRegionMBeans = new WaitCriterion() {

                @Override
                public boolean done() {
                    DistributedRegionMXBean[] beans = new DistributedRegionMXBean[6];
                    beans[0] = service.getDistributedRegionMXBean(DATA_REGION_NAME_PATH);
                    beans[1] = service.getDistributedRegionMXBean(DATA_REGION_NAME_VM1_PATH);
                    beans[2] = service.getDistributedRegionMXBean(DATA_REGION_NAME_VM2_PATH);
                    beans[3] = service.getDistributedRegionMXBean(DATA_PAR_REGION_NAME_PATH);
                    beans[4] = service.getDistributedRegionMXBean(DATA_PAR_REGION_NAME_VM1_PATH);
                    beans[5] = service.getDistributedRegionMXBean(DATA_PAR_REGION_NAME_VM2_PATH);
                    // SubRegion Bug : Proxy creation has some issues.
                    // beans[6] = service.getDistributedRegionMXBean(DATA_REGION_NAME_CHILD_1_PATH);
                    // beans[7] = service.getDistributedRegionMXBean(DATA_REGION_NAME_CHILD_1_2_PATH);
                    boolean flag = true;
                    for (DistributedRegionMXBean b : beans) {
                        if (b == null) {
                            flag = false;
                            break;
                        }
                    }
                    if (!flag) {
                        getLogWriter().info("Still probing for regionMbeans " + DATA_REGION_NAME_PATH + "=" + beans[0] + " " + DATA_REGION_NAME_VM1_PATH + "=" + beans[1] + " " + DATA_REGION_NAME_VM2_PATH + "=" + beans[2] + " " + DATA_PAR_REGION_NAME_PATH + "=" + beans[3] + " " + DATA_PAR_REGION_NAME_VM1_PATH + "=" + beans[4] + " " + DATA_PAR_REGION_NAME_VM2_PATH + "=" + beans[5] + " ");
                        return false;
                    } else {
                        getLogWriter().info("Probing complete for regionMbeans " + DATA_REGION_NAME_PATH + "=" + beans[0] + " " + DATA_REGION_NAME_VM1_PATH + "=" + beans[1] + " " + DATA_REGION_NAME_VM2_PATH + "=" + beans[2] + " " + DATA_PAR_REGION_NAME_PATH + "=" + beans[3] + " " + DATA_PAR_REGION_NAME_VM1_PATH + "=" + beans[4] + " " + DATA_PAR_REGION_NAME_VM2_PATH + "=" + beans[5] + " ");
                        // bean1.getMemberCount()==1)
                        return true;
                    // else{
                    // getLogWriter().info("Still probing for regionMbeans for aggregation bean1=" +
                    // bean1.getMemberCount() + " bean2="+ bean2.getMemberCount() + " bean3" +
                    // bean3.getMemberCount());
                    // return false;
                    // }
                    }
                }

                @Override
                public String description() {
                    return "Probing for regionMbeans";
                }
            };
            waitForCriterion(waitForRegionMBeans, 30000, 2000, true);
            String[] regions = { DATA_REGION_NAME_PATH, DATA_REGION_NAME_VM1_PATH, DATA_REGION_NAME_VM2_PATH, DATA_PAR_REGION_NAME_PATH, DATA_PAR_REGION_NAME_VM1_PATH, DATA_PAR_REGION_NAME_VM2_PATH };
            for (String region : regions) {
                bean = service.getDistributedRegionMXBean(region);
                assertNotNull(bean);
                String[] membersName = bean.getMembers();
                getLogWriter().info("Members Array for region " + region + " : " + StringUtils.objectToString(membersName, true, 10));
                if (bean.getMemberCount() < 1)
                    fail("Even after waiting mbean reports number of member hosting region " + DATA_REGION_NAME_VM1_PATH + " is less than one");
            // assertIndexDetailsEquals(1, membersName.length); //exists in one members vm1
            }
        }
    };
    manager.invoke(checkRegionMBeans);
}
Also used : HeadlessGfsh(org.apache.geode.management.internal.cli.HeadlessGfsh) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) InternalCache(org.apache.geode.internal.cache.InternalCache) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributedRegionMXBean(org.apache.geode.management.DistributedRegionMXBean) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) ManagementService(org.apache.geode.management.ManagementService) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) RegionFactory(org.apache.geode.cache.RegionFactory) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) ManagerMXBean(org.apache.geode.management.ManagerMXBean)

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