Search in sources :

Example 1 with NodeStatusCalculatorConfig

use of org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig in project opennms by OpenNMS.

the class DefaultGeolocationService method calculateStatus.

private Status calculateStatus(GeolocationQuery query, Set<Integer> nodeIds) {
    final NodeStatusCalculatorConfig nodeStatusCalculatorConfig = new NodeStatusCalculatorConfig();
    nodeStatusCalculatorConfig.setIncludeAcknowledgedAlarms(query.isIncludeAcknowledgedAlarms());
    nodeStatusCalculatorConfig.setLocation(query.getLocation());
    if (query.getSeverity() != null) {
        final OnmsSeverity severity = OnmsSeverity.get(query.getSeverity().getId());
        final List<OnmsSeverity> severityFilter = Arrays.stream(OnmsSeverity.values()).filter(s -> s.isGreaterThanOrEqual(severity)).collect(Collectors.toList());
        nodeStatusCalculatorConfig.setSeverities(severityFilter);
    }
    nodeStatusCalculatorConfig.setCalculationStrategy(NodeStatusCalculationStrategy.None);
    if (query.getStatusCalculationStrategy() != null) {
        nodeStatusCalculatorConfig.setCalculationStrategy(NodeStatusCalculationStrategy.valueOf(query.getStatusCalculationStrategy().name()));
    }
    nodeStatusCalculatorConfig.setNodeIds(nodeIds);
    final Status status = nodeStatusCalculator.calculateStatus(nodeStatusCalculatorConfig);
    return status;
}
Also used : AddressInfo(org.opennms.features.geolocation.api.AddressInfo) Arrays(java.util.Arrays) NodeStatusCalculationStrategy(org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy) Status(org.opennms.features.status.api.node.strategy.Status) NodeStatusCalculatorConfig(org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig) ArrayList(java.util.ArrayList) Coordinates(org.opennms.features.geolocation.api.Coordinates) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo) GenericPersistenceAccessor(org.opennms.netmgt.dao.api.GenericPersistenceAccessor) OnmsNode(org.opennms.netmgt.model.OnmsNode) 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) NodeStatusCalculator(org.opennms.features.status.api.node.NodeStatusCalculator) 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) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) GeolocationService(org.opennms.features.geolocation.api.GeolocationService) Status(org.opennms.features.status.api.node.strategy.Status) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) NodeStatusCalculatorConfig(org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig)

Example 2 with NodeStatusCalculatorConfig

use of org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig in project opennms by OpenNMS.

the class NodeStatusService method getStatus.

public List<StatusEntity<OnmsNode>> getStatus(NodeQuery query) {
    // Build query
    final NodeStatusCalculatorConfig config = buildFrom(query);
    // Calculate Status
    final Status status = statusCalculator.calculateStatus(config);
    // Find nodes for node id
    final List<OnmsNode> nodes = getNodes(status.getIds());
    final Map<Integer, OnmsNode> nodeIdMap = nodes.stream().collect(Collectors.toMap(n -> n.getId(), n -> n));
    // convert to wrapper
    return status.getIds().stream().map(nodeId -> {
        OnmsSeverity nodeStatus = status.getSeverity(nodeId);
        OnmsNode node = nodeIdMap.get(nodeId);
        if (nodeStatus == null) {
            throw new IllegalStateException("nodeStatus should not be null");
        }
        if (node == null) {
            throw new IllegalStateException("node should not be null");
        }
        return new StatusEntityWrapper<>(node, nodeStatus);
    }).collect(Collectors.toList());
}
Also used : Status(org.opennms.features.status.api.node.strategy.Status) NodeDao(org.opennms.netmgt.dao.api.NodeDao) NodeStatusCalculationStrategy(org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy) Status(org.opennms.features.status.api.node.strategy.Status) Autowired(org.springframework.beans.factory.annotation.Autowired) NodeStatusCalculatorConfig(org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig) StatusEntityWrapper(org.opennms.features.status.api.StatusEntityWrapper) Collectors(java.util.stream.Collectors) StatusEntity(org.opennms.features.status.api.StatusEntity) ArrayList(java.util.ArrayList) List(java.util.List) StatusSummary(org.opennms.features.status.api.StatusSummary) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Map(java.util.Map) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) NodeStatusCalculatorConfig(org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig)

Example 3 with NodeStatusCalculatorConfig

use of org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig in project opennms by OpenNMS.

the class NodeStatusService method getSummary.

public StatusSummary getSummary(NodeStatusCalculationStrategy strategy) {
    final NodeStatusCalculatorConfig config = new NodeStatusCalculatorConfig();
    config.setSeverities(Lists.newArrayList(OnmsSeverity.NORMAL, OnmsSeverity.WARNING, OnmsSeverity.MINOR, OnmsSeverity.MAJOR, OnmsSeverity.CRITICAL));
    config.setCalculationStrategy(strategy);
    final Map<OnmsSeverity, Long> statusOverviewMap = statusCalculator.calculateStatusOverview(config);
    final long totalCount = nodeDao.countAll();
    return new StatusSummary(statusOverviewMap, totalCount);
}
Also used : StatusSummary(org.opennms.features.status.api.StatusSummary) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) NodeStatusCalculatorConfig(org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig)

Example 4 with NodeStatusCalculatorConfig

use of org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig in project opennms by OpenNMS.

the class NodeStatusService method buildFrom.

private NodeStatusCalculatorConfig buildFrom(NodeQuery query) {
    final NodeStatusCalculatorConfig config = new NodeStatusCalculatorConfig();
    config.setCalculationStrategy(query.getStatusCalculationStrategy());
    if (query.getSeverityFilter() != null && query.getSeverityFilter().getSeverities() != null) {
        config.setSeverities(query.getSeverityFilter().getSeverities());
    }
    if (query.getParameters().getOffset() != null) {
        config.setOffset(query.getParameters().getOffset());
    }
    if (query.getParameters().getLimit() != null) {
        config.setLimit(query.getParameters().getLimit());
    }
    if (query.getParameters().getOrder() != null) {
        config.setOrder(query.getParameters().getOrder());
    }
    return config;
}
Also used : NodeStatusCalculatorConfig(org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig)

Example 5 with NodeStatusCalculatorConfig

use of org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig in project opennms by OpenNMS.

the class NodeStatusService method count.

public int count(NodeQuery query) {
    NodeStatusCalculatorConfig config = buildFrom(query);
    config.prepareForCounting();
    return statusCalculator.countStatus(config);
}
Also used : NodeStatusCalculatorConfig(org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig)

Aggregations

NodeStatusCalculatorConfig (org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig)5 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)2 StatusSummary (org.opennms.features.status.api.StatusSummary)2 NodeStatusCalculationStrategy (org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy)2 Status (org.opennms.features.status.api.node.strategy.Status)2 OnmsNode (org.opennms.netmgt.model.OnmsNode)2 Lists (com.google.common.collect.Lists)1 Arrays (java.util.Arrays)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Restrictions (org.opennms.core.criteria.restrictions.Restrictions)1 InetAddressUtils (org.opennms.core.utils.InetAddressUtils)1 AddressInfo (org.opennms.features.geolocation.api.AddressInfo)1 Coordinates (org.opennms.features.geolocation.api.Coordinates)1 GeolocationInfo (org.opennms.features.geolocation.api.GeolocationInfo)1