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;
}
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);
}
Aggregations