Search in sources :

Example 81 with VertexRef

use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.

the class ApplicationStatusProvider method getStatusForVertices.

@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
    Map<VertexRef, Status> returnMap = new HashMap<>();
    Map<ApplicationStatusEntity.Key, Status> statusMap = new HashMap<>();
    List<ApplicationStatusEntity> result = applicationDao.getAlarmStatus();
    for (ApplicationStatusEntity eachRow : result) {
        DefaultStatus status = createStatus(eachRow.getSeverity(), eachRow.getCount());
        statusMap.put(eachRow.getKey(), status);
    }
    // status for all known node ids
    Collection<VertexRef> vertexRefsForNamespace = getVertexRefsForNamespace(vertices);
    Collection<VertexRef> vertexRefsRoot = getRootElements(vertexRefsForNamespace);
    Collection<VertexRef> vertexRefs = new ArrayList<>(vertexRefsForNamespace);
    vertexRefs.removeAll(vertexRefsRoot);
    // calculate status for children
    for (VertexRef eachVertex : vertexRefs) {
        ApplicationVertex applicationVertex = (ApplicationVertex) eachVertex;
        Status alarmStatus = statusMap.get(createKey(applicationVertex));
        if (alarmStatus == null) {
            alarmStatus = createStatus(OnmsSeverity.NORMAL, 0);
        }
        returnMap.put(eachVertex, alarmStatus);
    }
    // calculate status for root
    for (VertexRef eachRoot : vertexRefsRoot) {
        ApplicationVertex eachRootApplication = (ApplicationVertex) eachRoot;
        OnmsSeverity maxSeverity = OnmsSeverity.NORMAL;
        int count = 0;
        for (VertexRef eachChild : eachRootApplication.getChildren()) {
            ApplicationVertex eachChildApplication = (ApplicationVertex) eachChild;
            ApplicationStatusEntity.Key childKey = createKey(eachChildApplication);
            Status childStatus = statusMap.get(childKey);
            if (childStatus != null && maxSeverity.isLessThan(createSeverity(childStatus.computeStatus()))) {
                maxSeverity = createSeverity(childStatus.computeStatus());
                count = Integer.parseInt(childStatus.getStatusProperties().get("statusCount"));
            }
        }
        returnMap.put(eachRoot, createStatus(maxSeverity, count));
    }
    return returnMap;
}
Also used : DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) Status(org.opennms.features.topology.api.topo.Status) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ApplicationStatusEntity(org.opennms.netmgt.dao.api.ApplicationStatusEntity) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 82 with VertexRef

use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.

the class ResourceGraphsOperation method execute.

@Override
public void execute(final List<VertexRef> targets, final OperationContext operationContext) {
    try {
        String label = "";
        int nodeID = -1;
        if (targets != null) {
            for (final VertexRef target : targets) {
                final String labelValue = getLabelValue(operationContext, target);
                final Integer nodeValue = getNodeIdValue(operationContext, target);
                if (nodeValue != null && nodeValue > 0) {
                    label = labelValue == null ? "" : labelValue;
                    nodeID = nodeValue.intValue();
                    break;
                }
            }
        }
        final Node node = new Node(nodeID, null, label);
        final String url;
        if (node.getNodeID() >= 0) {
            url = getResourceGraphNodeURL() + "[" + node.getNodeID() + "]";
        } else {
            url = getResourceGraphListURL();
        }
        final URL fullUrl = new URL(getFullUrl(url));
        operationContext.getMainWindow().addWindow(new ResourceGraphsWindow(node, fullUrl));
    } catch (final Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        } else {
            throw new RuntimeException("Failed to create resource graph window.", e);
        }
    }
}
Also used : Node(org.opennms.features.topology.netutils.internal.Node) VertexRef(org.opennms.features.topology.api.topo.VertexRef) URL(java.net.URL) ResourceGraphsWindow(org.opennms.features.topology.netutils.internal.ResourceGraphsWindow)

Example 83 with VertexRef

use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.

the class SSHOperation method execute.

@Override
public Undoer execute(final List<VertexRef> targets, final OperationContext operationContext) {
    String ipAddr = "";
    int port = 22;
    if (targets != null) {
        for (final VertexRef target : targets) {
            final Item vertexItem = operationContext.getGraphContainer().getBaseTopology().getVertex(target, operationContext.getGraphContainer().getCriteria()).getItem();
            if (vertexItem != null) {
                final Property<String> ipAddrProperty = vertexItem.getItemProperty("ipAddr");
                ipAddr = ipAddrProperty == null ? "" : (String) ipAddrProperty.getValue();
                //Property portProperty = operationContext.getGraphContainer().getVertexItem(target).getItemProperty("port");
                //portProperty == null ? -1 : (Integer) portProperty.getValue();
                port = 22;
            }
        }
    }
    operationContext.getMainWindow().addWindow(new AuthWindow(ipAddr, port));
    return null;
}
Also used : Item(com.vaadin.data.Item) AuthWindow(org.opennms.features.topology.ssh.internal.AuthWindow) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 84 with VertexRef

use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.

the class NodeInfoOperation method execute.

@Override
public void execute(final List<VertexRef> targets, final OperationContext operationContext) {
    try {
        String label = "";
        int nodeID = -1;
        if (targets != null) {
            for (final VertexRef target : targets) {
                final String labelValue = getLabelValue(operationContext, target);
                final Integer nodeValue = getNodeIdValue(operationContext, target);
                if (nodeValue != null && nodeValue > 0) {
                    label = labelValue == null ? "" : labelValue;
                    nodeID = nodeValue.intValue();
                    break;
                }
            }
        }
        final Node node = new Node(nodeID, null, label);
        final String url;
        if (node.getNodeID() >= 0) {
            url = getNodePageURL() + node.getNodeID();
        } else {
            url = getNodeListURL();
        }
        final URL fullUrl = new URL(getFullUrl(url));
        operationContext.getMainWindow().addWindow(new NodeInfoWindow(node, fullUrl));
    } catch (final Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        } else {
            throw new RuntimeException("Failed to create node window.", e);
        }
    }
}
Also used : Node(org.opennms.features.topology.netutils.internal.Node) NodeInfoWindow(org.opennms.features.topology.netutils.internal.NodeInfoWindow) VertexRef(org.opennms.features.topology.api.topo.VertexRef) URL(java.net.URL)

Example 85 with VertexRef

use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.

the class LinkdHopCriteria method getVertices.

@Override
public Set<VertexRef> getVertices() {
    Integer id = Integer.valueOf(m_nodeId);
    OnmsNode node = m_nodeDao.get(id);
    Set<VertexRef> vertices = new TreeSet<VertexRef>(new RefComparator());
    if (node != null) {
        String label = node.getLabel();
        vertices.add(new DefaultVertexRef("nodes", m_nodeId, label));
    }
    return vertices;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) TreeSet(java.util.TreeSet) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) RefComparator(org.opennms.features.topology.api.topo.RefComparator)

Aggregations

VertexRef (org.opennms.features.topology.api.topo.VertexRef)94 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)30 Vertex (org.opennms.features.topology.api.topo.Vertex)29 Point (org.opennms.features.topology.api.Point)23 Edge (org.opennms.features.topology.api.topo.Edge)22 EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)18 ArrayList (java.util.ArrayList)17 Test (org.junit.Test)17 List (java.util.List)13 Criteria (org.opennms.features.topology.api.topo.Criteria)13 SparseGraph (edu.uci.ics.jung.graph.SparseGraph)12 Collectors (java.util.stream.Collectors)12 Layout (org.opennms.features.topology.api.Layout)12 HashMap (java.util.HashMap)10 HashSet (java.util.HashSet)10 GraphContainer (org.opennms.features.topology.api.GraphContainer)10 Collection (java.util.Collection)9 Map (java.util.Map)9 Set (java.util.Set)8 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)8