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;
}
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);
}
}
}
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);
}
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;
}
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());
}
Aggregations