Search in sources :

Example 1 with BusinessServiceStateMachine

use of org.opennms.netmgt.bsm.service.BusinessServiceStateMachine 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 BusinessServiceStateMachine

use of org.opennms.netmgt.bsm.service.BusinessServiceStateMachine in project opennms by OpenNMS.

the class BusinessServiceEdgeStatusInfoPanelItemProvider method createComponent.

private Component createComponent(BusinessServiceEdge ref, GraphContainer container) {
    FormLayout formLayout = new FormLayout();
    formLayout.setMargin(false);
    formLayout.setSpacing(false);
    formLayout.addStyleName("severity");
    final BusinessServiceStateMachine stateMachine = SimulationAwareStateMachineFactory.createStateMachine(businessServiceManager, container.getCriteria());
    final Status outgoingStatus = BusinessServicesStatusProvider.getStatus(stateMachine, ref);
    final Status incomingStatus = BusinessServicesStatusProvider.getStatus(stateMachine, ((AbstractBusinessServiceVertex) ref.getTarget().getVertex()));
    formLayout.addComponent(createStatusLabel("Outgoing Severity", outgoingStatus));
    formLayout.addComponent(createStatusLabel("Incoming Severity", incomingStatus));
    return formLayout;
}
Also used : FormLayout(com.vaadin.ui.FormLayout) Status(org.opennms.netmgt.bsm.service.model.Status) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) AbstractBusinessServiceVertex(org.opennms.features.topology.plugins.topo.bsm.AbstractBusinessServiceVertex)

Example 3 with BusinessServiceStateMachine

use of org.opennms.netmgt.bsm.service.BusinessServiceStateMachine in project opennms by OpenNMS.

the class SimulationAwareStateMachineFactory method createSimulatedStateMachine.

public static BusinessServiceStateMachine createSimulatedStateMachine(BusinessServiceManager manager, Criteria[] criteria) {
    // Gather the statuses and group them by reduction key
    final Map<String, Status> statusByReductionKey = Arrays.stream(criteria).filter(c -> c instanceof SetStatusToCriteria).map(c -> (SetStatusToCriteria) c).filter(c -> c.getStatus() != null).collect(Collectors.toMap(SetStatusToCriteria::getReductionKey, SetStatusToCriteria::getStatus));
    // Determine whether or not we should inherit the existing state
    final boolean shouldInheritState = Arrays.stream(criteria).anyMatch(c -> c instanceof InheritStateCriteria);
    // Grab a copy of the state machine, and update push alarms
    // that reflect the simulated state of the reduction keys
    final BusinessServiceStateMachine stateMachine = manager.getStateMachine().clone(shouldInheritState);
    for (Entry<String, Status> entry : statusByReductionKey.entrySet()) {
        stateMachine.handleNewOrUpdatedAlarm(new AlarmWrapper() {

            @Override
            public String getReductionKey() {
                return entry.getKey();
            }

            @Override
            public Status getStatus() {
                return entry.getValue();
            }
        });
    }
    return stateMachine;
}
Also used : Arrays(java.util.Arrays) Status(org.opennms.netmgt.bsm.service.model.Status) Map(java.util.Map) Criteria(org.opennms.features.topology.api.topo.Criteria) Entry(java.util.Map.Entry) BusinessServiceManager(org.opennms.netmgt.bsm.service.BusinessServiceManager) AlarmWrapper(org.opennms.netmgt.bsm.service.model.AlarmWrapper) Collectors(java.util.stream.Collectors) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) Status(org.opennms.netmgt.bsm.service.model.Status) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) AlarmWrapper(org.opennms.netmgt.bsm.service.model.AlarmWrapper)

Example 4 with BusinessServiceStateMachine

use of org.opennms.netmgt.bsm.service.BusinessServiceStateMachine in project opennms by OpenNMS.

the class BusinessServiceVertexStatusInfoPanelItemProvider method createComponent.

private Component createComponent(BusinessServiceVertex vertex, GraphContainer container) {
    final FormLayout rootLayout = new FormLayout();
    rootLayout.setSizeFull();
    rootLayout.setSpacing(false);
    rootLayout.setMargin(false);
    rootLayout.addStyleName("severity");
    final BusinessServiceStateMachine stateMachine = SimulationAwareStateMachineFactory.createStateMachine(businessServiceManager, container.getCriteria());
    final Status overallStatus = BusinessServicesStatusProvider.getStatus(stateMachine, vertex);
    rootLayout.addComponent(createStatusLabel("Overall", overallStatus));
    rootLayout.addComponent(new Label());
    final BusinessServiceGraph graph = stateMachine.getGraph();
    final BusinessService businessService = businessServiceManager.getBusinessServiceById(vertex.getServiceId());
    final Set<GraphVertex> impactingVertices = getImpactingVertices(stateMachine, graph, businessService);
    for (final Edge edge : businessService.getEdges()) {
        // Get the topology vertex for the child to determine the display label
        final Vertex childVertex = businessServicesTopologyProvider.getVertex(edge.accept(new EdgeVisitor<VertexRef>() {

            @Override
            public VertexRef visit(final IpServiceEdge edge) {
                return new IpServiceVertex(edge.getIpService(), 0);
            }

            @Override
            public VertexRef visit(final ReductionKeyEdge edge) {
                return new ReductionKeyVertex(edge.getReductionKey(), 0);
            }

            @Override
            public VertexRef visit(final ChildEdge edge) {
                return new BusinessServiceVertex(edge.getChild(), 0);
            }
        }));
        final Status edgeStatus = stateMachine.getOperationalStatus(edge);
        rootLayout.addComponent(createStatusLabel(childVertex.getLabel(), edgeStatus, String.format("%s &times; %d <i class=\"pull-right glyphicon %s\"></i>", edgeStatus.getLabel(), edge.getWeight(), impactingVertices.contains(graph.getVertexByEdgeId(edge.getId())) ? "glyphicon-flash" : "")));
    }
    return rootLayout;
}
Also used : FormLayout(com.vaadin.ui.FormLayout) Status(org.opennms.netmgt.bsm.service.model.Status) Vertex(org.opennms.features.topology.api.topo.Vertex) IpServiceVertex(org.opennms.features.topology.plugins.topo.bsm.IpServiceVertex) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) BusinessServiceVertex(org.opennms.features.topology.plugins.topo.bsm.BusinessServiceVertex) ReductionKeyVertex(org.opennms.features.topology.plugins.topo.bsm.ReductionKeyVertex) ReductionKeyVertex(org.opennms.features.topology.plugins.topo.bsm.ReductionKeyVertex) ChildEdge(org.opennms.netmgt.bsm.service.model.edge.ChildEdge) Label(com.vaadin.ui.Label) UIHelper.createLabel(org.opennms.netmgt.vaadin.core.UIHelper.createLabel) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) EdgeVisitor(org.opennms.netmgt.bsm.service.model.edge.EdgeVisitor) IpServiceVertex(org.opennms.features.topology.plugins.topo.bsm.IpServiceVertex) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) ChildEdge(org.opennms.netmgt.bsm.service.model.edge.ChildEdge) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge) Edge(org.opennms.netmgt.bsm.service.model.edge.Edge) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) BusinessServiceVertex(org.opennms.features.topology.plugins.topo.bsm.BusinessServiceVertex)

Example 5 with BusinessServiceStateMachine

use of org.opennms.netmgt.bsm.service.BusinessServiceStateMachine in project opennms by OpenNMS.

the class AbstractAnalysisOperation method execute.

@Override
public void execute(List<VertexRef> targets, OperationContext operationContext) {
    final List<AbstractBusinessServiceVertex> vertices = getVertices(targets);
    final BusinessServiceStateMachine stateMachine = SimulationAwareStateMachineFactory.createStateMachine(businessServiceManager, operationContext.getGraphContainer().getCriteria());
    final Set<GraphVertex> graphVerticesToFocus = Sets.newHashSet();
    final BusinessServiceVertexVisitor<Collection<GraphVertex>> visitor = getVisitorForVerticesToFocus(stateMachine);
    for (AbstractBusinessServiceVertex vertex : vertices) {
        graphVerticesToFocus.addAll(vertex.accept(visitor));
    }
    LOG.debug("Found {} business services.", graphVerticesToFocus.size());
    if (graphVerticesToFocus.isEmpty()) {
        new InfoDialog("No result", getMessageForNoResultDialog()).open();
    } else {
        focusOnVertices(targets.get(0), graphVerticesToFocus, operationContext.getGraphContainer());
    }
}
Also used : GraphVertex(org.opennms.netmgt.bsm.service.model.graph.GraphVertex) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) InfoDialog(org.opennms.netmgt.vaadin.core.InfoDialog) Collection(java.util.Collection) AbstractBusinessServiceVertex(org.opennms.features.topology.plugins.topo.bsm.AbstractBusinessServiceVertex)

Aggregations

BusinessServiceStateMachine (org.opennms.netmgt.bsm.service.BusinessServiceStateMachine)7 Status (org.opennms.netmgt.bsm.service.model.Status)4 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)3 FormLayout (com.vaadin.ui.FormLayout)2 File (java.io.File)2 Collection (java.util.Collection)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Collectors (java.util.stream.Collectors)2 Test (org.junit.Test)2 AbstractBusinessServiceVertex (org.opennms.features.topology.plugins.topo.bsm.AbstractBusinessServiceVertex)2 MockBusinessServiceHierarchy (org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy)2 AlarmWrapper (org.opennms.netmgt.bsm.service.model.AlarmWrapper)2 GraphVertex (org.opennms.netmgt.bsm.service.model.graph.GraphVertex)2 Throwables (com.google.common.base.Throwables)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 Label (com.vaadin.ui.Label)1 KKLayout (edu.uci.ics.jung.algorithms.layout.KKLayout)1 Layout (edu.uci.ics.jung.algorithms.layout.Layout)1