private OnmsIpInterface lookupIpInterface(OnmsNode node, String ipAddress) { final OnmsIpInterface ipInterface = ipInterfaceDao.findByNodeIdAndIpAddress(node.getId(), ipAddress); if (ipInterface == null) { throw new IllegalArgumentException(String.format("No interface found with IP %s on node %s", ipAddress, node.getId())); } return ipInterface; } }
@Override public List<OnmsIpInterface> findMatching(Criteria criteria) { return ipInterfaceDao.findMatching(criteria); } }
/** {@inheritDoc} */ @Transactional @Override public OnmsMonitoredService addMonitoredService(final Integer ipInterfaceId, final String svcName) { final OnmsIpInterface iface = m_ipInterfaceDao.get(ipInterfaceId); assertNotNull(iface, "could not find interface with id %d", ipInterfaceId); return addMonitoredService(iface, svcName); }
@Transactional private OnmsIpInterface saveOrUpdate(final OnmsIpInterface iface) { iface.visit(new ServiceTypeFulfiller()); LOG.info("SaveOrUpdating IpInterface {}", iface); m_ipInterfaceDao.saveOrUpdate(iface); m_ipInterfaceDao.flush(); return iface; }
@Override public void update(Integer nodeid, ReverseDnsRecord rdr) { OnmsIpInterface ipInterface = m_ipInterfaceDao.findByNodeIdAndIpAddress(nodeid, rdr.getIp().getHostAddress()); if (ipInterface != null) { ipInterface.setIpHostName(rdr.getHostname()); m_ipInterfaceDao.update(ipInterface); } }
return null; final OnmsIpInterface svcIface = m_ipInterfaceDao.findByNodeIdAndIpAddress(nodeId, ipAddress); if (svcIface == null) { LOG.info("unable to find IPInterface for nodeId={}, ipAddress={}", nodeId, ipAddress); m_ipInterfaceDao.saveOrUpdate(svcIface); m_ipInterfaceDao.flush(); primaryIface= svcIface; } else { svcIface.setIsSnmpPrimary(PrimaryType.SECONDARY); m_ipInterfaceDao.saveOrUpdate(svcIface); m_ipInterfaceDao.flush(); m_ipInterfaceDao.initialize(primaryIface); return primaryIface;
protected final OnmsIpInterface getIpInterface() { return m_ifaceDao.load(m_ifaceId); }
private void setupInterface(OnmsIpInterface iface) { expect(m_ipIfDao.findByServiceType("SNMP")).andReturn(Collections.singletonList(iface)); expect(m_ipIfDao.load(iface.getId())).andReturn(iface).atLeastOnce(); }
m_snmpInterfaceDao.delete(snmpIface); for (final OnmsIpInterface iface : m_ipInterfaceDao.findAll()) { iface.setSnmpInterface(null); iface.getNode().getIpInterfaces().remove(iface); m_ipInterfaceDao.delete(iface); m_eventDao.flush(); m_snmpInterfaceDao.flush(); m_ipInterfaceDao.flush(); m_nodeDao.flush(); m_serviceTypeDao.flush();
@Override protected OnmsIpInterface doUpdate(final OnmsIpInterface dbIface) { final EventAccumulator accumulator = new EventAccumulator(m_eventForwarder); if(dbIface.isManaged() && !scannedIface.isManaged()){ final Set<OnmsMonitoredService> monSvcs = dbIface.getMonitoredServices(); for(final OnmsMonitoredService monSvc : monSvcs){ monSvc.visit(new DeleteEventVisitor(accumulator)); } monSvcs.clear(); } dbIface.updateSnmpInterface(scannedIface); dbIface.mergeInterfaceAttributes(scannedIface); LOG.info("Updating IpInterface {}", dbIface); m_ipInterfaceDao.update(dbIface); m_ipInterfaceDao.flush(); accumulator.flush(); return dbIface; }
getIpInterfaceDao().delete(iface); getIpInterfaceDao().saveOrUpdate(iface);
@Override public void deleteObsoleteInterfaces(final Integer nodeId, final Date scanStamp) { final OnmsNode node = get(nodeId); if (node == null) return; for (final OnmsIpInterface iface : findObsoleteIpInterfaces(nodeId, scanStamp)) { LOG.debug("Deleting obsolete IP interface: {}", iface); node.getIpInterfaces().remove(iface); getIpInterfaceDao().delete(iface.getId()); } for (final OnmsSnmpInterface iface : findObsoleteSnmpInterfaces(nodeId, scanStamp)) { LOG.debug("Deleting obsolete SNMP interface: {}", iface); node.getSnmpInterfaces().remove(iface); getSnmpInterfaceDao().delete(iface.getId()); } }
map.put("Number of IP Interfaces", getResource(Integer.toString(m_ipInterfaceDao.countAll())));
private Collection<OnmsIpInterface> findInterfacesWithService(String svcName) { instrumentation().beginFindInterfacesWithService(svcName); int count = -1; try { Collection<OnmsIpInterface> ifaces = m_ifaceDao.findByServiceType(svcName); count = ifaces.size(); return ifaces; } finally { instrumentation().endFindInterfacesWithService(svcName, count); } }
@Override protected OnmsIpInterface doInsert() { final OnmsNode dbNode = m_nodeDao.load(nodeId); assertNotNull(dbNode, "no node found with nodeId %d", nodeId); // for performance reasons we don't add the IP interface to the node so we avoid loading all the interfaces // setNode only sets the node in the interface scannedIface.setNode(dbNode); saveOrUpdate(scannedIface); m_ipInterfaceDao.flush(); final AddEventVisitor visitor = new AddEventVisitor(m_eventForwarder); scannedIface.visit(visitor); return scannedIface; } }.execute();
@Override public MonitoredService doInTransaction(TransactionStatus status) { final List<OnmsIpInterface> ips = ipInterfaceDao.findByIpAddress(ipAddress); if (ips == null || ips.size() == 0) { System.err.printf("Error: Can't find the IP address %s on the database\n", ipAddress); return null; } if (ips.size() > 1) { System.out.printf("Warning: there are several IP interface objects associated with the IP address %s (picking the first one)\n", ipAddress); } OnmsNode n = ips.get(0).getNode(); return new SimpleMonitoredService(addr, n.getId(), n.getLabel(), serviceName); } });
@Before public void setUp() { MockLogAppender.setupLogging(); m_populator.populateDatabase(); m_interfaces = m_ipInterfaceDao.findAll(); }
return null; final OnmsIpInterface svcIface = m_ipInterfaceDao.findByNodeIdAndIpAddress(nodeId, ipAddress); if (svcIface == null) { LOG.info("unable to find IPInterface for nodeId={}, ipAddress={}", nodeId, ipAddress); m_ipInterfaceDao.saveOrUpdate(svcIface); m_ipInterfaceDao.flush(); primaryIface= svcIface; } else { svcIface.setIsSnmpPrimary(PrimaryType.SECONDARY); m_ipInterfaceDao.saveOrUpdate(svcIface); m_ipInterfaceDao.flush(); m_ipInterfaceDao.initialize(primaryIface); return primaryIface;
protected final OnmsIpInterface getIpInterface() { return m_ifaceDao.load(m_ifaceId); }
EasyMock.expect(m_ifaceDao.findByServiceType(snmp.getName())).andReturn(initialIfs).anyTimes(); EasyMock.expect(m_ifaceDao.load(2)).andReturn(ifaceBlder.getInterface()).anyTimes();