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();
}
Aggregations