Search in sources :

Example 1 with TopologyMemberImpl

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

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

the class AMQPConnectionCallback method getFailoverList.

public URI getFailoverList() {
    ClusterManager clusterManager = server.getClusterManager();
    ClusterConnection clusterConnection = clusterManager.getDefaultConnection(null);
    if (clusterConnection != null) {
        TopologyMemberImpl member = clusterConnection.getTopology().getMember(server.getNodeID().toString());
        return member.toBackupURI();
    }
    return null;
}
Also used : TopologyMemberImpl(org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) ClusterManager(org.apache.activemq.artemis.core.server.cluster.ClusterManager)

Example 3 with TopologyMemberImpl

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

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

the class QuorumManager method vote.

/**
 * ask the quorum to vote within a specific quorum.
 *
 * @param quorumVote the vote to acquire
 */
public void vote(final QuorumVote quorumVote) {
    List<VoteRunnable> runnables = new ArrayList<>();
    synchronized (voteRunnables) {
        if (!started)
            return;
        // send a vote to each node
        ActiveMQServerLogger.LOGGER.initiatingQuorumVote(quorumVote.getName());
        for (TopologyMemberImpl tm : clusterController.getDefaultClusterTopology().getMembers()) {
            // but not ourselves
            if (!tm.getNodeId().equals(clusterController.getNodeID().toString())) {
                Pair<TransportConfiguration, TransportConfiguration> pair = tm.getConnector();
                final TransportConfiguration serverTC = pair.getA();
                VoteRunnable voteRunnable = new VoteRunnable(serverTC, quorumVote);
                runnables.add(voteRunnable);
            }
        }
        if (runnables.size() > 0) {
            voteRunnables.put(quorumVote, new VoteRunnableHolder(quorumVote, runnables, runnables.size()));
            for (VoteRunnable runnable : runnables) {
                executor.submit(runnable);
            }
        } else {
            quorumVote.allVotesCast(clusterController.getDefaultClusterTopology());
        }
    }
}
Also used : TopologyMemberImpl(org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl) ArrayList(java.util.ArrayList) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration)

Example 5 with TopologyMemberImpl

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

Aggregations

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