use of org.opennms.netmgt.model.AttributeStatisticVisitorWithResults in project opennms by OpenNMS.
the class ReportDefinitionTest method testBogusReportClass.
@SuppressWarnings("unchecked")
public void testBogusReportClass() throws Exception {
// Not replaying anything, but need to do it before verifyAll() happens
m_mocks.replayAll();
ReportDefinition def = new ReportDefinition();
Class<? extends AttributeStatisticVisitorWithResults> clazz = (Class<? extends AttributeStatisticVisitorWithResults>) Class.forName("java.lang.String");
ThrowableAnticipator ta = new ThrowableAnticipator();
ta.anticipate(new IllegalArgumentException(ThrowableAnticipator.IGNORE_MESSAGE));
try {
def.setReportClass(clazz);
} catch (Throwable t) {
ta.throwableReceived(t);
}
ta.verifyAnticipated();
}
use of org.opennms.netmgt.model.AttributeStatisticVisitorWithResults 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;
}
use of org.opennms.netmgt.model.AttributeStatisticVisitorWithResults in project opennms by OpenNMS.
the class ReportDefinition method createReport.
/**
* <p>createReport</p>
*
* @param resourceDao a {@link org.opennms.netmgt.dao.api.ResourceDao} object.
* @param fetchStrategy an object.
* @param filterDao a {@link org.opennms.netmgt.filter.api.FilterDao} object.
* @return a {@link org.opennms.netmgt.statsd.ReportInstance} object.
* @throws java.lang.Exception if any.
*/
public ReportInstance createReport(NodeDao nodeDao, ResourceDao resourceDao, MeasurementFetchStrategy fetchStrategy, FilterDao filterDao) throws Exception {
Assert.notNull(resourceDao, "resourceDao argument must not be null");
Assert.notNull(fetchStrategy, "fetchStrategy argument must not be null");
Assert.notNull(filterDao, "filterDao argument must not be null");
AttributeStatisticVisitorWithResults visitor;
try {
visitor = getReportClass().newInstance();
} catch (Throwable e) {
throw new DataAccessResourceFailureException("Could not instantiate visitor object; nested exception: " + e, e);
}
ReportInstance report;
if (getReport().getPackage().getFilter() != null) {
FilteredReportInstance thisReport = new FilteredReportInstance(visitor);
thisReport.setNodeDao(nodeDao);
thisReport.setResourceDao(resourceDao);
thisReport.setFetchStrategy(fetchStrategy);
thisReport.setFilterDao(filterDao);
thisReport.setFilter(getReport().getPackage().getFilter());
report = thisReport;
} else {
UnfilteredReportInstance thisReport = new UnfilteredReportInstance(visitor);
thisReport.setResourceDao(resourceDao);
thisReport.setFetchStrategy(fetchStrategy);
report = thisReport;
}
report.setReportDefinition(this);
report.setStartTime(getRelativeTime().getStart().getTime());
report.setEndTime(getRelativeTime().getEnd().getTime());
report.setCount(getCount());
report.setConsolidationFunction(getConsolidationFunction());
report.setResourceTypeMatch(getResourceTypeMatch());
report.setAttributeMatch(getAttributeMatch());
report.setResourceAttributeKey(m_resourceAttributeKey);
report.setResourceAttributeValueMatch(m_resourceAttributeValueMatch);
if (report instanceof InitializingBean) {
((InitializingBean) report).afterPropertiesSet();
}
return report;
}
Aggregations