Search in sources :

Example 6 with FindCoordinatorResponse

use of org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorResponse in project geode by apache.

the class GMSJoinLeave method processFindCoordinatorRequest.

private void processFindCoordinatorRequest(FindCoordinatorRequest req) {
    FindCoordinatorResponse resp;
    if (this.isJoined) {
        NetView v = currentView;
        resp = new FindCoordinatorResponse(v.getCoordinator(), localAddress, services.getMessenger().getPublicKey(v.getCoordinator()), req.getRequestId());
    } else {
        resp = new FindCoordinatorResponse(localAddress, localAddress, services.getMessenger().getPublicKey(localAddress), req.getRequestId());
    }
    resp.setRecipient(req.getMemberID());
    services.getMessenger().send(resp);
}
Also used : FindCoordinatorResponse(org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorResponse) NetView(org.apache.geode.distributed.internal.membership.NetView)

Example 7 with FindCoordinatorResponse

use of org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorResponse in project geode by apache.

the class TcpServerBackwardCompatDUnitTest method testGossipVersionBackwardCompatibility.

/**
   * This test starts two locators with current GOSSIPVERSION and then shuts down one of them and
   * restart it with new GOSSIPVERSION and verifies that it has recoverd the system View. Then we
   * upgrade next locator.
   */
@Test
public void testGossipVersionBackwardCompatibility() {
    Host host = Host.getHost(0);
    final VM locator0 = host.getVM(0);
    final VM locator1 = host.getVM(1);
    final VM locatorRestart0 = host.getVM(2);
    final VM member = host.getVM(3);
    int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
    // Create properties for locator0
    final int port0 = ports[0];
    // new File("");
    final File logFile0 = null;
    // Create properties for locator1
    final int port1 = ports[1];
    // new File("");
    final File logFile1 = null;
    final String locators = host.getHostName() + "[" + port0 + "]," + host.getHostName() + "[" + port1 + "]";
    final Properties props = new Properties();
    props.setProperty(LOCATORS, locators);
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
    // props.setProperty(LOG_LEVEL, "finest");
    // Start locator0 with props.
    // props.setProperty(DistributionConfig.START_LOCATOR_NAME, host.getHostName() + "["+port0+"]");
    locator0.invoke(new CacheSerializableRunnable("Starting first locator on port " + port0) {

        @Override
        public void run2() throws CacheException {
            try {
                TcpServer.getGossipVersionMapForTestOnly().put(TcpServer.TESTVERSION - 100, Version.CURRENT_ORDINAL);
                Locator.startLocatorAndDS(port0, logFile0, props);
            } catch (IOException e) {
                org.apache.geode.test.dunit.Assert.fail("Locator1 start failed with Gossip Version: " + TcpServer.GOSSIPVERSION + "!", e);
            }
        }
    });
    // Start a new member to add it to discovery set of locator0.
    member.invoke(new CacheSerializableRunnable("Start a member") {

        @Override
        public void run2() throws CacheException {
            disconnectFromDS();
            TcpServer.getGossipVersionMapForTestOnly().put(TcpServer.TESTVERSION - 100, Version.CURRENT_ORDINAL);
            InternalDistributedSystem.connect(props);
        }
    });
    // Start locator1 with props.
    // props.setProperty(DistributionConfig.START_LOCATOR_NAME, host.getHostName() + "["+port1+"]");
    locator1.invoke(new CacheSerializableRunnable("Starting second locator on port " + port1) {

        @Override
        public void run2() throws CacheException {
            try {
                TcpServer.TESTVERSION -= 100;
                TcpServer.OLDTESTVERSION -= 100;
                TcpServer.getGossipVersionMapForTestOnly().put(TcpServer.TESTVERSION, Version.CURRENT_ORDINAL);
                TcpServer.getGossipVersionMapForTestOnly().put(TcpServer.OLDTESTVERSION, Version.GFE_57.ordinal());
                // assertIndexDetailsEquals("Gossip Version and Test version are not same",
                // TcpServer.GOSSIPVERSION, TcpServer.TESTVERSION);
                // assertIndexDetailsEquals("Previous Gossip Version and Test version are not same",
                // TcpServer.OLDGOSSIPVERSION, TcpServer.OLDTESTVERSION);
                Locator.startLocatorAndDS(port1, logFile1, props);
                // Start a gossip client to connect to first locator "locator0".
                FindCoordinatorRequest req = new FindCoordinatorRequest(new InternalDistributedMember(SocketCreator.getLocalHost(), 1234));
                FindCoordinatorResponse response = null;
                response = (FindCoordinatorResponse) new TcpClient().requestToServer(SocketCreator.getLocalHost(), port1, req, 5000);
                assertNotNull(response);
            } catch (Exception e) {
                org.apache.geode.test.dunit.Assert.fail("Locator1 start failed with Gossip Version: " + TcpServer.GOSSIPVERSION + "!", e);
            }
        }
    });
    // Stop first locator currently running in locator0 VM.
    locator0.invoke(new CacheSerializableRunnable("Stopping first locator") {

        @Override
        public void run2() throws CacheException {
            Locator.getLocator().stop();
            disconnectFromDS();
        }
    });
    // Restart first locator in new VM.
    // props.setProperty(DistributionConfig.START_LOCATOR_NAME, host.getHostName() + "["+port0+"]");
    locatorRestart0.invoke(new CacheSerializableRunnable("Restarting first locator on port " + port0) {

        @Override
        public void run2() throws CacheException {
            try {
                TcpServer.TESTVERSION -= 100;
                TcpServer.OLDTESTVERSION -= 100;
                TcpServer.getGossipVersionMapForTestOnly().put(TcpServer.TESTVERSION, Version.CURRENT_ORDINAL);
                TcpServer.getGossipVersionMapForTestOnly().put(TcpServer.OLDTESTVERSION, Version.GFE_57.ordinal());
                // assertIndexDetailsEquals("Gossip Version and Test version are not same",
                // TcpServer.GOSSIPVERSION, TcpServer.TESTVERSION);
                // assertIndexDetailsEquals("Previous Gossip Version and Test version are not same",
                // TcpServer.OLDGOSSIPVERSION, TcpServer.OLDTESTVERSION);
                Locator.startLocatorAndDS(port0, logFile0, props);
                // Start a gossip client to connect to first locator "locator0".
                FindCoordinatorRequest req = new FindCoordinatorRequest(new InternalDistributedMember(SocketCreator.getLocalHost(), 1234));
                FindCoordinatorResponse response = null;
                response = (FindCoordinatorResponse) new TcpClient().requestToServer(SocketCreator.getLocalHost(), port0, req, 5000);
                assertNotNull(response);
            } catch (Exception e) {
                org.apache.geode.test.dunit.Assert.fail("Locator0 start failed with Gossip Version: " + TcpServer.GOSSIPVERSION + "!", e);
            }
        }
    });
}
Also used : FindCoordinatorResponse(org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorResponse) CacheException(org.apache.geode.cache.CacheException) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) FindCoordinatorRequest(org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorRequest) VM(org.apache.geode.test.dunit.VM) File(java.io.File) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 8 with FindCoordinatorResponse

use of org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorResponse in project geode by apache.

the class GMSJoinLeaveJUnitTest method testCoordinatorFindRequestSuccess.

@Test
public void testCoordinatorFindRequestSuccess() throws Exception {
    try {
        initMocks(false);
        HashSet<InternalDistributedMember> registrants = new HashSet<>();
        registrants.add(mockMembers[0]);
        FindCoordinatorResponse fcr = new FindCoordinatorResponse(mockMembers[0], mockMembers[0], false, null, registrants, false, true, null);
        NetView view = createView();
        JoinResponseMessage jrm = new JoinResponseMessage(mockMembers[0], view, 0);
        TcpClientWrapper tcpClientWrapper = mock(TcpClientWrapper.class);
        gmsJoinLeave.setTcpClientWrapper(tcpClientWrapper);
        FindCoordinatorRequest fcreq = new FindCoordinatorRequest(gmsJoinLeaveMemberId, new HashSet<>(), -1, null, 0, "");
        int connectTimeout = (int) services.getConfig().getMemberTimeout() * 2;
        when(tcpClientWrapper.sendCoordinatorFindRequest(new InetSocketAddress("localhost", 12345), fcreq, connectTimeout)).thenReturn(fcr);
        callAsnyc(() -> {
            gmsJoinLeave.installView(view);
        });
        assertTrue("Should be able to join ", gmsJoinLeave.join());
    } finally {
    }
}
Also used : TcpClientWrapper(org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave.TcpClientWrapper) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) FindCoordinatorResponse(org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorResponse) FindCoordinatorRequest(org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorRequest) InetSocketAddress(java.net.InetSocketAddress) NetView(org.apache.geode.distributed.internal.membership.NetView) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) HashSet(java.util.HashSet) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

FindCoordinatorResponse (org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorResponse)8 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)7 NetView (org.apache.geode.distributed.internal.membership.NetView)7 HashSet (java.util.HashSet)6 FindCoordinatorRequest (org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorRequest)5 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)5 Test (org.junit.Test)5 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 InetSocketAddress (java.net.InetSocketAddress)3 IOException (java.io.IOException)2 Properties (java.util.Properties)2 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)2 TcpClientWrapper (org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave.TcpClientWrapper)2 JoinResponseMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 GemFireConfigException (org.apache.geode.GemFireConfigException)1