Search in sources :

Example 11 with InternalLocator

use of org.apache.geode.distributed.internal.InternalLocator in project geode by apache.

the class MyDistributedSystemListener method removedDistributedSystem.

public void removedDistributedSystem(int remoteDsId) {
    removeCount++;
    List<Locator> locatorsConfigured = Locator.getLocators();
    Locator locator = locatorsConfigured.get(0);
    Map<Integer, Set<DistributionLocatorId>> allSiteMetaData = ((InternalLocator) locator).getlocatorMembershipListener().getAllLocatorsInfo();
    System.out.println("Removed : allSiteMetaData : " + allSiteMetaData);
}
Also used : Locator(org.apache.geode.distributed.Locator) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) Set(java.util.Set)

Example 12 with InternalLocator

use of org.apache.geode.distributed.internal.InternalLocator in project geode by apache.

the class CreateAlterDestroyRegionCommandsDUnitTest method testDestroyRegionWithSharedConfig.

@Test
public void testDestroyRegionWithSharedConfig() {
    disconnectAllFromDS();
    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
    jmxPort = ports[0];
    httpPort = ports[1];
    try {
        jmxHost = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException ignore) {
        jmxHost = "localhost";
    }
    final String regionName = "testRegionSharedConfigRegion";
    final String regionPath = "/" + regionName;
    final String groupName = "testRegionSharedConfigGroup";
    // Start the Locator and wait for shared configuration to be available
    final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    final Properties locatorProps = new Properties();
    locatorProps.setProperty(NAME, "Locator");
    locatorProps.setProperty(MCAST_PORT, "0");
    locatorProps.setProperty(LOG_LEVEL, "fine");
    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));
    Host.getHost(0).getVM(0).invoke(() -> {
        final File locatorLogFile = new File("locator-" + locatorPort + ".log");
        try {
            final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort, locatorLogFile, null, locatorProps);
            waitAtMost(5, TimeUnit.SECONDS).until(() -> locator.isSharedConfigurationRunning());
        } catch (IOException ioex) {
            fail("Unable to create a locator with a shared configuration");
        }
    });
    connect(jmxHost, jmxPort, httpPort, getDefaultShell());
    // Create a cache in VM 1
    VM vm = Host.getHost(0).getVM(1);
    vm.invoke(() -> {
        Properties localProps = new Properties();
        localProps.setProperty(MCAST_PORT, "0");
        localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
        localProps.setProperty(GROUPS, groupName);
        getSystem(localProps);
        assertNotNull(getCache());
    });
    // Test creating the region
    CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_REGION);
    commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGION, regionName);
    commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, "REPLICATE");
    commandStringBuilder.addOption(CliStrings.CREATE_REGION__STATISTICSENABLED, "true");
    commandStringBuilder.addOption(CliStrings.CREATE_REGION__GROUP, groupName);
    CommandResult cmdResult = executeCommand(commandStringBuilder.toString());
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    // Make sure that the region has been registered with the Manager MXBean
    waitForRegionMBeanCreation(regionPath, 1);
    // Make sure the region exists in the shared config
    Host.getHost(0).getVM(0).invoke(() -> {
        ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
        try {
            assertTrue(sharedConfig.getConfiguration(groupName).getCacheXmlContent().contains(regionName));
        } catch (Exception e) {
            fail("Error occurred in cluster configuration service");
        }
    });
    // Test destroying the region
    commandStringBuilder = new CommandStringBuilder(CliStrings.DESTROY_REGION);
    commandStringBuilder.addOption(CliStrings.DESTROY_REGION__REGION, regionName);
    cmdResult = executeCommand(commandStringBuilder.toString());
    getLogWriter().info("#SB" + commandResultToString(cmdResult));
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    // Make sure the region was removed from the shared config
    Host.getHost(0).getVM(0).invoke(() -> {
        ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
        try {
            assertFalse(sharedConfig.getConfiguration(groupName).getCacheXmlContent().contains(regionName));
        } catch (Exception e) {
            fail("Error occurred in cluster configuration service");
        }
    });
    // Restart the data vm to make sure the region is not existing any more
    vm = Host.getHost(0).getVM(1);
    vm.invoke(() -> {
        Cache cache = getCache();
        assertNotNull(cache);
        cache.close();
        assertTrue(cache.isClosed());
        Properties localProps = new Properties();
        localProps.setProperty(MCAST_PORT, "0");
        localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
        localProps.setProperty(GROUPS, groupName);
        localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
        getSystem(localProps);
        cache = getCache();
        assertNotNull(cache);
        Region region = cache.getRegion(regionName);
        assertNull(region);
        return null;
    });
}
Also used : UnknownHostException(java.net.UnknownHostException) IOException(java.io.IOException) Properties(java.util.Properties) MalformedObjectNameException(javax.management.MalformedObjectNameException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) ClusterConfigurationService(org.apache.geode.distributed.internal.ClusterConfigurationService) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) VM(org.apache.geode.test.dunit.VM) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) File(java.io.File) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 13 with InternalLocator

use of org.apache.geode.distributed.internal.InternalLocator in project geode by apache.

the class DistributedMulticastRegionDUnitTest method closeLocator.

private void closeLocator() {
    VM locator1Vm = Host.getHost(0).getVM(locatorVM);
    ;
    SerializableRunnable locatorCleanup = new SerializableRunnable() {

        @Override
        public void run() {
            System.out.println("test Locator closing " + locatorPort);
            ;
            InternalLocator locator = InternalLocator.getLocator();
            if (locator != null) {
                locator.stop();
                System.out.println("test Locator closed " + locatorPort);
                ;
            }
        }
    };
    locator1Vm.invoke(locatorCleanup);
}
Also used : InternalLocator(org.apache.geode.distributed.internal.InternalLocator) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable)

Example 14 with InternalLocator

use of org.apache.geode.distributed.internal.InternalLocator in project geode by apache.

the class ReconnectDUnitTest method doTestReconnectOnForcedDisconnect.

public void doTestReconnectOnForcedDisconnect(final boolean createInAppToo) throws Exception {
    IgnoredException.addIgnoredException("killing member's ds");
    // getSystem().disconnect();
    // getLogWriter().fine("Cache Closed ");
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final int locPort = locatorPort;
    final int secondLocPort = AvailablePortHelper.getRandomAvailableTCPPort();
    DistributedTestUtils.deleteLocatorStateFile(locPort, secondLocPort);
    final String xmlFileLoc = (new File(".")).getAbsolutePath();
    SerializableCallable create1 = new SerializableCallable("Create Cache and Regions from cache.xml") {

        public Object call() throws CacheException {
            // DebuggerSupport.waitForJavaDebugger(getLogWriter(), " about to create region");
            locatorPort = locPort;
            Properties props = getDistributedSystemProperties();
            props.put(CACHE_XML_FILE, xmlFileLoc + fileSeparator + "MyDisconnect-cache.xml");
            props.put(MAX_WAIT_TIME_RECONNECT, "1000");
            props.put(MAX_NUM_RECONNECT_TRIES, "2");
            // props.put("log-file", "autoReconnectVM"+VM.getCurrentVMNum()+"_"+getPID()+".log");
            Cache cache = new CacheFactory(props).create();
            Region myRegion = cache.getRegion("root/myRegion");
            ReconnectDUnitTest.savedSystem = cache.getDistributedSystem();
            myRegion.put("MyKey1", "MyValue1");
            // myRegion.put("Mykey2", "MyValue2");
            return savedSystem.getDistributedMember();
        }
    };
    SerializableCallable create2 = new SerializableCallable("Create Cache and Regions from cache.xml") {

        public Object call() throws CacheException {
            // DebuggerSupport.waitForJavaDebugger(getLogWriter(), " about to create region");
            locatorPort = locPort;
            final Properties props = getDistributedSystemProperties();
            props.put(CACHE_XML_FILE, xmlFileLoc + fileSeparator + "MyDisconnect-cache.xml");
            props.put(MAX_WAIT_TIME_RECONNECT, "5000");
            props.put(MAX_NUM_RECONNECT_TRIES, "2");
            props.put(START_LOCATOR, "localhost[" + secondLocPort + "]");
            props.put(LOCATORS, props.get(LOCATORS) + ",localhost[" + secondLocPort + "]");
            // props.put("log-file", "autoReconnectVM"+VM.getCurrentVMNum()+"_"+getPID()+".log");
            getSystem(props);
            // MembershipManagerHelper.getMembershipManager(system).setDebugJGroups(true);
            final Cache cache = getCache();
            ReconnectDUnitTest.savedSystem = cache.getDistributedSystem();
            Region myRegion = cache.getRegion("root/myRegion");
            // myRegion.put("MyKey1", "MyValue1");
            myRegion.put("Mykey2", "MyValue2");
            assertNotNull(myRegion.get("MyKey1"));
            // getLogWriter().fine("MyKey1 value is : "+myRegion.get("MyKey1"));
            if (createInAppToo) {
                Thread recreateCacheThread = new Thread("ReconnectDUnitTest.createInAppThread") {

                    public void run() {
                        while (!cache.isClosed()) {
                            Wait.pause(100);
                        }
                        try {
                            new CacheFactory(props).create();
                            LogWriterUtils.getLogWriter().error("testReconnectCollidesWithApplication failed - application thread was able to create a cache");
                        } catch (IllegalStateException cacheExists) {
                        // expected
                        }
                    }
                };
                recreateCacheThread.setDaemon(true);
                recreateCacheThread.start();
            }
            return cache.getDistributedSystem().getDistributedMember();
        }
    };
    vm0.invoke(create1);
    DistributedMember dm = (DistributedMember) vm1.invoke(create2);
    IgnoredException.addIgnoredException("ForcedDisconnectException");
    forceDisconnect(vm1);
    DistributedMember newdm = (DistributedMember) vm1.invoke(new SerializableCallable("wait for reconnect(1)") {

        public Object call() {
            final DistributedSystem ds = ReconnectDUnitTest.savedSystem;
            ReconnectDUnitTest.savedSystem = null;
            Wait.waitForCriterion(new WaitCriterion() {

                public boolean done() {
                    return ds.isReconnecting();
                }

                public String description() {
                    return "waiting for ds to begin reconnecting";
                }
            }, 30000, 1000, true);
            LogWriterUtils.getLogWriter().info("entering reconnect wait for " + ds);
            LogWriterUtils.getLogWriter().info("ds.isReconnecting() = " + ds.isReconnecting());
            boolean failure = true;
            try {
                ds.waitUntilReconnected(60, TimeUnit.SECONDS);
                ReconnectDUnitTest.savedSystem = ds.getReconnectedSystem();
                InternalLocator locator = (InternalLocator) Locator.getLocator();
                assertTrue("Expected system to be restarted", ds.getReconnectedSystem() != null);
                assertTrue("Expected system to be running", ds.getReconnectedSystem().isConnected());
                assertTrue("Expected there to be a locator", locator != null);
                assertTrue("Expected locator to be restarted", !locator.isStopped());
                failure = false;
                return ds.getReconnectedSystem().getDistributedMember();
            } catch (InterruptedException e) {
                LogWriterUtils.getLogWriter().warning("interrupted while waiting for reconnect");
                return null;
            } finally {
                if (failure) {
                    ds.disconnect();
                }
            }
        }
    });
    assertNotSame(dm, newdm);
    // force another reconnect and show that stopReconnecting works
    forceDisconnect(vm1);
    boolean stopped = (Boolean) vm1.invoke(new SerializableCallable("wait for reconnect and stop") {

        public Object call() {
            final DistributedSystem ds = ReconnectDUnitTest.savedSystem;
            ReconnectDUnitTest.savedSystem = null;
            Wait.waitForCriterion(new WaitCriterion() {

                public boolean done() {
                    return ds.isReconnecting() || ds.getReconnectedSystem() != null;
                }

                public String description() {
                    return "waiting for reconnect to commence in " + ds;
                }
            }, 10000, 1000, true);
            ds.stopReconnecting();
            assertFalse(ds.isReconnecting());
            DistributedSystem newDs = InternalDistributedSystem.getAnyInstance();
            if (newDs != null) {
                LogWriterUtils.getLogWriter().warning("expected distributed system to be disconnected: " + newDs);
                newDs.disconnect();
                return false;
            }
            return true;
        }
    });
    assertTrue("expected DistributedSystem to disconnect", stopped);
    // recreate the system in vm1 without a locator and crash it
    dm = (DistributedMember) vm1.invoke(create1);
    forceDisconnect(vm1);
    newdm = waitForReconnect(vm1);
    assertNotSame("expected a reconnect to occur in member", dm, newdm);
    DistributedTestUtils.deleteLocatorStateFile(locPort);
    DistributedTestUtils.deleteLocatorStateFile(secondLocPort);
}
Also used : ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) File(java.io.File)

Example 15 with InternalLocator

use of org.apache.geode.distributed.internal.InternalLocator in project geode by apache.

the class ClusterConfigWithSecurityDUnitTest method testImportNotOverwriteSecurity.

@Test
public void testImportNotOverwriteSecurity() throws Exception {
    connector.connect(locator0, CliStrings.CONNECT__USERNAME, "cluster", CliStrings.CONNECT__PASSWORD, "cluster");
    connector.executeAndVerifyCommand("import cluster-configuration --zip-file-name=" + clusterConfigZipPath);
    locator0.invoke(() -> {
        InternalLocator locator = LocatorServerStartupRule.locatorStarter.getLocator();
        ClusterConfigurationService sc = locator.getSharedConfiguration();
        Properties properties = sc.getConfiguration("cluster").getGemfireProperties();
        assertThat(properties.getProperty(MCAST_PORT)).isEqualTo("0");
        assertThat(properties.getProperty(LOG_FILE_SIZE_LIMIT)).isEqualTo("8000");
        // the security manager is still the locator's security manager, not the imported one.
        assertThat(properties.getProperty(SECURITY_MANAGER)).isEqualTo(SimpleTestSecurityManager.class.getName());
    });
}
Also used : InternalLocator(org.apache.geode.distributed.internal.InternalLocator) ClusterConfigurationService(org.apache.geode.distributed.internal.ClusterConfigurationService) Properties(java.util.Properties) SimpleTestSecurityManager(org.apache.geode.security.SimpleTestSecurityManager) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

InternalLocator (org.apache.geode.distributed.internal.InternalLocator)41 File (java.io.File)21 IOException (java.io.IOException)18 Properties (java.util.Properties)18 Test (org.junit.Test)17 VM (org.apache.geode.test.dunit.VM)16 ClusterConfigurationService (org.apache.geode.distributed.internal.ClusterConfigurationService)15 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)15 Cache (org.apache.geode.cache.Cache)9 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)9 UnknownHostException (java.net.UnknownHostException)8 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)8 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)8 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)7 Locator (org.apache.geode.distributed.Locator)6 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)6 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)6 List (java.util.List)5 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)5 Set (java.util.Set)4