Search in sources :

Example 1 with NodeIdentification

use of org.opennms.netmgt.model.ncs.NCSComponent.NodeIdentification in project opennms by OpenNMS.

the class EventMappingRulesIT method findSubcomponentsOnNode.

private Set<String> findSubcomponentsOnNode(NCSComponent svc, String nodeForeignSource, String nodeForeignId) {
    final Set<String> expectedIds = new HashSet<String>();
    final NodeIdentification nodeIdent = new NodeIdentification(nodeForeignSource, nodeForeignId);
    NCSComponentVisitor visitor = new AbstractNCSComponentVisitor() {

        @Override
        public void visitComponent(NCSComponent component) {
            if (nodeIdent.equals(component.getNodeIdentification())) {
                expectedIds.add(component.getForeignSource() + ":" + component.getForeignId());
            }
        }
    };
    svc.visit(visitor);
    return expectedIds;
}
Also used : NCSComponentVisitor(org.opennms.netmgt.model.ncs.NCSComponentVisitor) AbstractNCSComponentVisitor(org.opennms.netmgt.model.ncs.AbstractNCSComponentVisitor) NCSComponent(org.opennms.netmgt.model.ncs.NCSComponent) AbstractNCSComponentVisitor(org.opennms.netmgt.model.ncs.AbstractNCSComponentVisitor) NodeIdentification(org.opennms.netmgt.model.ncs.NCSComponent.NodeIdentification) HashSet(java.util.HashSet)

Example 2 with NodeIdentification

use of org.opennms.netmgt.model.ncs.NCSComponent.NodeIdentification in project opennms by OpenNMS.

the class NCSEdgeProvider method getEdges.

/**
	 * This factory works by using {@link NCSServiceCriteria} to construct edges based on
	 * connecting all of the ServiceElements that make up a Service to each other.
	 * 
	 * @param criteria An {@link NCSServiceCriteria} object
	 */
@Override
public List<Edge> getEdges(Criteria... criteria) {
    List<Edge> retval = new ArrayList<Edge>();
    for (Criteria criterium : criteria) {
        try {
            NCSServiceCriteria crit = (NCSServiceCriteria) criterium;
            for (Long id : crit) {
                NCSComponent service = m_dao.get(id);
                if (service == null) {
                    LoggerFactory.getLogger(this.getClass()).warn("NCSComponent not found for ID {}", id);
                } else {
                    //Check foreignsource of the subcomponents to make sure it matches the Service's foreignsource
                    NCSComponent[] subs = checkForeignSource(service.getForeignSource(), service.getSubcomponents());
                    // Connect all of the ServiceElements to one another
                    for (int i = 0; i < subs.length; i++) {
                        for (int j = i + 1; j < subs.length; j++) {
                            String foreignSource = null, foreignId = null;
                            OnmsNode sourceNode = null, targetNode = null;
                            NodeIdentification ident = subs[i].getNodeIdentification();
                            String sourceLabel = subs[i].getName();
                            if (ident != null) {
                                foreignSource = ident.getForeignSource();
                                foreignId = ident.getForeignId();
                                sourceNode = m_nodeDao.findByForeignId(foreignSource, foreignId);
                                if (sourceNode == null) {
                                    continue;
                                }
                                if (sourceLabel == null) {
                                    sourceLabel = sourceNode.getLabel();
                                }
                            }
                            ident = subs[j].getNodeIdentification();
                            String targetLabel = subs[j].getName();
                            if (ident != null) {
                                foreignSource = ident.getForeignSource();
                                foreignId = ident.getForeignId();
                                targetNode = m_nodeDao.findByForeignId(foreignSource, foreignId);
                                if (targetNode == null) {
                                    continue;
                                }
                                if (targetLabel == null) {
                                    targetLabel = targetNode.getLabel();
                                }
                            }
                            String sourceElementName = subs[i].getForeignSource() + "::" + subs[i].getForeignId();
                            String targetElementName = subs[j].getForeignSource() + "::" + subs[j].getForeignId();
                            retval.add(new NCSEdge(subs[i].getForeignId(), service.getName(), sourceElementName, targetElementName, new NCSVertex(String.valueOf(sourceNode.getId()), sourceLabel), new NCSVertex(String.valueOf(targetNode.getId()), targetLabel)));
                        }
                    }
                }
            }
        } catch (ClassCastException e) {
        }
    }
    return retval;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) ArrayList(java.util.ArrayList) Criteria(org.opennms.features.topology.api.topo.Criteria) NCSComponent(org.opennms.netmgt.model.ncs.NCSComponent) NodeIdentification(org.opennms.netmgt.model.ncs.NCSComponent.NodeIdentification) Edge(org.opennms.features.topology.api.topo.Edge) AbstractEdge(org.opennms.features.topology.api.topo.AbstractEdge)

Aggregations

NCSComponent (org.opennms.netmgt.model.ncs.NCSComponent)2 NodeIdentification (org.opennms.netmgt.model.ncs.NCSComponent.NodeIdentification)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AbstractEdge (org.opennms.features.topology.api.topo.AbstractEdge)1 Criteria (org.opennms.features.topology.api.topo.Criteria)1 Edge (org.opennms.features.topology.api.topo.Edge)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 AbstractNCSComponentVisitor (org.opennms.netmgt.model.ncs.AbstractNCSComponentVisitor)1 NCSComponentVisitor (org.opennms.netmgt.model.ncs.NCSComponentVisitor)1