Search in sources :

Example 6 with HealthCheckResult

use of org.xipki.common.HealthCheckResult in project xipki by xipki.

the class HealthCheckServlet method service0.

private FullHttpResponse service0(FullHttpRequest request, ServletURI servletUri, SSLSession sslSession) {
    HttpVersion version = request.protocolVersion();
    HttpMethod method = request.method();
    if (method != HttpMethod.GET) {
        return createErrorResponse(version, HttpResponseStatus.METHOD_NOT_ALLOWED);
    }
    try {
        if (server == null) {
            LOG.error("server in servlet not configured");
            return createErrorResponse(version, HttpResponseStatus.INTERNAL_SERVER_ERROR);
        }
        ResponderAndPath responderAndPath = server.getResponderForPath(servletUri.getPath());
        if (responderAndPath == null) {
            return createErrorResponse(version, HttpResponseStatus.NOT_FOUND);
        }
        HealthCheckResult healthResult = server.healthCheck(responderAndPath.getResponder());
        HttpResponseStatus status = healthResult.isHealthy() ? HttpResponseStatus.OK : HttpResponseStatus.INTERNAL_SERVER_ERROR;
        byte[] respBytes = healthResult.toJsonMessage(true).getBytes();
        return createResponse(version, status, HealthCheckServlet.CT_RESPONSE, respBytes);
    } catch (Throwable th) {
        if (th instanceof EOFException) {
            LogUtil.warn(LOG, th, "connection reset by peer");
        } else {
            LOG.error("Throwable thrown, this should not happen", th);
        }
        return createErrorResponse(version, HttpResponseStatus.INTERNAL_SERVER_ERROR);
    }
}
Also used : HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) EOFException(java.io.EOFException) HealthCheckResult(org.xipki.common.HealthCheckResult) ResponderAndPath(org.xipki.ocsp.api.ResponderAndPath) HttpVersion(io.netty.handler.codec.http.HttpVersion) HttpMethod(io.netty.handler.codec.http.HttpMethod)

Example 7 with HealthCheckResult

use of org.xipki.common.HealthCheckResult in project xipki by xipki.

the class HealthCheckServlet method doGet.

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
    resp.setHeader("Access-Control-Allow-Origin", "*");
    OcspServer server = ServletHelper.getServer();
    if (server == null) {
        LOG.error("ServletHelper.server not configured");
        resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        resp.setContentLength(0);
        return;
    }
    try {
        String path = StringUtil.getRelativeRequestUri(req.getServletPath(), req.getRequestURI());
        ResponderAndPath responderAndPath = server.getResponderForPath(path);
        if (responderAndPath == null) {
            resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
            resp.setContentLength(0);
            return;
        }
        HealthCheckResult healthResult = server.healthCheck(responderAndPath.getResponder());
        int status = healthResult.isHealthy() ? HttpServletResponse.SC_OK : HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
        byte[] respBytes = healthResult.toJsonMessage(true).getBytes();
        resp.setStatus(status);
        resp.setContentType(HealthCheckServlet.CT_RESPONSE);
        resp.setContentLength(respBytes.length);
        resp.getOutputStream().write(respBytes);
    } catch (Throwable th) {
        if (th instanceof EOFException) {
            LogUtil.warn(LOG, th, "connection reset by peer");
        } else {
            LOG.error("Throwable thrown, this should not happen", th);
        }
        resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        resp.setContentLength(0);
    } finally {
        resp.flushBuffer();
    }
}
Also used : EOFException(java.io.EOFException) HealthCheckResult(org.xipki.common.HealthCheckResult) ResponderAndPath(org.xipki.ocsp.api.ResponderAndPath) OcspServer(org.xipki.ocsp.api.OcspServer)

Example 8 with HealthCheckResult

use of org.xipki.common.HealthCheckResult in project xipki by xipki.

the class X509CaCmpResponderImpl method healthCheck.

public HealthCheckResult healthCheck() {
    HealthCheckResult result = getCa().healthCheck();
    boolean healthy = result.isHealthy();
    boolean responderHealthy = caManager.getResponderWrapper(getResponderName()).getSigner().isHealthy();
    healthy &= responderHealthy;
    HealthCheckResult responderHealth = new HealthCheckResult("Responder");
    responderHealth.setHealthy(responderHealthy);
    result.addChildCheck(responderHealth);
    result.setHealthy(healthy);
    return result;
}
Also used : HealthCheckResult(org.xipki.common.HealthCheckResult)

Example 9 with HealthCheckResult

use of org.xipki.common.HealthCheckResult in project xipki by xipki.

the class X509Ca method healthCheck.

// method removeExpirtedCerts
public HealthCheckResult healthCheck() {
    HealthCheckResult result = new HealthCheckResult("X509CA");
    boolean healthy = true;
    ConcurrentContentSigner signer = caInfo.getSigner(null);
    if (signer != null) {
        boolean caSignerHealthy = signer.isHealthy();
        healthy &= caSignerHealthy;
        HealthCheckResult signerHealth = new HealthCheckResult("Signer");
        signerHealth.setHealthy(caSignerHealthy);
        result.addChildCheck(signerHealth);
    }
    boolean databaseHealthy = certstore.isHealthy();
    healthy &= databaseHealthy;
    HealthCheckResult databaseHealth = new HealthCheckResult("Database");
    databaseHealth.setHealthy(databaseHealthy);
    result.addChildCheck(databaseHealth);
    X509CrlSignerEntryWrapper crlSigner = getCrlSigner();
    if (crlSigner != null && crlSigner.getSigner() != null) {
        boolean crlSignerHealthy = crlSigner.getSigner().isHealthy();
        healthy &= crlSignerHealthy;
        HealthCheckResult crlSignerHealth = new HealthCheckResult("CRLSigner");
        crlSignerHealth.setHealthy(crlSignerHealthy);
        result.addChildCheck(crlSignerHealth);
    }
    for (IdentifiedX509CertPublisher publisher : publishers()) {
        boolean ph = publisher.isHealthy();
        healthy &= ph;
        HealthCheckResult publisherHealth = new HealthCheckResult("Publisher");
        publisherHealth.setHealthy(publisher.isHealthy());
        result.addChildCheck(publisherHealth);
    }
    result.setHealthy(healthy);
    return result;
}
Also used : ConcurrentContentSigner(org.xipki.security.ConcurrentContentSigner) HealthCheckResult(org.xipki.common.HealthCheckResult)

Example 10 with HealthCheckResult

use of org.xipki.common.HealthCheckResult in project xipki by xipki.

the class HealthCheckResultTest method test5.

@Test
public void test5() {
    HealthCheckResult result = new HealthCheckResult("mycheck-positive");
    result.setHealthy(true);
    HealthCheckResult childCheck = new HealthCheckResult("childcheck");
    result.addChildCheck(childCheck);
    childCheck.setHealthy(false);
    HealthCheckResult childCheck2 = new HealthCheckResult("childcheck2");
    result.addChildCheck(childCheck2);
    childCheck.setHealthy(false);
    HealthCheckResult childChildCheck = new HealthCheckResult("childChildCheck");
    childCheck.addChildCheck(childChildCheck);
    childChildCheck.setHealthy(false);
    String noPrettyJson = "{\"healthy\":true,\"checks\":{\"childcheck\":{\"healthy\":false," + "\"checks\":{\"childChildCheck\":{\"healthy\":false}}},\"childcheck2\":" + "{\"healthy\":false}}}";
    String prettyJson = "{\n" + "    \"healthy\":true,\n" + "    \"checks\":{\n" + "        \"childcheck\":{\n" + "            \"healthy\":false,\n" + "            \"checks\":{\n" + "                \"childChildCheck\":{\n" + "                    \"healthy\":false\n" + "                }\n" + "            }\n" + "        },\n" + "        \"childcheck2\":{\n" + "            \"healthy\":false\n" + "        }\n" + "    }\n" + "}";
    check(result, noPrettyJson, prettyJson);
}
Also used : HealthCheckResult(org.xipki.common.HealthCheckResult) Test(org.junit.Test)

Aggregations

HealthCheckResult (org.xipki.common.HealthCheckResult)14 Test (org.junit.Test)5 EOFException (java.io.EOFException)4 HttpMethod (io.netty.handler.codec.http.HttpMethod)2 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)2 HttpVersion (io.netty.handler.codec.http.HttpVersion)2 X509CaCmpResponder (org.xipki.ca.server.api.X509CaCmpResponder)2 ResponderAndPath (org.xipki.ocsp.api.ResponderAndPath)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 CaClientException (org.xipki.ca.client.api.CaClientException)1 ResponderManager (org.xipki.ca.server.api.ResponderManager)1 IllegalCmdParamException (org.xipki.console.karaf.IllegalCmdParamException)1 OcspServer (org.xipki.ocsp.api.OcspServer)1 OcspStore (org.xipki.ocsp.api.OcspStore)1 ConcurrentContentSigner (org.xipki.security.ConcurrentContentSigner)1