use of org.opennms.netmgt.bsm.service.model.IpService in project opennms by OpenNMS.
the class BusinessServiceManagerImplIT method testGetOperationalStatusForBusinessService.
@Test
public void testGetOperationalStatusForBusinessService() {
BusinessService bsService1 = createBusinessService("Dummy Business Service");
BusinessService bsService2 = createBusinessService("Another Dummy Business Service");
businessServiceStateMachine.setBusinessServices(Lists.newArrayList(bsService1, bsService2));
final IpService ipServiceWithId5 = getIpService(5);
final IpService ipServiceWithId6 = getIpService(6);
// no ip services attached
Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(bsService1));
Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(bsService2));
// ip services attached
businessServiceManager.addIpServiceEdge(bsService1, ipServiceWithId5, new Identity(), Edge.DEFAULT_WEIGHT);
businessServiceManager.addIpServiceEdge(bsService2, ipServiceWithId6, new Identity(), Edge.DEFAULT_WEIGHT);
bsService1.save();
bsService2.save();
businessServiceDao.flush();
Assert.assertFalse("Services are equal but should not", Objects.equals(bsService1, bsService2));
businessServiceStateMachine.setBusinessServices(Lists.newArrayList(bsService1, bsService2));
// should not have any effect
Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(bsService1));
Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(bsService2));
// attach NORMAL alarm to service 1
final IpServiceEdge ipServiceEdgeOnBsService1 = bsService1.getIpServiceEdges().iterator().next();
businessServiceStateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper(monitoredServiceDao.get(5), OnmsSeverity.NORMAL));
Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(ipServiceEdgeOnBsService1));
Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(bsService1));
Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(bsService2));
// attach INDETERMINATE alarm to service 1
businessServiceStateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper(monitoredServiceDao.get(5), OnmsSeverity.INDETERMINATE));
Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(ipServiceEdgeOnBsService1));
Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(bsService1));
Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(bsService2));
// attach WARNING alarm to service 1
businessServiceStateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper(monitoredServiceDao.get(5), OnmsSeverity.WARNING));
Assert.assertEquals(Status.WARNING, businessServiceManager.getOperationalStatus(ipServiceEdgeOnBsService1));
Assert.assertEquals(Status.WARNING, businessServiceManager.getOperationalStatus(bsService1));
Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(bsService2));
// attach CRITICAL alarm to service 1
businessServiceStateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper(monitoredServiceDao.get(5), OnmsSeverity.CRITICAL));
Assert.assertEquals(Status.CRITICAL, businessServiceManager.getOperationalStatus(ipServiceEdgeOnBsService1));
Assert.assertEquals(Status.CRITICAL, businessServiceManager.getOperationalStatus(bsService1));
Assert.assertEquals(Status.NORMAL, businessServiceManager.getOperationalStatus(bsService2));
}
use of org.opennms.netmgt.bsm.service.model.IpService 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.IpService in project opennms by OpenNMS.
the class BusinessServiceVertexInfoPanelItemProvider method createComponent.
private Component createComponent(AbstractBusinessServiceVertex ref, GraphContainer graphContainer) {
final FormLayout formLayout = new FormLayout();
formLayout.setSpacing(false);
formLayout.setMargin(false);
ref.accept(new BusinessServiceVertexVisitor<Void>() {
@Override
public Void visit(BusinessServiceVertex vertex) {
final BusinessService businessService = businessServiceManager.getBusinessServiceById(vertex.getServiceId());
formLayout.addComponent(createLabel("Reduce function", getReduceFunctionDescription(businessService.getReduceFunction())));
// Apply Reduce Function specific details
businessService.getReduceFunction().accept(new ReduceFunctionVisitor<Void>() {
@Override
public Void visit(HighestSeverity highestSeverity) {
return null;
}
@Override
public Void visit(HighestSeverityAbove highestSeverityAbove) {
return null;
}
@Override
public // Threshold is not very transparent, we add an Explain Button in these cases
Void visit(Threshold threshold) {
final Button explainButton = createButton("Explain", "Explain the Threshold function", FontAwesome.TABLE, (Button.ClickListener) event -> {
ThresholdExplanationWindow explainWindow = new ThresholdExplanationWindow(SimulationAwareStateMachineFactory.createSimulatedStateMachine(businessServiceManager, graphContainer.getCriteria()).explain(businessService, (Threshold) businessService.getReduceFunction()));
UI.getCurrent().addWindow(explainWindow);
});
explainButton.setStyleName(BaseTheme.BUTTON_LINK);
formLayout.addComponent(explainButton);
return null;
}
@Override
public Void visit(ExponentialPropagation exponentialPropagation) {
return null;
}
});
return null;
}
@Override
public Void visit(IpServiceVertex vertex) {
IpService ipService = businessServiceManager.getIpServiceById(vertex.getIpServiceId());
formLayout.addComponent(createLabel("Interface", ipService.getIpAddress()));
formLayout.addComponent(createLabel("Service", ipService.getServiceName()));
if (!ipService.getServiceName().equals(vertex.getLabel())) {
formLayout.addComponent(createLabel("Friendly Name", vertex.getLabel()));
}
return null;
}
@Override
public Void visit(ReductionKeyVertex vertex) {
formLayout.addComponent(createLabel("Reduction Key", vertex.getReductionKey()));
if (!vertex.getReductionKey().equals(vertex.getLabel())) {
formLayout.addComponent(createLabel("Friendly Name", vertex.getLabel()));
}
return null;
}
});
return formLayout;
}
use of org.opennms.netmgt.bsm.service.model.IpService in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method addIpServiceEdge.
@Override
public boolean addIpServiceEdge(BusinessService businessService, IpService ipService, MapFunction mapFunction, int weight, String friendlyName) {
final BusinessServiceEntity parentEntity = getBusinessServiceEntity(businessService);
// Create the edge
final IpServiceEdge edge = createEdge(IpServiceEdge.class, businessService, mapFunction, weight);
edge.setIpService(ipService);
edge.setFriendlyName(friendlyName);
// if already exists, no update
final IPServiceEdgeEntity edgeEntity = getBusinessServiceEdgeEntity(edge);
long count = parentEntity.getIpServiceEdges().stream().filter(e -> e.equalsDefinition(edgeEntity)).count();
if (count > 0) {
return false;
}
parentEntity.addEdge(((IpServiceEdgeImpl) edge).getEntity());
return true;
}
use of org.opennms.netmgt.bsm.service.model.IpService in project opennms by OpenNMS.
the class BusinessServiceRestService method addIpServiceEdge.
@POST
@Path("{id}/ip-service-edge")
public // Add IpService
Response addIpServiceEdge(@PathParam("id") final Long serviceId, final IpServiceEdgeRequestDTO edgeRequest) {
final BusinessService businessService = getManager().getBusinessServiceById(serviceId);
final IpService ipService = getManager().getIpServiceById(edgeRequest.getIpServiceId());
boolean changed = getManager().addIpServiceEdge(businessService, ipService, transform(edgeRequest.getMapFunction()), edgeRequest.getWeight(), edgeRequest.getFriendlyName());
if (!changed) {
return Response.notModified().build();
}
businessService.save();
return Response.ok().build();
}
Aggregations