Search in sources :

Example 1 with JoinRequestMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage in project geode by apache.

the class GMSJoinLeave method attemptToJoin.

/**
   * send a join request and wait for a reply. Process the reply. This may throw a
   * SystemConnectException or an AuthenticationFailedException
   *
   * @return true if the attempt succeeded, false if it timed out
   */
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "WA_NOT_IN_LOOP")
boolean attemptToJoin() {
    SearchState state = searchState;
    // send a join request to the coordinator and wait for a response
    InternalDistributedMember coord = state.possibleCoordinator;
    if (state.alreadyTried.contains(coord)) {
        logger.info("Probable coordinator is still {} - waiting for a join-response", coord);
    } else {
        logger.info("Attempting to join the distributed system through coordinator " + coord + " using address " + this.localAddress);
        int port = services.getHealthMonitor().getFailureDetectionPort();
        JoinRequestMessage req = new JoinRequestMessage(coord, this.localAddress, services.getAuthenticator().getCredentials(coord), port, services.getMessenger().getRequestId());
        // services.getMessenger().send(req, state.view);
        services.getMessenger().send(req);
    }
    JoinResponseMessage response;
    try {
        response = waitForJoinResponse();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return false;
    }
    if (response == null) {
        if (!isJoined) {
            logger.debug("received no join response");
        }
        return isJoined;
    }
    logger.debug("received join response {}", response);
    joinResponse[0] = null;
    String failReason = response.getRejectionMessage();
    if (failReason != null) {
        if (failReason.contains("Rejecting the attempt of a member using an older version") || failReason.contains("15806")) {
            throw new SystemConnectException(failReason);
        } else if (failReason.contains("Failed to find credentials")) {
            throw new AuthenticationRequiredException(failReason);
        }
        throw new GemFireSecurityException(failReason);
    }
    // there is no way we can rech here right now
    throw new RuntimeException("Join Request Failed with response " + joinResponse[0]);
}
Also used : GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) AuthenticationRequiredException(org.apache.geode.security.AuthenticationRequiredException) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) SystemConnectException(org.apache.geode.SystemConnectException)

Example 2 with JoinRequestMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage in project geode by apache.

the class GMSJoinLeaveJUnitTest method testClearViewRequests.

@Test
public void testClearViewRequests() throws Exception {
    try {
        initMocks(false);
        System.setProperty(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY, "true");
        gmsJoinLeave.join();
        gmsJoinLeave.processMessage(new JoinRequestMessage(mockMembers[0], mockMembers[0], credentials, -1, 0));
        int viewRequests = gmsJoinLeave.getViewRequests().size();
        assertEquals("There should be 1 viewRequest", 1, viewRequests);
        Awaitility.await().atMost(2 * ServiceConfig.MEMBER_REQUEST_COLLECTION_INTERVAL, MILLISECONDS).until(() -> gmsJoinLeave.getViewRequests().size(), equalTo(0));
    } finally {
        System.getProperties().remove(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY);
    }
}
Also used : JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with JoinRequestMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage in project geode by apache.

the class GMSJoinLeaveJUnitTest method testDuplicateJoinRequestDoesNotCauseNewView.

// @Category(FlakyTest.class) // GEODE-2074: timed out waiting for view #7
@Test
public void testDuplicateJoinRequestDoesNotCauseNewView() throws Exception {
    initMocks();
    when(healthMonitor.checkIfAvailable(isA(InternalDistributedMember.class), isA(String.class), isA(Boolean.class))).thenReturn(true);
    gmsJoinLeave.unitTesting.add("noRandomViewChange");
    prepareAndInstallView(gmsJoinLeaveMemberId, createMemberList(gmsJoinLeaveMemberId, mockMembers[0]));
    gmsJoinLeave.getView().add(mockMembers[1]);
    GMSJoinLeaveTestHelper.becomeCoordinatorForTest(gmsJoinLeave);
    JoinRequestMessage msg = new JoinRequestMessage(gmsJoinLeaveMemberId, mockMembers[2], null, -1, 0);
    msg.setSender(mockMembers[2]);
    gmsJoinLeave.processMessage(msg);
    msg = new JoinRequestMessage(gmsJoinLeaveMemberId, mockMembers[2], null, -1, 0);
    msg.setSender(mockMembers[2]);
    gmsJoinLeave.processMessage(msg);
    waitForViewAndNoRequestsInProgress(7);
    NetView view = gmsJoinLeave.getView();
    assertTrue("expected member to be added: " + mockMembers[2] + "; view: " + view, view.contains(mockMembers[2]));
    List<InternalDistributedMember> members = view.getMembers();
    int occurrences = 0;
    for (InternalDistributedMember mbr : members) {
        if (mbr.equals(mockMembers[2])) {
            occurrences += 1;
        }
    }
    assertTrue("expected member to only be in the view once: " + mockMembers[2] + "; view: " + view, occurrences == 1);
    verify(healthMonitor, times(5)).checkIfAvailable(isA(InternalDistributedMember.class), isA(String.class), isA(Boolean.class));
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) NetView(org.apache.geode.distributed.internal.membership.NetView) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with JoinRequestMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage in project geode by apache.

the class GMSJoinLeaveJUnitTest method testProcessJoinMessageWithAuthenticationButNullCredentials.

@Test
public void testProcessJoinMessageWithAuthenticationButNullCredentials() throws IOException {
    initMocks();
    when(services.getAuthenticator()).thenReturn(authenticator);
    when(authenticator.authenticate(mockMembers[0], null)).thenThrow(new AuthenticationFailedException("we want to fail auth here"));
    when(services.getMessenger()).thenReturn(messenger);
    gmsJoinLeave.processMessage(new JoinRequestMessage(mockMembers[0], mockMembers[0], null, -1, 0));
    assertTrue("JoinRequest should not have been added to view request", gmsJoinLeave.getViewRequests().size() == 0);
    verify(messenger).send(isA(JoinResponseMessage.class));
}
Also used : AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 5 with JoinRequestMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage in project geode by apache.

the class GMSJoinLeaveJUnitTest method testProcessJoinMessageWithBadAuthentication.

@Test
public void testProcessJoinMessageWithBadAuthentication() throws IOException {
    initMocks();
    when(services.getAuthenticator()).thenReturn(authenticator);
    when(authenticator.authenticate(mockMembers[0], credentials)).thenThrow(new AuthenticationFailedException("we want to fail auth here"));
    when(services.getMessenger()).thenReturn(messenger);
    gmsJoinLeave.processMessage(new JoinRequestMessage(mockMembers[0], mockMembers[0], credentials, -1, 0));
    assertTrue("JoinRequest should not have been added to view request", gmsJoinLeave.getViewRequests().size() == 0);
    verify(messenger).send(isA(JoinResponseMessage.class));
}
Also used : AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

JoinRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)12 JoinResponseMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage)7 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)6 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)6 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)6 Test (org.junit.Test)6 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)4 NetView (org.apache.geode.distributed.internal.membership.NetView)4 LeaveRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage)3 SerialAckedMessage (org.apache.geode.distributed.internal.SerialAckedMessage)2 MessageHandler (org.apache.geode.distributed.internal.membership.gms.interfaces.MessageHandler)2 InstallViewMessage (org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage)2 AuthenticationFailedException (org.apache.geode.security.AuthenticationFailedException)2 Event (org.jgroups.Event)2 Message (org.jgroups.Message)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 SystemConnectException (org.apache.geode.SystemConnectException)1