Search in sources :

Example 6 with JoinResponseMessage

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

the class GMSJoinLeave method processJoinRequest.

/**
   * process a join request from another member. If this is the coordinator this method will enqueue
   * the request for processing in another thread. If this is not the coordinator but the
   * coordinator is known, the message is forwarded to the coordinator.
   *
   * @param incomingRequest the request to be processed
   */
private void processJoinRequest(JoinRequestMessage incomingRequest) {
    logger.info("received join request from {}", incomingRequest.getMemberID());
    if (incomingRequest.getMemberID().getVersionObject().compareTo(Version.CURRENT) < 0) {
        logger.warn("detected an attempt to start a peer using an older version of the product {}", incomingRequest.getMemberID());
        JoinResponseMessage m = new JoinResponseMessage("Rejecting the attempt of a member using an older version of the " + "product to join the distributed system", incomingRequest.getRequestId());
        m.setRecipient(incomingRequest.getMemberID());
        services.getMessenger().send(m);
        return;
    }
    Object creds = incomingRequest.getCredentials();
    String rejection;
    try {
        rejection = services.getAuthenticator().authenticate(incomingRequest.getMemberID(), (Properties) creds);
    } catch (Exception e) {
        rejection = e.getMessage();
    }
    if (rejection != null && rejection.length() > 0) {
        JoinResponseMessage m = new JoinResponseMessage(rejection, 0);
        m.setRecipient(incomingRequest.getMemberID());
        services.getMessenger().send(m);
        return;
    }
    // Remove JoinResponseMessage to fix GEODE-870
    // if (!this.localAddress.getNetMember().preferredForCoordinator() &&
    // incomingRequest.getMemberID().getNetMember().preferredForCoordinator()) {
    // JoinResponseMessage joinResponseMessage = new
    // JoinResponseMessage(incomingRequest.getMemberID(), currentView, true);
    // services.getMessenger().send(joinResponseMessage);
    // return;
    // }
    recordViewRequest(incomingRequest);
}
Also used : JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) Properties(java.util.Properties) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) AuthenticationRequiredException(org.apache.geode.security.AuthenticationRequiredException)

Example 7 with JoinResponseMessage

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

the class JGroupsMessenger method filterIncomingMessage.

void filterIncomingMessage(DistributionMessage m) {
    switch(m.getDSFID()) {
        case JOIN_RESPONSE:
            JoinResponseMessage jrsp = (JoinResponseMessage) m;
            if (jrsp.getRejectionMessage() == null && services.getConfig().getTransport().isMcastEnabled()) {
                byte[] serializedDigest = jrsp.getMessengerData();
                ByteArrayInputStream bis = new ByteArrayInputStream(serializedDigest);
                DataInputStream dis = new DataInputStream(bis);
                try {
                    Digest digest = new Digest();
                    digest.readFrom(dis);
                    logger.trace("installing JGroups message digest {}", digest);
                    this.myChannel.getProtocolStack().getTopProtocol().down(new Event(Event.MERGE_DIGEST, digest));
                    jrsp.setMessengerData(null);
                } catch (Exception e) {
                    logger.fatal("Unable to read JGroups messaging digest", e);
                }
            }
            break;
        default:
            break;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Digest(org.jgroups.util.Digest) Event(org.jgroups.Event) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) DataInputStream(java.io.DataInputStream) MemberShunnedException(org.apache.geode.internal.tcp.MemberShunnedException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) GemFireIOException(org.apache.geode.GemFireIOException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 8 with JoinResponseMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage 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 9 with JoinResponseMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage 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)

Example 10 with JoinResponseMessage

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

the class JGroupsMessenger method filterOutgoingMessage.

/** look for certain messages that may need to be altered before being sent */
void filterOutgoingMessage(DistributionMessage m) {
    switch(m.getDSFID()) {
        case JOIN_RESPONSE:
            JoinResponseMessage jrsp = (JoinResponseMessage) m;
            if (jrsp.getRejectionMessage() == null && services.getConfig().getTransport().isMcastEnabled()) {
                // get the multicast message digest and pass it with the join response
                Digest digest = (Digest) this.myChannel.getProtocolStack().getTopProtocol().down(Event.GET_DIGEST_EVT);
                HeapDataOutputStream hdos = new HeapDataOutputStream(500, Version.CURRENT);
                try {
                    digest.writeTo(hdos);
                } catch (Exception e) {
                    logger.fatal("Unable to serialize JGroups messaging digest", e);
                }
                jrsp.setMessengerData(hdos.toByteArray());
            }
            break;
        default:
            break;
    }
}
Also used : Digest(org.jgroups.util.Digest) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) MemberShunnedException(org.apache.geode.internal.tcp.MemberShunnedException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) GemFireIOException(org.apache.geode.GemFireIOException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Aggregations

JoinResponseMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage)11 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)6 NetView (org.apache.geode.distributed.internal.membership.NetView)6 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)5 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)5 Test (org.junit.Test)5 SystemConnectException (org.apache.geode.SystemConnectException)4 IOException (java.io.IOException)3 GemFireConfigException (org.apache.geode.GemFireConfigException)3 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 InetSocketAddress (java.net.InetSocketAddress)2 UnknownHostException (java.net.UnknownHostException)2 HashSet (java.util.HashSet)2 Properties (java.util.Properties)2 ForcedDisconnectException (org.apache.geode.ForcedDisconnectException)2 GemFireIOException (org.apache.geode.GemFireIOException)2 FindCoordinatorRequest (org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorRequest)2