Search in sources :

Example 6 with JoinRequestMessage

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

the class JGroupsMessengerJUnitTest method doTestBigMessageIsFragmented.

public void doTestBigMessageIsFragmented(boolean mcastEnabled, boolean mcastMsg) throws Exception {
    initMocks(mcastEnabled);
    MessageHandler mh = mock(MessageHandler.class);
    messenger.addHandler(JoinRequestMessage.class, mh);
    InternalDistributedMember sender = messenger.getMemberID();
    NetView v = new NetView(sender);
    when(joinLeave.getView()).thenReturn(v);
    messenger.installView(v);
    JoinRequestMessage msg = new JoinRequestMessage(messenger.localAddress, sender, null, -1, 0);
    if (mcastMsg) {
        msg.setMulticast(true);
    }
    messenger.send(msg);
    int sentMessages = (mcastEnabled && mcastMsg) ? interceptor.mcastSentDataMessages : interceptor.unicastSentDataMessages;
    assertTrue("expected 1 message to be sent but found " + sentMessages, sentMessages == 1);
    // send a big message and expect fragmentation
    msg = new JoinRequestMessage(messenger.localAddress, sender, new byte[(int) (services.getConfig().getDistributionConfig().getUdpFragmentSize() * (1.5))], -1, 0);
    // configure an incoming message handler for JoinRequestMessage
    final DistributionMessage[] messageReceived = new DistributionMessage[1];
    MessageHandler handler = new MessageHandler() {

        @Override
        public void processMessage(DistributionMessage m) {
            messageReceived[0] = m;
        }
    };
    messenger.addHandler(JoinRequestMessage.class, handler);
    // configure the outgoing message interceptor
    interceptor.unicastSentDataMessages = 0;
    interceptor.collectMessages = true;
    interceptor.collectedMessages.clear();
    messenger.send(msg);
    assertTrue("expected 2 messages to be sent but found " + interceptor.unicastSentDataMessages, interceptor.unicastSentDataMessages == 2);
    List<Message> messages = new ArrayList<>(interceptor.collectedMessages);
    UUID fakeMember = new UUID(50, 50);
    short unicastHeaderId = ClassConfigurator.getProtocolId(UNICAST3.class);
    int seqno = 1;
    for (Message m : messages) {
        m.setSrc(fakeMember);
        UNICAST3.Header oldHeader = (UNICAST3.Header) m.getHeader(unicastHeaderId);
        if (oldHeader == null)
            continue;
        UNICAST3.Header newHeader = UNICAST3.Header.createDataHeader(seqno, oldHeader.connId(), seqno == 1);
        seqno += 1;
        m.putHeader(unicastHeaderId, newHeader);
        interceptor.up(new Event(Event.MSG, m));
    }
    Thread.sleep(5000);
    System.out.println("received message = " + messageReceived[0]);
}
Also used : MessageHandler(org.apache.geode.distributed.internal.membership.gms.interfaces.MessageHandler) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) SerialAckedMessage(org.apache.geode.distributed.internal.SerialAckedMessage) Message(org.jgroups.Message) NetView(org.apache.geode.distributed.internal.membership.NetView) ArrayList(java.util.ArrayList) UNICAST3(org.jgroups.protocols.UNICAST3) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) Event(org.jgroups.Event) UUID(org.jgroups.util.UUID) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)

Example 7 with JoinRequestMessage

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

the class JGroupsMessengerJUnitTest method testEncryptedJoinRequest.

@Test
public void testEncryptedJoinRequest() throws Exception {
    InternalDistributedMember otherMbr = new InternalDistributedMember("localhost", 8888);
    Properties p = new Properties();
    p.put(ConfigurationProperties.SECURITY_UDP_DHALGO, "AES:128");
    initMocks(false, p);
    NetView v = createView(otherMbr);
    GMSEncrypt otherMbrEncrptor = new GMSEncrypt(services);
    messenger.setPublicKey(otherMbrEncrptor.getPublicKeyBytes(), otherMbr);
    messenger.initClusterKey();
    JoinRequestMessage gfmsg = new JoinRequestMessage(otherMbr, messenger.getMemberID(), null, 9789, 1);
    short version = Version.CURRENT_ORDINAL;
    HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
    messenger.writeEncryptedMessage(gfmsg, version, out);
    byte[] requestBytes = out.toByteArray();
    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(requestBytes));
    DistributionMessage distributionMessage = messenger.readEncryptedMessage(dis, version, otherMbrEncrptor);
    assertEquals(gfmsg, distributionMessage);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ByteArrayInputStream(java.io.ByteArrayInputStream) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) NetView(org.apache.geode.distributed.internal.membership.NetView) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DataInputStream(java.io.DataInputStream) 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 8 with JoinRequestMessage

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

the class GMSJoinLeave method installView.

public void installView(NetView newView) {
    synchronized (viewInstallationLock) {
        if (currentView != null && currentView.getViewId() >= newView.getViewId()) {
            // old view - ignore it
            return;
        }
        logger.info("received new view: {}\nold view is: {}", newView, currentView);
        if (currentView == null && !this.isJoined) {
            boolean found = false;
            for (InternalDistributedMember mbr : newView.getMembers()) {
                if (this.localAddress.equals(mbr)) {
                    found = true;
                    this.birthViewId = mbr.getVmViewId();
                    this.localAddress.setVmViewId(this.birthViewId);
                    GMSMember me = (GMSMember) this.localAddress.getNetMember();
                    me.setBirthViewId(birthViewId);
                    break;
                }
            }
            if (!found) {
                logger.info("rejecting view (not yet joined)");
                return;
            }
        }
        if (isJoined && isNetworkPartition(newView, true)) {
            if (quorumRequired) {
                Set<InternalDistributedMember> crashes = newView.getActualCrashedMembers(currentView);
                forceDisconnect(LocalizedStrings.Network_partition_detected.toLocalizedString(crashes.size(), crashes));
                return;
            }
        }
        previousView = currentView;
        currentView = newView;
        preparedView = null;
        lastConflictingView = null;
        services.installView(newView);
        if (!isJoined) {
            logger.debug("notifying join thread");
            isJoined = true;
            synchronized (joinResponse) {
                joinResponse.notifyAll();
            }
        }
        if (!newView.getCreator().equals(this.localAddress)) {
            if (newView.shouldBeCoordinator(this.localAddress)) {
                becomeCoordinator();
            } else if (this.isCoordinator) {
                // stop being coordinator
                stopCoordinatorServices();
                this.isCoordinator = false;
            }
        }
        if (!this.isCoordinator) {
            // resend these
            synchronized (viewRequests) {
                for (Iterator<DistributionMessage> it = viewRequests.iterator(); it.hasNext(); ) {
                    DistributionMessage m = it.next();
                    if (m instanceof JoinRequestMessage) {
                        if (currentView.contains(((JoinRequestMessage) m).getMemberID())) {
                            it.remove();
                        }
                    } else if (m instanceof LeaveRequestMessage) {
                        if (!currentView.contains(((LeaveRequestMessage) m).getMemberID())) {
                            it.remove();
                        }
                    } else if (m instanceof RemoveMemberMessage) {
                        if (!currentView.contains(((RemoveMemberMessage) m).getMemberID())) {
                            it.remove();
                        }
                    }
                }
            }
        }
    }
    synchronized (removedMembers) {
        removeMembersFromCollectionIfNotInView(removedMembers, currentView);
    }
    synchronized (leftMembers) {
        removeMembersFromCollectionIfNotInView(leftMembers, currentView);
    }
}
Also used : LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) RemoveMemberMessage(org.apache.geode.distributed.internal.membership.gms.messages.RemoveMemberMessage) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) GMSMember(org.apache.geode.distributed.internal.membership.gms.GMSMember) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)

Example 9 with JoinRequestMessage

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

the class GMSJoinLeave method recordViewRequest.

private void recordViewRequest(DistributionMessage request) {
    logger.debug("Recording the request to be processed in the next membership view");
    synchronized (viewRequests) {
        viewRequests.add(request);
        if (viewCreator != null && services.getMessenger().getClusterSecretKey() != null) {
            if (request instanceof JoinRequestMessage) {
                JoinRequestMessage jreq = (JoinRequestMessage) request;
                // this will inform about cluster-secret key, as we have authenticated at this point
                JoinResponseMessage response = new JoinResponseMessage(jreq.getSender(), services.getMessenger().getClusterSecretKey(), jreq.getRequestId());
                services.getMessenger().send(response);
            }
        }
        viewRequests.notifyAll();
    }
}
Also used : JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)

Example 10 with JoinRequestMessage

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

the class JGroupsMessengerJUnitTest method doTestMessageDeliveredToHandler.

private void doTestMessageDeliveredToHandler(boolean mcast) throws Exception {
    initMocks(mcast);
    MessageHandler mh = mock(MessageHandler.class);
    messenger.addHandler(JoinRequestMessage.class, mh);
    InternalDistributedMember addr = messenger.getMemberID();
    NetView v = new NetView(addr);
    when(joinLeave.getView()).thenReturn(v);
    InternalDistributedMember sender = createAddress(8888);
    JoinRequestMessage msg = new JoinRequestMessage(messenger.localAddress, sender, null, -1, 0);
    Message jmsg = messenger.createJGMessage(msg, messenger.jgAddress, Version.CURRENT_ORDINAL);
    interceptor.up(new Event(Event.MSG, jmsg));
    verify(mh, times(1)).processMessage(any(JoinRequestMessage.class));
    LeaveRequestMessage lmsg = new LeaveRequestMessage(messenger.localAddress, sender, "testing");
    when(joinLeave.getMemberID(any())).thenReturn(sender);
    jmsg = messenger.createJGMessage(lmsg, messenger.jgAddress, Version.CURRENT_ORDINAL);
    interceptor.up(new Event(Event.MSG, jmsg));
    verify(manager).processMessage(any(LeaveRequestMessage.class));
}
Also used : LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage) MessageHandler(org.apache.geode.distributed.internal.membership.gms.interfaces.MessageHandler) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) SerialAckedMessage(org.apache.geode.distributed.internal.SerialAckedMessage) Message(org.jgroups.Message) NetView(org.apache.geode.distributed.internal.membership.NetView) Event(org.jgroups.Event) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)

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