use of nl.nn.adapterframework.util.RunState in project iaf by ibissource.
the class ShowConfigurationStatus method mapAdapterReceivers.
private ArrayList<Object> mapAdapterReceivers(Adapter adapter, boolean showPendingMsgCount) {
ArrayList<Object> receivers = new ArrayList<Object>();
for (Receiver<?> receiver : adapter.getReceivers()) {
Map<String, Object> receiverInfo = new HashMap<>();
RunState receiverRunState = receiver.getRunState();
receiverInfo.put("name", receiver.getName());
receiverInfo.put("state", receiverRunState.name().toLowerCase());
Map<String, Object> messages = new HashMap<String, Object>(3);
messages.put("received", receiver.getMessagesReceived());
messages.put("retried", receiver.getMessagesRetried());
messages.put("rejected", receiver.getMessagesRejected());
receiverInfo.put("messages", messages);
Set<ProcessState> knownStates = receiver.knownProcessStates();
Map<ProcessState, Object> tsInfo = new LinkedHashMap<ProcessState, Object>();
for (ProcessState state : knownStates) {
IMessageBrowser<?> ts = receiver.getMessageBrowser(state);
if (ts != null) {
Map<String, Object> info = new HashMap<>();
try {
info.put("numberOfMessages", ts.getMessageCount());
} catch (Exception e) {
log.warn("Cannot determine number of messages in process state [" + state + "]", e);
info.put("numberOfMessages", "error");
}
info.put("name", state.getName());
tsInfo.put(state, info);
}
}
receiverInfo.put("transactionalStores", tsInfo);
ISender sender = null;
IListener<?> listener = receiver.getListener();
if (listener != null) {
Map<String, Object> listenerInfo = new HashMap<String, Object>();
listenerInfo.put("name", listener.getName());
listenerInfo.put("class", ClassUtils.nameOf(listener));
if (listener instanceof HasPhysicalDestination) {
String pd = ((HasPhysicalDestination) receiver.getListener()).getPhysicalDestinationName();
listenerInfo.put("destination", pd);
}
if (listener instanceof HasSender) {
sender = ((HasSender) listener).getSender();
}
boolean isRestListener = (listener instanceof RestListener);
listenerInfo.put("isRestListener", isRestListener);
if (isRestListener) {
RestListener rl = (RestListener) listener;
listenerInfo.put("restUriPattern", rl.getRestUriPattern());
listenerInfo.put("isView", rl.isView());
}
receiverInfo.put("listener", listenerInfo);
}
if ((listener instanceof JmsListenerBase) && showPendingMsgCount) {
JmsListenerBase jlb = (JmsListenerBase) listener;
JmsBrowser<javax.jms.Message> jmsBrowser;
if (StringUtils.isEmpty(jlb.getMessageSelector())) {
jmsBrowser = new JmsBrowser<>();
} else {
jmsBrowser = new JmsBrowser<>(jlb.getMessageSelector());
}
jmsBrowser.setName("MessageBrowser_" + jlb.getName());
jmsBrowser.setJmsRealm(jlb.getJmsRealmName());
jmsBrowser.setDestinationName(jlb.getDestinationName());
jmsBrowser.setDestinationType(jlb.getDestinationType());
String numMsgs;
try {
int messageCount = jmsBrowser.getMessageCount();
numMsgs = String.valueOf(messageCount);
} catch (Throwable t) {
log.warn("Cannot determine number of messages in errorstore [" + jmsBrowser.getName() + "]", t);
numMsgs = "?";
}
receiverInfo.put("pendingMessagesCount", numMsgs);
}
boolean isEsbJmsFFListener = false;
if (listener instanceof EsbJmsListener) {
EsbJmsListener ejl = (EsbJmsListener) listener;
if (ejl.getMessageProtocol() != null) {
if (ejl.getMessageProtocol().equalsIgnoreCase("FF")) {
isEsbJmsFFListener = true;
}
if (showPendingMsgCount) {
String esbNumMsgs = EsbUtils.getQueueMessageCount(ejl);
if (esbNumMsgs == null) {
esbNumMsgs = "?";
}
receiverInfo.put("esbPendingMessagesCount", esbNumMsgs);
}
}
}
receiverInfo.put("isEsbJmsFFListener", isEsbJmsFFListener);
ISender rsender = receiver.getSender();
if (rsender != null) {
// this sender has preference, but avoid overwriting listeners sender with null
sender = rsender;
}
if (sender != null) {
receiverInfo.put("senderName", sender.getName());
receiverInfo.put("senderClass", ClassUtils.nameOf(sender));
if (sender instanceof HasPhysicalDestination) {
String pd = ((HasPhysicalDestination) sender).getPhysicalDestinationName();
receiverInfo.put("senderDestination", pd);
}
}
if (receiver.isThreadCountReadable()) {
receiverInfo.put("threadCount", receiver.getCurrentThreadCount());
receiverInfo.put("maxThreadCount", receiver.getMaxThreadCount());
}
if (receiver.isThreadCountControllable()) {
receiverInfo.put("threadCountControllable", "true");
}
receivers.add(receiverInfo);
}
return receivers;
}
use of nl.nn.adapterframework.util.RunState 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