use of org.opennms.netmgt.bsm.service.model.graph.GraphVertex in project opennms by OpenNMS.
the class BusinessServicesTopologyProvider method load.
private void load() {
resetContainer();
BusinessServiceGraph graph = businessServiceManager.getGraph();
for (GraphVertex topLevelBusinessService : graph.getVerticesByLevel(0)) {
addVertex(graph, topLevelBusinessService, null);
}
}
use of org.opennms.netmgt.bsm.service.model.graph.GraphVertex in project opennms by OpenNMS.
the class DefaultBusinessServiceStateMachine method setBusinessServices.
@Override
public void setBusinessServices(List<BusinessService> businessServices) {
m_rwLock.writeLock().lock();
try {
// Create a new graph
BusinessServiceGraph g = new BusinessServiceGraphImpl(businessServices);
// Prime the graph with the state from the previous graph and
// keep track of the new reductions keys
Set<String> reductionsKeysToLookup = Sets.newHashSet();
for (String reductionKey : g.getReductionKeys()) {
GraphVertex reductionKeyVertex = m_g.getVertexByReductionKey(reductionKey);
if (reductionKeyVertex != null) {
updateAndPropagateVertex(g, g.getVertexByReductionKey(reductionKey), reductionKeyVertex.getStatus());
} else {
reductionsKeysToLookup.add(reductionKey);
}
}
if (m_alarmProvider == null && reductionsKeysToLookup.size() > 0) {
LOG.warn("There are one or more reduction keys to lookup, but no alarm provider is set.");
} else {
// graph without having to wait for calls to handleNewOrUpdatedAlarm()
if (reductionsKeysToLookup.size() > 0) {
final Map<String, AlarmWrapper> lookup = m_alarmProvider.lookup(reductionsKeysToLookup);
for (Entry<String, AlarmWrapper> eachEntry : lookup.entrySet()) {
updateAndPropagateVertex(g, g.getVertexByReductionKey(eachEntry.getKey()), eachEntry.getValue().getStatus());
}
}
}
m_g = g;
} finally {
m_rwLock.writeLock().unlock();
}
}
use of org.opennms.netmgt.bsm.service.model.graph.GraphVertex 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.GraphVertex 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.GraphVertex in project opennms by OpenNMS.
the class DefaultBusinessServiceStateMachine method getOperationalStatus.
@Override
public Status getOperationalStatus(BusinessService businessService) {
Objects.requireNonNull(businessService);
m_rwLock.readLock().lock();
try {
GraphVertex vertex = m_g.getVertexByBusinessServiceId(businessService.getId());
if (vertex != null) {
return vertex.getStatus();
}
return null;
} finally {
m_rwLock.readLock().unlock();
}
}
Aggregations