Search in sources :

Example 6 with Status

use of org.candlepin.model.Status in project candlepin by candlepin.

the class StatusResourceTest method unknown.

@Test
public void unknown() throws Exception {
    PrintStream ps = new PrintStream(new File(this.getClass().getClassLoader().getResource("version.properties").toURI()));
    ps.println("foo");
    StatusResource sr = new StatusResource(rulesCurator, config, jsProvider, candlepinCache, modeManager);
    Status s = sr.status();
    ps.close();
    assertNotNull(s);
    assertEquals("Unknown", s.getRelease());
    assertEquals("Unknown", s.getVersion());
    assertTrue(s.getResult());
}
Also used : Status(org.candlepin.model.Status) PrintStream(java.io.PrintStream) File(java.io.File) Test(org.junit.Test)

Example 7 with Status

use of org.candlepin.model.Status in project candlepin by candlepin.

the class StatusResourceTest method simulateVersionFilter.

@Test
public void simulateVersionFilter() throws Exception {
    // setup logger to see if we actually log anything
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    Logger srLogger = lc.getLogger(StatusResource.class);
    Appender mockapp = mock(Appender.class);
    srLogger.addAppender(mockapp);
    srLogger.setLevel(Level.DEBUG);
    ArgumentCaptor<LoggingEvent> message = ArgumentCaptor.forClass(LoggingEvent.class);
    PrintStream ps = new PrintStream(new File(this.getClass().getClassLoader().getResource("version.properties").toURI()));
    ps.println("version=${version}");
    ps.println("release=${release}");
    StatusResource sr = new StatusResource(rulesCurator, config, jsProvider, candlepinCache, modeManager);
    Status s = sr.status();
    ps.close();
    // make sure we did not log anything which indicates
    // an exception
    verify(mockapp, never()).doAppend(message.capture());
    assertEquals("${release}", s.getRelease());
    assertEquals("${version}", s.getVersion());
    assertTrue(s.getResult());
    assertFalse(s.getStandalone());
}
Also used : Appender(ch.qos.logback.core.Appender) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) Status(org.candlepin.model.Status) PrintStream(java.io.PrintStream) Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) File(java.io.File) Test(org.junit.Test)

Example 8 with Status

use of org.candlepin.model.Status 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;
}
Also used : Status(org.candlepin.model.Status) StatusCache(org.candlepin.cache.StatusCache) CandlepinModeChange(org.candlepin.model.CandlepinModeChange) SecurityHole(org.candlepin.common.auth.SecurityHole) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

Status (org.candlepin.model.Status)8 Test (org.junit.Test)7 File (java.io.File)4 PrintStream (java.io.PrintStream)4 Date (java.util.Date)3 Logger (ch.qos.logback.classic.Logger)1 LoggerContext (ch.qos.logback.classic.LoggerContext)1 LoggingEvent (ch.qos.logback.classic.spi.LoggingEvent)1 Appender (ch.qos.logback.core.Appender)1 ApiOperation (io.swagger.annotations.ApiOperation)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 StatusCache (org.candlepin.cache.StatusCache)1 SecurityHole (org.candlepin.common.auth.SecurityHole)1 CandlepinModeChange (org.candlepin.model.CandlepinModeChange)1