Search in sources :

Example 1 with Adapter

use of nl.nn.adapterframework.core.Adapter in project iaf by ibissource.

the class ShowAdapterStatistics method getStatistics.

@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/adapters/{adapterName}/statistics")
@Relation("statistics")
@Produces(MediaType.APPLICATION_JSON)
public Response getStatistics(@PathParam("adapterName") String adapterName) throws ApiException {
    initBase(servletConfig);
    Map<String, Object> statisticsMap = new HashMap<String, Object>();
    Adapter adapter = (Adapter) ibisManager.getRegisteredAdapter(adapterName);
    if (adapter == null) {
        throw new ApiException("Adapter not found!");
    }
    StatisticsKeeper sk = adapter.getStatsMessageProcessingDuration();
    statisticsMap.put("totalMessageProccessingTime", statisticsKeeperToMapBuilder(sk));
    long[] numOfMessagesStartProcessingByHour = adapter.getNumOfMessagesStartProcessingByHour();
    List<Map<String, Object>> hourslyStatistics = new ArrayList<Map<String, Object>>();
    for (int i = 0; i < numOfMessagesStartProcessingByHour.length; i++) {
        Map<String, Object> item = new HashMap<String, Object>(2);
        String startTime;
        if (i < 10) {
            startTime = "0" + i + ":00";
        } else {
            startTime = i + ":00";
        }
        item.put("time", startTime);
        item.put("count", numOfMessagesStartProcessingByHour[i]);
        hourslyStatistics.add(item);
    }
    statisticsMap.put("hourly", hourslyStatistics);
    List<Map<String, Object>> receivers = new ArrayList<Map<String, Object>>();
    Iterator<?> recIt = adapter.getReceiverIterator();
    if (recIt.hasNext()) {
        while (recIt.hasNext()) {
            IReceiver receiver = (IReceiver) recIt.next();
            Map<String, Object> receiverMap = new HashMap<String, Object>();
            receiverMap.put("name", receiver.getName());
            receiverMap.put("class", receiver.getClass().getName());
            receiverMap.put("messagesReceived", receiver.getMessagesReceived());
            receiverMap.put("messagesRetried", receiver.getMessagesRetried());
            if (receiver instanceof IReceiverStatistics) {
                IReceiverStatistics statReceiver = (IReceiverStatistics) receiver;
                Iterator<?> statsIter;
                statsIter = statReceiver.getProcessStatisticsIterator();
                if (statsIter != null) {
                    ArrayList<Map<String, Object>> procStatsMap = new ArrayList<Map<String, Object>>();
                    // procStatsXML.addSubElement(statisticsKeeperToXmlBuilder(statReceiver.getResponseSizeStatistics(), "stat"));
                    while (statsIter.hasNext()) {
                        StatisticsKeeper pstat = (StatisticsKeeper) statsIter.next();
                        procStatsMap.add(statisticsKeeperToMapBuilder(pstat));
                    }
                    receiverMap.put("processing", procStatsMap);
                }
                statsIter = statReceiver.getIdleStatisticsIterator();
                if (statsIter != null) {
                    ArrayList<Map<String, Object>> idleStatsMap = new ArrayList<Map<String, Object>>();
                    while (statsIter.hasNext()) {
                        StatisticsKeeper pstat = (StatisticsKeeper) statsIter.next();
                        idleStatsMap.add(statisticsKeeperToMapBuilder(pstat));
                    }
                    receiverMap.put("idle", idleStatsMap);
                }
                receivers.add(receiverMap);
            }
        }
    }
    statisticsMap.put("receivers", receivers);
    Map<String, Object> tmp = new HashMap<String, Object>();
    StatisticsKeeperToXml handler = new StatisticsKeeperToXml(tmp);
    handler.configure();
    Object handle = handler.start(null, null, null);
    try {
        adapter.getPipeLine().iterateOverStatistics(handler, tmp, HasStatistics.STATISTICS_ACTION_FULL);
        statisticsMap.put("durationPerPipe", tmp.get("pipeStats"));
        statisticsMap.put("sizePerPipe", tmp.get("sizeStats"));
    } catch (SenderException e) {
        log.error(e);
    } finally {
        handler.end(handle);
    }
    return Response.status(Response.Status.CREATED).entity(statisticsMap).build();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Adapter(nl.nn.adapterframework.core.Adapter) IReceiver(nl.nn.adapterframework.core.IReceiver) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) IReceiverStatistics(nl.nn.adapterframework.core.IReceiverStatistics) SenderException(nl.nn.adapterframework.core.SenderException) HashMap(java.util.HashMap) Map(java.util.Map) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with Adapter

use of nl.nn.adapterframework.core.Adapter in project iaf by ibissource.

the class ShowConfigurationStatus method getAdapters.

@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/adapters")
@Produces(MediaType.APPLICATION_JSON)
public Response getAdapters(@QueryParam("expanded") String expanded, @QueryParam("showPendingMsgCount") boolean showPendingMsgCount) throws ApiException {
    initBase(servletConfig);
    if (ibisManager == null) {
        throw new ApiException("Config not found!");
    }
    Map<String, Object> adapterList = new HashMap<String, Object>();
    List<IAdapter> registeredAdapters = ibisManager.getRegisteredAdapters();
    for (Iterator<IAdapter> adapterIt = registeredAdapters.iterator(); adapterIt.hasNext(); ) {
        Adapter adapter = (Adapter) adapterIt.next();
        Map<String, Object> adapterInfo = mapAdapter(adapter);
        if (expanded != null && !expanded.isEmpty()) {
            if (expanded.equalsIgnoreCase("all")) {
                adapterInfo.put("receivers", mapAdapterReceivers(adapter, showPendingMsgCount));
                adapterInfo.put("pipes", mapAdapterPipes(adapter));
                adapterInfo.put("messages", mapAdapterMessages(adapter));
            } else if (expanded.equalsIgnoreCase("receivers")) {
                adapterInfo.put("receivers", mapAdapterReceivers(adapter, showPendingMsgCount));
            } else if (expanded.equalsIgnoreCase("pipes")) {
                adapterInfo.put("pipes", mapAdapterPipes(adapter));
            } else if (expanded.equalsIgnoreCase("messages")) {
                adapterInfo.put("messages", mapAdapterMessages(adapter));
            } else {
                throw new ApiException("Invalid value [" + expanded + "] for parameter expanded supplied!");
            }
        }
        adapterList.put((String) adapterInfo.get("name"), adapterInfo);
    }
    Response.ResponseBuilder response = null;
    // Calculate the ETag on last modified date of user resource
    EntityTag etag = new EntityTag(adapterList.hashCode() + "");
    // Verify if it matched with etag available in http request
    response = request.evaluatePreconditions(etag);
    // If ETag matches the response will be non-null;
    if (response != null) {
        return response.tag(etag).build();
    }
    response = Response.status(Response.Status.CREATED).entity(adapterList).tag(etag);
    return response.build();
}
Also used : Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) EntityTag(javax.ws.rs.core.EntityTag) IAdapter(nl.nn.adapterframework.core.IAdapter) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with Adapter

use of nl.nn.adapterframework.core.Adapter in project iaf by ibissource.

the class ShowConfigurationStatus method getAdapterPipes.

@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/adapters/{name}/pipes")
@Produces(MediaType.APPLICATION_JSON)
public Response getAdapterPipes(@PathParam("name") String adapterName) throws ApiException {
    initBase(servletConfig);
    Adapter adapter = (Adapter) ibisManager.getRegisteredAdapter(adapterName);
    if (adapter == null) {
        throw new ApiException("Adapter not found!");
    }
    ArrayList<Object> adapterInfo = mapAdapterPipes(adapter);
    if (adapterInfo == null)
        throw new ApiException("Adapter not configured!");
    return Response.status(Response.Status.CREATED).entity(adapterInfo).build();
}
Also used : Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with Adapter

use of nl.nn.adapterframework.core.Adapter in project iaf by ibissource.

the class SlotIdRecord method getSlotmap.

private Map<String, SlotIdRecord> getSlotmap() {
    Map<String, SlotIdRecord> slotmap = new HashMap<String, SlotIdRecord>();
    for (IAdapter iAdapter : ibisManager.getRegisteredAdapters()) {
        Adapter adapter = (Adapter) iAdapter;
        for (Iterator<?> receiverIt = adapter.getReceiverIterator(); receiverIt.hasNext(); ) {
            ReceiverBase receiver = (ReceiverBase) receiverIt.next();
            ITransactionalStorage errorStorage = receiver.getErrorStorage();
            if (errorStorage != null) {
                String slotId = errorStorage.getSlotId();
                if (StringUtils.isNotEmpty(slotId)) {
                    SlotIdRecord sir = new SlotIdRecord(adapter.getName(), receiver.getName(), null);
                    String type = errorStorage.getType();
                    slotmap.put(type + "/" + slotId, sir);
                }
            }
            ITransactionalStorage messageLog = receiver.getMessageLog();
            if (messageLog != null) {
                String slotId = messageLog.getSlotId();
                if (StringUtils.isNotEmpty(slotId)) {
                    SlotIdRecord sir = new SlotIdRecord(adapter.getName(), receiver.getName(), null);
                    String type = messageLog.getType();
                    slotmap.put(type + "/" + slotId, sir);
                }
            }
        }
        PipeLine pipeline = adapter.getPipeLine();
        if (pipeline != null) {
            for (int i = 0; i < pipeline.getPipeLineSize(); i++) {
                IPipe pipe = pipeline.getPipe(i);
                if (pipe instanceof MessageSendingPipe) {
                    MessageSendingPipe msp = (MessageSendingPipe) pipe;
                    ITransactionalStorage messageLog = msp.getMessageLog();
                    if (messageLog != null) {
                        String slotId = messageLog.getSlotId();
                        if (StringUtils.isNotEmpty(slotId)) {
                            SlotIdRecord sir = new SlotIdRecord(adapter.getName(), null, msp.getName());
                            String type = messageLog.getType();
                            slotmap.put(type + "/" + slotId, sir);
                            slotmap.put(slotId, sir);
                        }
                    }
                }
            }
        }
    }
    return slotmap;
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) MessageSendingPipe(nl.nn.adapterframework.pipes.MessageSendingPipe) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) PipeLine(nl.nn.adapterframework.core.PipeLine) IAdapter(nl.nn.adapterframework.core.IAdapter) IPipe(nl.nn.adapterframework.core.IPipe)

Example 5 with Adapter

use of nl.nn.adapterframework.core.Adapter in project iaf by ibissource.

the class Webservices method getLogDirectory.

@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/webservices")
@Relation("webservices")
@Produces(MediaType.APPLICATION_JSON)
public Response getLogDirectory() throws ApiException {
    initBase(servletConfig);
    Map<String, Object> returnMap = new HashMap<String, Object>();
    List<Map<String, Object>> webServices = new ArrayList<Map<String, Object>>();
    for (IAdapter a : ibisManager.getRegisteredAdapters()) {
        Adapter adapter = (Adapter) a;
        Iterator<IReceiver> recIt = adapter.getReceiverIterator();
        while (recIt.hasNext()) {
            IReceiver receiver = recIt.next();
            if (receiver instanceof ReceiverBase) {
                ReceiverBase rb = (ReceiverBase) receiver;
                IListener listener = rb.getListener();
                if (listener instanceof RestListener) {
                    RestListener rl = (RestListener) listener;
                    if (rl.isView()) {
                        Map<String, Object> service = new HashMap<String, Object>(2);
                        service.put("name", rb.getName());
                        service.put("uriPattern", rl.getUriPattern());
                        webServices.add(service);
                    }
                }
            }
        }
    }
    returnMap.put("services", webServices);
    List<Map<String, Object>> wsdls = new ArrayList<Map<String, Object>>();
    for (IAdapter a : ibisManager.getRegisteredAdapters()) {
        Map<String, Object> wsdlMap = new HashMap<String, Object>(2);
        try {
            Adapter adapter = (Adapter) a;
            Wsdl wsdl = new Wsdl(adapter.getPipeLine());
            wsdlMap.put("name", wsdl.getName());
            wsdlMap.put("extention", getWsdlExtention());
        } catch (Exception e) {
            wsdlMap.put("name", a.getName());
            if (e.getMessage() != null) {
                wsdlMap.put("error", e.getMessage());
            } else {
                wsdlMap.put("error", e.toString());
            }
        }
        wsdls.add(wsdlMap);
    }
    returnMap.put("wsdls", wsdls);
    return Response.status(Response.Status.OK).entity(returnMap).build();
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) HashMap(java.util.HashMap) IListener(nl.nn.adapterframework.core.IListener) ArrayList(java.util.ArrayList) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) Wsdl(nl.nn.adapterframework.soap.Wsdl) RestListener(nl.nn.adapterframework.http.RestListener) IReceiver(nl.nn.adapterframework.core.IReceiver) HashMap(java.util.HashMap) Map(java.util.Map) IAdapter(nl.nn.adapterframework.core.IAdapter) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Adapter (nl.nn.adapterframework.core.Adapter)31 IAdapter (nl.nn.adapterframework.core.IAdapter)24 Iterator (java.util.Iterator)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 ReceiverBase (nl.nn.adapterframework.receivers.ReceiverBase)10 RolesAllowed (javax.annotation.security.RolesAllowed)9 IReceiver (nl.nn.adapterframework.core.IReceiver)9 GET (javax.ws.rs.GET)8 PipeLine (nl.nn.adapterframework.core.PipeLine)8 ArrayList (java.util.ArrayList)7 Configuration (nl.nn.adapterframework.configuration.Configuration)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)5 IListener (nl.nn.adapterframework.core.IListener)5 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)5 ServletException (javax.servlet.ServletException)4 Response (javax.ws.rs.core.Response)4 IPipe (nl.nn.adapterframework.core.IPipe)4