use of org.opennms.netmgt.bsm.service.BusinessServiceManager 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.BusinessServiceManager in project opennms by OpenNMS.
the class SimulationAwareStateMachineFactory method createSimulatedStateMachine.
public static BusinessServiceStateMachine createSimulatedStateMachine(BusinessServiceManager manager, Criteria[] criteria) {
// Gather the statuses and group them by reduction key
final Map<String, Status> statusByReductionKey = Arrays.stream(criteria).filter(c -> c instanceof SetStatusToCriteria).map(c -> (SetStatusToCriteria) c).filter(c -> c.getStatus() != null).collect(Collectors.toMap(SetStatusToCriteria::getReductionKey, SetStatusToCriteria::getStatus));
// Determine whether or not we should inherit the existing state
final boolean shouldInheritState = Arrays.stream(criteria).anyMatch(c -> c instanceof InheritStateCriteria);
// Grab a copy of the state machine, and update push alarms
// that reflect the simulated state of the reduction keys
final BusinessServiceStateMachine stateMachine = manager.getStateMachine().clone(shouldInheritState);
for (Entry<String, Status> entry : statusByReductionKey.entrySet()) {
stateMachine.handleNewOrUpdatedAlarm(new AlarmWrapper() {
@Override
public String getReductionKey() {
return entry.getKey();
}
@Override
public Status getStatus() {
return entry.getValue();
}
});
}
return stateMachine;
}
use of org.opennms.netmgt.bsm.service.BusinessServiceManager in project opennms by OpenNMS.
the class BusinessServiceVertexProviderTest method testVertexRefId.
@Test
public void testVertexRefId() {
// Mock the manager to return a node label
BusinessServiceManager managerMock = EasyMock.createNiceMock(BusinessServiceManager.class);
EasyMock.expect(managerMock.getNodeById(EasyMock.anyInt())).andReturn(new Node() {
@Override
public String getLabel() {
return "localhost";
}
@Override
public Integer getId() {
return 1;
}
}).anyTimes();
EasyMock.replay(managerMock);
// create 3 business service vertices, where the first 2 should be equal
BusinessServiceEntityBuilder builder = new BusinessServiceEntityBuilder().id(10L).name("Name");
BusinessService bs1 = new BusinessServiceImpl(managerMock, builder.toEntity());
BusinessService bs2 = new BusinessServiceImpl(managerMock, builder.toEntity());
// is different
BusinessService bs3 = new BusinessServiceImpl(managerMock, builder.id(11L).toEntity());
BusinessServiceVertex bsVertex1 = new BusinessServiceVertex(bs1, 0);
BusinessServiceVertex bsVertex2 = new BusinessServiceVertex(bs2, 0);
BusinessServiceVertex bsVertex3 = new BusinessServiceVertex(bs3, 0);
// create 2 ip Service vertices where all of them should be equal
IpService ipService1 = new IpServiceImpl(managerMock, BsmTestUtils.createMonitoredService(1, 1, "127.0.0.1", "SSH"));
IpService ipService2 = new IpServiceImpl(managerMock, BsmTestUtils.createMonitoredService(1, 1, "127.0.0.1", "SSH"));
IpServiceVertex ipServiceVertex1 = new IpServiceVertex(ipService1, 0);
IpServiceVertex ipServiceVertex2 = new IpServiceVertex(ipService2, 0);
// create 3 reduction key vertices where 2 of them should be equal
ReductionKeyVertex rkVertex1 = new ReductionKeyVertex("key1", 0);
ReductionKeyVertex rkVertex2 = new ReductionKeyVertex("key1", 0);
ReductionKeyVertex rkVertex3 = new ReductionKeyVertex("key2", 0);
// Add all the above vertices. Some of them even twice to ensure that the getRefId() methods work correctly
BusinessServiceVertexProvider vertexProvider = new BusinessServiceVertexProvider(BusinessServicesTopologyProvider.TOPOLOGY_NAMESPACE);
// adding twice on purpose
vertexProvider.add(bsVertex1, bsVertex1, bsVertex2, bsVertex2, bsVertex3, bsVertex3);
// adding twice on purpose
vertexProvider.add(ipServiceVertex1, ipServiceVertex1, ipServiceVertex2, ipServiceVertex2);
// adding twice on purpose
vertexProvider.add(rkVertex1, rkVertex1);
// adding twice on purpose
vertexProvider.add(rkVertex2, rkVertex2);
// adding twice on purpose
vertexProvider.add(rkVertex3, rkVertex3);
// In total there should be 5 vertices
Assert.assertEquals(5, vertexProvider.getVertices().size());
Assert.assertSame(ipServiceVertex2, vertexProvider.getVertex(ipServiceVertex1));
Assert.assertSame(ipServiceVertex2, vertexProvider.getVertex(ipServiceVertex2));
Assert.assertSame(bsVertex2, vertexProvider.getVertex(bsVertex1));
Assert.assertSame(bsVertex2, vertexProvider.getVertex(bsVertex2));
Assert.assertSame(bsVertex3, vertexProvider.getVertex(bsVertex3));
Assert.assertNotSame(bsVertex1, vertexProvider.getVertex(bsVertex3));
Assert.assertNotSame(bsVertex2, vertexProvider.getVertex(bsVertex3));
Assert.assertSame(rkVertex2, vertexProvider.getVertex(rkVertex1));
Assert.assertSame(rkVertex2, vertexProvider.getVertex(rkVertex2));
Assert.assertNotSame(rkVertex1, vertexProvider.getVertex(rkVertex3));
Assert.assertSame(rkVertex3, vertexProvider.getVertex(rkVertex3));
EasyMock.verify(managerMock);
}
use of org.opennms.netmgt.bsm.service.BusinessServiceManager in project opennms by OpenNMS.
the class BusinessServiceStatusService method getStatus.
public List<StatusEntity<BusinessService>> getStatus(Query query) {
final BusinessServiceSearchCriteriaBuilder criteria = buildFrom(query);
final List<BusinessService> services = criteria.apply(businessServiceManager, businessServiceManager.getAllBusinessServices());
final List<StatusEntity<BusinessService>> mappedServices = services.stream().map(eachService -> new StatusEntityWrapper<>(eachService, OnmsSeverity.get(eachService.getOperationalStatus().getLabel()))).collect(Collectors.toList());
return mappedServices;
}
use of org.opennms.netmgt.bsm.service.BusinessServiceManager in project opennms by OpenNMS.
the class DefaultBusinessServiceStateMachineIT method ensureReductionKeyLookupIsFastEnough.
/**
* Builds 200 business services.
* Each business Services has one parent and two children.
* Each children has 12 reduction key edges.
* In sum there are:
* - 600 business services
* - 4800 reduction key edges
* - 400 child edges
* - 5200 edges
*
* See NMS-8978 for more details.
*/
@Test
public void ensureReductionKeyLookupIsFastEnough() {
for (int i = 0; i < 200; i++) {
BusinessServiceEntity parentEntity = new BusinessServiceEntityBuilder().name("Parent " + i).reduceFunction(new HighestSeverityEntity()).toEntity();
for (int c = 0; c < 2; c++) {
BusinessServiceEntityBuilder childBuilder = new BusinessServiceEntityBuilder().name("Child " + i + " " + c).reduceFunction(new HighestSeverityEntity());
for (int a = 0; a < 12; a++) {
childBuilder.addReductionKey("custom." + i + "." + c + "." + a, new IdentityEntity());
}
BusinessServiceEntity childEntity = childBuilder.toEntity();
parentEntity.addChildServiceEdge(childEntity, new IdentityEntity());
businessServiceDao.save(childEntity);
}
businessServiceDao.save(parentEntity);
}
final Set<String> uniqueReductionKeys = businessServiceDao.findMatching(new CriteriaBuilder(BusinessServiceEntity.class).like("name", "Child%").toCriteria()).stream().flatMap(service -> service.getReductionKeyEdges().stream()).flatMap(edge -> edge.getReductionKeys().stream()).collect(Collectors.toSet());
for (String eachKey : uniqueReductionKeys) {
final OnmsAlarm alarm = new OnmsAlarm();
alarm.setUei("custom");
alarm.setAlarmType(OnmsAlarm.PROBLEM_TYPE);
alarm.setDescription("dummy");
alarm.setLogMsg("dummy");
alarm.setSeverity(OnmsSeverity.WARNING);
alarm.setReductionKey(eachKey);
alarm.setDistPoller(distPollerDao.whoami());
alarm.setCounter(1);
populator.getAlarmDao().save(alarm);
}
populator.getAlarmDao().flush();
businessServiceDao.flush();
// Simulate lookup of reduction keys
final long start = System.currentTimeMillis();
final DefaultBusinessServiceStateMachine stateMachine = new DefaultBusinessServiceStateMachine();
stateMachine.setAlarmProvider(alarmProvider);
stateMachine.setBusinessServices(businessServiceDao.findAll().stream().map(e -> new BusinessServiceImpl(businessServiceManager, e)).collect(Collectors.toList()));
long diff = System.currentTimeMillis() - start;
LoggerFactory.getLogger(getClass()).info("Took {} ms to initialize state machine", diff);
Assert.assertTrue("Reduction Key lookup took much longer than expected. Expected was 1000 ms, but took " + diff + " ms", 1000 >= diff);
}
Aggregations