Search in sources :

Example 1 with MeasurementSet

use of org.opennms.nrtg.api.model.MeasurementSet in project opennms by OpenNMS.

the class CollectionJobListener method onMessage.

@Override
public void onMessage(Message message) {
    try {
        // FIXME abstraction between technology and job handling is missing
        CollectionJob collectionJob = (CollectionJob) simpleMessageConverter.fromMessage(message);
        collectionJob = protocolCollectorRegistry.getProtocolCollector(collectionJob.getService()).collect(collectionJob);
        Date finishedTimestamp = new Date();
        collectionJob.setFinishedTimestamp(finishedTimestamp);
        Map<String, MeasurementSet> measurementSets = collectionJob.getMeasurementSetsByDestination();
        int val = counter.incrementAndGet();
        if (val % 1000 == 0) {
            logger.debug("processed job #{}, {} measurement set(s)", val, measurementSets.size());
        } else {
            logger.trace("processed job #{}, {} measurement set(s)", val, measurementSets.size());
        }
        for (String destinationString : measurementSets.keySet()) {
            jmsTemplate.convertAndSend(destinationString, measurementSets.get(destinationString));
            logger.info("** sending msg '{}' to '{}'", measurementSets.get(destinationString), destinationString);
        }
        LightweightMeasurementSet errorMeasurementSet = new LightweightMeasurementSet(collectionJob.getNodeId(), collectionJob.getService(), collectionJob.getNetInterface(), collectionJob.getFinishedTimestamp());
        for (String metricId : collectionJob.getAllMetrics()) {
            if (collectionJob.getMetricValue(metricId) == null) {
                errorMeasurementSet.addMeasurement(metricId, collectionJob.getMetricType(metricId), null, collectionJob.getOnmsLogicMetricId(metricId));
            }
            logger.trace("collected metric of job #{}='{}'", counter + ": " + metricId, collectionJob.getMetricValue(metricId));
        }
        if (errorMeasurementSet.getMeasurements().size() > 0) {
            logger.warn("result set of job #{} contains {} null values", counter, errorMeasurementSet.getMeasurements().size());
            jmsTemplate.convertAndSend("error", errorMeasurementSet);
            logger.trace("** sending to 'error'");
        }
    } catch (JMSException ex) {
        logger.error(ex.getMessage());
    // FIXME react, don't continue
    } catch (MessageConversionException ex) {
        logger.error(ex.getMessage());
    // FIXME react, don't continue
    }
}
Also used : MessageConversionException(org.springframework.jms.support.converter.MessageConversionException) CollectionJob(org.opennms.nrtg.api.model.CollectionJob) JMSException(javax.jms.JMSException) Date(java.util.Date) MeasurementSet(org.opennms.nrtg.api.model.MeasurementSet) LightweightMeasurementSet(org.opennms.nrtg.api.model.LightweightMeasurementSet) LightweightMeasurementSet(org.opennms.nrtg.api.model.LightweightMeasurementSet)

Example 2 with MeasurementSet

use of org.opennms.nrtg.api.model.MeasurementSet in project opennms by OpenNMS.

the class NrtController method getMeasurementSetsForDestination.

/**
     * Will be called by the JS-Graphing-Frontend as http/GET Get Measurements from NrtBroker, transform them into Json and return
     * them to the JS-Graphing-Frontend
     *
     * @param nrtCollectionTaskId
     * @return Json Representation of MeasurementeSets for the given nrtCollectionTaskId
     */
public String getMeasurementSetsForDestination(String nrtCollectionTaskId) {
    List<MeasurementSet> measurementSets = m_nrtBroker.receiveMeasurementSets(nrtCollectionTaskId);
    StringBuffer buffer = new StringBuffer();
    for (MeasurementSet measurementSet : measurementSets) {
        if (buffer.length() > 0) {
            buffer.append(", ");
        }
        buffer.append(measurementSet.toString());
    }
    return "{\"measurement_sets\":[" + buffer.toString() + "]}";
}
Also used : MeasurementSet(org.opennms.nrtg.api.model.MeasurementSet)

Example 3 with MeasurementSet

use of org.opennms.nrtg.api.model.MeasurementSet in project opennms by OpenNMS.

the class NrtBrokerJms method receiveMeasurementSets.

@Override
public List<MeasurementSet> receiveMeasurementSets(String nrtCollectionTaskId) {
    List<MeasurementSet> result = new ArrayList<MeasurementSet>();
    m_jmsTemplate.setReceiveTimeout(125);
    Message message = m_jmsTemplate.receive(nrtCollectionTaskId);
    while (message != null) {
        MeasurementSet measurementSet;
        try {
            measurementSet = (MeasurementSet) simpleMessageConverter.fromMessage(message);
            result.add(measurementSet);
        } catch (JMSException ex) {
            logger.error("Error receiving messages", ex);
            return result;
        } catch (MessageConversionException ex) {
            logger.error("Error converting messages", ex);
            return result;
        }
        message = m_jmsTemplate.receive(nrtCollectionTaskId);
    }
    return result;
}
Also used : MessageConversionException(org.springframework.jms.support.converter.MessageConversionException) Message(javax.jms.Message) ArrayList(java.util.ArrayList) JMSException(javax.jms.JMSException) MeasurementSet(org.opennms.nrtg.api.model.MeasurementSet)

Aggregations

MeasurementSet (org.opennms.nrtg.api.model.MeasurementSet)3 JMSException (javax.jms.JMSException)2 MessageConversionException (org.springframework.jms.support.converter.MessageConversionException)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Message (javax.jms.Message)1 CollectionJob (org.opennms.nrtg.api.model.CollectionJob)1 LightweightMeasurementSet (org.opennms.nrtg.api.model.LightweightMeasurementSet)1