Search in sources :

Example 11 with ScaleDownPolicy

use of org.apache.activemq.artemis.core.server.cluster.ha.ScaleDownPolicy in project activemq-artemis by apache.

the class SharedStoreBackupActivation method run.

@Override
public void run() {
    try {
        activeMQServer.getNodeManager().startBackup();
        ScaleDownPolicy scaleDownPolicy = sharedStoreSlavePolicy.getScaleDownPolicy();
        boolean scalingDown = scaleDownPolicy != null && scaleDownPolicy.isEnabled();
        if (!activeMQServer.initialisePart1(scalingDown))
            return;
        activeMQServer.getBackupManager().start();
        activeMQServer.setState(ActiveMQServerImpl.SERVER_STATE.STARTED);
        ActiveMQServerLogger.LOGGER.backupServerStarted(activeMQServer.getVersion().getFullVersion(), activeMQServer.getNodeManager().getNodeId());
        activeMQServer.getNodeManager().awaitLiveNode();
        sharedStoreSlavePolicy.getSharedStoreMasterPolicy().setSharedStoreSlavePolicy(sharedStoreSlavePolicy);
        activeMQServer.setHAPolicy(sharedStoreSlavePolicy.getSharedStoreMasterPolicy());
        // activeMQServer.configuration.getHAPolicy().setPolicyType(HAPolicy.POLICY_TYPE.SHARED_STORE);
        activeMQServer.getBackupManager().activated();
        if (activeMQServer.getState() != ActiveMQServerImpl.SERVER_STATE.STARTED) {
            return;
        }
        activeMQServer.initialisePart2(scalingDown);
        activeMQServer.completeActivation();
        if (scalingDown) {
            ActiveMQServerLogger.LOGGER.backupServerScaledDown();
            Thread t = new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        activeMQServer.stop();
                        // we are shared store but if we were started by a parent server then we shouldn't restart
                        if (sharedStoreSlavePolicy.isRestartBackup()) {
                            activeMQServer.start();
                        }
                    } catch (Exception e) {
                        ActiveMQServerLogger.LOGGER.serverRestartWarning(e);
                    }
                }
            });
            t.start();
            return;
        } else {
            ActiveMQServerLogger.LOGGER.backupServerIsLive();
            activeMQServer.getNodeManager().releaseBackup();
        }
        if (sharedStoreSlavePolicy.isAllowAutoFailBack()) {
            startFailbackChecker();
        }
    } catch (ClosedChannelException | InterruptedException e) {
    // these are ok, we are being stopped
    } catch (Exception e) {
        if (!(e.getCause() instanceof InterruptedException)) {
            ActiveMQServerLogger.LOGGER.initializationError(e);
        }
    } catch (Throwable e) {
        ActiveMQServerLogger.LOGGER.initializationError(e);
    }
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) ScaleDownPolicy(org.apache.activemq.artemis.core.server.cluster.ha.ScaleDownPolicy) ClosedChannelException(java.nio.channels.ClosedChannelException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException)

Aggregations

ScaleDownPolicy (org.apache.activemq.artemis.core.server.cluster.ha.ScaleDownPolicy)11 HAPolicy (org.apache.activemq.artemis.core.server.cluster.ha.HAPolicy)10 Configuration (org.apache.activemq.artemis.core.config.Configuration)9 HAPolicyConfiguration (org.apache.activemq.artemis.core.config.HAPolicyConfiguration)9 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)9 Activation (org.apache.activemq.artemis.core.server.impl.Activation)9 ActiveMQServerImpl (org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl)9 ColocatedActivation (org.apache.activemq.artemis.core.server.impl.ColocatedActivation)9 LiveOnlyActivation (org.apache.activemq.artemis.core.server.impl.LiveOnlyActivation)9 SharedNothingBackupActivation (org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation)9 SharedNothingLiveActivation (org.apache.activemq.artemis.core.server.impl.SharedNothingLiveActivation)9 SharedStoreBackupActivation (org.apache.activemq.artemis.core.server.impl.SharedStoreBackupActivation)9 SharedStoreLiveActivation (org.apache.activemq.artemis.core.server.impl.SharedStoreLiveActivation)9 Test (org.junit.Test)8 LiveOnlyPolicy (org.apache.activemq.artemis.core.server.cluster.ha.LiveOnlyPolicy)4 ReplicaPolicy (org.apache.activemq.artemis.core.server.cluster.ha.ReplicaPolicy)3 SharedStoreSlavePolicy (org.apache.activemq.artemis.core.server.cluster.ha.SharedStoreSlavePolicy)3 ClosedChannelException (java.nio.channels.ClosedChannelException)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1