Search in sources :

Example 1 with LightweightMeasurementSet

use of org.opennms.nrtg.api.model.LightweightMeasurementSet 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)

Aggregations

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