Search in sources :

Example 36 with BusinessService

use of org.opennms.netmgt.bsm.service.model.BusinessService in project opennms by OpenNMS.

the class GenerateHierarchiesShellCommand method doExecute.

@Override
protected Object doExecute() throws Exception {
    final Map<String, BusinessService> businessServicesByName = businessServiceManager.getAllBusinessServices().stream().collect(Collectors.toMap(b -> b.getName(), b -> b));
    int showStatusEvery = 100;
    int numServicesToGenerate = numServices != null ? numServices : DEFAULT_NUM_SERVICES;
    int depthPerHierarchy = depth != null ? depth : DEFAULT_DEPTH;
    int currentDepth = 0;
    BusinessService lastBusinessService = null;
    for (int i = 0; i < numServicesToGenerate; i++) {
        if (i % showStatusEvery == 0) {
            System.out.printf("Generating business services %d -> %d\n", i, Math.min(i + showStatusEvery, numServicesToGenerate));
        }
        final String name = "B" + i;
        if (businessServicesByName.containsKey(name)) {
            lastBusinessService = businessServicesByName.get(name);
            continue;
        }
        BusinessService businessService = businessServiceManager.createBusinessService();
        businessService.setName(name);
        businessService.setReduceFunction(new HighestSeverity());
        businessService.getAttributes().put("generated", "true");
        businessServiceManager.saveBusinessService(businessService);
        if (lastBusinessService != null && currentDepth < depthPerHierarchy) {
            businessServiceManager.addChildEdge(lastBusinessService, businessService, new Identity(), 1);
            currentDepth++;
        } else if (currentDepth >= depthPerHierarchy) {
            currentDepth = 0;
        }
        lastBusinessService = businessService;
    }
    return null;
}
Also used : Objects(java.util.Objects) Argument(org.apache.felix.gogo.commands.Argument) OsgiCommandSupport(org.apache.karaf.shell.console.OsgiCommandSupport) Map(java.util.Map) BusinessServiceManager(org.opennms.netmgt.bsm.service.BusinessServiceManager) Identity(org.opennms.netmgt.bsm.service.model.functions.map.Identity) Command(org.apache.felix.gogo.commands.Command) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Collectors(java.util.stream.Collectors) HighestSeverity(org.opennms.netmgt.bsm.service.model.functions.reduce.HighestSeverity) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) HighestSeverity(org.opennms.netmgt.bsm.service.model.functions.reduce.HighestSeverity) Identity(org.opennms.netmgt.bsm.service.model.functions.map.Identity)

Example 37 with BusinessService

use of org.opennms.netmgt.bsm.service.model.BusinessService in project opennms by OpenNMS.

the class BusinessServiceContainer method createRowForVertex.

private void createRowForVertex(BusinessServiceGraph graph, GraphVertex graphVertex, BusinessServiceRow parentRow) {
    final BusinessService businessService = graphVertex.getBusinessService();
    if (businessService == null) {
        return;
    }
    final long rowId = rowIdCounter.incrementAndGet();
    final Long parentBusinessServiceId = parentRow != null ? parentRow.getBusinessService().getId() : null;
    final BusinessServiceRow row = new BusinessServiceRow(rowId, businessService, parentBusinessServiceId);
    if (parentRow != null) {
        rowIdToParentRowIdMapping.put(rowId, parentRow.getRowId());
    }
    addBean(row);
    // Recurse with all of the children
    graph.getOutEdges(graphVertex).stream().map(e -> graph.getOpposite(graphVertex, e)).filter(v -> v.getBusinessService() != null).sorted((v1, v2) -> v1.getBusinessService().getName().compareTo(v2.getBusinessService().getName())).forEach(v -> createRowForVertex(graph, v, row));
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) BeanContainer(com.vaadin.data.util.BeanContainer) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) Map(java.util.Map) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Collections(java.util.Collections) Maps(com.google.common.collect.Maps) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 38 with BusinessService

use of org.opennms.netmgt.bsm.service.model.BusinessService in project opennms by OpenNMS.

the class BusinessServiceCriteriaTest method createDummyBusinessService.

private BusinessService createDummyBusinessService(final long id, final String name, String attributeKey, String attributeValue, final Status status) {
    BusinessServiceEntity businessServiceEntity = new BusinessServiceEntity();
    businessServiceEntity.setId(id);
    businessServiceEntity.setAttribute(attributeKey, attributeValue);
    businessServiceEntity.setName(name);
    BusinessService businessService = new BusinessServiceImpl(businessServiceManager, businessServiceEntity) {

        @Override
        public Status getOperationalStatus() {
            return status;
        }
    };
    return businessService;
}
Also used : BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)

Example 39 with BusinessService

use of org.opennms.netmgt.bsm.service.model.BusinessService in project opennms by OpenNMS.

the class BusinessServiceManagerImplIT method ensureNoDanglingMapFunctions.

@Test
public void ensureNoDanglingMapFunctions() {
    // Create a business service with an edge
    final BusinessService bs = this.createBusinessService("bs1");
    bs.addReductionKeyEdge("my-reduction-key", new Increase(), Edge.DEFAULT_WEIGHT, "My Reduction Key");
    bs.save();
    // Ensure there is an associated mapping function
    assertEquals(1, mapFunctionDao.countAll());
    Iterables.getOnlyElement(bs.getReductionKeyEdges()).setMapFunction(new Decrease());
    bs.save();
    // Ensure there is still only one associated mapping function
    assertEquals(1, mapFunctionDao.countAll());
    // Delete an edge
    bs.delete();
    // Ensure there are no mapping functions left
    assertEquals(0, mapFunctionDao.countAll());
}
Also used : BsmTestUtils.createDummyBusinessService(org.opennms.netmgt.bsm.test.BsmTestUtils.createDummyBusinessService) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Decrease(org.opennms.netmgt.bsm.service.model.functions.map.Decrease) Increase(org.opennms.netmgt.bsm.service.model.functions.map.Increase) Test(org.junit.Test)

Aggregations

BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)39 Test (org.junit.Test)13 IpServiceEdge (org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge)10 Collectors (java.util.stream.Collectors)9 IpService (org.opennms.netmgt.bsm.service.model.IpService)9 Status (org.opennms.netmgt.bsm.service.model.Status)9 Edge (org.opennms.netmgt.bsm.service.model.edge.Edge)9 BusinessServiceGraph (org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)9 List (java.util.List)8 BusinessServiceManager (org.opennms.netmgt.bsm.service.BusinessServiceManager)8 BusinessServiceStateMachine (org.opennms.netmgt.bsm.service.BusinessServiceStateMachine)8 Map (java.util.Map)7 Objects (java.util.Objects)7 Path (javax.ws.rs.Path)7 ChildEdge (org.opennms.netmgt.bsm.service.model.edge.ChildEdge)7 ReductionKeyEdge (org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge)7 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)6 NoSuchElementException (java.util.NoSuchElementException)5 Set (java.util.Set)5 Criteria (org.opennms.core.criteria.Criteria)5