Search in sources :

Example 6 with GeolocationQuery

use of org.opennms.features.geolocation.api.GeolocationQuery in project opennms by OpenNMS.

the class GeolocationRestService method toQuery.

private static GeolocationQuery toQuery(GeolocationQueryDTO queryDTO) {
    if (queryDTO != null) {
        GeolocationQuery query = new GeolocationQuery();
        if (queryDTO.getSeverityFilter() != null) {
            query.setSeverity(getEnum(queryDTO.getSeverityFilter(), GeolocationSeverity.values()));
        }
        if (queryDTO.getStrategy() != null) {
            query.setStatusCalculationStrategy(getEnum(queryDTO.getStrategy(), StatusCalculationStrategy.values()));
        }
        query.setIncludeAcknowledgedAlarms(queryDTO.isIncludeAcknowledgedAlarms());
        return query;
    }
    return null;
}
Also used : GeolocationQuery(org.opennms.features.geolocation.api.GeolocationQuery)

Example 7 with GeolocationQuery

use of org.opennms.features.geolocation.api.GeolocationQuery in project opennms by OpenNMS.

the class DefaultGeolocationServiceIT method verifyMerging.

@Test
@Transactional
public void verifyMerging() {
    // Set coordinates for all
    nodeDao.findAll().forEach(n -> {
        n.getAssetRecord().getGeolocation().setLongitude(coordinates.getLongitude());
        n.getAssetRecord().getGeolocation().setLatitude(coordinates.getLatitude());
        nodeDao.saveOrUpdate(n);
    });
    // Query
    GeolocationQuery query = new GeolocationQueryBuilder().withStatusCalculationStrategy(StatusCalculationStrategy.Alarms).build();
    // We do not have any alarms, therefore all nodes should be "NORMAL"
    List<GeolocationInfo> locations = geolocationService.getLocations(query);
    Assert.assertEquals(nodeDao.countAll(), locations.size());
    locations.forEach(l -> Assert.assertEquals("Normal", l.getSeverityInfo().getLabel()));
    // Add an alarm for one node and try again
    alarmDao.save(TestUtils.createAlarm(databasePopulator.getNode1(), OnmsSeverity.MAJOR, distPollerDao.whoami()));
    locations = geolocationService.getLocations(query);
    Assert.assertEquals(nodeDao.countAll(), locations.size());
    locations.forEach(l -> {
        if (l.getNodeInfo().getNodeId() == databasePopulator.getNode1().getId()) {
            Assert.assertEquals("Major", l.getSeverityInfo().getLabel());
        } else {
            Assert.assertEquals("Normal", l.getSeverityInfo().getLabel());
        }
    });
}
Also used : GeolocationQueryBuilder(org.opennms.features.geolocation.api.GeolocationQueryBuilder) GeolocationQuery(org.opennms.features.geolocation.api.GeolocationQuery) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

GeolocationQuery (org.opennms.features.geolocation.api.GeolocationQuery)7 GeolocationInfo (org.opennms.features.geolocation.api.GeolocationInfo)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 Test (org.junit.Test)3 GeolocationQueryBuilder (org.opennms.features.geolocation.api.GeolocationQueryBuilder)3 GeolocationService (org.opennms.features.geolocation.api.GeolocationService)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 List (java.util.List)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)2 Restrictions (org.opennms.core.criteria.restrictions.Restrictions)2 InetAddressUtils (org.opennms.core.utils.InetAddressUtils)2 AddressInfo (org.opennms.features.geolocation.api.AddressInfo)2 Coordinates (org.opennms.features.geolocation.api.Coordinates)2 GeolocationResolver (org.opennms.features.geolocation.api.GeolocationResolver)2 NodeInfo (org.opennms.features.geolocation.api.NodeInfo)2