@Test @JUnitTemporaryDatabase public void testGetIpPrimaryAddress() throws SQLException { m_jdbcTemplate.update("INSERT INTO node (nodeId, nodeCreateTime, nodeType, nodeLabel) VALUES (12, now(), 'A', 'nodeLabel')"); m_jdbcTemplate.update("INSERT INTO ipinterface (nodeid, ipaddr, iplastcapsdpoll, issnmpprimary) VALUES (12, '172.168.1.1', now(), 'P')"); String ipAddr = NetworkElementFactory.getInstance(m_appContext).getIpPrimaryAddress(12); assertEquals(ipAddr, "172.168.1.1"); }
@Override public String getIpPrimaryAddress(int nodeId) { OnmsCriteria criteria = new OnmsCriteria(OnmsIpInterface.class); criteria.add(Restrictions.and(Restrictions.eq("node.id", nodeId), Restrictions.eq("isSnmpPrimary", PrimaryType.PRIMARY))); List<OnmsIpInterface> ifaces = m_ipInterfaceDao.findMatching(criteria); if(ifaces.size() > 0) { OnmsIpInterface iface = ifaces.get(0); return InetAddressUtils.str(iface.getIpAddress()); }else{ return null; } }
NetworkElementFactory implements InitializingBean, NetworkElementFactoryInterface { @Override public String getIpPrimaryAddress(int nodeId) { OnmsCriteria criteria = new OnmsCriteria(OnmsIpInterface.class); criteria.add(Restrictions.and(Restrictions.eq("node.id", nodeId), Restrictions.eq("isSnmpPrimary", PrimaryType.PRIMARY))); List<OnmsIpInterface> ifaces = m_ipInterfaceDao.findMatching(criteria); if(ifaces.size() > 0) { OnmsIpInterface iface = ifaces.get(0); return InetAddressUtils.str(iface.getIpAddress()); }else{ return null; } } }
NetworkElementFactory implements InitializingBean, NetworkElementFactoryInterface { @Override public String getIpPrimaryAddress(int nodeId) { OnmsCriteria criteria = new OnmsCriteria(OnmsIpInterface.class); criteria.add(Restrictions.and(Restrictions.eq("node.id", nodeId), Restrictions.eq("isSnmpPrimary", PrimaryType.PRIMARY))); List<OnmsIpInterface> ifaces = m_ipInterfaceDao.findMatching(criteria); if(ifaces.size() > 0) { OnmsIpInterface iface = ifaces.get(0); return InetAddressUtils.str(iface.getIpAddress()); }else{ return null; } }  }
NetworkElementFactory implements InitializingBean, NetworkElementFactoryInterface { @Override public String getIpPrimaryAddress(int nodeId) { OnmsCriteria criteria = new OnmsCriteria(OnmsIpInterface.class); criteria.add(Restrictions.and(Restrictions.eq("node.id", nodeId), Restrictions.eq("isSnmpPrimary", PrimaryType.PRIMARY))); List<OnmsIpInterface> ifaces = m_ipInterfaceDao.findMatching(criteria); if(ifaces.size() > 0) { OnmsIpInterface iface = ifaces.get(0); return InetAddressUtils.str(iface.getIpAddress()); }else{ return null; } }  static NetworkElementFactoryInterface getInstance(ServletContext servletContext); static NetworkElementFactoryInterface getInstance(ApplicationContext appContext); @Override String getNodeLabel(int nodeId); @Override String getIpPrimaryAddress(int nodeId); @Override OnmsNode getNode(int nodeId); @Override OnmsNode getNode(String  lookupCriteria); @Override List<OnmsNode> getAllNodes(); @Override List<OnmsNode> getNodesLike(String nodeLabel); @Override List<OnmsNode> getNodesWithIpLike(String iplike); @Override List<OnmsNode> getNodesWithService(int serviceId); @Override List<OnmsNode> getNodesWithPhysAddr(String macAddr); @Override List<OnmsNode> getNodesWithPhysAddrAtInterface(String macAddr); @Override List<OnmsNode> getNodesWithPhysAddrFromSnmpInterface(String macAddr); @Override List<OnmsNode> getNodesWithIfAlias(String ifAlias); @Override String getHostname(String ipAddress); @Override Integer getIfIndex(int ipinterfaceid); @Override Integer getIfIndex(int nodeID, String ipaddr); @Override Interface getInterface(int ipInterfaceId); @Override Interface getInterface(int nodeId, String ipAddress); @Override Interface getInterface(int nodeId, String ipAddress, int ifIndex); @Override Interface getSnmpInterface(int nodeId, int ifIndex); @Override Interface[] getInterfacesWithIpAddress(String ipAddress); @Override Interface[] getInterfacesWithIfAlias(int nodeId, String ifAlias); @Override Interface[] getAllInterfacesOnNode(int nodeId); @Override Interface[] getAllSnmpInterfacesOnNode(int nodeId); @Override Interface[] getActiveInterfacesOnNode(int nodeId); @Override Interface[] getAllInterfaces(); @Override Interface[] getAllInterfaces(boolean includeSnmp); @Override Interface[] getAllManagedIpInterfaces(boolean includeSNMP); @Override Service getService(int nodeId, String ipAddress, int serviceId); @Override Service getService(int ifServiceId); @Override Service[] getAllServices(); @Override Service[] getServicesOnInterface(int nodeId, String ipAddress); @Override Service[] getServicesOnInterface(int nodeId, String ipAddress, boolean includeDeletions); @Override Service[] getServicesOnNode(int nodeId); @Override Service[] getServicesOnNode(int nodeId, int serviceId); @Override String getServiceNameFromId(int serviceId); @Override int getServiceIdFromName(String serviceName); @Override Map<Integer, String> getServiceIdToNameMap(); @Override Map<String, Integer> getServiceNameToIdMap(); @Override List<OnmsNode> getNodesLikeAndIpLike(String nodeLabel, String iplike, int serviceId); @Override List<OnmsNode> getNodesLike(String nodeLabel, int serviceId); @Override List<OnmsNode> getNodesWithIpLike(String iplike, int serviceId); @Override List<OnmsNode> getAllNodes(int serviceId); @Override List<OnmsNode> getNodesFromPhysaddr(String AtPhysAddr); @Override AtInterface getAtInterface(int nodeId, String ipAddr); @Override IpRouteInterface[] getIpRoute(int nodeID); @Override boolean isParentNode(int nodeId); @Override boolean isBridgeNode(int nodeID); @Override boolean isRouteInfoNode(int nodeID); @Override Set<Integer> getLinkedNodeIdOnNode(int nodeID); @Override List<LinkInterface> getDataLinksOnNode(int nodeId); @Override List<LinkInterface> getDataLinksOnInterface(int nodeId, String ipAddress); @Override List<LinkInterface> getDataLinksOnInterface(int id); @Override List<LinkInterface> getDataLinksOnInterface(int nodeId, int ifIndex); @Override Vlan[] getVlansOnNode(int nodeID); @Override StpInterface[] getStpInterface(int nodeID); @Override StpInterface[] getStpInterface(int nodeID, int ifindex); @Override StpNode[] getStpNode(int nodeID); @Override List<Integer> getNodeIdsWithIpLike(String iplike); List<OnmsNode> getNodesWithCategories(TransactionTemplate transTemplate, final String[] categories1, final boolean onlyNodesWithDownAggregateStatus); @Override List<OnmsNode> getNodesWithCategories(String[] categories, boolean onlyNodesWithDownAggregateStatus); @Override List<OnmsNode> getNodesWithCategories(TransactionTemplate transTemplate, final String[] categories1, final String[] categories2, final boolean onlyNodesWithDownAggregateStatus); @Override List<OnmsNode> getNodesWithCategories(String[] categories1, String[] categories2, boolean onlyNodesWithDownAggregateStatus); @Override void afterPropertiesSet(); }
NetworkElementFactory implements InitializingBean, NetworkElementFactoryInterface { @Override public String getIpPrimaryAddress(int nodeId) { OnmsCriteria criteria = new OnmsCriteria(OnmsIpInterface.class); criteria.add(Restrictions.and(Restrictions.eq("node.id", nodeId), Restrictions.eq("isSnmpPrimary", PrimaryType.PRIMARY))); List<OnmsIpInterface> ifaces = m_ipInterfaceDao.findMatching(criteria); if(ifaces.size() > 0) { OnmsIpInterface iface = ifaces.get(0); return InetAddressUtils.str(iface.getIpAddress()); }else{ return null; } }  static NetworkElementFactoryInterface getInstance(ServletContext servletContext); static NetworkElementFactoryInterface getInstance(ApplicationContext appContext); @Override String getNodeLabel(int nodeId); @Override String getIpPrimaryAddress(int nodeId); @Override OnmsNode getNode(int nodeId); @Override OnmsNode getNode(String  lookupCriteria); @Override List<OnmsNode> getAllNodes(); @Override List<OnmsNode> getNodesLike(String nodeLabel); @Override List<OnmsNode> getNodesWithIpLike(String iplike); @Override List<OnmsNode> getNodesWithService(int serviceId); @Override List<OnmsNode> getNodesWithPhysAddr(String macAddr); @Override List<OnmsNode> getNodesWithPhysAddrAtInterface(String macAddr); @Override List<OnmsNode> getNodesWithPhysAddrFromSnmpInterface(String macAddr); @Override List<OnmsNode> getNodesWithIfAlias(String ifAlias); @Override String getHostname(String ipAddress); @Override Integer getIfIndex(int ipinterfaceid); @Override Integer getIfIndex(int nodeID, String ipaddr); @Override Interface getInterface(int ipInterfaceId); @Override Interface getInterface(int nodeId, String ipAddress); @Override Interface getInterface(int nodeId, String ipAddress, int ifIndex); @Override Interface getSnmpInterface(int nodeId, int ifIndex); @Override Interface[] getInterfacesWithIpAddress(String ipAddress); @Override Interface[] getInterfacesWithIfAlias(int nodeId, String ifAlias); @Override Interface[] getAllInterfacesOnNode(int nodeId); @Override Interface[] getAllSnmpInterfacesOnNode(int nodeId); @Override Interface[] getActiveInterfacesOnNode(int nodeId); @Override Interface[] getAllInterfaces(); @Override Interface[] getAllInterfaces(boolean includeSnmp); @Override Interface[] getAllManagedIpInterfaces(boolean includeSNMP); @Override Service getService(int nodeId, String ipAddress, int serviceId); @Override Service getService(int ifServiceId); @Override Service[] getAllServices(); @Override Service[] getServicesOnInterface(int nodeId, String ipAddress); @Override Service[] getServicesOnInterface(int nodeId, String ipAddress, boolean includeDeletions); @Override Service[] getServicesOnNode(int nodeId); @Override Service[] getServicesOnNode(int nodeId, int serviceId); @Override String getServiceNameFromId(int serviceId); @Override int getServiceIdFromName(String serviceName); @Override Map<Integer, String> getServiceIdToNameMap(); @Override Map<String, Integer> getServiceNameToIdMap(); @Override List<OnmsNode> getNodesLikeAndIpLike(String nodeLabel, String iplike, int serviceId); @Override List<OnmsNode> getNodesLike(String nodeLabel, int serviceId); @Override List<OnmsNode> getNodesWithIpLike(String iplike, int serviceId); @Override List<OnmsNode> getAllNodes(int serviceId); @Override List<OnmsNode> getNodesFromPhysaddr(String AtPhysAddr); @Override AtInterface getAtInterface(int nodeId, String ipAddr); @Override IpRouteInterface[] getIpRoute(int nodeID); @Override boolean isParentNode(int nodeId); @Override boolean isBridgeNode(int nodeID); @Override boolean isRouteInfoNode(int nodeID); @Override Set<Integer> getLinkedNodeIdOnNode(int nodeID); @Override List<LinkInterface> getDataLinksOnNode(int nodeId); @Override List<LinkInterface> getDataLinksOnInterface(int nodeId, String ipAddress); @Override List<LinkInterface> getDataLinksOnInterface(int id); @Override List<LinkInterface> getDataLinksOnInterface(int nodeId, int ifIndex); @Override Vlan[] getVlansOnNode(int nodeID); @Override StpInterface[] getStpInterface(int nodeID); @Override StpInterface[] getStpInterface(int nodeID, int ifindex); @Override StpNode[] getStpNode(int nodeID); @Override List<Integer> getNodeIdsWithIpLike(String iplike); List<OnmsNode> getNodesWithCategories(TransactionTemplate transTemplate, final String[] categories1, final boolean onlyNodesWithDownAggregateStatus); @Override List<OnmsNode> getNodesWithCategories(String[] categories, boolean onlyNodesWithDownAggregateStatus); @Override List<OnmsNode> getNodesWithCategories(TransactionTemplate transTemplate, final String[] categories1, final String[] categories2, final boolean onlyNodesWithDownAggregateStatus); @Override List<OnmsNode> getNodesWithCategories(String[] categories1, String[] categories2, boolean onlyNodesWithDownAggregateStatus); @Override void afterPropertiesSet();  }