Search in sources :

Example 1 with StatusEntityWrapper

use of org.opennms.features.status.api.StatusEntityWrapper 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 2 with StatusEntityWrapper

use of org.opennms.features.status.api.StatusEntityWrapper in project opennms by OpenNMS.

the class BusinessServiceStatusService method getStatus.

public List<StatusEntity<BusinessService>> getStatus(Query query) {
    final BusinessServiceSearchCriteriaBuilder criteria = buildFrom(query);
    final List<BusinessService> services = criteria.apply(businessServiceManager, businessServiceManager.getAllBusinessServices());
    final List<StatusEntity<BusinessService>> mappedServices = services.stream().map(eachService -> new StatusEntityWrapper<>(eachService, OnmsSeverity.get(eachService.getOperationalStatus().getLabel()))).collect(Collectors.toList());
    return mappedServices;
}
Also used : QueryParameters(org.opennms.web.utils.QueryParameters) BusinessServiceManager(org.opennms.netmgt.bsm.service.BusinessServiceManager) Autowired(org.springframework.beans.factory.annotation.Autowired) Query(org.opennms.features.status.api.Query) StatusEntityWrapper(org.opennms.features.status.api.StatusEntityWrapper) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Collectors(java.util.stream.Collectors) StatusEntity(org.opennms.features.status.api.StatusEntity) BusinessServiceSearchCriteriaBuilder(org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteriaBuilder) List(java.util.List) StatusSummary(org.opennms.features.status.api.StatusSummary) Status(org.opennms.netmgt.bsm.service.model.Status) Service(org.springframework.stereotype.Service) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) StatusEntityWrapper(org.opennms.features.status.api.StatusEntityWrapper) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) BusinessServiceSearchCriteriaBuilder(org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteriaBuilder) StatusEntity(org.opennms.features.status.api.StatusEntity)

Aggregations

List (java.util.List)2 Collectors (java.util.stream.Collectors)2 StatusEntity (org.opennms.features.status.api.StatusEntity)2 StatusEntityWrapper (org.opennms.features.status.api.StatusEntityWrapper)2 StatusSummary (org.opennms.features.status.api.StatusSummary)2 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Service (org.springframework.stereotype.Service)2 Lists (com.google.common.collect.Lists)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)1 Query (org.opennms.features.status.api.Query)1 NodeStatusCalculationStrategy (org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy)1 NodeStatusCalculatorConfig (org.opennms.features.status.api.node.strategy.NodeStatusCalculatorConfig)1 Status (org.opennms.features.status.api.node.strategy.Status)1 BusinessServiceManager (org.opennms.netmgt.bsm.service.BusinessServiceManager)1 BusinessServiceSearchCriteriaBuilder (org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteriaBuilder)1 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)1 Status (org.opennms.netmgt.bsm.service.model.Status)1