Search in sources :

Example 11 with Identity

use of org.opennms.netmgt.bsm.service.model.functions.map.Identity 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 12 with Identity

use of org.opennms.netmgt.bsm.service.model.functions.map.Identity in project opennms by OpenNMS.

the class BusinessServiceManagerImplIT method testLoopCreation.

@Test
public void testLoopCreation() {
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("Service will form a loop");
    BusinessServiceEntity service1 = createDummyBusinessService("Business Service #1");
    BusinessServiceEntity service2 = createDummyBusinessService("Business Service #2");
    BusinessServiceEntity service3 = createDummyBusinessService("Business Service #3");
    Long serviceId1 = businessServiceDao.save(service1);
    Long serviceId2 = businessServiceDao.save(service2);
    Long serviceId3 = businessServiceDao.save(service3);
    businessServiceManager.addChildEdge(getBusinessService(serviceId1), getBusinessService(serviceId2), new Identity(), Edge.DEFAULT_WEIGHT);
    businessServiceManager.addChildEdge(getBusinessService(serviceId2), getBusinessService(serviceId3), new Identity(), Edge.DEFAULT_WEIGHT);
    businessServiceManager.addChildEdge(getBusinessService(serviceId3), getBusinessService(serviceId1), new Identity(), Edge.DEFAULT_WEIGHT);
}
Also used : BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) Identity(org.opennms.netmgt.bsm.service.model.functions.map.Identity) Test(org.junit.Test)

Aggregations

Identity (org.opennms.netmgt.bsm.service.model.functions.map.Identity)12 Test (org.junit.Test)10 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)7 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)5 BsmTestUtils.createDummyBusinessService (org.opennms.netmgt.bsm.test.BsmTestUtils.createDummyBusinessService)5 HighestSeverityEntity (org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity)3 BusinessServiceEntityBuilder (org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder)3 FunctionsManager (org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager)3 IpServiceEdge (org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge)2 Map (java.util.Map)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Argument (org.apache.felix.gogo.commands.Argument)1 Command (org.apache.felix.gogo.commands.Command)1 OsgiCommandSupport (org.apache.karaf.shell.console.OsgiCommandSupport)1 BusinessServiceManager (org.opennms.netmgt.bsm.service.BusinessServiceManager)1 AlarmWrapper (org.opennms.netmgt.bsm.service.model.AlarmWrapper)1 IpService (org.opennms.netmgt.bsm.service.model.IpService)1 Status (org.opennms.netmgt.bsm.service.model.Status)1 Decrease (org.opennms.netmgt.bsm.service.model.functions.map.Decrease)1