Search in sources :

Example 1 with Mode

use of org.candlepin.model.CandlepinModeChange.Mode in project candlepin by candlepin.

the class ModeManagerImpl method enterMode.

@Override
public void enterMode(Mode m, Reason reason) {
    /**
     * When suspend mode is disabled, the Candlepin should never get into Suspend Mode.
     * Candlepin is starting always in NORMAL mode, so disalowing the transition here should
     * guarantee that.
     *
     * In fact, this method enterMode shouldn't be even called when SUSPEND mode is disabled.
     * So this check here is more of a defensive programming approach.
     */
    if (!config.getBoolean(ConfigProperties.SUSPEND_MODE_ENABLED)) {
        log.debug("Suspend mode is disabled, ignoring mode transition");
        return;
    }
    if (reason == null) {
        String noReasonErrorString = "No reason supplied when trying to change CandlepinModeChange.";
        log.error(noReasonErrorString);
        throw new IllegalArgumentException(noReasonErrorString);
    }
    log.info("Entering new mode {} for reason {}", m, reason);
    Mode previousMode = cpMode.getMode();
    if (previousMode != m) {
        fireModeChangeEvent(m);
    }
    if (m.equals(Mode.SUSPEND)) {
        log.warn("Candlepin is entering suspend mode for the following reason: {}", reason);
    }
    cpMode = new CandlepinModeChange(new Date(), m, reason);
}
Also used : Mode(org.candlepin.model.CandlepinModeChange.Mode) CandlepinModeChange(org.candlepin.model.CandlepinModeChange) Date(java.util.Date)

Example 2 with Mode

use of org.candlepin.model.CandlepinModeChange.Mode in project candlepin by candlepin.

the class ModeManagerTest method testEnterMode.

@Test
public void testEnterMode() throws InterruptedException {
    Date previousTime = modeManager.getLastCandlepinModeChange().getChangeTime();
    Mode mode = Mode.SUSPEND;
    sleep(1);
    modeManager.enterMode(mode, testReason);
    assertEquals(mode, modeManager.getLastCandlepinModeChange().getMode());
    assertEquals(testReason, modeManager.getLastCandlepinModeChange().getReason());
    assertTrue(previousTime.before(modeManager.getLastCandlepinModeChange().getChangeTime()));
}
Also used : Mode(org.candlepin.model.CandlepinModeChange.Mode) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Date (java.util.Date)2 Mode (org.candlepin.model.CandlepinModeChange.Mode)2 CandlepinModeChange (org.candlepin.model.CandlepinModeChange)1 Test (org.junit.Test)1