Search in sources :

Example 1 with Topology

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

the class ActiveMQServerControlImpl method listNetworkTopology.

@Override
public String listNetworkTopology() throws Exception {
    checkStarted();
    clearIO();
    try {
        JsonArrayBuilder brokers = JsonLoader.createArrayBuilder();
        ClusterManager clusterManager = server.getClusterManager();
        if (clusterManager != null) {
            Set<ClusterConnection> clusterConnections = clusterManager.getClusterConnections();
            for (ClusterConnection clusterConnection : clusterConnections) {
                Topology topology = clusterConnection.getTopology();
                Collection<TopologyMemberImpl> members = topology.getMembers();
                for (TopologyMemberImpl member : members) {
                    JsonObjectBuilder obj = JsonLoader.createObjectBuilder();
                    TransportConfiguration live = member.getLive();
                    if (live != null) {
                        obj.add("nodeID", member.getNodeId()).add("live", live.getParams().get("host") + ":" + live.getParams().get("port"));
                        TransportConfiguration backup = member.getBackup();
                        if (backup != null) {
                            obj.add("backup", backup.getParams().get("host") + ":" + backup.getParams().get("port"));
                        }
                    }
                    brokers.add(obj);
                }
            }
        }
        return brokers.build().toString();
    } finally {
        blockOnIO();
    }
}
Also used : TopologyMemberImpl(org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JsonArrayBuilder(javax.json.JsonArrayBuilder) Topology(org.apache.activemq.artemis.core.client.impl.Topology) JsonObjectBuilder(javax.json.JsonObjectBuilder) ClusterManager(org.apache.activemq.artemis.core.server.cluster.ClusterManager)

Example 2 with Topology

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

the class NonHATopologyTest method internalTest.

public void internalTest(boolean isNetty) throws Exception {
    ActiveMQServer server = null;
    ServerLocatorInternal locator = null;
    try {
        server = createServer(false, isNetty);
        if (!isNetty) {
            server.getConfiguration().getAcceptorConfigurations().add(new TransportConfiguration(NETTY_ACCEPTOR_FACTORY));
            server.getConfiguration().getConnectorConfigurations().put("netty", new TransportConfiguration(NETTY_CONNECTOR_FACTORY));
            ArrayList<String> list = new ArrayList<>();
            list.add("netty");
            Configuration config = server.getConfiguration();
            config.getClusterConfigurations().add(new ClusterConnectionConfiguration().setName("tst").setAddress("jms").setConnectorName("netty").setRetryInterval(1000).setConfirmationWindowSize(1000).setMessageLoadBalancingType(MessageLoadBalancingType.ON_DEMAND).setStaticConnectors(list).setAllowDirectConnectionsOnly(true));
        }
        server.start();
        locator = (ServerLocatorInternal) createNonHALocator(isNetty);
        ClientSessionFactory factory = createSessionFactory(locator);
        Topology topology = locator.getTopology();
        assertEquals(1, topology.getMembers().size());
        factory.close();
        TopologyMemberImpl member = topology.getMembers().iterator().next();
        if (isNetty) {
            assertEquals(NettyConnectorFactory.class.getName(), member.getLive().getFactoryClassName());
        } else {
            assertEquals(InVMConnectorFactory.class.getName(), member.getLive().getFactoryClassName());
        }
    } finally {
        try {
            locator.close();
        } catch (Exception ignored) {
        }
        try {
            server.stop();
        } catch (Exception ignored) {
        }
        server = null;
        locator = null;
    }
}
Also used : ClusterConnectionConfiguration(org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration) TopologyMemberImpl(org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl) Configuration(org.apache.activemq.artemis.core.config.Configuration) ClusterConnectionConfiguration(org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) NettyConnectorFactory(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory) ArrayList(java.util.ArrayList) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) Topology(org.apache.activemq.artemis.core.client.impl.Topology) ServerLocatorInternal(org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) InVMConnectorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory)

Example 3 with Topology

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

the class SingleLiveMultipleBackupsFailoverTest method testMultipleFailovers.

@Test
public void testMultipleFailovers() throws Exception {
    nodeManager = new InVMNodeManager(!sharedStore);
    createLiveConfig(0);
    createBackupConfig(0, 1, 0, 2, 3, 4, 5);
    createBackupConfig(0, 2, 0, 1, 3, 4, 5);
    createBackupConfig(0, 3, 0, 1, 2, 4, 5);
    createBackupConfig(0, 4, 0, 1, 2, 3, 5);
    createBackupConfig(0, 5, 0, 1, 2, 3, 4);
    servers.get(0).start();
    waitForServerToStart(servers.get(0).getServer());
    servers.get(1).start();
    waitForServerToStart(servers.get(1).getServer());
    servers.get(2).start();
    servers.get(3).start();
    servers.get(4).start();
    servers.get(5).start();
    locator = (ServerLocatorImpl) getServerLocator(0);
    Topology topology = locator.getTopology();
    // for logging and debugging
    topology.setOwner("testMultipleFailovers");
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setReconnectAttempts(15);
    ClientSessionFactoryInternal sf = createSessionFactoryAndWaitForTopology(locator, 2);
    int backupNode;
    ClientSession session = sendAndConsume(sf, true);
    log.info("failing node 0");
    servers.get(0).crash(session);
    session.close();
    backupNode = waitForNewLive(5, true, servers, 1, 2, 3, 4, 5);
    session = sendAndConsume(sf, false);
    log.info("failing node " + backupNode);
    servers.get(backupNode).crash(session);
    session.close();
    backupNode = waitForNewLive(5, true, servers, 1, 2, 3, 4, 5);
    session = sendAndConsume(sf, false);
    log.info("failing node " + backupNode);
    servers.get(backupNode).crash(session);
    session.close();
    backupNode = waitForNewLive(5, true, servers, 1, 2, 3, 4, 5);
    session = sendAndConsume(sf, false);
    log.info("failing node " + backupNode);
    servers.get(backupNode).crash(session);
    session.close();
    backupNode = waitForNewLive(5, true, servers, 1, 2, 3, 4, 5);
    session = sendAndConsume(sf, false);
    log.info("failing node " + backupNode);
    servers.get(backupNode).crash(session);
    session.close();
    backupNode = waitForNewLive(5, false, servers, 1, 2, 3, 4, 5);
    session = sendAndConsume(sf, false);
    session.close();
    servers.get(backupNode).stop();
    locator.close();
}
Also used : ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Topology(org.apache.activemq.artemis.core.client.impl.Topology) Test(org.junit.Test)

Example 4 with Topology

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

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

the class AutomaticColocatedQuorumVoteTest method testSimpleDistributionOfBackupsMaxBackupsExceeded.

@Test
public void testSimpleDistributionOfBackupsMaxBackupsExceeded() throws Exception {
    ActiveMQServer server0 = createServer(0, 1, false);
    ActiveMQServer server1 = createServer(1, 0, false);
    ActiveMQServer server2 = createServer(2, 0, false);
    ActiveMQServer server3 = createServer(3, 0, false);
    TransportConfiguration liveConnector0 = getConnectorTransportConfiguration("liveConnector" + 0, 0);
    TransportConfiguration liveConnector1 = getConnectorTransportConfiguration("liveConnector" + 1, 1);
    TransportConfiguration liveConnector2 = getConnectorTransportConfiguration("liveConnector" + 2, 2);
    TransportConfiguration liveConnector3 = getConnectorTransportConfiguration("liveConnector" + 3, 3);
    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());
        server2.start();
        // just give server2 time to try both server 0 and 1
        ClientSessionFactory sessionFactory2 = serverLocator.createSessionFactory(liveConnector2);
        server3.start();
        ClientSessionFactory sessionFactory3 = serverLocator.createSessionFactory(liveConnector3);
        waitForRemoteBackup(sessionFactory2, 10);
        waitForRemoteBackup(sessionFactory3, 10);
        Assert.assertEquals(members.size(), 2);
        Map<String, ActiveMQServer> backupServers2 = server2.getClusterManager().getHAManager().getBackupServers();
        Assert.assertEquals(backupServers2.size(), 1);
        Map<String, ActiveMQServer> backupServers3 = server3.getClusterManager().getHAManager().getBackupServers();
        Assert.assertEquals(backupServers3.size(), 1);
        ActiveMQServer backupServer2 = backupServers2.values().iterator().next();
        ActiveMQServer backupServer3 = backupServers3.values().iterator().next();
        waitForRemoteBackupSynchronization(backupServer2);
        waitForRemoteBackupSynchronization(backupServer3);
        Assert.assertEquals(server0.getNodeID(), backupServer1.getNodeID());
        Assert.assertEquals(server1.getNodeID(), backupServer0.getNodeID());
        Assert.assertEquals(server2.getNodeID(), backupServer3.getNodeID());
        Assert.assertEquals(server3.getNodeID(), backupServer2.getNodeID());
    } finally {
        server0.stop();
        server1.stop();
        server2.stop();
        server3.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)

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