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