Search in sources :

Example 6 with HeadlessGfsh

use of org.apache.geode.management.internal.cli.HeadlessGfsh in project geode by apache.

the class GfshShellConnectionRule method before.

@Override
protected void before(Description description) throws Throwable {
    this.gfsh = new HeadlessGfsh(getClass().getName(), 30, temporaryFolder.newFolder("gfsh_files").getAbsolutePath());
    ignoredException = addIgnoredException("java.rmi.NoSuchObjectException: no such object in table");
    // do not auto connect if no port initialized
    if (portSupplier == null) {
        return;
    }
    // do not auto connect if it's not used with ConnectionConfiguration
    ConnectionConfiguration config = description.getAnnotation(ConnectionConfiguration.class);
    if (config == null) {
        return;
    }
    connect(portSupplier.get(), portType, CliStrings.CONNECT__USERNAME, config.user(), CliStrings.CONNECT__PASSWORD, config.password());
}
Also used : HeadlessGfsh(org.apache.geode.management.internal.cli.HeadlessGfsh)

Example 7 with HeadlessGfsh

use of org.apache.geode.management.internal.cli.HeadlessGfsh in project geode by apache.

the class GfshShellConnectionRule method connect.

public void connect(int port, PortType type, String... options) throws Exception {
    CliUtil.isGfshVM = true;
    if (gfsh == null) {
        this.gfsh = new HeadlessGfsh(getClass().getName(), 30, temporaryFolder.newFolder("gfsh_files").getAbsolutePath());
    }
    final CommandStringBuilder connectCommand = new CommandStringBuilder(CliStrings.CONNECT);
    String endpoint;
    if (type == PortType.locator) {
        // port is the locator port
        endpoint = "localhost[" + port + "]";
        connectCommand.addOption(CliStrings.CONNECT__LOCATOR, endpoint);
    } else if (type == PortType.http) {
        endpoint = "http://localhost:" + port + "/gemfire/v1";
        connectCommand.addOption(CliStrings.CONNECT__USE_HTTP, Boolean.TRUE.toString());
        connectCommand.addOption(CliStrings.CONNECT__URL, endpoint);
    } else {
        endpoint = "localhost[" + port + "]";
        connectCommand.addOption(CliStrings.CONNECT__JMX_MANAGER, endpoint);
    }
    // add the extra options
    if (options != null) {
        for (int i = 0; i < options.length; i += 2) {
            connectCommand.addOption(options[i], options[i + 1]);
        }
    }
    // when we connect too soon, we would get "Failed to retrieve RMIServer stub:
    // javax.naming.CommunicationException [Root exception is java.rmi.NoSuchObjectException: no
    // such object in table]" Exception.
    // can not use Awaitility here because it starts another thead, but the Gfsh instance is in a
    // threadLocal variable, See Gfsh.getExistingInstance()
    CommandResult result = null;
    for (int i = 0; i < 50; i++) {
        result = executeCommand(connectCommand.toString());
        if (!gfsh.outputString.contains("no such object in table")) {
            break;
        }
        Thread.currentThread().sleep(2000);
    }
    connected = (result.getStatus() == Result.Status.OK);
}
Also used : HeadlessGfsh(org.apache.geode.management.internal.cli.HeadlessGfsh) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult)

Example 8 with HeadlessGfsh

use of org.apache.geode.management.internal.cli.HeadlessGfsh in project geode by apache.

the class ClusterConfigurationServiceEndToEndDUnitTest method testStartServerAndExecuteCommands.

// GEODE-1606
@Category(FlakyTest.class)
@Test
public void testStartServerAndExecuteCommands() throws Exception {
    final HeadlessGfsh gfsh = new HeadlessGfsh("gfsh2", 300, this.gfshDir);
    assertNotNull(gfsh);
    connect(jmxHost, jmxPort, httpPort, gfsh);
    serverNames.addAll(startServers(gfsh, locatorString, 2, "Server", 1));
    doCreateCommands();
    serverNames.addAll(startServers(gfsh, locatorString, 1, "NewMember", 4));
    verifyRegionCreateOnAllMembers(REGION1);
    verifyRegionCreateOnAllMembers(REGION2);
    verifyIndexCreationOnAllMembers(INDEX1);
    verifyAsyncEventQueueCreation();
}
Also used : HeadlessGfsh(org.apache.geode.management.internal.cli.HeadlessGfsh) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 9 with HeadlessGfsh

use of org.apache.geode.management.internal.cli.HeadlessGfsh in project geode by apache.

the class ClusterConfigurationServiceEndToEndDUnitTest method setup.

private Object[] setup() throws IOException {
    final int[] ports = getRandomAvailableTCPPorts(3);
    final int locator1Port = ports[0];
    final String locator1Name = "locator1-" + locator1Port;
    final String locatorLogPath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "locator-" + locator1Port + ".log";
    VM locatorAndMgr = getHost(0).getVM(3);
    Object[] result = (Object[]) locatorAndMgr.invoke(new SerializableCallable() {

        @Override
        public Object call() throws IOException {
            int httpPort;
            int jmxPort;
            String jmxHost;
            try {
                jmxHost = InetAddress.getLocalHost().getHostName();
            } catch (UnknownHostException ignore) {
                jmxHost = "localhost";
            }
            final int[] ports = getRandomAvailableTCPPorts(2);
            jmxPort = ports[0];
            httpPort = ports[1];
            final File locatorLogFile = new File(locatorLogPath);
            final Properties locatorProps = new Properties();
            locatorProps.setProperty(NAME, locator1Name);
            locatorProps.setProperty(MCAST_PORT, "0");
            locatorProps.setProperty(LOG_LEVEL, "config");
            locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
            locatorProps.setProperty(JMX_MANAGER, "true");
            locatorProps.setProperty(JMX_MANAGER_START, "true");
            locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
            locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
            locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
            final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator1Port, locatorLogFile, null, locatorProps);
            WaitCriterion wc = new WaitCriterion() {

                @Override
                public boolean done() {
                    return locator.isSharedConfigurationRunning();
                }

                @Override
                public String description() {
                    return "Waiting for shared configuration to be started";
                }
            };
            waitForCriterion(wc, TIMEOUT, INTERVAL, true);
            final Object[] result = new Object[4];
            result[0] = locator1Port;
            result[1] = jmxHost;
            result[2] = jmxPort;
            result[3] = httpPort;
            return result;
        }
    });
    HeadlessGfsh gfsh = getDefaultShell();
    String jmxHost = (String) result[1];
    int jmxPort = (Integer) result[2];
    int httpPort = (Integer) result[3];
    connect(jmxHost, jmxPort, httpPort, gfsh);
    // Create a cache in VM 1
    VM dataMember = getHost(0).getVM(1);
    dataMember.invoke(new SerializableCallable() {

        @Override
        public Object call() {
            Properties localProps = new Properties();
            localProps.setProperty(MCAST_PORT, "0");
            localProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
            localProps.setProperty(NAME, "DataMember");
            getSystem(localProps);
            InternalCache cache = getCache();
            assertNotNull(cache);
            return getAllNormalMembers(cache);
        }
    });
    return result;
}
Also used : UnknownHostException(java.net.UnknownHostException) HeadlessGfsh(org.apache.geode.management.internal.cli.HeadlessGfsh) InternalCache(org.apache.geode.internal.cache.InternalCache) Properties(java.util.Properties) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) File(java.io.File)

Example 10 with HeadlessGfsh

use of org.apache.geode.management.internal.cli.HeadlessGfsh 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

HeadlessGfsh (org.apache.geode.management.internal.cli.HeadlessGfsh)11 Properties (java.util.Properties)5 VM (org.apache.geode.test.dunit.VM)4 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)4 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)4 Test (org.junit.Test)4 InternalCache (org.apache.geode.internal.cache.InternalCache)3 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)3 Category (org.junit.experimental.categories.Category)3 File (java.io.File)2 UnknownHostException (java.net.UnknownHostException)2 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)2 InternalLocator (org.apache.geode.distributed.internal.InternalLocator)2 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)2 IOException (java.io.IOException)1 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)1 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)1 Region (org.apache.geode.cache.Region)1 RegionFactory (org.apache.geode.cache.RegionFactory)1 DistributedRegionMXBean (org.apache.geode.management.DistributedRegionMXBean)1