Search in sources :

Example 1 with CollectionFailed

use of org.opennms.netmgt.collection.api.CollectionFailed in project opennms by OpenNMS.

the class CollectableService method doCollection.

/**
 * Perform data collection.
 */
private void doCollection() throws CollectionException {
    LOG.info("run: starting new collection for {}/{}/{}/{}", m_nodeId, getHostAddress(), m_spec.getServiceName(), m_spec.getPackageName());
    CollectionSet result = null;
    try {
        result = m_spec.collect(m_agent);
        if (result != null) {
            Collectd.instrumentation().beginPersistingServiceData(m_spec.getPackageName(), m_nodeId, getHostAddress(), m_spec.getServiceName());
            try {
                CollectionSetVisitor persister = m_persisterFactory.createPersister(m_params, m_repository, result.ignorePersist(), false, false);
                if (Boolean.getBoolean(USE_COLLECTION_START_TIME_SYS_PROP)) {
                    final ConstantTimeKeeper timeKeeper = new ConstantTimeKeeper(new Date(m_lastScheduledCollectionTime));
                    // Wrap the persister visitor such that calls to CollectionResource.getTimeKeeper() return the given timeKeeper
                    persister = wrapResourcesWithTimekeeper(persister, timeKeeper);
                }
                result.visit(persister);
            } finally {
                Collectd.instrumentation().endPersistingServiceData(m_spec.getPackageName(), m_nodeId, getHostAddress(), m_spec.getServiceName());
            }
            /*
                         * Do the thresholding; this could be made more generic (listeners being passed the collectionset), but frankly, why bother?
                         * The first person who actually needs to configure that sort of thing on the fly can code it up.
                         */
            if (m_thresholdVisitor != null) {
                if (m_thresholdVisitor.isNodeInOutage()) {
                    LOG.info("run: the threshold processing will be skipped because the node {} is on a scheduled outage.", m_nodeId);
                } else if (m_thresholdVisitor.hasThresholds()) {
                    // Required to reinitialize the counters.
                    m_thresholdVisitor.setCounterReset(result.ignorePersist());
                    result.visit(m_thresholdVisitor);
                }
            }
            if (!CollectionStatus.SUCCEEDED.equals(result.getStatus())) {
                throw new CollectionFailed(result.getStatus());
            }
        }
    } catch (CollectionException e) {
        LOG.warn("run: failed collection for {}/{}/{}/{}", m_nodeId, getHostAddress(), m_spec.getServiceName(), m_spec.getPackageName());
        throw e;
    } catch (Throwable t) {
        LOG.warn("run: failed collection for {}/{}/{}/{}", m_nodeId, getHostAddress(), m_spec.getServiceName(), m_spec.getPackageName());
        throw new CollectionException("An undeclared throwable was caught during data collection for interface " + m_nodeId + "/" + getHostAddress() + "/" + m_spec.getServiceName(), t);
    }
    LOG.info("run: finished collection for {}/{}/{}/{}", m_nodeId, getHostAddress(), m_spec.getServiceName(), m_spec.getPackageName());
}
Also used : CollectionException(org.opennms.netmgt.collection.api.CollectionException) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) CollectionFailed(org.opennms.netmgt.collection.api.CollectionFailed) ConstantTimeKeeper(org.opennms.netmgt.collection.support.ConstantTimeKeeper) Date(java.util.Date) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet)

Aggregations

Date (java.util.Date)1 CollectionException (org.opennms.netmgt.collection.api.CollectionException)1 CollectionFailed (org.opennms.netmgt.collection.api.CollectionFailed)1 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)1 CollectionSetVisitor (org.opennms.netmgt.collection.api.CollectionSetVisitor)1 ConstantTimeKeeper (org.opennms.netmgt.collection.support.ConstantTimeKeeper)1