Search in sources :

Example 6 with ClusterConnectionImpl

use of org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl in project activemq-artemis by apache.

the class ClusterTestBase method logTopologyDiagram.

private void logTopologyDiagram() {
    StringBuffer topologyDiagram = new StringBuffer();
    for (ActiveMQServer activeMQServer : servers) {
        if (activeMQServer != null) {
            topologyDiagram.append("\n").append(activeMQServer.getIdentity()).append("\n");
            if (activeMQServer.isStarted()) {
                Set<ClusterConnection> ccs = activeMQServer.getClusterManager().getClusterConnections();
                if (ccs.size() >= 1) {
                    ClusterConnectionImpl clusterConnection = (ClusterConnectionImpl) ccs.iterator().next();
                    Collection<TopologyMemberImpl> members = clusterConnection.getTopology().getMembers();
                    for (TopologyMemberImpl member : members) {
                        String nodeId = member.getNodeId();
                        String liveServer = null;
                        String backupServer = null;
                        for (ActiveMQServer server : servers) {
                            if (server != null && server.getNodeID() != null && server.isActive() && server.getNodeID().toString().equals(nodeId)) {
                                if (server.isActive()) {
                                    liveServer = server.getIdentity();
                                    if (member.getLive() != null) {
                                        liveServer += "(notified)";
                                    } else {
                                        liveServer += "(not notified)";
                                    }
                                } else {
                                    backupServer = server.getIdentity();
                                    if (member.getBackup() != null) {
                                        liveServer += "(notified)";
                                    } else {
                                        liveServer += "(not notified)";
                                    }
                                }
                            }
                        }
                        topologyDiagram.append("\t").append("|\n").append("\t->").append(liveServer).append("/").append(backupServer).append("\n");
                    }
                } else {
                    topologyDiagram.append("-> no cluster connections\n");
                }
            } else {
                topologyDiagram.append("-> stopped\n");
            }
        }
    }
    topologyDiagram.append("\n");
    log.info(topologyDiagram.toString());
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) TopologyMemberImpl(org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClusterConnectionImpl(org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl)

Example 7 with ClusterConnectionImpl

use of org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl in project activemq-artemis by apache.

the class OneWayChainClusterTest method testChainClusterConnections.

@Test
public void testChainClusterConnections() throws Exception {
    setupClusterConnection("cluster0-1", 0, 1, "queues", MessageLoadBalancingType.ON_DEMAND, 4, isNetty(), true);
    setupClusterConnection("cluster1-2", 1, 2, "queues", MessageLoadBalancingType.ON_DEMAND, 4, isNetty(), true);
    setupClusterConnection("cluster2-3", 2, 3, "queues", MessageLoadBalancingType.ON_DEMAND, 4, isNetty(), true);
    setupClusterConnection("cluster3-4", 3, 4, "queues", MessageLoadBalancingType.ON_DEMAND, 4, isNetty(), true);
    setupClusterConnection("cluster4-X", 4, -1, "queues", MessageLoadBalancingType.ON_DEMAND, 4, isNetty(), true);
    startServers(0, 1, 2, 3, 4);
    Set<ClusterConnection> connectionSet = getServer(0).getClusterManager().getClusterConnections();
    assertNotNull(connectionSet);
    assertEquals(1, connectionSet.size());
    ClusterConnectionImpl ccon = (ClusterConnectionImpl) connectionSet.iterator().next();
    long timeout = System.currentTimeMillis() + 5000;
    Map<String, MessageFlowRecord> records = null;
    while (timeout > System.currentTimeMillis()) {
        records = ccon.getRecords();
        if (records != null && records.size() == 1) {
            break;
        }
    }
    assertNotNull(records);
    assertEquals(records.size(), 1);
    getServer(1).getClusterManager().getClusterConnections();
    assertNotNull(connectionSet);
    assertEquals(1, connectionSet.size());
    ccon = (ClusterConnectionImpl) connectionSet.iterator().next();
    records = ccon.getRecords();
    assertNotNull(records);
    assertEquals(records.size(), 1);
    getServer(2).getClusterManager().getClusterConnections();
    assertNotNull(connectionSet);
    assertEquals(1, connectionSet.size());
    ccon = (ClusterConnectionImpl) connectionSet.iterator().next();
    records = ccon.getRecords();
    assertNotNull(records);
    assertEquals(records.size(), 1);
    getServer(3).getClusterManager().getClusterConnections();
    assertNotNull(connectionSet);
    assertEquals(1, connectionSet.size());
    ccon = (ClusterConnectionImpl) connectionSet.iterator().next();
    records = ccon.getRecords();
    assertNotNull(records);
    assertEquals(records.size(), 1);
    getServer(4).getClusterManager().getClusterConnections();
    assertNotNull(connectionSet);
    assertEquals(1, connectionSet.size());
    ccon = (ClusterConnectionImpl) connectionSet.iterator().next();
    records = ccon.getRecords();
    assertNotNull(records);
    assertEquals(records.size(), 1);
}
Also used : MessageFlowRecord(org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) ClusterConnectionImpl(org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl) Test(org.junit.Test)

Example 8 with ClusterConnectionImpl

use of org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl in project activemq-artemis by apache.

the class JMSUtil method waitForFailoverTopology.

public static void waitForFailoverTopology(final int timeToWait, final ActiveMQServer backupServer, final ActiveMQServer... liveServers) throws Exception {
    long start = System.currentTimeMillis();
    final int waitMillis = 2000;
    final int sleepTime = 50;
    int nWaits = 0;
    while ((backupServer.getClusterManager() == null || backupServer.getClusterManager().getClusterConnections().size() != 1) && nWaits++ < waitMillis / sleepTime) {
        Thread.sleep(sleepTime);
    }
    Set<ClusterConnection> ccs = backupServer.getClusterManager().getClusterConnections();
    if (ccs.size() != 1) {
        throw new IllegalStateException("You need a single cluster connection on this version of waitForTopology on ServiceTestBase");
    }
    boolean exists = false;
    for (ActiveMQServer liveServer : liveServers) {
        ClusterConnectionImpl clusterConnection = (ClusterConnectionImpl) ccs.iterator().next();
        Topology topology = clusterConnection.getTopology();
        TransportConfiguration nodeConnector = liveServer.getClusterManager().getClusterConnections().iterator().next().getConnector();
        do {
            Collection<TopologyMemberImpl> members = topology.getMembers();
            for (TopologyMemberImpl member : members) {
                if (member.getConnector().getA() != null && member.getConnector().getA().equals(nodeConnector)) {
                    exists = true;
                    break;
                }
            }
            if (exists) {
                break;
            }
            Thread.sleep(10);
        } while (System.currentTimeMillis() - start < timeToWait);
        if (!exists) {
            String msg = "Timed out waiting for cluster topology of " + backupServer + " (received " + topology.getMembers().size() + ") topology = " + topology + ")";
            throw new Exception(msg);
        }
    }
}
Also used : TopologyMemberImpl(org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) Topology(org.apache.activemq.artemis.core.client.impl.Topology) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) JMSException(javax.jms.JMSException) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) ClusterConnectionImpl(org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl)

Example 9 with ClusterConnectionImpl

use of org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl in project activemq-artemis by apache.

the class BindingsClusterTest method crash.

private void crash() throws Exception {
    /*
       * Rather than just calling stop() on the server here we want to simulate an actual node crash or bridge failure
       * so the bridge's failure listener needs to get something other than a DISCONNECTED message.  In this case we
       * simulate a NOT_CONNECTED exception.
       */
    final CountDownLatch latch = new CountDownLatch(1);
    ClusterConnectionImpl next = (ClusterConnectionImpl) server1.getClusterManager().getClusterConnections().iterator().next();
    BridgeImpl bridge = (BridgeImpl) next.getRecords().values().iterator().next().getBridge();
    RemotingConnection forwardingConnection = getForwardingConnection(bridge);
    forwardingConnection.addFailureListener(new FailureListener() {

        @Override
        public void connectionFailed(ActiveMQException exception, boolean failedOver) {
            latch.countDown();
        }

        @Override
        public void connectionFailed(final ActiveMQException me, boolean failedOver, String scaleDownTargetNodeID) {
            connectionFailed(me, failedOver);
        }
    });
    forwardingConnection.fail(new ActiveMQNotConnectedException());
    assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
    if (crash) {
        jmsServer2.stop();
    }
}
Also used : BridgeImpl(org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) FailureListener(org.apache.activemq.artemis.core.remoting.FailureListener) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterConnectionImpl(org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl)

Aggregations

ClusterConnectionImpl (org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl)9 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)6 ClusterConnection (org.apache.activemq.artemis.core.server.cluster.ClusterConnection)4 MessageFlowRecord (org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)3 TopologyMemberImpl (org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl)3 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)3 Test (org.junit.Test)3 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)2 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 Topology (org.apache.activemq.artemis.core.client.impl.Topology)2 ClusterConnectionBridge (org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionBridge)2 Field (java.lang.reflect.Field)1 URISyntaxException (java.net.URISyntaxException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 JMSException (javax.jms.JMSException)1 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)1 DiscoveryGroupConfiguration (org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration)1