Search in sources :

Example 1 with BusinessServiceGraph

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();
    }
}
Also used : IpService(org.opennms.netmgt.bsm.service.model.IpService) Point2D(java.awt.geom.Point2D) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) AlarmWrapper(org.opennms.netmgt.bsm.service.model.AlarmWrapper) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Transformer(org.apache.commons.collections15.Transformer) StatusWithIndices(org.opennms.netmgt.bsm.service.model.StatusWithIndices) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) BigInteger(java.math.BigInteger) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ThresholdResultExplanation(org.opennms.netmgt.bsm.service.model.functions.reduce.ThresholdResultExplanation) BufferedImage(java.awt.image.BufferedImage) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) Dimension(java.awt.Dimension) List(java.util.List) Edge(org.opennms.netmgt.bsm.service.model.edge.Edge) BusinessServiceStateChangeHandler(org.opennms.netmgt.bsm.service.BusinessServiceStateChangeHandler) Entry(java.util.Map.Entry) Optional(java.util.Optional) GraphEdge(org.opennms.netmgt.bsm.service.model.graph.GraphEdge) VisualizationImageServer(edu.uci.ics.jung.visualization.VisualizationImageServer) Threshold(org.opennms.netmgt.bsm.service.model.functions.reduce.Threshold) HashMap(java.util.HashMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Function(java.util.function.Function) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Lists(com.google.common.collect.Lists) KKLayout(edu.uci.ics.jung.algorithms.layout.KKLayout) Status(org.opennms.netmgt.bsm.service.model.Status) AlarmProvider(org.opennms.netmgt.bsm.service.AlarmProvider) Layout(edu.uci.ics.jung.algorithms.layout.Layout) Logger(org.slf4j.Logger) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) BusinessServiceGraphImpl(org.opennms.netmgt.bsm.service.model.graph.internal.BusinessServiceGraphImpl) File(java.io.File) StatusWithIndex(org.opennms.netmgt.bsm.service.model.StatusWithIndex) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) GraphAlgorithms(org.opennms.netmgt.bsm.service.model.graph.internal.GraphAlgorithms) Collections(java.util.Collections) Status(org.opennms.netmgt.bsm.service.model.Status) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) AlarmWrapper(org.opennms.netmgt.bsm.service.model.AlarmWrapper) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)

Example 2 with BusinessServiceGraph

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();
    }
}
Also used : GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) BusinessServiceGraphImpl(org.opennms.netmgt.bsm.service.model.graph.internal.BusinessServiceGraphImpl) AlarmWrapper(org.opennms.netmgt.bsm.service.model.AlarmWrapper) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)

Example 3 with BusinessServiceGraph

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);
}
Also used : TopologyLinkBuilder(org.opennms.features.topology.link.TopologyLinkBuilder) TransactionAwareUI(org.opennms.netmgt.vaadin.core.TransactionAwareUI) BeanItem(com.vaadin.data.util.BeanItem) TreeTable(com.vaadin.ui.TreeTable) Alignment(com.vaadin.ui.Alignment) BusinessServiceManager(org.opennms.netmgt.bsm.service.BusinessServiceManager) UIHelper(org.opennms.netmgt.vaadin.core.UIHelper) HashBasedTable(com.google.common.collect.HashBasedTable) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Strings(com.google.common.base.Strings) FontAwesome(com.vaadin.server.FontAwesome) Status(org.opennms.netmgt.bsm.service.model.Status) Map(java.util.Map) Label(com.vaadin.ui.Label) ContainerHierarchicalWrapper(com.vaadin.data.util.ContainerHierarchicalWrapper) TopologyProvider(org.opennms.features.topology.link.TopologyProvider) Item(com.vaadin.data.Item) Property(com.vaadin.data.Property) Collection(java.util.Collection) Layout(org.opennms.features.topology.link.Layout) Link(com.vaadin.ui.Link) Collectors(java.util.stream.Collectors) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) Objects(java.util.Objects) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) List(java.util.List) ExternalResource(com.vaadin.server.ExternalResource) Button(com.vaadin.ui.Button) Table(com.vaadin.ui.Table) HorizontalLayout(com.vaadin.ui.HorizontalLayout) Optional(java.util.Optional) Optional(java.util.Optional) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService)

Example 4 with BusinessServiceGraph

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());
    }
}
Also used : Builder(org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy.Builder) MockBusinessServiceHierarchy(org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) Test(org.junit.Test)

Example 5 with BusinessServiceGraph

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);
    }
}
Also used : GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)

Aggregations

BusinessServiceGraph (org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)10 GraphVertex (org.opennms.netmgt.bsm.service.model.graph.GraphVertex)7 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)5 List (java.util.List)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 Status (org.opennms.netmgt.bsm.service.model.Status)4 Optional (java.util.Optional)3 BusinessServiceStateMachine (org.opennms.netmgt.bsm.service.BusinessServiceStateMachine)3 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 Sets (com.google.common.collect.Sets)2 Label (com.vaadin.ui.Label)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Objects (java.util.Objects)2 Set (java.util.Set)2 AlarmWrapper (org.opennms.netmgt.bsm.service.model.AlarmWrapper)2 GraphEdge (org.opennms.netmgt.bsm.service.model.graph.GraphEdge)2 BusinessServiceGraphImpl (org.opennms.netmgt.bsm.service.model.graph.internal.BusinessServiceGraphImpl)2