Search in sources :

Example 1 with QpidStatus

use of org.candlepin.audit.QpidQmf.QpidStatus in project candlepin by candlepin.

the class CandlepinContextListener method withInjector.

@Override
public void withInjector(Injector injector) {
    // Must call super.contextInitialized() before accessing injector
    insertValidationEventListeners(injector);
    ResourceLocatorMap map = injector.getInstance(ResourceLocatorMap.class);
    map.init();
    if (config.getBoolean(ConfigProperties.AMQP_INTEGRATION_ENABLED) && !config.getBoolean(ConfigProperties.SUSPEND_MODE_ENABLED)) {
        QpidQmf qmf = injector.getInstance(QpidQmf.class);
        QpidStatus status = qmf.getStatus();
        if (status != QpidStatus.CONNECTED) {
            log.error("Qpid is in status {}. Please fix Qpid configuration " + "and make sure Qpid is up and running. Candlepin will shutdown " + "now.", status);
            throw new RuntimeException("Error during Startup: Qpid is in status " + status);
        }
    }
    if (config.getBoolean(ConfigProperties.AMQP_INTEGRATION_ENABLED) && config.getBoolean(ConfigProperties.SUSPEND_MODE_ENABLED)) {
        SuspendModeTransitioner mw = injector.getInstance(SuspendModeTransitioner.class);
        mw.transitionAppropriately();
        mw.startPeriodicExecutions();
    }
    if (config.getBoolean(ACTIVEMQ_ENABLED)) {
        try {
            activeMQContextListener = injector.getInstance(ActiveMQContextListener.class);
            activeMQContextListener.contextInitialized(injector);
        } catch (Exception e) {
            log.error("Exception occurred while trying to load ActiveMQ", e);
        }
    }
    if (config.getBoolean(ConfigProperties.CACHE_JMX_STATS)) {
        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
        ManagementService.registerMBeans(CacheManager.getInstance(), mBeanServer, true, true, true, true);
    }
    pinsetterListener = injector.getInstance(PinsetterContextListener.class);
    pinsetterListener.contextInitialized();
    loggerListener = injector.getInstance(LoggerContextListener.class);
    /**
     * Custom ModelConverter to handle our specific serialization requirements
     */
    ModelConverters.getInstance().addConverter(injector.getInstance(CandlepinSwaggerModelConverter.class));
    this.injector = injector;
}
Also used : SuspendModeTransitioner(org.candlepin.controller.SuspendModeTransitioner) ActiveMQContextListener(org.candlepin.audit.ActiveMQContextListener) LoggerContextListener(org.candlepin.logging.LoggerContextListener) QpidStatus(org.candlepin.audit.QpidQmf.QpidStatus) PinsetterContextListener(org.candlepin.pinsetter.core.PinsetterContextListener) CandlepinSwaggerModelConverter(org.candlepin.swagger.CandlepinSwaggerModelConverter) QpidQmf(org.candlepin.audit.QpidQmf) ResourceLocatorMap(org.candlepin.resteasy.ResourceLocatorMap) ConfigurationException(org.candlepin.common.config.ConfigurationException) MBeanServer(javax.management.MBeanServer)

Example 2 with QpidStatus

use of org.candlepin.audit.QpidQmf.QpidStatus in project candlepin by candlepin.

the class SuspendModeTransitioner method transitionAppropriately.

/**
 * Attempts to transition Candlepin according to current Mode and current status of
 * the Qpid Broker. Logs and swallows possible exceptions - theoretically
 * there should be none.
 *
 * Most of the time the transition won't be required and this method will be no-op.
 * There is an edge-case when transitioning from SUSPEND to NORMAL mode.
 * During that transition, there is a small time window between checking the
 * Qpid status and attempt to reconnect. If the Qpid status is reported as
 * Qpid up, the transitioner will try to reconnect to the broker. This reconnect
 * may fail. In that case the transition to NORMAL mode shouldn't go through.
 */
public synchronized void transitionAppropriately() {
    log.debug("Attempting to transition to appropriate Mode");
    try {
        QpidStatus status = qmf.getStatus();
        CandlepinModeChange modeChange = modeManager.getLastCandlepinModeChange();
        log.debug("Qpid status is {}, the current mode is {}", status, modeChange);
        if (status != QpidStatus.CONNECTED) {
            qpidConnection.setConnectionStatus(STATUS.JMS_OBJECTS_STALE);
        }
        if (modeChange.getMode() == Mode.SUSPEND) {
            switch(status) {
                case CONNECTED:
                    log.info("Connection to qpid is restored! Reconnecting Qpid and" + " entering NORMAL mode");
                    failedAttempts = BigInteger.ZERO;
                    modeManager.enterMode(Mode.NORMAL, Reason.QPID_UP);
                    cleanStatusCache();
                    break;
                case FLOW_STOPPED:
                case DOWN:
                    failedAttempts = failedAttempts.add(BigInteger.ONE);
                    log.debug("Staying in {} mode. So far {} failed attempts", status, failedAttempts);
                    break;
                default:
                    throw new RuntimeException("Unknown status: " + status);
            }
        } else if (modeChange.getMode() == Mode.NORMAL) {
            switch(status) {
                case FLOW_STOPPED:
                    log.debug("Will need to transition Candlepin into SUSPEND Mode because " + "the Qpid connection is flow stopped");
                    modeManager.enterMode(Mode.SUSPEND, Reason.QPID_FLOW_STOPPED);
                    cleanStatusCache();
                    break;
                case DOWN:
                    log.debug("Will need to transition Candlepin into SUSPEND Mode because " + "the Qpid connection is down");
                    modeManager.enterMode(Mode.SUSPEND, Reason.QPID_DOWN);
                    cleanStatusCache();
                    break;
                case CONNECTED:
                    log.debug("Connection to Qpid is ok and current mode is NORMAL. No-op!");
                    break;
                default:
                    throw new RuntimeException("Unknown status: " + status);
            }
        }
    } catch (Throwable t) {
        log.error("Error while executing period Suspend Transitioner check", t);
    /*
             * Nothing more we can do here, since this is scheduled thread. We must
             * hope that this error won't infinitely recur with each scheduled execution
             */
    }
}
Also used : QpidStatus(org.candlepin.audit.QpidQmf.QpidStatus) CandlepinModeChange(org.candlepin.model.CandlepinModeChange)

Aggregations

QpidStatus (org.candlepin.audit.QpidQmf.QpidStatus)2 MBeanServer (javax.management.MBeanServer)1 ActiveMQContextListener (org.candlepin.audit.ActiveMQContextListener)1 QpidQmf (org.candlepin.audit.QpidQmf)1 ConfigurationException (org.candlepin.common.config.ConfigurationException)1 SuspendModeTransitioner (org.candlepin.controller.SuspendModeTransitioner)1 LoggerContextListener (org.candlepin.logging.LoggerContextListener)1 CandlepinModeChange (org.candlepin.model.CandlepinModeChange)1 PinsetterContextListener (org.candlepin.pinsetter.core.PinsetterContextListener)1 ResourceLocatorMap (org.candlepin.resteasy.ResourceLocatorMap)1 CandlepinSwaggerModelConverter (org.candlepin.swagger.CandlepinSwaggerModelConverter)1