Search in sources :

Example 1 with GeolocationInfo

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

the class DefaultGeolocationService method applyStatus.

private void applyStatus(GeolocationQuery query, List<GeolocationInfo> locations) {
    final Set<Integer> nodeIds = locations.stream().map(l -> l.getNodeInfo().getNodeId()).collect(Collectors.toSet());
    if (!nodeIds.isEmpty()) {
        final StatusCalculator calculator = getStatusCalculator(query.getStatusCalculationStrategy());
        final Status status = calculator.calculateStatus(query, nodeIds);
        // Appliing the calculated status to each location
        for (GeolocationInfo info : locations) {
            OnmsSeverity severity = status.getSeverity(info.getNodeInfo().getNodeId());
            // Therefore for all locations with no status must be set to "NORMAL" in the result
            if (severity == null) {
                severity = OnmsSeverity.NORMAL;
            }
            info.setSeverityInfo(new SeverityInfo(severity.getId(), severity.getLabel()));
            info.setAlarmUnackedCount(status.getUnacknowledgedAlarmCount(info.getNodeInfo().getNodeId()));
        }
    }
}
Also used : AddressInfo(org.opennms.features.geolocation.api.AddressInfo) OutageStatusCalculator(org.opennms.features.geolocation.services.status.OutageStatusCalculator) Status(org.opennms.features.geolocation.services.status.Status) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) Coordinates(org.opennms.features.geolocation.api.Coordinates) StatusCalculator(org.opennms.features.geolocation.services.status.StatusCalculator) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo) GenericPersistenceAccessor(org.opennms.netmgt.dao.api.GenericPersistenceAccessor) OnmsNode(org.opennms.netmgt.model.OnmsNode) Logger(org.slf4j.Logger) InetAddressUtils(org.opennms.core.utils.InetAddressUtils) Set(java.util.Set) SeverityInfo(org.opennms.features.geolocation.api.SeverityInfo) Collectors(java.util.stream.Collectors) Restrictions(org.opennms.core.criteria.restrictions.Restrictions) Objects(java.util.Objects) OnmsGeolocation(org.opennms.netmgt.model.OnmsGeolocation) List(java.util.List) GeolocationQuery(org.opennms.features.geolocation.api.GeolocationQuery) NodeInfo(org.opennms.features.geolocation.api.NodeInfo) StatusCalculationStrategy(org.opennms.features.geolocation.api.StatusCalculationStrategy) AlarmStatusCalculator(org.opennms.features.geolocation.services.status.AlarmStatusCalculator) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) GeolocationResolver(org.opennms.features.geolocation.api.GeolocationResolver) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) GeolocationService(org.opennms.features.geolocation.api.GeolocationService) Status(org.opennms.features.geolocation.services.status.Status) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) SeverityInfo(org.opennms.features.geolocation.api.SeverityInfo) OutageStatusCalculator(org.opennms.features.geolocation.services.status.OutageStatusCalculator) StatusCalculator(org.opennms.features.geolocation.services.status.StatusCalculator) AlarmStatusCalculator(org.opennms.features.geolocation.services.status.AlarmStatusCalculator) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo)

Example 2 with GeolocationInfo

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

the class DefaultGeolocationService method getLocations.

@Override
public List<GeolocationInfo> getLocations(GeolocationQuery query) {
    if (query == null) {
        return new ArrayList<>();
    }
    final List<OnmsNode> nodes = getNodes(query);
    final List<GeolocationInfo> nodesWithCoordinates = nodes.stream().filter(n -> geoLocation(n) != null && geoLocation(n).getLongitude() != null && geoLocation(n).getLatitude() != null).filter(n -> geoLocation(n).getLatitude() != Float.NEGATIVE_INFINITY && geoLocation(n).getLongitude() != Float.NEGATIVE_INFINITY).map(node -> convert(node)).collect(Collectors.toList());
    if (query.getStatusCalculationStrategy() != null) {
        applyStatus(query, nodesWithCoordinates);
    }
    if (query.getSeverity() != null) {
        OnmsSeverity severity = OnmsSeverity.get(query.getSeverity().getId());
        return nodesWithCoordinates.stream().filter(n -> severity.getId() <= n.getSeverityInfo().getId()).collect(Collectors.toList());
    }
    return nodesWithCoordinates;
}
Also used : AddressInfo(org.opennms.features.geolocation.api.AddressInfo) OutageStatusCalculator(org.opennms.features.geolocation.services.status.OutageStatusCalculator) Status(org.opennms.features.geolocation.services.status.Status) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) Coordinates(org.opennms.features.geolocation.api.Coordinates) StatusCalculator(org.opennms.features.geolocation.services.status.StatusCalculator) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo) GenericPersistenceAccessor(org.opennms.netmgt.dao.api.GenericPersistenceAccessor) OnmsNode(org.opennms.netmgt.model.OnmsNode) Logger(org.slf4j.Logger) InetAddressUtils(org.opennms.core.utils.InetAddressUtils) Set(java.util.Set) SeverityInfo(org.opennms.features.geolocation.api.SeverityInfo) Collectors(java.util.stream.Collectors) Restrictions(org.opennms.core.criteria.restrictions.Restrictions) Objects(java.util.Objects) OnmsGeolocation(org.opennms.netmgt.model.OnmsGeolocation) List(java.util.List) GeolocationQuery(org.opennms.features.geolocation.api.GeolocationQuery) NodeInfo(org.opennms.features.geolocation.api.NodeInfo) StatusCalculationStrategy(org.opennms.features.geolocation.api.StatusCalculationStrategy) AlarmStatusCalculator(org.opennms.features.geolocation.services.status.AlarmStatusCalculator) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) GeolocationResolver(org.opennms.features.geolocation.api.GeolocationResolver) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) GeolocationService(org.opennms.features.geolocation.api.GeolocationService) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) ArrayList(java.util.ArrayList) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo)

Example 3 with GeolocationInfo

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

the class DefaultGeolocationService method convert.

private GeolocationInfo convert(OnmsNode node) {
    GeolocationInfo geolocationInfo = new GeolocationInfo();
    // Coordinates
    OnmsGeolocation onmsGeolocation = geoLocation(node);
    if (onmsGeolocation != null) {
        geolocationInfo.setAddressInfo(toAddressInfo(onmsGeolocation));
        if (onmsGeolocation.getLongitude() != null && onmsGeolocation.getLatitude() != null) {
            geolocationInfo.setCoordinates(new Coordinates(onmsGeolocation.getLongitude(), onmsGeolocation.getLatitude()));
        }
    }
    // NodeInfo
    NodeInfo nodeInfo = new NodeInfo();
    nodeInfo.setNodeId(node.getId());
    nodeInfo.setNodeLabel(node.getLabel());
    nodeInfo.setNodeLabel(node.getLabel());
    nodeInfo.setForeignSource(node.getForeignSource());
    nodeInfo.setForeignId(node.getForeignId());
    nodeInfo.setLocation(node.getLocation().getLocationName());
    if (node.getAssetRecord() != null) {
        nodeInfo.setDescription(node.getAssetRecord().getDescription());
        nodeInfo.setMaintcontract(node.getAssetRecord().getMaintcontract());
    }
    if (node.getPrimaryInterface() != null) {
        nodeInfo.setIpAddress(InetAddressUtils.str(node.getPrimaryInterface().getIpAddress()));
    }
    nodeInfo.setCategories(node.getCategories().stream().map(c -> c.getName()).collect(Collectors.toList()));
    geolocationInfo.setNodeInfo(nodeInfo);
    return geolocationInfo;
}
Also used : NodeInfo(org.opennms.features.geolocation.api.NodeInfo) Coordinates(org.opennms.features.geolocation.api.Coordinates) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo) OnmsGeolocation(org.opennms.netmgt.model.OnmsGeolocation)

Example 4 with GeolocationInfo

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

the class NodeMapComponent method refresh.

public void refresh() {
    List<GeolocationInfo> locations = geolocationService.getLocations(new GeolocationQueryBuilder().withIncludeAcknowledgedAlarms(false).withStatusCalculationStrategy(StatusCalculationStrategy.Alarms).withSeverity(GeolocationSeverity.Normal).build());
    // apply acl filter if enabled
    if (m_aclsEnabled) {
        Map<Integer, String> nodes = m_nodeDao.getAllLabelsById();
        locations = locations.stream().filter(l -> nodes.containsKey(l.getNodeInfo().getNodeId())).collect(Collectors.toList());
    }
    // Convert
    m_activeNodes = locations.stream().map(l -> createMapNode(l)).collect(Collectors.toMap(l -> Integer.valueOf(l.getNodeId()), Function.identity()));
    showNodes(m_activeNodes);
}
Also used : GeolocationQueryBuilder(org.opennms.features.geolocation.api.GeolocationQueryBuilder) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo)

Example 5 with GeolocationInfo

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

the class GeolocationRestService method getLocations.

@POST
@Path("/")
public Response getLocations(GeolocationQueryDTO queryDTO) {
    final GeolocationService service = getServiceRegistry().findProvider(GeolocationService.class);
    if (service == null) {
        return temporarilyNotAvailable();
    }
    try {
        validate(queryDTO);
        GeolocationQuery query = toQuery(queryDTO);
        final List<GeolocationInfo> locations = service.getLocations(query);
        if (locations.isEmpty()) {
            return Response.noContent().build();
        }
        return Response.ok(locations).build();
    } catch (InvalidQueryException ex) {
        return Response.status(Response.Status.BAD_REQUEST).entity(ex.getMessage()).build();
    }
}
Also used : GeolocationService(org.opennms.features.geolocation.api.GeolocationService) GeolocationQuery(org.opennms.features.geolocation.api.GeolocationQuery) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

GeolocationInfo (org.opennms.features.geolocation.api.GeolocationInfo)7 GeolocationQuery (org.opennms.features.geolocation.api.GeolocationQuery)4 GeolocationService (org.opennms.features.geolocation.api.GeolocationService)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 AddressInfo (org.opennms.features.geolocation.api.AddressInfo)3 Coordinates (org.opennms.features.geolocation.api.Coordinates)3 GeolocationQueryBuilder (org.opennms.features.geolocation.api.GeolocationQueryBuilder)3 NodeInfo (org.opennms.features.geolocation.api.NodeInfo)3 StatusCalculationStrategy (org.opennms.features.geolocation.api.StatusCalculationStrategy)3 OnmsGeolocation (org.opennms.netmgt.model.OnmsGeolocation)3 Objects (java.util.Objects)2 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)2 Restrictions (org.opennms.core.criteria.restrictions.Restrictions)2 InetAddressUtils (org.opennms.core.utils.InetAddressUtils)2 GeolocationResolver (org.opennms.features.geolocation.api.GeolocationResolver)2 SeverityInfo (org.opennms.features.geolocation.api.SeverityInfo)2 AlarmStatusCalculator (org.opennms.features.geolocation.services.status.AlarmStatusCalculator)2