use of org.opennms.netmgt.bsm.service.model.graph.GraphEdge in project opennms by OpenNMS.
the class BusinessServiceGraphImpl method addBusinessServiceVertex.
private GraphVertex addBusinessServiceVertex(BusinessService businessService) {
// Use an existing vertex if we already created one
GraphVertex businessServiceVertex = m_verticesByBusinessServiceId.get(businessService.getId());
if (businessServiceVertex != null) {
return businessServiceVertex;
}
// Create
businessServiceVertex = new GraphVertexImpl(businessService.getReduceFunction(), businessService);
// Add
addVertex(businessServiceVertex);
// Index
m_verticesByBusinessServiceId.put(businessService.getId(), businessServiceVertex);
for (Edge edge : businessService.getEdges()) {
// Create the edge
GraphEdge graphEdge = new GraphEdgeImpl(edge);
// Use an existing vertex if we already created one
final GraphVertex[] vertexForEdge = { getExistingVertex(edge) };
// If we couldn't find an existing vertex, create one
if (vertexForEdge[0] == null) {
edge.accept(new EdgeVisitor<Void>() {
@Override
public Void visit(ChildEdge edge) {
vertexForEdge[0] = addBusinessServiceVertex(edge.getChild());
return null;
}
@Override
public Void visit(IpServiceEdge edge) {
// There are multiple reductions keys for this edge
// Create an intermediary vertex using the Most Critical reduction function
vertexForEdge[0] = new GraphVertexImpl(REDUCE_HIGHEST_SEVERITY, edge.getIpService());
addVertex(vertexForEdge[0]);
m_verticesByIpServiceId.put(vertexForEdge[0].getIpService().getId(), vertexForEdge[0]);
// SPECIAL CASE: Map the reductions keys to the intermediary vertex using the Identity map
for (String reductionKey : edge.getReductionKeys()) {
GraphVertex reductionKeyVertex = m_verticesByReductionKey.get(reductionKey);
if (reductionKeyVertex == null) {
// not already added
reductionKeyVertex = new GraphVertexImpl(REDUCE_HIGHEST_SEVERITY, reductionKey);
addVertex(reductionKeyVertex);
m_verticesByReductionKey.put(reductionKey, reductionKeyVertex);
}
// Always add an edge
GraphEdgeImpl intermediaryEdge = new GraphEdgeImpl(MAP_IDENTITY);
addEdge(intermediaryEdge, vertexForEdge[0], reductionKeyVertex);
}
return null;
}
@Override
public Void visit(ReductionKeyEdge edge) {
String reductionKey = edge.getReductionKey();
vertexForEdge[0] = new GraphVertexImpl(REDUCE_HIGHEST_SEVERITY, edge.getReductionKey());
addVertex(vertexForEdge[0]);
m_verticesByReductionKey.put(reductionKey, vertexForEdge[0]);
return null;
}
});
}
// Link and index
addEdge(graphEdge, businessServiceVertex, vertexForEdge[0]);
m_verticesByEdgeId.put(edge.getId(), vertexForEdge[0]);
m_edgesByEdgeId.put(edge.getId(), graphEdge);
}
return businessServiceVertex;
}
use of org.opennms.netmgt.bsm.service.model.graph.GraphEdge in project opennms by OpenNMS.
the class DefaultBusinessServiceStateMachine method renderGraphToPng.
@Override
public void renderGraphToPng(File tempFile) {
m_rwLock.readLock().lock();
try {
Layout<GraphVertex, GraphEdge> layout = new KKLayout<GraphVertex, GraphEdge>(m_g);
// Size of the layout
layout.setSize(new Dimension(1024, 1024));
VisualizationImageServer<GraphVertex, GraphEdge> vv = new VisualizationImageServer<GraphVertex, GraphEdge>(layout, layout.getSize());
// Viewing area size
vv.setPreferredSize(new Dimension(1200, 1200));
vv.getRenderContext().setVertexLabelTransformer(new Transformer<GraphVertex, String>() {
@Override
public String transform(GraphVertex vertex) {
if (vertex.getBusinessService() != null) {
return String.format("BS[%s]", vertex.getBusinessService().getName());
}
if (vertex.getIpService() != null) {
IpService ipService = vertex.getIpService();
return String.format("IP_SERVICE[%s,%s]", ipService.getId(), ipService.getServiceName());
}
if (vertex.getReductionKey() != null) {
return String.format("RK[%s]", vertex.getReductionKey());
}
return "UNKNOWN";
}
});
vv.getRenderContext().setEdgeLabelTransformer(new Transformer<GraphEdge, String>() {
@Override
public String transform(GraphEdge edge) {
return String.format("%s", edge.getMapFunction().getClass().getSimpleName());
}
});
// Create the buffered image
BufferedImage image = (BufferedImage) vv.getImage(new Point2D.Double(vv.getGraphLayout().getSize().getWidth() / 2, vv.getGraphLayout().getSize().getHeight() / 2), new Dimension(vv.getGraphLayout().getSize()));
// Render
try {
ImageIO.write(image, "png", tempFile);
} catch (IOException e) {
throw Throwables.propagate(e);
}
} finally {
m_rwLock.readLock().unlock();
}
}
use of org.opennms.netmgt.bsm.service.model.graph.GraphEdge in project opennms by OpenNMS.
the class DefaultBusinessServiceStateMachine method updateAndPropagateVertex.
private void updateAndPropagateVertex(BusinessServiceGraph graph, GraphVertex vertex, Status newStatus) {
if (vertex == null) {
// Nothing to do here
return;
}
// Apply lower bound
newStatus = newStatus.isLessThan(MIN_SEVERITY) ? MIN_SEVERITY : newStatus;
// Update the status if necessary
Status previousStatus = vertex.getStatus();
if (previousStatus.equals(newStatus)) {
// The status hasn't changed, there's nothing to propagate
return;
}
vertex.setStatus(newStatus);
// Notify the listeners
onStatusUpdated(graph, vertex, previousStatus);
// Update the edges with the mapped status
List<GraphEdge> updatedEges = Lists.newArrayList();
for (GraphEdge edge : graph.getInEdges(vertex)) {
Status mappedStatus = newStatus;
if (newStatus.isGreaterThan(MIN_SEVERITY)) {
// Only apply the map function when the status is > the minimum
mappedStatus = edge.getMapFunction().map(newStatus).orElse(MIN_SEVERITY);
} else {
mappedStatus = newStatus;
}
if (mappedStatus.equals(edge.getStatus())) {
// The status hasn't changed
continue;
}
// Update the status and add it to the list of edges to propagate
edge.setStatus(mappedStatus);
updatedEges.add(edge);
}
// Propagate once all of the edges have been updated
for (GraphEdge edge : updatedEges) {
reduceUpdateAndPropagateVertex(graph, graph.getOpposite(vertex, edge));
}
}
use of org.opennms.netmgt.bsm.service.model.graph.GraphEdge in project opennms by OpenNMS.
the class BusinessServicesStatusProvider method getStatus.
public static org.opennms.netmgt.bsm.service.model.Status getStatus(BusinessServiceStateMachine stateMachine, BusinessServiceEdge edge) {
final BusinessServiceGraph graph = stateMachine.getGraph();
// We need both the source and target vertices to find the edge in the graph
final GraphVertex source = getGraphVertex(edge.getBusinessServiceSource(), stateMachine.getGraph());
final GraphVertex target = getGraphVertex(edge.getBusinessServiceTarget(), stateMachine.getGraph());
final GraphEdge graphEdge = graph.findEdge(source, target);
return graphEdge != null ? graphEdge.getStatus() : null;
}
use of org.opennms.netmgt.bsm.service.model.graph.GraphEdge in project opennms by OpenNMS.
the class BusinessServicesTopologyProvider method addVertex.
private void addVertex(BusinessServiceGraph graph, GraphVertex graphVertex, AbstractBusinessServiceVertex topologyVertex) {
if (topologyVertex == null) {
// Create a topology vertex for the current vertex
topologyVertex = createTopologyVertex(graphVertex);
addVertices(topologyVertex);
}
for (GraphEdge graphEdge : graph.getOutEdges(graphVertex)) {
GraphVertex childVertex = graph.getOpposite(graphVertex, graphEdge);
// Create a topology vertex for the child vertex
AbstractBusinessServiceVertex childTopologyVertex = createTopologyVertex(childVertex);
graph.getInEdges(childVertex).stream().map(GraphEdge::getFriendlyName).filter(s -> !Strings.isNullOrEmpty(s)).findFirst().ifPresent(childTopologyVertex::setLabel);
addVertices(childTopologyVertex);
// Connect the two
childTopologyVertex.setParent(topologyVertex);
Edge edge = new BusinessServiceEdge(graphEdge, topologyVertex, childTopologyVertex);
addEdges(edge);
// Recurse
addVertex(graph, childVertex, childTopologyVertex);
}
}
Aggregations