use of org.candlepin.model.CandlepinModeChange in project candlepin by candlepin.
the class StatusResourceTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
CandlepinModeChange mockModeChange = new CandlepinModeChange(new Date(), Mode.NORMAL, Reason.STARTUP);
CandlepinQuery mockCPQuery = mock(CandlepinQuery.class);
when(mockCPQuery.list()).thenReturn(new ArrayList<Rules>());
when(rulesCurator.listAll()).thenReturn(mockCPQuery);
when(rulesCurator.getRules()).thenReturn(new Rules("// Version: 2.0\nBLAH"));
when(mockedStatusCache.getStatus()).thenReturn(null);
when(candlepinCache.getStatusCache()).thenReturn(mockedStatusCache);
when(modeManager.getLastCandlepinModeChange()).thenReturn(mockModeChange);
}
use of org.candlepin.model.CandlepinModeChange in project candlepin by candlepin.
the class SuspendModeTransitionerTest method setUp.
@Before
public void setUp() {
when(candlepinCache.getStatusCache()).thenReturn(cache);
CandlepinCommonTestConfig testConfig = new CandlepinCommonTestConfig();
transitioner = new SuspendModeTransitioner(testConfig, execService, candlepinCache);
transitioner.setModeManager(modeManager);
transitioner.setQmf(qmf);
transitioner.setQpidConnection(qpidConnection);
startupModeChange = new CandlepinModeChange(new Date(), Mode.NORMAL, Reason.STARTUP);
downModeChange = new CandlepinModeChange(new Date(), Mode.SUSPEND, Reason.QPID_DOWN);
normalModeChange = new CandlepinModeChange(new Date(), Mode.NORMAL, Reason.QPID_UP);
}
use of org.candlepin.model.CandlepinModeChange 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);
}
use of org.candlepin.model.CandlepinModeChange in project candlepin by candlepin.
the class StatusResource method status.
/**
* Retrieves the Status of the System
* <p>
* <pre>
* {
* "result" : true,
* "version" : "0.9.10",
* "rulesVersion" : "5.8",
* "release" : "1",
* "standalone" : true,
* "timeUTC" : [date],
* "managerCapabilities" : [ "cores", "ram", "instance_multiplier" ],
* "rulesSource" : "DEFAULT"
* }
* </pre>
* <p>
* Status to see if a server is up and running
*
* @return a Status object
* @httpcode 200
*/
@GET
@ApiOperation(value = "Status", notes = "Returns status of the server", authorizations = {})
@Produces({ MediaType.APPLICATION_JSON })
@SecurityHole(noAuth = true, anon = true)
public Status status() {
StatusCache statusCache = candlepinCache.getStatusCache();
Status cached = statusCache.getStatus();
if (cached != null) {
return cached;
}
/*
* Originally this was used to indicate database connectivity being good/bad.
* In reality it could never be false, the request would fail. This check has
* been moved to GET /status/db.
*/
boolean good = true;
try {
rulesCurator.getUpdatedFromDB();
} catch (Exception e) {
log.error("Error checking database connection", e);
good = false;
}
CandlepinModeChange modeChange = modeManager.getLastCandlepinModeChange();
if (modeChange.getMode() != Mode.NORMAL) {
good = false;
}
Status status = new Status(good, version, release, standalone, jsProvider.getRulesVersion(), jsProvider.getRulesSource(), modeChange.getMode(), modeChange.getReason(), modeChange.getChangeTime());
statusCache.setStatus(status);
return status;
}
use of org.candlepin.model.CandlepinModeChange 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
*/
}
}
Aggregations