Search in sources :

Example 1 with StatisticsReportData

use of org.opennms.netmgt.model.StatisticsReportData in project opennms by OpenNMS.

the class DefaultStatisticsReportServiceTest method testDatumWithNonExistentResource.

@Test
public void testDatumWithNonExistentResource() {
    StatisticsReport report = new StatisticsReport();
    report.setId(1);
    StatisticsReportData datum = new StatisticsReportData();
    ResourceReference resourceRef = new ResourceReference();
    resourceRef.setId(1);
    resourceRef.setResourceId("node[1].interfaceSnmp[en0]");
    datum.setId(1);
    datum.setResource(resourceRef);
    datum.setReport(report);
    datum.setValue(0.1d);
    report.addData(datum);
    StatisticsReportCommand command = new StatisticsReportCommand();
    command.setId(report.getId());
    BindException errors = new BindException(command, "");
    expect(m_statisticsReportDao.load(report.getId())).andReturn(report);
    m_statisticsReportDao.initialize(report);
    m_statisticsReportDao.initialize(report.getData());
    expect(m_resourceDao.getResourceById(ResourceId.fromString(resourceRef.getResourceId()))).andReturn(null);
    m_mocks.replayAll();
    StatisticsReportModel model = m_service.getReport(command, errors);
    assertNotNull("model should not be null", model);
    assertNotNull("model.getData() should not be null", model.getData());
    SortedSet<Datum> data = model.getData();
    assertEquals("data size", 1, data.size());
    Datum d = data.first();
    assertNotNull("first datum should not be null", d);
    assertNull("first datum resource should be null", d.getResource());
}
Also used : Datum(org.opennms.web.svclayer.model.StatisticsReportModel.Datum) StatisticsReport(org.opennms.netmgt.model.StatisticsReport) StatisticsReportData(org.opennms.netmgt.model.StatisticsReportData) BindException(org.springframework.validation.BindException) ResourceReference(org.opennms.netmgt.model.ResourceReference) StatisticsReportCommand(org.opennms.web.svclayer.model.StatisticsReportCommand) StatisticsReportModel(org.opennms.web.svclayer.model.StatisticsReportModel) Test(org.junit.Test)

Example 2 with StatisticsReportData

use of org.opennms.netmgt.model.StatisticsReportData in project opennms by OpenNMS.

the class DatabaseReportPersister method persist.

/**
 * {@inheritDoc}
 */
@Override
public void persist(ReportInstance report) {
    StatisticsReport dbReport = new StatisticsReport();
    dbReport.setName(report.getName());
    dbReport.setDescription(report.getDescription());
    dbReport.setStartDate(new Date(report.getStartTime()));
    dbReport.setEndDate(new Date(report.getEndTime()));
    dbReport.setJobStartedDate(report.getJobStartedDate());
    dbReport.setJobCompletedDate(report.getJobCompletedDate());
    dbReport.setPurgeDate(new Date(report.getJobCompletedDate().getTime() + report.getRetainInterval()));
    for (AttributeStatistic stat : report.getResults()) {
        ResourceReference resource = getResourceReference(stat.getAttribute().getResource().getId().toString());
        StatisticsReportData data = new StatisticsReportData();
        data.setResource(resource);
        data.setReport(dbReport);
        data.setValue(stat.getStatistic());
        dbReport.addData(data);
        LOG.debug("Adding {}", data);
    }
    if (dbReport.getData().isEmpty()) {
        LOG.warn("Cannot store {} because it doesn't contain data. Probably all the metrics are NaN for the report period.", report);
    } else {
        m_statisticsReportDao.save(dbReport);
    }
}
Also used : StatisticsReport(org.opennms.netmgt.model.StatisticsReport) AttributeStatistic(org.opennms.netmgt.model.AttributeStatistic) StatisticsReportData(org.opennms.netmgt.model.StatisticsReportData) ResourceReference(org.opennms.netmgt.model.ResourceReference) Date(java.util.Date)

Example 3 with StatisticsReportData

use of org.opennms.netmgt.model.StatisticsReportData in project opennms by OpenNMS.

the class StatisticsReportsIT method hasReportLinkThatMatchDescription.

@Test
public void hasReportLinkThatMatchDescription() throws Exception {
    Date startOfTest = new Date();
    HibernateDaoFactory daoFactory = new HibernateDaoFactory(getPostgresService());
    ResourceReferenceDao resourceReferenceDao = daoFactory.getDao(ResourceReferenceDaoHibernate.class);
    StatisticsReportDao statisticsReportDao = daoFactory.getDao(StatisticsReportDaoHibernate.class);
    StatisticsReport report = new StatisticsReport();
    report.setName("Top10_Response_Hourly");
    report.setDescription("Hourly Top 10 responses across all nodes");
    report.setStartDate(new Date());
    report.setEndDate(new Date());
    report.setJobStartedDate(new Date());
    report.setJobCompletedDate(new Date());
    report.setPurgeDate(new Date());
    ResourceReference resource = new ResourceReference();
    resource.setResourceId("node1");
    resourceReferenceDao.save(resource);
    StatisticsReportData data = new StatisticsReportData();
    data.setReport(report);
    data.setResource(resource);
    data.setValue(4.0);
    report.addData(data);
    statisticsReportDao.save(report);
    await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.findMatchingCallable(statisticsReportDao, new CriteriaBuilder(StatisticsReport.class).ge("startDate", startOfTest).toCriteria()), notNullValue());
    m_driver.navigate().refresh();
    assertNotNull(findElementByLink("Hourly Top 10 responses across all nodes"));
}
Also used : StatisticsReportDao(org.opennms.netmgt.dao.api.StatisticsReportDao) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) HibernateDaoFactory(org.opennms.smoketest.utils.HibernateDaoFactory) StatisticsReport(org.opennms.netmgt.model.StatisticsReport) StatisticsReportData(org.opennms.netmgt.model.StatisticsReportData) ResourceReferenceDao(org.opennms.netmgt.dao.api.ResourceReferenceDao) ResourceReference(org.opennms.netmgt.model.ResourceReference) Date(java.util.Date) Test(org.junit.Test)

Example 4 with StatisticsReportData

use of org.opennms.netmgt.model.StatisticsReportData in project opennms by OpenNMS.

the class StatisticsReportDaoIT method testSave.

@Test
@Transactional
public void testSave() throws Exception {
    StatisticsReport report = new StatisticsReport();
    report.setName("A Mighty Fine Report");
    report.setDescription("hello!");
    report.setStartDate(new Date());
    report.setEndDate(new Date());
    report.setJobStartedDate(new Date());
    report.setJobCompletedDate(new Date());
    report.setPurgeDate(new Date());
    {
        ResourceReference resource = new ResourceReference();
        resource.setResourceId("foo");
        m_resourceReferenceDao.save(resource);
        StatisticsReportData data = new StatisticsReportData();
        data.setReport(report);
        data.setResource(resource);
        data.setValue(0.0);
        report.addData(data);
    }
    {
        ResourceReference resource = new ResourceReference();
        resource.setResourceId("bar");
        m_resourceReferenceDao.save(resource);
        StatisticsReportData data = new StatisticsReportData();
        data.setReport(report);
        data.setResource(resource);
        data.setValue(0.0);
        report.addData(data);
    }
    m_statisticsReportDao.save(report);
}
Also used : StatisticsReport(org.opennms.netmgt.model.StatisticsReport) StatisticsReportData(org.opennms.netmgt.model.StatisticsReportData) ResourceReference(org.opennms.netmgt.model.ResourceReference) Date(java.util.Date) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with StatisticsReportData

use of org.opennms.netmgt.model.StatisticsReportData in project opennms by OpenNMS.

the class DefaultStatisticsReportService method getReport.

/**
 * {@inheritDoc}
 */
@Override
public StatisticsReportModel getReport(StatisticsReportCommand command, BindingResult errors) {
    StatisticsReportModel model = new StatisticsReportModel();
    model.setErrors(errors);
    if (errors.hasErrors()) {
        return model;
    }
    Assert.notNull(command.getId(), "id property on command object cannot be null");
    StatisticsReport report = m_statisticsReportDao.load(command.getId());
    model.setReport(report);
    m_statisticsReportDao.initialize(report);
    final Set<StatisticsReportData> data = report.getData();
    m_statisticsReportDao.initialize(data);
    for (StatisticsReportData reportDatum : data) {
        Datum d = new Datum();
        d.setValue(reportDatum.getValue());
        OnmsResource resource = m_resourceDao.getResourceById(ResourceId.fromString(reportDatum.getResourceId()));
        if (resource == null) {
            LOG.warn("Could not find resource for statistics report: {}", reportDatum.getResourceId());
        } else {
            d.setResource(resource);
        }
        model.addData(d);
    }
    return model;
}
Also used : Datum(org.opennms.web.svclayer.model.StatisticsReportModel.Datum) OnmsResource(org.opennms.netmgt.model.OnmsResource) StatisticsReport(org.opennms.netmgt.model.StatisticsReport) StatisticsReportData(org.opennms.netmgt.model.StatisticsReportData) StatisticsReportModel(org.opennms.web.svclayer.model.StatisticsReportModel)

Aggregations

StatisticsReport (org.opennms.netmgt.model.StatisticsReport)5 StatisticsReportData (org.opennms.netmgt.model.StatisticsReportData)5 ResourceReference (org.opennms.netmgt.model.ResourceReference)4 Date (java.util.Date)3 Test (org.junit.Test)3 StatisticsReportModel (org.opennms.web.svclayer.model.StatisticsReportModel)2 Datum (org.opennms.web.svclayer.model.StatisticsReportModel.Datum)2 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)1 ResourceReferenceDao (org.opennms.netmgt.dao.api.ResourceReferenceDao)1 StatisticsReportDao (org.opennms.netmgt.dao.api.StatisticsReportDao)1 AttributeStatistic (org.opennms.netmgt.model.AttributeStatistic)1 OnmsResource (org.opennms.netmgt.model.OnmsResource)1 HibernateDaoFactory (org.opennms.smoketest.utils.HibernateDaoFactory)1 StatisticsReportCommand (org.opennms.web.svclayer.model.StatisticsReportCommand)1 Transactional (org.springframework.transaction.annotation.Transactional)1 BindException (org.springframework.validation.BindException)1