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;
}
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());
}
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);
}
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;
}
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);
}
Aggregations