Search in sources :

Example 31 with InternalLocator

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

the class LocatorLauncherTest method shouldBeMockable.

@Test
public void shouldBeMockable() throws Exception {
    LocatorLauncher mockLocatorLauncher = mock(LocatorLauncher.class);
    InternalLocator mockInternalLocator = mock(InternalLocator.class);
    when(mockLocatorLauncher.getLocator()).thenReturn(mockInternalLocator);
    when(mockLocatorLauncher.getId()).thenReturn("ID");
    assertThat(mockLocatorLauncher.getLocator()).isSameAs(mockInternalLocator);
    assertThat(mockLocatorLauncher.getId()).isEqualTo("ID");
}
Also used : InternalLocator(org.apache.geode.distributed.internal.InternalLocator) UnitTest(org.apache.geode.test.junit.categories.UnitTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 32 with InternalLocator

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

the class GMSMembershipManager method forceDisconnect.

@Override
public void forceDisconnect(final String reason) {
    if (GMSMembershipManager.this.shutdownInProgress || isJoining()) {
        // probably a race condition
        return;
    }
    setShutdown();
    final Exception shutdownCause = new ForcedDisconnectException(reason);
    // cache the exception so it can be appended to ShutdownExceptions
    services.setShutdownCause(shutdownCause);
    services.getCancelCriterion().cancel(reason);
    AlertAppender.getInstance().shuttingDown();
    if (!inhibitForceDisconnectLogging) {
        logger.fatal(LocalizedMessage.create(LocalizedStrings.GroupMembershipService_MEMBERSHIP_SERVICE_FAILURE_0, reason), shutdownCause);
    }
    if (!services.getConfig().getDistributionConfig().getDisableAutoReconnect()) {
        saveCacheXmlForReconnect();
    }
    Thread reconnectThread = new Thread(() -> {
        // stop server locators immediately since they may not have correct
        // information. This has caused client failures in bridge/wan
        // network-down testing
        InternalLocator loc = (InternalLocator) Locator.getLocator();
        if (loc != null) {
            loc.stop(true, !services.getConfig().getDistributionConfig().getDisableAutoReconnect(), false);
        }
        uncleanShutdown(reason, shutdownCause);
    });
    reconnectThread.setName("DisconnectThread");
    reconnectThread.setDaemon(false);
    reconnectThread.start();
}
Also used : InternalLocator(org.apache.geode.distributed.internal.InternalLocator) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) MemberShunnedException(org.apache.geode.internal.tcp.MemberShunnedException) TimeoutException(java.util.concurrent.TimeoutException) ShunnedMemberException(org.apache.geode.distributed.internal.direct.ShunnedMemberException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CancelException(org.apache.geode.CancelException) DistributionException(org.apache.geode.distributed.internal.DistributionException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) ToDataException(org.apache.geode.ToDataException)

Example 33 with InternalLocator

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

the class UploadJarFunction method execute.

@Override
public void execute(FunctionContext context) {
    InternalLocator locator = (InternalLocator) Locator.getLocator();
    Object[] args = (Object[]) context.getArguments();
    String group = (String) args[0];
    String jarName = (String) args[1];
    if (locator != null && group != null && jarName != null) {
        ClusterConfigurationService sharedConfig = locator.getSharedConfiguration();
        if (sharedConfig != null) {
            try {
                byte[] jarBytes = sharedConfig.getJarBytesFromThisLocator(group, jarName);
                context.getResultSender().lastResult(jarBytes);
            } catch (Exception e) {
                logger.error(e);
                context.getResultSender().sendException(e);
            }
        }
    }
    // TODO: Why does this not throw an IllegalStateException?
    context.getResultSender().lastResult(null);
}
Also used : InternalLocator(org.apache.geode.distributed.internal.InternalLocator) ClusterConfigurationService(org.apache.geode.distributed.internal.ClusterConfigurationService)

Example 34 with InternalLocator

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

the class ReconnectDUnitTest method testReconnectALocator.

@Test
public void testReconnectALocator() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM locatorVm = host.getVM(3);
    DistributedMember dm, newdm;
    final int locPort = locatorPort;
    final int secondLocPort = AvailablePortHelper.getRandomAvailableTCPPort();
    DistributedTestUtils.deleteLocatorStateFile(locPort, secondLocPort);
    final String xmlFileLoc = (new File(".")).getAbsolutePath();
    // This locator was started in setUp.
    File locatorViewLog = new File(locatorVm.getWorkingDirectory(), "locator" + locatorPort + "views.log");
    assertTrue("Expected to find " + locatorViewLog.getPath() + " file", locatorViewLog.exists());
    long logSize = locatorViewLog.length();
    vm0.invoke("Create a second locator", () -> {
        locatorPort = locPort;
        Properties props = getDistributedSystemProperties();
        props.put(MAX_WAIT_TIME_RECONNECT, "1000");
        props.put(MAX_NUM_RECONNECT_TRIES, "2");
        props.put(LOCATORS, props.get(LOCATORS) + ",localhost[" + locPort + "]");
        props.put(ENABLE_CLUSTER_CONFIGURATION, "false");
        try {
            Locator.startLocatorAndDS(secondLocPort, null, props);
        } catch (IOException e) {
            Assert.fail("exception starting locator", e);
        }
    });
    File locator2ViewLog = new File(vm0.getWorkingDirectory(), "locator" + secondLocPort + "views.log");
    assertTrue("Expected to find " + locator2ViewLog.getPath() + " file", locator2ViewLog.exists());
    long log2Size = locator2ViewLog.length();
    // create a cache in vm1 so there is more weight in the system
    vm1.invoke("Create Cache and Regions from cache.xml", () -> {
        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");
        ReconnectDUnitTest.savedSystem = getSystem(props);
        Cache cache = getCache();
        Region myRegion = cache.getRegion("root/myRegion");
        myRegion.put("MyKey1", "MyValue1");
        return savedSystem.getDistributedMember();
    });
    try {
        dm = getDMID(vm0);
        createGfshWaitingThread(vm0);
        forceDisconnect(vm0);
        newdm = waitForReconnect(vm0);
        assertGfshWaitingThreadAlive(vm0);
        assertTrue("Expected the restarted member to be hosting a running locator", vm0.invoke("check for running locator", () -> {
            Awaitility.await("waiting for locator to restart").atMost(30, TimeUnit.SECONDS).until(Locator::getLocator, notNullValue());
            if (((InternalLocator) Locator.getLocator()).isStopped()) {
                LogWriterUtils.getLogWriter().error("found a stopped locator");
                return false;
            }
            return true;
        }));
        assertNotSame("expected a reconnect to occur in the locator", dm, newdm);
        // the log should have been opened and appended with a new view
        assertTrue("expected " + locator2ViewLog.getPath() + " to grow in size", locator2ViewLog.length() > log2Size);
        // the other locator should have logged a new view
        assertTrue("expected " + locatorViewLog.getPath() + " to grow in size", locatorViewLog.length() > logSize);
    } finally {
        vm0.invoke(new SerializableRunnable("stop locator") {

            public void run() {
                Locator loc = Locator.getLocator();
                if (loc != null) {
                    loc.stop();
                }
                if (gfshThread != null && gfshThread.isAlive()) {
                    gfshThread.interrupt();
                }
                gfshThread = null;
            }
        });
        DistributedTestUtils.deleteLocatorStateFile(locPort);
        DistributedTestUtils.deleteLocatorStateFile(secondLocPort);
    }
}
Also used : IOException(java.io.IOException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) ServerLocator(org.apache.geode.distributed.internal.ServerLocator) Locator(org.apache.geode.distributed.Locator) 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) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 35 with InternalLocator

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

the class FetchSharedConfigurationStatusFunction method execute.

@Override
public void execute(FunctionContext context) {
    InternalLocator locator = InternalLocator.getLocator();
    InternalCache cache = GemFireCacheImpl.getInstance();
    DistributedMember member = cache.getDistributedSystem().getDistributedMember();
    SharedConfigurationStatus status = locator.getSharedConfigurationStatus().getStatus();
    String memberId = member.getName();
    if (StringUtils.isBlank(memberId)) {
        memberId = member.getId();
    }
    CliFunctionResult result = new CliFunctionResult(memberId, new String[] { status.name() });
    context.getResultSender().lastResult(result);
}
Also used : SharedConfigurationStatus(org.apache.geode.management.internal.configuration.domain.SharedConfigurationStatus) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache)

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