Search in sources :

Example 6 with Topology

use of org.apache.activemq.artemis.core.client.impl.Topology 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 7 with Topology

use of org.apache.activemq.artemis.core.client.impl.Topology in project activemq-artemis by apache.

the class IsolatedTopologyTest method checkTopology.

private void checkTopology(final ActiveMQServer serverParameter, final String clusterName, final String nodeId1, final String nodeId2, final TransportConfiguration cfg1, final TransportConfiguration cfg2) {
    Topology topology = serverParameter.getClusterManager().getClusterConnection(clusterName).getTopology();
    TopologyMemberImpl member1 = topology.getMember(nodeId1);
    TopologyMemberImpl member2 = topology.getMember(nodeId2);
    Assert.assertEquals(member1.getLive().getParams().toString(), cfg1.getParams().toString());
    Assert.assertEquals(member2.getLive().getParams().toString(), cfg2.getParams().toString());
}
Also used : TopologyMemberImpl(org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl) Topology(org.apache.activemq.artemis.core.client.impl.Topology)

Example 8 with Topology

use of org.apache.activemq.artemis.core.client.impl.Topology in project activemq-artemis by apache.

the class AutomaticColocatedQuorumVoteTest method testSimpleDistributionBackupStrategyScaleDown.

@Test
public void testSimpleDistributionBackupStrategyScaleDown() throws Exception {
    ActiveMQServer server0 = createServer(0, 1, true);
    ActiveMQServer server1 = createServer(1, 0, true);
    TransportConfiguration liveConnector0 = getConnectorTransportConfiguration("liveConnector" + 0, 0);
    TransportConfiguration liveConnector1 = getConnectorTransportConfiguration("liveConnector" + 1, 1);
    try (ServerLocator serverLocator = ActiveMQClient.createServerLocatorWithoutHA(liveConnector0)) {
        server0.start();
        server1.start();
        ClientSessionFactory sessionFactory0 = serverLocator.createSessionFactory(liveConnector0);
        waitForRemoteBackup(sessionFactory0, 10);
        ClientSessionFactory sessionFactory1 = serverLocator.createSessionFactory(liveConnector1);
        waitForRemoteBackup(sessionFactory1, 10);
        Topology topology = serverLocator.getTopology();
        Collection<TopologyMemberImpl> members = topology.getMembers();
        Assert.assertEquals(members.size(), 2);
        Map<String, ActiveMQServer> backupServers0 = server0.getClusterManager().getHAManager().getBackupServers();
        Assert.assertEquals(backupServers0.size(), 1);
        Map<String, ActiveMQServer> backupServers1 = server1.getClusterManager().getHAManager().getBackupServers();
        Assert.assertEquals(backupServers1.size(), 1);
        ActiveMQServer backupServer0 = backupServers0.values().iterator().next();
        ActiveMQServer backupServer1 = backupServers1.values().iterator().next();
        waitForRemoteBackupSynchronization(backupServer0);
        waitForRemoteBackupSynchronization(backupServer1);
        Assert.assertEquals(server0.getNodeID(), backupServer1.getNodeID());
        Assert.assertEquals(server1.getNodeID(), backupServer0.getNodeID());
        Set<TransportConfiguration> backupAcceptors0 = backupServer0.getConfiguration().getAcceptorConfigurations();
        Assert.assertEquals(0, backupAcceptors0.size());
        Set<TransportConfiguration> backupAcceptors1 = backupServer1.getConfiguration().getAcceptorConfigurations();
        Assert.assertEquals(0, backupAcceptors1.size());
        Map<String, TransportConfiguration> connectorConfigurations0 = backupServer0.getConfiguration().getConnectorConfigurations();
        Assert.assertEquals(2, connectorConfigurations0.size());
        Assert.assertEquals("61616", connectorConfigurations0.get("liveConnector0").getParams().get("port"));
        Assert.assertEquals("61617", connectorConfigurations0.get("remoteConnector0").getParams().get("port"));
        Map<String, TransportConfiguration> connectorConfigurations1 = backupServer1.getConfiguration().getConnectorConfigurations();
        Assert.assertEquals(2, connectorConfigurations1.size());
        Assert.assertEquals("61617", connectorConfigurations1.get("liveConnector1").getParams().get("port"));
        Assert.assertEquals("61616", connectorConfigurations1.get("remoteConnector1").getParams().get("port"));
        if (!replicated) {
            Assert.assertEquals(server0.getConfiguration().getJournalDirectory(), backupServer1.getConfiguration().getJournalDirectory());
            Assert.assertEquals(server0.getConfiguration().getBindingsDirectory(), backupServer1.getConfiguration().getBindingsDirectory());
            Assert.assertEquals(server0.getConfiguration().getLargeMessagesDirectory(), backupServer1.getConfiguration().getLargeMessagesDirectory());
            Assert.assertEquals(server0.getConfiguration().getPagingDirectory(), backupServer1.getConfiguration().getPagingDirectory());
            Assert.assertEquals(server1.getConfiguration().getJournalDirectory(), backupServer0.getConfiguration().getJournalDirectory());
            Assert.assertEquals(server1.getConfiguration().getBindingsDirectory(), backupServer0.getConfiguration().getBindingsDirectory());
            Assert.assertEquals(server1.getConfiguration().getLargeMessagesDirectory(), backupServer0.getConfiguration().getLargeMessagesDirectory());
            Assert.assertEquals(server1.getConfiguration().getPagingDirectory(), backupServer0.getConfiguration().getPagingDirectory());
        } else {
            Assert.assertNotEquals(server0.getConfiguration().getJournalDirectory(), backupServer1.getConfiguration().getJournalDirectory());
            Assert.assertNotEquals(server0.getConfiguration().getBindingsDirectory(), backupServer1.getConfiguration().getBindingsDirectory());
            Assert.assertNotEquals(server0.getConfiguration().getLargeMessagesDirectory(), backupServer1.getConfiguration().getLargeMessagesDirectory());
            Assert.assertNotEquals(server0.getConfiguration().getPagingDirectory(), backupServer1.getConfiguration().getPagingDirectory());
            Assert.assertNotEquals(server1.getConfiguration().getJournalDirectory(), backupServer0.getConfiguration().getJournalDirectory());
            Assert.assertNotEquals(server1.getConfiguration().getBindingsDirectory(), backupServer0.getConfiguration().getBindingsDirectory());
            Assert.assertNotEquals(server1.getConfiguration().getLargeMessagesDirectory(), backupServer0.getConfiguration().getLargeMessagesDirectory());
            Assert.assertNotEquals(server1.getConfiguration().getPagingDirectory(), backupServer0.getConfiguration().getPagingDirectory());
        }
    } finally {
        try {
            server0.stop();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        server1.stop();
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) TopologyMemberImpl(org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) Topology(org.apache.activemq.artemis.core.client.impl.Topology) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 9 with Topology

use of org.apache.activemq.artemis.core.client.impl.Topology in project activemq-artemis by apache.

the class AutomaticColocatedQuorumVoteTest method testSimpleDistributionBackupStrategyFull.

@Test
public void testSimpleDistributionBackupStrategyFull() throws Exception {
    ActiveMQServer server0 = createServer(0, 1, false);
    ActiveMQServer server1 = createServer(1, 0, false);
    TransportConfiguration liveConnector0 = getConnectorTransportConfiguration("liveConnector" + 0, 0);
    TransportConfiguration liveConnector1 = getConnectorTransportConfiguration("liveConnector" + 1, 1);
    try (ServerLocator serverLocator = ActiveMQClient.createServerLocatorWithoutHA(liveConnector0)) {
        server0.start();
        server1.start();
        ClientSessionFactory sessionFactory0 = serverLocator.createSessionFactory(liveConnector0);
        waitForRemoteBackup(sessionFactory0, 10);
        ClientSessionFactory sessionFactory1 = serverLocator.createSessionFactory(liveConnector1);
        waitForRemoteBackup(sessionFactory1, 10);
        Topology topology = serverLocator.getTopology();
        Collection<TopologyMemberImpl> members = topology.getMembers();
        Assert.assertEquals(members.size(), 2);
        Map<String, ActiveMQServer> backupServers0 = server0.getClusterManager().getHAManager().getBackupServers();
        Assert.assertEquals(backupServers0.size(), 1);
        Map<String, ActiveMQServer> backupServers1 = server1.getClusterManager().getHAManager().getBackupServers();
        Assert.assertEquals(backupServers1.size(), 1);
        ActiveMQServer backupServer0 = backupServers0.values().iterator().next();
        ActiveMQServer backupServer1 = backupServers1.values().iterator().next();
        waitForRemoteBackupSynchronization(backupServer0);
        waitForRemoteBackupSynchronization(backupServer1);
        Assert.assertEquals(server0.getNodeID(), backupServer1.getNodeID());
        Assert.assertEquals(server1.getNodeID(), backupServer0.getNodeID());
        Set<TransportConfiguration> backupAcceptors0 = backupServer0.getConfiguration().getAcceptorConfigurations();
        Assert.assertEquals(1, backupAcceptors0.size());
        Assert.assertEquals("61716", backupAcceptors0.iterator().next().getParams().get("port"));
        Set<TransportConfiguration> backupAcceptors1 = backupServer1.getConfiguration().getAcceptorConfigurations();
        Assert.assertEquals(1, backupAcceptors1.size());
        Assert.assertEquals("61717", backupAcceptors1.iterator().next().getParams().get("port"));
        Map<String, TransportConfiguration> connectorConfigurations0 = backupServer0.getConfiguration().getConnectorConfigurations();
        Assert.assertEquals(2, connectorConfigurations0.size());
        Assert.assertEquals("61716", connectorConfigurations0.get("liveConnector0").getParams().get("port"));
        Assert.assertEquals("61617", connectorConfigurations0.get("remoteConnector0").getParams().get("port"));
        Map<String, TransportConfiguration> connectorConfigurations1 = backupServer1.getConfiguration().getConnectorConfigurations();
        Assert.assertEquals(2, connectorConfigurations1.size());
        Assert.assertEquals("61717", connectorConfigurations1.get("liveConnector1").getParams().get("port"));
        Assert.assertEquals("61616", connectorConfigurations1.get("remoteConnector1").getParams().get("port"));
        if (!replicated) {
            Assert.assertEquals(server0.getConfiguration().getJournalDirectory(), backupServer1.getConfiguration().getJournalDirectory());
            Assert.assertEquals(server0.getConfiguration().getBindingsDirectory(), backupServer1.getConfiguration().getBindingsDirectory());
            Assert.assertEquals(server0.getConfiguration().getLargeMessagesDirectory(), backupServer1.getConfiguration().getLargeMessagesDirectory());
            Assert.assertEquals(server0.getConfiguration().getPagingDirectory(), backupServer1.getConfiguration().getPagingDirectory());
            Assert.assertEquals(server1.getConfiguration().getJournalDirectory(), backupServer0.getConfiguration().getJournalDirectory());
            Assert.assertEquals(server1.getConfiguration().getBindingsDirectory(), backupServer0.getConfiguration().getBindingsDirectory());
            Assert.assertEquals(server1.getConfiguration().getLargeMessagesDirectory(), backupServer0.getConfiguration().getLargeMessagesDirectory());
            Assert.assertEquals(server1.getConfiguration().getPagingDirectory(), backupServer0.getConfiguration().getPagingDirectory());
        } else {
            Assert.assertNotEquals(server0.getConfiguration().getJournalDirectory(), backupServer1.getConfiguration().getJournalDirectory());
            Assert.assertNotEquals(server0.getConfiguration().getBindingsDirectory(), backupServer1.getConfiguration().getBindingsDirectory());
            Assert.assertNotEquals(server0.getConfiguration().getLargeMessagesDirectory(), backupServer1.getConfiguration().getLargeMessagesDirectory());
            Assert.assertNotEquals(server0.getConfiguration().getPagingDirectory(), backupServer1.getConfiguration().getPagingDirectory());
            Assert.assertNotEquals(server1.getConfiguration().getJournalDirectory(), backupServer0.getConfiguration().getJournalDirectory());
            Assert.assertNotEquals(server1.getConfiguration().getBindingsDirectory(), backupServer0.getConfiguration().getBindingsDirectory());
            Assert.assertNotEquals(server1.getConfiguration().getLargeMessagesDirectory(), backupServer0.getConfiguration().getLargeMessagesDirectory());
            Assert.assertNotEquals(server1.getConfiguration().getPagingDirectory(), backupServer0.getConfiguration().getPagingDirectory());
        }
    } finally {
        try {
            server0.stop();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        server1.stop();
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) TopologyMemberImpl(org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) Topology(org.apache.activemq.artemis.core.client.impl.Topology) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 10 with Topology

use of org.apache.activemq.artemis.core.client.impl.Topology 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)

Aggregations

Topology (org.apache.activemq.artemis.core.client.impl.Topology)11 TopologyMemberImpl (org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl)9 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)7 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)6 ClusterConnection (org.apache.activemq.artemis.core.server.cluster.ClusterConnection)5 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)4 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)4 Test (org.junit.Test)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 XAException (javax.transaction.xa.XAException)2 ClusterConnectionImpl (org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl)2 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 JMSException (javax.jms.JMSException)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1