Search in sources :

Example 1 with BootState

use of nl.nn.adapterframework.lifecycle.ConfigurableLifecycle.BootState in project iaf by ibissource.

the class ServerStatistics method getIbisHealth.

@GET
@PermitAll
@Path("/server/health")
@Produces(MediaType.APPLICATION_JSON)
public Response getIbisHealth() {
    Map<String, Object> response = new HashMap<>();
    try {
        getIbisManager();
    } catch (Exception e) {
        Throwable c = e.getCause();
        response.put("status", Response.Status.INTERNAL_SERVER_ERROR);
        response.put("error", c.getMessage());
        response.put("stackTrace", c.getStackTrace());
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(response).build();
    }
    Map<RunState, Integer> stateCount = new HashMap<>();
    List<String> errors = new ArrayList<>();
    for (Configuration config : getIbisManager().getConfigurations()) {
        BootState state = config.getState();
        if (state != BootState.STARTED) {
            if (config.getConfigurationException() != null) {
                errors.add("configuration[" + config.getName() + "] is in state[ERROR]");
            } else {
                errors.add("configuration[" + config.getName() + "] is in state[" + state + "]");
            }
            // We're not really using stateCount other then to determine the HTTP response code.
            stateCount.put(RunState.ERROR, 1);
        }
    }
    for (Adapter adapter : getIbisManager().getRegisteredAdapters()) {
        // Let's not make it difficult for ourselves and only use STARTED/ERROR enums
        RunState state = adapter.getRunState();
        if (state == RunState.STARTED) {
            for (Receiver<?> receiver : adapter.getReceivers()) {
                RunState rState = receiver.getRunState();
                if (rState != RunState.STARTED) {
                    errors.add("receiver[" + receiver.getName() + "] of adapter[" + adapter.getName() + "] is in state[" + rState.toString() + "]");
                    state = RunState.ERROR;
                }
            }
        } else {
            errors.add("adapter[" + adapter.getName() + "] is in state[" + state.toString() + "]");
            state = RunState.ERROR;
        }
        int count;
        if (stateCount.containsKey(state))
            count = stateCount.get(state);
        else
            count = 0;
        stateCount.put(state, ++count);
    }
    Status status = Response.Status.OK;
    if (stateCount.containsKey(RunState.ERROR))
        status = Response.Status.SERVICE_UNAVAILABLE;
    if (!errors.isEmpty()) {
        response.put("errors", errors);
    }
    response.put("status", status);
    return Response.status(status).entity(response).build();
}
Also used : Status(javax.ws.rs.core.Response.Status) Configuration(nl.nn.adapterframework.configuration.Configuration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Adapter(nl.nn.adapterframework.core.Adapter) BootState(nl.nn.adapterframework.lifecycle.ConfigurableLifecycle.BootState) RunState(nl.nn.adapterframework.util.RunState) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PermitAll(javax.annotation.security.PermitAll)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 PermitAll (javax.annotation.security.PermitAll)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Status (javax.ws.rs.core.Response.Status)1 Configuration (nl.nn.adapterframework.configuration.Configuration)1 Adapter (nl.nn.adapterframework.core.Adapter)1 BootState (nl.nn.adapterframework.lifecycle.ConfigurableLifecycle.BootState)1 RunState (nl.nn.adapterframework.util.RunState)1