/** * mergeSnmpInterfaces * * @param scannedNode a {@link org.opennms.netmgt.model.OnmsNode} object. * @param deleteMissing a boolean. */ public void mergeSnmpInterfaces(OnmsNode scannedNode, boolean deleteMissing) { // we need to skip this step if there is an indication that snmp data collection failed if (scannedNode.getSnmpInterfaces().size() == 0) { // we assume here that snmp collection failed and we don't update the snmp data return; } // Build map of ifIndices to scanned SnmpInterfaces Map<Integer, OnmsSnmpInterface> scannedInterfaceMap = new HashMap<Integer, OnmsSnmpInterface>(); for (OnmsSnmpInterface snmpIface : scannedNode.getSnmpInterfaces()) { if (snmpIface.getIfIndex() != null) { scannedInterfaceMap.put(snmpIface.getIfIndex(), snmpIface); } } // for each interface on existing node... for (Iterator<OnmsSnmpInterface> it = getSnmpInterfaces().iterator(); it.hasNext(); ) { OnmsSnmpInterface iface = it.next(); OnmsSnmpInterface imported = scannedInterfaceMap.get(iface.getIfIndex()); // remove it since there is no corresponding scanned interface if (imported == null) { if (deleteMissing) { it.remove(); scannedInterfaceMap.remove(iface.getIfIndex()); } } else { // merge the data from the corresponding scanned interface iface.mergeSnmpInterfaceAttributes(imported); scannedInterfaceMap.remove(iface.getIfIndex()); } } // for any scanned interface that was not found on the node add it the database for (OnmsSnmpInterface snmpIface : scannedInterfaceMap.values()) { addSnmpInterface(snmpIface); } }