use of org.opennms.netmgt.bsm.service.model.graph.GraphEdge in project opennms by OpenNMS.
the class DefaultBusinessServiceStateMachine method weighStatuses.
/**
* Apply the edges weights to the associated statuses set in the map,
* ignoring the actual status stored in the edge. Can be used for simulations
* without needing to change the actual edge's status.
*
* @param edgesWithStatus
* @return
*/
public static List<StatusWithIndex> weighStatuses(Map<GraphEdge, Status> edgesWithStatus) {
// Find the greatest common divisor of all the weights
int gcd = edgesWithStatus.keySet().stream().map(GraphEdge::getWeight).reduce((a, b) -> BigInteger.valueOf(a).gcd(BigInteger.valueOf(b)).intValue()).orElse(1);
// Multiply the statuses based on their relative weight
List<StatusWithIndex> statuses = Lists.newArrayList();
int k = 0;
for (Entry<GraphEdge, Status> entry : edgesWithStatus.entrySet()) {
int relativeWeight = Math.floorDiv(entry.getKey().getWeight(), gcd);
for (int i = 0; i < relativeWeight; i++) {
statuses.add(new StatusWithIndex(entry.getValue(), k));
}
k++;
}
return statuses;
}
use of org.opennms.netmgt.bsm.service.model.graph.GraphEdge in project opennms by OpenNMS.
the class DefaultBusinessServiceStateMachine method explain.
@Override
public ThresholdResultExplanation explain(BusinessService businessService, Threshold threshold) {
final GraphVertex vertex = getGraph().getVertexByBusinessServiceId(businessService.getId());
// Calculate the weighed statuses from the child edges
List<StatusWithIndex> statusesWithIndices = weighEdges(getGraph().getOutEdges(vertex));
List<Status> statuses = statusesWithIndices.stream().map(StatusWithIndex::getStatus).collect(Collectors.toList());
// Reduce
Status reducedStatus = threshold.reduce(statusesWithIndices).orElse(new StatusWithIndices(MIN_SEVERITY, Collections.emptyList())).getStatus();
ThresholdResultExplanation explanation = new ThresholdResultExplanation();
explanation.setStatus(reducedStatus);
explanation.setHitsByStatus(threshold.getHitsByStatus(statuses));
explanation.setGraphEdges(getGraph().getOutEdges(vertex));
explanation.setWeightStatuses(statuses);
explanation.setFunction(threshold);
Map<GraphEdge, GraphVertex> graphEdgeToGraphVertex = new HashMap<>();
for (Edge eachEdge : businessService.getEdges()) {
GraphVertex vertexForEdge = getGraph().getVertexByEdgeId(eachEdge.getId());
GraphEdge graphEdge = getGraph().getGraphEdgeByEdgeId(eachEdge.getId());
if (vertexForEdge != null && graphEdge != null) {
graphEdgeToGraphVertex.put(graphEdge, vertexForEdge);
}
}
explanation.setGraphEdgeToGraphVertexMapping(graphEdgeToGraphVertex);
return explanation;
}
use of org.opennms.netmgt.bsm.service.model.graph.GraphEdge in project opennms by OpenNMS.
the class BusinessServiceGraphImpl method calculateAndIndexLevels.
private void calculateAndIndexLevels() {
// Start by finding the root vertices
// These are the vertices with no incoming edges
final Set<GraphVertex> rootVertices = Sets.newHashSet();
for (GraphVertex vertex : getVertices()) {
if (getInEdges(vertex).size() == 0) {
rootVertices.add(vertex);
}
}
// Now calculate the distance of every node to each of the root nodes
final GraphLevelIndexer<GraphVertex, GraphEdge> levelIndexer = new GraphLevelIndexer<>();
levelIndexer.indexLevel(this, rootVertices);
for (Entry<GraphVertex, Integer> entry : levelIndexer.getLevelMap().entrySet()) {
final int level = entry.getValue().intValue();
final GraphVertexImpl vertex = (GraphVertexImpl) entry.getKey();
// Store the maximum level within the vertex
vertex.setLevel(Math.max(level, vertex.getLevel()));
}
// Index the vertices by level
for (GraphVertex vertex : getVertices()) {
Set<GraphVertex> verticesAtLevel = m_verticesByLevel.get(vertex.getLevel());
if (verticesAtLevel == null) {
verticesAtLevel = Sets.newHashSet();
m_verticesByLevel.put(vertex.getLevel(), verticesAtLevel);
}
verticesAtLevel.add(vertex);
}
}
Aggregations