Search in sources :

Example 1 with ApplicationWarnings

use of nl.nn.adapterframework.configuration.ApplicationWarnings in project iaf by ibissource.

the class ServerStatistics method getServerConfiguration.

@GET
@PermitAll
@Path("/server/warnings")
@Produces(MediaType.APPLICATION_JSON)
public Response getServerConfiguration() throws ApiException {
    Map<String, Object> returnMap = new HashMap<String, Object>();
    ApplicationWarnings globalConfigWarnings = getIbisContext().getBean("applicationWarnings", ApplicationWarnings.class);
    MessageEventListener eventListener = getIbisContext().getBean("MessageEventListener", MessageEventListener.class);
    long totalErrorStoreCount = 0;
    boolean showCountErrorStore = AppConstants.getInstance().getBoolean("errorStore.count.show", true);
    if (!showCountErrorStore)
        totalErrorStoreCount = -1;
    for (Configuration configuration : getIbisManager().getConfigurations()) {
        Map<String, Object> configurationsMap = new HashMap<String, Object>();
        // Configuration specific exceptions
        if (configuration.getConfigurationException() != null) {
            String message = configuration.getConfigurationException().getMessage();
            configurationsMap.put("exception", message);
        }
        if (configuration.isActive()) {
            // ErrorStore count
            if (showCountErrorStore) {
                long esr = 0;
                for (Adapter adapter : configuration.getRegisteredAdapters()) {
                    for (Receiver<?> receiver : adapter.getReceivers()) {
                        IMessageBrowser<?> errorStorage = receiver.getMessageBrowser(ProcessState.ERROR);
                        if (errorStorage != null) {
                            try {
                                esr += errorStorage.getMessageCount();
                            } catch (Exception e) {
                                // error("error occured on getting number of errorlog records for adapter ["+adapter.getName()+"]",e);
                                log.warn("Assuming there are no errorlog records for adapter [" + adapter.getName() + "]");
                            }
                        }
                    }
                }
                totalErrorStoreCount += esr;
                configurationsMap.put("errorStoreCount", esr);
            }
            // Configuration specific warnings
            ConfigurationWarnings configWarns = configuration.getConfigurationWarnings();
            if (configWarns != null && configWarns.size() > 0) {
                configurationsMap.put("warnings", configWarns.getWarnings());
            }
            // Configuration specific messages
            MessageKeeper messageKeeper = eventListener.getMessageKeeper(configuration.getName());
            if (messageKeeper != null) {
                List<Object> messages = mapMessageKeeperMessages(messageKeeper);
                if (!messages.isEmpty()) {
                    configurationsMap.put("messages", messages);
                }
            }
        }
        returnMap.put(configuration.getName(), configurationsMap);
    }
    // Total ErrorStore Count
    returnMap.put("totalErrorStoreCount", totalErrorStoreCount);
    // Global warnings
    if (globalConfigWarnings.size() > 0) {
        List<Object> warnings = new ArrayList<>();
        for (int j = 0; j < globalConfigWarnings.size(); j++) {
            warnings.add(globalConfigWarnings.get(j));
        }
        returnMap.put("warnings", warnings);
    }
    // Global messages
    MessageKeeper messageKeeper = eventListener.getMessageKeeper();
    List<Object> messages = mapMessageKeeperMessages(messageKeeper);
    if (!messages.isEmpty()) {
        returnMap.put("messages", messages);
    }
    Response.ResponseBuilder response = null;
    // Calculate the ETag on last modified date of user resource
    EntityTag etag = new EntityTag(returnMap.hashCode() + "");
    // Verify if it matched with etag available in http request
    response = rsRequest.evaluatePreconditions(etag);
    // If ETag matches the response will be non-null;
    if (response != null) {
        return response.tag(etag).build();
    }
    response = Response.status(Response.Status.OK).entity(returnMap).tag(etag);
    return response.build();
}
Also used : ConfigurationWarnings(nl.nn.adapterframework.configuration.ConfigurationWarnings) Configuration(nl.nn.adapterframework.configuration.Configuration) HashMap(java.util.HashMap) MessageEventListener(nl.nn.adapterframework.lifecycle.MessageEventListener) ArrayList(java.util.ArrayList) MessageKeeper(nl.nn.adapterframework.util.MessageKeeper) Adapter(nl.nn.adapterframework.core.Adapter) Response(javax.ws.rs.core.Response) ApplicationWarnings(nl.nn.adapterframework.configuration.ApplicationWarnings) EntityTag(javax.ws.rs.core.EntityTag) 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 EntityTag (javax.ws.rs.core.EntityTag)1 Response (javax.ws.rs.core.Response)1 ApplicationWarnings (nl.nn.adapterframework.configuration.ApplicationWarnings)1 Configuration (nl.nn.adapterframework.configuration.Configuration)1 ConfigurationWarnings (nl.nn.adapterframework.configuration.ConfigurationWarnings)1 Adapter (nl.nn.adapterframework.core.Adapter)1 MessageEventListener (nl.nn.adapterframework.lifecycle.MessageEventListener)1 MessageKeeper (nl.nn.adapterframework.util.MessageKeeper)1