use of org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph in project opennms by OpenNMS.
the class DefaultBusinessServiceStateMachine method clone.
@Override
public BusinessServiceStateMachine clone(boolean preserveState) {
m_rwLock.readLock().lock();
try {
final BusinessServiceStateMachine sm = new DefaultBusinessServiceStateMachine();
// Rebuild the graph using the business services from the existing state machine
final BusinessServiceGraph graph = getGraph();
sm.setBusinessServices(graph.getVertices().stream().filter(v -> v.getBusinessService() != null).map(v -> v.getBusinessService()).collect(Collectors.toList()));
// Prime the state
if (preserveState) {
for (String reductionKey : graph.getReductionKeys()) {
GraphVertex reductionKeyVertex = graph.getVertexByReductionKey(reductionKey);
sm.handleNewOrUpdatedAlarm(new AlarmWrapper() {
@Override
public String getReductionKey() {
return reductionKey;
}
@Override
public Status getStatus() {
return reductionKeyVertex.getStatus();
}
});
}
}
return sm;
} finally {
m_rwLock.readLock().unlock();
}
}
use of org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph in project opennms by OpenNMS.
the class DefaultBusinessServiceStateMachine method setBusinessServices.
@Override
public void setBusinessServices(List<BusinessService> businessServices) {
m_rwLock.writeLock().lock();
try {
// Create a new graph
BusinessServiceGraph g = new BusinessServiceGraphImpl(businessServices);
// Prime the graph with the state from the previous graph and
// keep track of the new reductions keys
Set<String> reductionsKeysToLookup = Sets.newHashSet();
for (String reductionKey : g.getReductionKeys()) {
GraphVertex reductionKeyVertex = m_g.getVertexByReductionKey(reductionKey);
if (reductionKeyVertex != null) {
updateAndPropagateVertex(g, g.getVertexByReductionKey(reductionKey), reductionKeyVertex.getStatus());
} else {
reductionsKeysToLookup.add(reductionKey);
}
}
if (m_alarmProvider == null && reductionsKeysToLookup.size() > 0) {
LOG.warn("There are one or more reduction keys to lookup, but no alarm provider is set.");
} else {
// graph without having to wait for calls to handleNewOrUpdatedAlarm()
if (reductionsKeysToLookup.size() > 0) {
final Map<String, AlarmWrapper> lookup = m_alarmProvider.lookup(reductionsKeysToLookup);
for (Entry<String, AlarmWrapper> eachEntry : lookup.entrySet()) {
updateAndPropagateVertex(g, g.getVertexByReductionKey(eachEntry.getKey()), eachEntry.getValue().getStatus());
}
}
}
m_g = g;
} finally {
m_rwLock.writeLock().unlock();
}
}
use of org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph in project opennms by OpenNMS.
the class BusinessServiceTreeTable method refresh.
/**
* Refreshes table entries.
*/
public void refresh() {
final com.google.common.collect.Table<Long, Optional<Long>, Boolean> expandState = getCurrentExpandState();
final BusinessServiceContainer newContainer = new BusinessServiceContainer();
if (!Strings.isNullOrEmpty(businessServiceNameFilter)) {
newContainer.addContainerFilter(new BusinessServiceFilter(newContainer, businessServiceNameFilter));
}
// Build a graph using all of the business services stored in the database
// We don't use the existing graph, since it only contains the services know by the state machine
List<BusinessService> allBusinessServices = businessServiceManager.getAllBusinessServices();
final BusinessServiceGraph graph = businessServiceManager.getGraph(allBusinessServices);
// Recursively generate the table rows, starting with the roots
graph.getVerticesByLevel(0).stream().filter(v -> v.getBusinessService() != null).sorted((v1, v2) -> v1.getBusinessService().getName().compareTo(v2.getBusinessService().getName())).forEach(v -> newContainer.addRow(graph, v));
// Make it hierarchical
Hierarchical hierarchicalContainer = createHierarchicalContainer(newContainer);
// Update datasource
setContainerDataSource(hierarchicalContainer);
// reset visible columns
setVisibleColumns("name", "links", "edit / delete");
// Restore the previous collapsed state
List<BusinessServiceRow> rows = getItemIds().stream().map(itemId -> getItem(itemId).getBean()).collect(Collectors.toList());
applyExpandState(expandState, rows);
}
use of org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph in project opennms by OpenNMS.
the class BusinessServiceGraphImplTest method canCalculateVertexLevelForDeepHierarchy.
@Test
public void canCalculateVertexLevelForDeepHierarchy() {
final String[][] BUSINESS_SERVICE_NAMES = new String[][] { { "b1" }, { "b2" }, { "b3", "c21", "c22" }, { "b4", "c31", "c32", "c33" }, { "b5", "c41" }, { "b6", "c51", "c52" }, { "b7", "c61" }, { "b8", "c71", "c72", "c73", "c74" }, { "b9", "c81", "c82" }, { "b10", "c91", "c92", "c93", "c94", "c95", "c96", "c97", "c98", "c99" }, { "b11", "c101" }, { "b12", "c111", "c112" }, { "b13", "c121" }, { "b14" } };
// Build the hierarchy, linking every level to the left most business service
// in the line above
Map<Long, Integer> businessServiceIdToLevel = Maps.newHashMap();
Builder builder = MockBusinessServiceHierarchy.builder();
long k = 0;
for (int level = 0; level < BUSINESS_SERVICE_NAMES.length; level++) {
String[] servicesAtLevel = BUSINESS_SERVICE_NAMES[level];
for (int i = servicesAtLevel.length - 1; i >= 0; i--) {
builder = builder.withBusinessService(k).withName(servicesAtLevel[i]);
businessServiceIdToLevel.put(k, level);
k++;
if (i != 0) {
builder = builder.commit();
}
}
}
for (int level = 0; level < BUSINESS_SERVICE_NAMES.length; level++) {
builder = builder.commit();
}
// Create the graph
MockBusinessServiceHierarchy h = builder.build();
BusinessServiceGraph graph = new BusinessServiceGraphImpl(h.getBusinessServices());
// Verify
for (Entry<Long, Integer> entry : businessServiceIdToLevel.entrySet()) {
long id = entry.getKey();
int expectedLevel = entry.getValue();
assertEquals(expectedLevel, graph.getVertexByBusinessServiceId(id).getLevel());
}
}
use of org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph in project opennms by OpenNMS.
the class BusinessServicesTopologyProvider method load.
private void load() {
resetContainer();
BusinessServiceGraph graph = businessServiceManager.getGraph();
for (GraphVertex topLevelBusinessService : graph.getVerticesByLevel(0)) {
addVertex(graph, topLevelBusinessService, null);
}
}
Aggregations