@Override public OnmsSnmpInterface query() { final OnmsSnmpInterface dbSnmpIface = m_snmpInterfaceDao.findByNodeIdAndIfIndex(nodeId, snmpInterface.getIfIndex()); LOG.debug("nodeId = {}, ifIndex = {}, dbSnmpIface = {}", nodeId, snmpInterface.getIfIndex(), dbSnmpIface); return dbSnmpIface; }
map.put("Number of SNMP Interfaces", getResource(Integer.toString(m_snmpInterfaceDao.countAll())));
public ElasticFlowRepository(MetricRegistry metricRegistry, JestClient jestClient, IndexStrategy indexStrategy, DocumentEnricher documentEnricher, ClassificationEngine classificationEngine, TransactionOperations transactionOperations, NodeDao nodeDao, SnmpInterfaceDao snmpInterfaceDao, int bulkRetryCount, long maxFlowDurationMs) { this.client = Objects.requireNonNull(jestClient); this.indexStrategy = Objects.requireNonNull(indexStrategy); this.documentEnricher = Objects.requireNonNull(documentEnricher); this.classificationEngine = Objects.requireNonNull(classificationEngine); this.transactionOperations = Objects.requireNonNull(transactionOperations); this.nodeDao = Objects.requireNonNull(nodeDao); this.snmpInterfaceDao = Objects.requireNonNull(snmpInterfaceDao); this.bulkRetryCount = bulkRetryCount; this.indexSelector = new IndexSelector(TYPE, indexStrategy, maxFlowDurationMs); flowsPersistedMeter = metricRegistry.meter("flowsPersisted"); logConversionTimer = metricRegistry.timer("logConversion"); logEnrichementTimer = metricRegistry.timer("logEnrichment"); logPersistingTimer = metricRegistry.timer("logPersisting"); logMarkingTimer = metricRegistry.timer("logMarking"); flowsPerLog = metricRegistry.histogram("flowsPerLog"); // Pre-populate marker cache with values from DB this.transactionOperations.execute(cb -> { for (final OnmsNode node : this.nodeDao.findAllHavingFlows()) { this.markerCache.put(node.getId(), this.snmpInterfaceDao.findAllHavingFlows(node.getId()).stream() .map(OnmsSnmpInterface::getIfIndex) .collect(Collectors.toCollection(Sets::newConcurrentHashSet))); } return null; }); }
@Override public OnmsSnmpInterface doUpdate(final OnmsSnmpInterface dbSnmpIface) { // update the interface that was found dbSnmpIface.mergeSnmpInterfaceAttributes(snmpInterface); LOG.info("Updating SnmpInterface {}", dbSnmpIface); m_snmpInterfaceDao.update(dbSnmpIface); m_snmpInterfaceDao.flush(); return dbSnmpIface; }
@Override public OnmsSnmpInterface doInsert() { // add the interface to the node, if it wasn't found final OnmsNode dbNode = m_nodeDao.load(nodeId); assertNotNull(dbNode, "no node found with nodeId %d", nodeId); // for performance reasons we don't add the snmp interface to the node so we avoid loading all the interfaces // setNode only sets the node in the interface snmpInterface.setNode(dbNode); LOG.info("Saving SnmpInterface {}", snmpInterface); m_snmpInterfaceDao.save(snmpInterface); m_snmpInterfaceDao.flush(); return snmpInterface; }
for (final OnmsSnmpInterface snmpIface : m_snmpInterfaceDao.findAll()) { for (OnmsIpInterface eachIf : snmpIface.getIpInterfaces()) { eachIf.setSnmpInterface(null); m_snmpInterfaceDao.delete(snmpIface); m_alarmDao.flush(); m_eventDao.flush(); m_snmpInterfaceDao.flush(); m_ipInterfaceDao.flush(); m_nodeDao.flush();
/** {@inheritDoc} */ @Override public void update(OnmsSnmpInterface snmpinterface) { OnmsSnmpInterface dbSnmpInterface = getSnmpInterfaceDao().findByNodeIdAndIfIndex(snmpinterface.getNode().getId(), snmpinterface.getIfIndex()); if (dbSnmpInterface == null) { log().debug("updating SnmpInterface: no interface found on db for: " + snmpinterface.toString()); } else { dbSnmpInterface.setIfOperStatus(snmpinterface.getIfOperStatus()); dbSnmpInterface.setIfAdminStatus(snmpinterface.getIfAdminStatus()); dbSnmpInterface.setLastSnmpPoll(snmpinterface.getLastSnmpPoll()); log().debug("updating SnmpInterface: " + dbSnmpInterface.toString()); getSnmpInterfaceDao().update(dbSnmpInterface); } }
for (final OnmsSnmpInterface iface : dbNode.getSnmpInterfaces()) { if (!node.getSnmpInterfaces().contains(iface)) { getSnmpInterfaceDao().delete(iface); getSnmpInterfaceDao().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()); } }
builder.eq("ipInterfaces.ipAddress", ipAddr); List<OnmsSnmpInterface> ifaces = m_snmpInterfaceDao.findMatching(builder.toCriteria());
@Override public SnmpInterface findByNodeIdAndDescrOrName(Integer nodeId, String descrOrName) { // Note that the SnmpInterfaceDaoHibernate#findByNodeIdAndDescription method actually // searches by either the ifName or the ifDescr return sessionUtils.withReadOnlyTransaction(() -> ModelMappers.toSnmpInterface(snmpInterfaceDao.findByNodeIdAndDescription(nodeId, descrOrName))); }
@Before public void setUp() { MockLogAppender.setupLogging(); m_populator.populateDatabase(); m_interfaces = m_snmpInterfaceDao.findAll(); }
@Override public OnmsSnmpInterface doUpdate(final OnmsSnmpInterface dbSnmpIface) { // update the interface that was found dbSnmpIface.mergeSnmpInterfaceAttributes(snmpInterface); LOG.info("Updating SnmpInterface {}", dbSnmpIface); m_snmpInterfaceDao.update(dbSnmpIface); m_snmpInterfaceDao.flush(); return dbSnmpIface; }
@Override public OnmsSnmpInterface doInsert() { // add the interface to the node, if it wasn't found final OnmsNode dbNode = m_nodeDao.load(nodeId); assertNotNull(dbNode, "no node found with nodeId %d", nodeId); // for performance reasons we don't add the snmp interface to the node so we avoid loading all the interfaces // setNode only sets the node in the interface snmpInterface.setNode(dbNode); LOG.info("Saving SnmpInterface {}", snmpInterface); m_snmpInterfaceDao.save(snmpInterface); m_snmpInterfaceDao.flush(); return snmpInterface; }
for (final OnmsSnmpInterface iface : dbNode.getSnmpInterfaces()) { if (!node.getSnmpInterfaces().contains(iface)) { getSnmpInterfaceDao().delete(iface); getSnmpInterfaceDao().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()); } }
/** {@inheritDoc} */ @Override public List<OnmsSnmpInterface> get(int nodeId, String criteria) { CriteriaBuilder builder = new CriteriaBuilder(OnmsSnmpInterface.class); builder.sql(criteria).eq("node.id", nodeId).eq("poll", "P"); builder.alias("ipInterfaces", "ipInterface", JoinType.LEFT_JOIN); return getSnmpInterfaceDao().findMatching(builder.toCriteria()); }
OnmsSnmpInterface iface = m_snmpInterfaceDao.findByNodeIdAndDescription(nodeId, queryDesc);
@Override public OnmsSnmpInterface query() { final OnmsSnmpInterface dbSnmpIface = m_snmpInterfaceDao.findByNodeIdAndIfIndex(nodeId, snmpInterface.getIfIndex()); LOG.debug("nodeId = {}, ifIndex = {}, dbSnmpIface = {}", nodeId, snmpInterface.getIfIndex(), dbSnmpIface); return dbSnmpIface; }
@Override public void delete(final OnmsNode node) { for (final OnmsIpInterface iface : node.getIpInterfaces()) { getIpInterfaceDao().delete(iface); } for (final OnmsSnmpInterface iface : node.getSnmpInterfaces()) { getSnmpInterfaceDao().delete(iface); } super.delete(node); }