Search in sources :

Example 1 with ClusterManager

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

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;
}
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 ClusterManager

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;
}
Also used : ManagementServiceImpl(org.apache.activemq.artemis.core.server.management.impl.ManagementServiceImpl) RemotingServiceImpl(org.apache.activemq.artemis.core.remoting.server.impl.RemotingServiceImpl) ReloadManagerImpl(org.apache.activemq.artemis.core.server.reload.ReloadManagerImpl) ResourceManagerImpl(org.apache.activemq.artemis.core.transaction.impl.ResourceManagerImpl) SecurityStoreImpl(org.apache.activemq.artemis.core.security.impl.SecurityStoreImpl) MemoryManager(org.apache.activemq.artemis.core.server.MemoryManager) ClusterManager(org.apache.activemq.artemis.core.server.cluster.ClusterManager) BackupManager(org.apache.activemq.artemis.core.server.cluster.BackupManager) PostOfficeImpl(org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl)

Example 4 with ClusterManager

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);
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) ClusterManager(org.apache.activemq.artemis.core.server.cluster.ClusterManager)

Example 5 with ClusterManager

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;
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) CountDownSessionFailureListener(org.apache.activemq.artemis.tests.util.CountDownSessionFailureListener) ClusterManager(org.apache.activemq.artemis.core.server.cluster.ClusterManager)

Aggregations

ClusterManager (org.apache.activemq.artemis.core.server.cluster.ClusterManager)10 ClusterConnection (org.apache.activemq.artemis.core.server.cluster.ClusterConnection)5 CountDownLatch (java.util.concurrent.CountDownLatch)3 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)3 Map (java.util.Map)2 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 TopologyMemberImpl (org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl)2 HttpString (io.undertow.util.HttpString)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1 XAException (javax.transaction.xa.XAException)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)1 SessionFailureListener (org.apache.activemq.artemis.api.core.client.SessionFailureListener)1 Topology (org.apache.activemq.artemis.core.client.impl.Topology)1