Search in sources :

Example 11 with RunState

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;
}
Also used : MessageKeeperMessage(nl.nn.adapterframework.util.MessageKeeperMessage) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ISender(nl.nn.adapterframework.core.ISender) EsbJmsListener(nl.nn.adapterframework.extensions.esb.EsbJmsListener) HasSender(nl.nn.adapterframework.core.HasSender) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) ListenerException(nl.nn.adapterframework.core.ListenerException) IOException(java.io.IOException) RunState(nl.nn.adapterframework.util.RunState) ProcessState(nl.nn.adapterframework.core.ProcessState) RestListener(nl.nn.adapterframework.http.RestListener) JmsListenerBase(nl.nn.adapterframework.jms.JmsListenerBase) HasPhysicalDestination(nl.nn.adapterframework.core.HasPhysicalDestination)

Example 12 with RunState

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

RunState (nl.nn.adapterframework.util.RunState)12 HashMap (java.util.HashMap)5 Configuration (nl.nn.adapterframework.configuration.Configuration)5 Adapter (nl.nn.adapterframework.core.Adapter)5 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)4 PermitAll (javax.annotation.security.PermitAll)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Status (javax.ws.rs.core.Response.Status)3 Date (java.util.Date)2 ListenerException (nl.nn.adapterframework.core.ListenerException)2 IOException (java.io.IOException)1 StringTokenizer (java.util.StringTokenizer)1 TransformerException (javax.xml.transform.TransformerException)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 IbisContext (nl.nn.adapterframework.configuration.IbisContext)1 HasPhysicalDestination (nl.nn.adapterframework.core.HasPhysicalDestination)1 HasSender (nl.nn.adapterframework.core.HasSender)1