use of org.apache.activemq.artemis.core.server.cluster.ClusterManager 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();
}
}
use of org.apache.activemq.artemis.core.server.cluster.ClusterManager 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;
}
use of org.apache.activemq.artemis.core.server.cluster.ClusterManager in project activemq-artemis by apache.
the class ActiveMQServerImpl method initialisePart1.
/**
* Starts everything apart from RemotingService and loading the data.
* <p>
* After optional intermediary steps, Part 1 is meant to be followed by part 2
* {@link #initialisePart2(boolean)}.
*
* @param scalingDown
*/
synchronized boolean initialisePart1(boolean scalingDown) throws Exception {
if (state == SERVER_STATE.STOPPED)
return false;
if (configuration.getJournalType() == JournalType.ASYNCIO) {
if (!AIOSequentialFileFactory.isSupported()) {
ActiveMQServerLogger.LOGGER.switchingNIO();
configuration.setJournalType(JournalType.NIO);
} else if (!AIOSequentialFileFactory.isSupported(configuration.getJournalLocation())) {
ActiveMQServerLogger.LOGGER.switchingNIOonPath(configuration.getJournalLocation().getAbsolutePath());
configuration.setJournalType(JournalType.NIO);
}
}
managementService = new ManagementServiceImpl(mbeanServer, configuration);
if (configuration.getMemoryMeasureInterval() != -1) {
memoryManager = new MemoryManager(configuration.getMemoryWarningThreshold(), configuration.getMemoryMeasureInterval());
memoryManager.start();
}
// Create the hard-wired components
callPreActiveCallbacks();
// startReplication();
storageManager = createStorageManager();
if (configuration.getClusterConfigurations().size() > 0 && ActiveMQDefaultConfiguration.getDefaultClusterUser().equals(configuration.getClusterUser()) && ActiveMQDefaultConfiguration.getDefaultClusterPassword().equals(configuration.getClusterPassword())) {
ActiveMQServerLogger.LOGGER.clusterSecurityRisk();
}
securityStore = new SecurityStoreImpl(securityRepository, securityManager, configuration.getSecurityInvalidationInterval(), configuration.isSecurityEnabled(), configuration.getClusterUser(), configuration.getClusterPassword(), managementService);
queueFactory = new QueueFactoryImpl(executorFactory, scheduledPool, addressSettingsRepository, storageManager, this);
pagingManager = createPagingManager();
resourceManager = new ResourceManagerImpl((int) (configuration.getTransactionTimeout() / 1000), configuration.getTransactionTimeoutScanPeriod(), scheduledPool);
postOffice = new PostOfficeImpl(this, storageManager, pagingManager, queueFactory, managementService, configuration.getMessageExpiryScanPeriod(), configuration.getMessageExpiryThreadPriority(), configuration.getWildcardConfiguration(), configuration.getIDCacheSize(), configuration.isPersistIDCache(), addressSettingsRepository);
// This can't be created until node id is set
clusterManager = new ClusterManager(executorFactory, this, postOffice, scheduledPool, managementService, configuration, nodeManager, haPolicy.isBackup());
backupManager = new BackupManager(this, executorFactory, scheduledPool, nodeManager, configuration, clusterManager);
clusterManager.deploy();
remotingService = new RemotingServiceImpl(clusterManager, configuration, this, managementService, scheduledPool, protocolManagerFactories, executorFactory.getExecutor(), serviceRegistry);
messagingServerControl = managementService.registerServer(postOffice, securityStore, storageManager, configuration, addressSettingsRepository, securityRepository, resourceManager, remotingService, this, queueFactory, scheduledPool, pagingManager, haPolicy.isBackup());
if (!scalingDown) {
deployAddressSettingsFromConfiguration();
}
storageManager.start();
postOffice.start();
pagingManager.start();
managementService.start();
resourceManager.start();
deploySecurityFromConfiguration();
deployGroupingHandlerConfiguration(configuration.getGroupingHandlerConfiguration());
this.reloadManager = new ReloadManagerImpl(getScheduledPool(), executorFactory.getExecutor(), configuration.getConfigurationFileRefreshPeriod());
if (configuration.getConfigurationUrl() != null && getScheduledPool() != null) {
reloadManager.addCallback(configuration.getConfigurationUrl(), new ConfigurationFileReloader());
}
return true;
}
use of org.apache.activemq.artemis.core.server.cluster.ClusterManager in project activemq-artemis by apache.
the class TopologyClusterTestBase method waitForClusterConnections.
protected void waitForClusterConnections(final int node, final int expected) throws Exception {
ActiveMQServer server = servers[node];
if (server == null) {
throw new IllegalArgumentException("No server at " + node);
}
ClusterManager clusterManager = server.getClusterManager();
long start = System.currentTimeMillis();
int nodesCount;
do {
nodesCount = 0;
for (ClusterConnection clusterConn : clusterManager.getClusterConnections()) {
Map<String, String> nodes = clusterConn.getNodes();
for (String id : nodes.keySet()) {
if (clusterConn.isNodeActive(id)) {
nodesCount++;
}
}
}
if (nodesCount == expected) {
return;
}
Thread.sleep(10);
} while (System.currentTimeMillis() - start < ActiveMQTestBase.WAIT_TIMEOUT);
log.error(clusterDescription(servers[node]));
Assert.assertEquals("Timed out waiting for cluster connections for server " + node, expected, nodesCount);
}
use of org.apache.activemq.artemis.core.server.cluster.ClusterManager in project activemq-artemis by apache.
the class SameProcessActiveMQServer method crash.
@Override
public CountDownLatch crash(boolean failover, boolean waitFailure, ClientSession... sessions) throws Exception {
CountDownLatch latch = new CountDownLatch(sessions.length);
CountDownSessionFailureListener[] listeners = new CountDownSessionFailureListener[sessions.length];
for (int i = 0; i < sessions.length; i++) {
listeners[i] = new CountDownSessionFailureListener(latch, sessions[i]);
sessions[i].addFailureListener(listeners[i]);
}
ClusterManager clusterManager = server.getClusterManager();
clusterManager.flushExecutor();
clusterManager.clear();
Assert.assertTrue("server should be running!", server.isStarted());
server.fail(failover);
if (waitFailure) {
// Wait to be informed of failure
boolean ok = latch.await(10000, TimeUnit.MILLISECONDS);
Assert.assertTrue("Failed to stop the server! Latch count is " + latch.getCount() + " out of " + sessions.length, ok);
}
return latch;
}
Aggregations