Search in sources :

Example 6 with ClusterConnection

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

the class ClusterTestBase method clusterDescription.

protected String clusterDescription(ActiveMQServer server) {
    String br = "-------------------------\n";
    String out = br;
    out += "ActiveMQ Artemis server " + server + "\n";
    ClusterManager clusterManager = server.getClusterManager();
    if (clusterManager == null) {
        out += "N/A";
    } else {
        for (ClusterConnection cc : clusterManager.getClusterConnections()) {
            out += cc.describe() + "\n";
            out += cc.getTopology().describe();
        }
    }
    out += "\n\nfull topology:";
    return out + br;
}
Also used : ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClusterManager(org.apache.activemq.artemis.core.server.cluster.ClusterManager)

Example 7 with ClusterConnection

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

the class ClusterTestBase method waitForFailoverTopology.

protected void waitForFailoverTopology(final int bNode, final int... nodes) throws Exception {
    ActiveMQServer server = servers[bNode];
    log.debug("waiting for " + Arrays.toString(nodes) + " on the topology for server = " + server);
    long start = System.currentTimeMillis();
    final int waitMillis = 2000;
    final int sleepTime = 50;
    int nWaits = 0;
    while (server.getClusterManager() == null && nWaits++ < waitMillis / sleepTime) {
        Thread.sleep(sleepTime);
    }
    Set<ClusterConnection> ccs = server.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 (int node : nodes) {
        ClusterConnectionImpl clusterConnection = (ClusterConnectionImpl) ccs.iterator().next();
        Topology topology = clusterConnection.getTopology();
        TransportConfiguration nodeConnector = servers[node].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 < WAIT_TIMEOUT);
        if (!exists) {
            String msg = "Timed out waiting for cluster topology of " + Arrays.toString(nodes) + " (received " + topology.getMembers().size() + ") topology = " + topology + ")";
            log.error(msg);
            logTopologyDiagram();
            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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) URISyntaxException(java.net.URISyntaxException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) 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 8 with ClusterConnection

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

the class ActiveMQTestBase method waitForTopology.

protected Topology waitForTopology(final ActiveMQServer server, final int liveNodes, final int backupNodes, final long timeout) throws Exception {
    logger.debug("waiting for " + liveNodes + " on the topology for server = " + server);
    long start = System.currentTimeMillis();
    Set<ClusterConnection> ccs = server.getClusterManager().getClusterConnections();
    if (ccs.size() != 1) {
        throw new IllegalStateException("You need a single cluster connection on this version of waitForTopology on ServiceTestBase");
    }
    Topology topology = server.getClusterManager().getDefaultConnection(null).getTopology();
    int liveNodesCount = 0;
    int backupNodesCount = 0;
    do {
        liveNodesCount = 0;
        backupNodesCount = 0;
        for (TopologyMemberImpl member : topology.getMembers()) {
            if (member.getLive() != null) {
                liveNodesCount++;
                ActiveMQServerLogger.LOGGER.info("Found live server connected to " + server.getNodeID());
            }
            if (member.getBackup() != null) {
                backupNodesCount++;
            }
        }
        if ((liveNodes == -1 || liveNodes == liveNodesCount) && (backupNodes == -1 || backupNodes == backupNodesCount)) {
            return topology;
        }
        Thread.sleep(10);
    } while (System.currentTimeMillis() - start < timeout);
    String msg = "Timed out waiting for cluster topology of live=" + liveNodes + ",backup=" + backupNodes + " (received live=" + liveNodesCount + ", backup=" + backupNodesCount + ") topology = " + topology.describe() + ")";
    ActiveMQServerLogger.LOGGER.error(msg);
    throw new Exception(msg);
}
Also used : TopologyMemberImpl(org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) Topology(org.apache.activemq.artemis.core.client.impl.Topology) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) XAException(javax.transaction.xa.XAException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 9 with ClusterConnection

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

the class RemotingServiceImpl method lookupClusterConnection.

private ClusterConnection lookupClusterConnection(TransportConfiguration acceptorConfig) {
    String clusterConnectionName = (String) acceptorConfig.getParams().get(org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants.CLUSTER_CONNECTION);
    ClusterConnection clusterConnection = null;
    if (clusterConnectionName != null) {
        clusterConnection = clusterManager.getClusterConnection(clusterConnectionName);
    }
    // if not found we will still use the default name, even if a name was provided
    if (clusterConnection == null) {
        clusterConnection = clusterManager.getDefaultConnection(acceptorConfig);
    }
    return clusterConnection;
}
Also used : ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection)

Example 10 with ClusterConnection

use of org.apache.activemq.artemis.core.server.cluster.ClusterConnection 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)

Aggregations

ClusterConnection (org.apache.activemq.artemis.core.server.cluster.ClusterConnection)16 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)7 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)6 TopologyMemberImpl (org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl)6 Topology (org.apache.activemq.artemis.core.client.impl.Topology)5 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)5 ClusterManager (org.apache.activemq.artemis.core.server.cluster.ClusterManager)5 ClusterConnectionImpl (org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl)4 IOException (java.io.IOException)3 SQLException (java.sql.SQLException)3 XAException (javax.transaction.xa.XAException)3 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)3 MessageFlowRecord (org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord)2 Test (org.junit.Test)2 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 JMSException (javax.jms.JMSException)1