Search in sources :

Example 1 with StatsdPackage

use of org.opennms.netmgt.config.statsd.model.StatsdPackage in project opennms by OpenNMS.

the class ReportDefinitionBuilder method buildReportDefinitions.

/**
 * Builds and schedules all reports enabled in the statsd-configuration.
 * This method has the capability to throw a ton of exceptions, just generically throwing <code>Exception</code>
 *
 * @return a <code>Collection</code> of enabled reports from the statsd-configuration.
 * @throws java.lang.Exception if any.
 */
public Collection<ReportDefinition> buildReportDefinitions() throws Exception {
    Set<ReportDefinition> reportDefinitions = new HashSet<>();
    for (StatsdPackage pkg : m_statsdConfigDao.getPackages()) {
        for (PackageReport packageReport : pkg.getReports()) {
            Report report = packageReport.getReport();
            if (!packageReport.isEnabled()) {
                LOG.debug("skipping report '{}' in package '{}' because the report is not enabled", report.getName(), pkg.getName());
                continue;
            }
            Class<? extends AttributeStatisticVisitorWithResults> clazz;
            try {
                clazz = createClassForReport(report);
            } catch (ClassNotFoundException e) {
                throw new DataAccessResourceFailureException("Could not find class '" + report.getClassName() + "'; nested exception: " + e, e);
            }
            Assert.isAssignable(AttributeStatisticVisitorWithResults.class, clazz, "the class specified by class-name in the '" + report.getName() + "' report does not implement the interface " + AttributeStatisticVisitorWithResults.class.getName() + "; ");
            ReportDefinition reportDef = new ReportDefinition();
            reportDef.setReport(packageReport);
            reportDef.setReportClass(clazz);
            BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(reportDef);
            try {
                bw.setPropertyValues(packageReport.getAggregateParameters());
            } catch (BeansException e) {
                LOG.error("Could not set properties on report definition: {}", e.getMessage(), e);
            }
            reportDef.afterPropertiesSet();
            reportDefinitions.add(reportDef);
        }
    }
    return reportDefinitions;
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) PackageReport(org.opennms.netmgt.config.statsd.model.PackageReport) Report(org.opennms.netmgt.config.statsd.model.Report) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) AttributeStatisticVisitorWithResults(org.opennms.netmgt.model.AttributeStatisticVisitorWithResults) PackageReport(org.opennms.netmgt.config.statsd.model.PackageReport) StatsdPackage(org.opennms.netmgt.config.statsd.model.StatsdPackage) HashSet(java.util.HashSet) BeansException(org.springframework.beans.BeansException)

Example 2 with StatsdPackage

use of org.opennms.netmgt.config.statsd.model.StatsdPackage in project opennms by OpenNMS.

the class ReportDefinitionTest method createPackageReport.

private static PackageReport createPackageReport() {
    PackageReport packageReport;
    packageReport = new PackageReport();
    packageReport.setDescription("a package!");
    packageReport.setEnabled(true);
    packageReport.setPackage(new StatsdPackage());
    packageReport.setReport(null);
    packageReport.setRetainInterval(Long.valueOf(86400 * 1000));
    packageReport.setSchedule("hmm");
    return packageReport;
}
Also used : PackageReport(org.opennms.netmgt.config.statsd.model.PackageReport) StatsdPackage(org.opennms.netmgt.config.statsd.model.StatsdPackage)

Aggregations

PackageReport (org.opennms.netmgt.config.statsd.model.PackageReport)2 StatsdPackage (org.opennms.netmgt.config.statsd.model.StatsdPackage)2 HashSet (java.util.HashSet)1 Report (org.opennms.netmgt.config.statsd.model.Report)1 AttributeStatisticVisitorWithResults (org.opennms.netmgt.model.AttributeStatisticVisitorWithResults)1 BeanWrapper (org.springframework.beans.BeanWrapper)1 BeansException (org.springframework.beans.BeansException)1 DataAccessResourceFailureException (org.springframework.dao.DataAccessResourceFailureException)1