@Test @JUnitSnmpAgents( value = {@JUnitSnmpAgent(host = Sluck001_IP, port = 161, resource = Sluck001_SNMP_RESOURCE)}) public void testNetworkLinksCiscoJuniperVlan() throws Exception { m_nodeDao.save(builder.getSluck001()); m_nodeDao.flush(); Package example1 = m_linkdConfig.getPackage("example1"); example1.setUseIsisDiscovery(false); example1.setUseIpRouteDiscovery(false); example1.setUseOspfDiscovery(false); example1.setUseLldpDiscovery(false); example1.setUseCdpDiscovery(false); example1.setUseBridgeDiscovery(false); example1.setEnableVlanDiscovery(true); example1.setSaveStpNodeTable(false); example1.setSaveStpInterfaceTable(false); example1.setSaveRouteTable(false); final OnmsNode switchCisco = m_nodeDao.findByForeignId("linkd", Sluck001_NAME); assertTrue(m_linkd.scheduleNodeCollection(switchCisco.getId())); assertTrue(m_linkd.runSingleSnmpCollection(switchCisco.getId())); assertEquals(7, m_vlanDao.countAll()); }
@Transactional(readOnly = true) private OnmsNode getDbNode(final OnmsNode node) { OnmsNode dbNode; if (node.getId() != null) { dbNode = m_nodeDao.get(node.getId()); } else { dbNode = m_nodeDao.findByForeignId(node.getForeignSource(), node.getForeignId()); } return dbNode; }
protected OnmsIpInterface getAddress(OnmsNode node) { // OnmsIpInterface ip = node.getPrimaryInterface(); OnmsIpInterface ip = getIpInterfaceDao().findPrimaryInterfaceByNodeId(node.getId()); if (ip == null) { // for (OnmsIpInterface iterip: node.getIpInterfaces()) { for (OnmsIpInterface iterip : getIpInterfaceDao().findByNodeId(node.getId())) { ip = iterip; break; } } return ip; }
protected void saveLink( final BridgeTopologyLink bridgelink, Integer nodeId, Map<Integer, Integer> bridgeportIfIndex) { OnmsNode node = m_nodeDao.get(bridgelink.getBridgeTopologyPort().getNodeid()); if (node == null) return; OnmsNode designatenode = null; if (bridgelink.getDesignateBridgePort() != null) { designatenode = m_nodeDao.get(bridgelink.getDesignateBridgePort().getNodeid()); } if (bridgelink.getMacs().isEmpty() && designatenode != null) { BridgeBridgeLink link = new BridgeBridgeLink(); link.setNode(node); link.setBridgePort(bridgelink.getBridgeTopologyPort().getBridgePort()); if (node.getId().intValue() == nodeId.intValue() && bridgeportIfIndex.containsKey(bridgelink.getBridgeTopologyPort().getBridgePort())) { link.setBridgePortIfIndex( bridgeportIfIndex.get(bridgelink.getBridgeTopologyPort().getBridgePort())); } link.setDesignatedNode(designatenode); link.setDesignatedPort(bridgelink.getDesignateBridgePort().getBridgePort()); if (designatenode.getId().intValue() == nodeId.intValue() && bridgeportIfIndex.containsKey(bridgelink.getDesignateBridgePort().getBridgePort())) { link.setDesignatedPortIfIndex( bridgeportIfIndex.get(bridgelink.getDesignateBridgePort().getBridgePort())); } saveBridgeBridgeLink(link); return; } for (String mac : bridgelink.getMacs()) { BridgeMacLink maclink1 = new BridgeMacLink(); maclink1.setNode(node); maclink1.setBridgePort(bridgelink.getBridgeTopologyPort().getBridgePort()); if (node.getId().intValue() == nodeId.intValue() && bridgeportIfIndex.containsKey(bridgelink.getBridgeTopologyPort().getBridgePort())) { maclink1.setBridgePortIfIndex( bridgeportIfIndex.get(bridgelink.getBridgeTopologyPort().getBridgePort())); } maclink1.setMacAddress(mac); saveBridgeMacLink(maclink1); if (designatenode == null) continue; BridgeMacLink maclink2 = new BridgeMacLink(); maclink2.setNode(designatenode); maclink2.setBridgePort(bridgelink.getDesignateBridgePort().getBridgePort()); if (designatenode.getId().intValue() == nodeId.intValue() && bridgeportIfIndex.containsKey(bridgelink.getDesignateBridgePort().getBridgePort())) { maclink2.setBridgePortIfIndex( bridgeportIfIndex.get(bridgelink.getDesignateBridgePort().getBridgePort())); } maclink2.setMacAddress(mac); saveBridgeMacLink(maclink2); } }
private NodeScanSchedule createScheduleForNode(final OnmsNode node, final boolean force) { Assert.notNull(node, "Node may not be null"); final String actualForeignSource = node.getForeignSource(); if (actualForeignSource == null && !isDiscoveryEnabled()) { infof( this, "Not scheduling node %s to be scanned since it has a null foreignSource and handling of discovered nodes is disabled in provisiond", node); return null; } final String effectiveForeignSource = actualForeignSource == null ? "default" : actualForeignSource; try { final ForeignSource fs = m_foreignSourceRepository.getForeignSource(effectiveForeignSource); final Duration scanInterval = fs.getScanInterval(); Duration initialDelay = Duration.ZERO; if (node.getLastCapsdPoll() != null && !force) { final DateTime nextPoll = new DateTime(node.getLastCapsdPoll().getTime()).plus(scanInterval); final DateTime now = new DateTime(); if (nextPoll.isAfter(now)) { initialDelay = new Duration(now, nextPoll); } } return new NodeScanSchedule( node.getId(), actualForeignSource, node.getForeignId(), initialDelay, scanInterval); } catch (final ForeignSourceRepositoryException e) { warnf(this, e, "unable to get foreign source '%s' from repository", effectiveForeignSource); return null; } }
public Map<Integer, String> getNodeLabelsById() { Map<Integer, String> nodeLabelsById = new HashMap<Integer, String>(); for (OnmsNode node : getNodes()) { nodeLabelsById.put(node.getId(), node.getLabel()); } return nodeLabelsById; }
@Test @JUnitTemporaryDatabase // Relies on records created in @Before so we need a fresh database public void testUpdateNode() throws InterruptedException { AdapterOperationChecker verifyOperations = new AdapterOperationChecker(2); m_adapter.getOperationQueue().addListener(verifyOperations); try { OnmsNode node = m_nodeDao.get(NODE_ID); assertNotNull(node); int firstNodeId = node.getId(); assertNull(node.getAssetRecord().getComment()); m_adapter.addNode(firstNodeId); m_adapter.updateNode(firstNodeId); assertTrue(verifyOperations.enqueueLatch.await(4, TimeUnit.SECONDS)); assertTrue(verifyOperations.dequeueLatch.await(4, TimeUnit.SECONDS)); assertTrue(verifyOperations.executeLatch.await(4, TimeUnit.SECONDS)); assertEquals(0, m_adapter.getOperationQueue().getOperationQueueForNode(firstNodeId).size()); node = m_nodeDao.get(firstNodeId); assertNotNull(node); System.out.println("ID: " + node.getAssetRecord().getId()); System.out.println("Comment: " + node.getAssetRecord().getComment()); assertNotNull("AssetRecord comment is null", node.getAssetRecord().getComment()); assertEquals(EXPECTED_COMMENT_FIELD, node.getAssetRecord().getComment()); } finally { m_adapter.getOperationQueue().removeListener(verifyOperations); } }
/** {@inheritDoc} */ @Override public Long getParentNode(final Long nodeid) { final OnmsNode node = m_nodeDao.get(nodeid.intValue()); Assert.notNull(node, "Unable to find node with id " + nodeid); final OnmsNode parent = node.getParent(); return (parent == null ? null : new Long(parent.getId().longValue())); }
@Test @Transactional public void testGetIfIndexByName() throws SQLException { m_nodeDao.save(builder.getCiscoC870()); m_nodeDao.save(builder.getCiscoWsC2948()); m_nodeDao.flush(); OnmsNode ciscorouter = m_nodeDao.findByForeignId("linkd", CISCO_C870_NAME); assertEquals("FastEthernet2", ciscorouter.getSnmpInterfaceWithIfIndex(3).getIfDescr()); OnmsNode ciscosw = m_nodeDao.findByForeignId("linkd", CISCO_WS_C2948_NAME); assertEquals("2/44", ciscosw.getSnmpInterfaceWithIfIndex(52).getIfName()); HibernateEventWriter db = (HibernateEventWriter) m_linkd.getQueryManager(); assertEquals(3, db.getIfIndexByName(ciscorouter.getId(), "FastEthernet2")); assertEquals(52, db.getIfIndexByName(ciscosw.getId(), "2/44")); }
@Test public void testWorkStation() throws Exception { m_nodeDao.save(builder.getNodeWithoutSnmp(WORKSTATION_NAME, WORKSTATION_IP)); m_nodeDao.flush(); final OnmsNode workstation = m_nodeDao.findByForeignId("linkd", WORKSTATION_NAME); assertTrue(!m_linkd.scheduleNodeCollection(workstation.getId())); }
@Test public void testGetNodeidFromIp() throws UnknownHostException, SQLException { m_nodeDao.save(builder.getCiscoC870()); m_nodeDao.flush(); HibernateEventWriter db = (HibernateEventWriter) m_linkd.getQueryManager(); final OnmsNode node = db.getNodeidFromIp(InetAddressUtils.addr(CISCO_C870_IP)).get(0); assertEquals(m_nodeDao.findByForeignId("linkd", CISCO_C870_NAME).getId(), node.getId()); }
private void walkTable( final BatchTask currentPhase, final Set<InetAddress> provisionedIps, final TableTracker tracker) { final OnmsNode node = getNode(); LOG.info( "detecting IP interfaces for node {}/{}/{} using table tracker {}", node.getId(), node.getForeignSource(), node.getForeignId(), tracker); if (isAborted()) { LOG.debug("'{}' is marked as aborted; skipping scan of table {}", currentPhase, tracker); } else { Assert.notNull(getAgentConfigFactory(), "agentConfigFactory was not injected"); final SnmpAgentConfig agentConfig = getAgentConfigFactory().getAgentConfig(getAgentAddress()); final SnmpWalker walker = SnmpUtils.createWalker(agentConfig, "IP address tables", tracker); walker.start(); try { walker.waitFor(); if (walker.timedOut()) { abort("Aborting node scan : Agent timed out while scanning the IP address tables"); } else if (walker.failed()) { abort( "Aborting node scan : Agent failed while scanning the IP address tables : " + walker.getErrorMessage()); } else { // After processing the SNMP provided interfaces then we need to scan any that // were provisioned but missing from the ip table for (final InetAddress ipAddr : provisionedIps) { final OnmsIpInterface iface = node.getIpInterfaceByIpAddress(ipAddr); if (iface != null) { iface.setIpLastCapsdPoll(getScanStamp()); iface.setIsManaged("M"); currentPhase.add(ipUpdater(currentPhase, iface), "write"); } } LOG.debug("Finished phase {}", currentPhase); } } catch (final InterruptedException e) { abort("Aborting node scan : Scan thread failed while waiting for the IP address tables"); } } }
/* * fixed a fake link found using cdp: * caused by duplicated ip address s * r-uk-nott-newt-103:Fa0:(1)<------>(4):Fa3:r-ro-suce-pict-001 */ @Test @JUnitSnmpAgents( value = { @JUnitSnmpAgent(host = RPict001_IP, port = 161, resource = RPict001_SNMP_RESOURCE), @JUnitSnmpAgent(host = RNewt103_IP, port = 161, resource = RNewt103_SNMP_RESOURCE) }) public void testCdpFakeLinkRoUk() throws Exception { m_nodeDao.save(builder.getRPict001()); m_nodeDao.save(builder.getRNewt103()); m_nodeDao.flush(); Package example1 = m_linkdConfig.getPackage("example1"); example1.setUseIsisDiscovery(false); example1.setUseIpRouteDiscovery(false); example1.setUseOspfDiscovery(false); example1.setUseLldpDiscovery(false); example1.setUseCdpDiscovery(true); example1.setUseBridgeDiscovery(false); example1.setEnableVlanDiscovery(false); example1.setSaveStpNodeTable(false); example1.setSaveStpInterfaceTable(false); example1.setSaveRouteTable(false); final OnmsNode routerRo = m_nodeDao.findByForeignId("linkd", RPict001_NAME); final OnmsNode routerUk = m_nodeDao.findByForeignId("linkd", RNewt103_NAME); assertTrue(m_linkd.scheduleNodeCollection(routerRo.getId())); assertTrue(m_linkd.scheduleNodeCollection(routerUk.getId())); assertTrue(m_linkd.runSingleSnmpCollection(routerRo.getId())); assertTrue(m_linkd.runSingleSnmpCollection(routerUk.getId())); assertEquals(0, m_dataLinkInterfaceDao.countAll()); assertTrue(m_linkd.runSingleLinkDiscovery("example1")); assertEquals(0, m_dataLinkInterfaceDao.countAll()); }
/** * toString * * @return a {@link java.lang.String} object. */ public String toString() { return new ToStringBuilder(this) .append("Nodeid", m_node == null ? null : m_node.getId()) .append( "lldpChassisSubType", LldpChassisIdSubType.getTypeString(m_lldpChassisIdSubType.getValue())) .append("lldpChassisId", m_lldpChassisId) .append("lldpSysName", m_lldpSysname) .append("lldpNodeCreateTime", m_lldpNodeCreateTime) .append("lldpNodeLastPollTime", m_lldpNodeLastPollTime) .toString(); }
/** * detectAgents * * @param currentPhase a {@link org.opennms.core.tasks.BatchTask} object. */ public void detectAgents(final BatchTask currentPhase) { if (!isAborted()) { final OnmsNode node = getNode(); final OnmsIpInterface primaryIface = m_provisionService.getPrimaryInterfaceForNode(node); if (primaryIface != null && primaryIface.getMonitoredServiceByServiceType("SNMP") != null) { LOG.debug( "Found primary interface and SNMP service for node {}/{}/{}", node.getId(), node.getForeignSource(), node.getForeignId()); onAgentFound(currentPhase, primaryIface); } else { LOG.debug( "Failed to locate primary interface and SNMP service for node {}/{}/{}", node.getId(), node.getForeignSource(), node.getForeignId()); } } }
/* * We want to test that the next hop router discovered * links can be discovered using the ospf neb table */ @Test @JUnitSnmpAgents( value = { @JUnitSnmpAgent(host = PENROSE_IP, port = 161, resource = PENROSE_SNMP_RESOURCE), @JUnitSnmpAgent(host = DELAWARE_IP, port = 161, resource = DELAWARE_SNMP_RESOURCE) }) public void testNetwork1055StpLinks() throws Exception { m_nodeDao.save(builder.getPenrose()); m_nodeDao.save(builder.getDelaware()); m_nodeDao.flush(); Package example1 = m_linkdConfig.getPackage("example1"); example1.setUseBridgeDiscovery(true); example1.setUseLldpDiscovery(false); example1.setUseCdpDiscovery(false); example1.setUseIpRouteDiscovery(false); example1.setUseOspfDiscovery(false); example1.setUseIsisDiscovery(false); example1.setSaveRouteTable(false); example1.setSaveStpInterfaceTable(false); example1.setSaveStpNodeTable(false); final OnmsNode penrose = m_nodeDao.findByForeignId("linkd", PENROSE_NAME); final OnmsNode delaware = m_nodeDao.findByForeignId("linkd", DELAWARE_NAME); assertTrue(m_linkd.scheduleNodeCollection(penrose.getId())); assertTrue(m_linkd.scheduleNodeCollection(delaware.getId())); assertTrue(m_linkd.runSingleSnmpCollection(penrose.getId())); assertTrue(m_linkd.runSingleSnmpCollection(delaware.getId())); assertEquals(0, m_dataLinkInterfaceDao.countAll()); assertTrue(m_linkd.runSingleLinkDiscovery("example1")); assertEquals(1, m_dataLinkInterfaceDao.countAll()); }
/** * toString * * @return a {@link java.lang.String} object. */ public String toString() { return new ToStringBuilder(this) .append("NodeId", m_node.getId()) .append("ospfRouterId", str(m_ospfRouterId)) .append("ospfRouterIdNetmask", str(m_ospfRouterIdNetmask)) .append("ospfRouterIdIfindex", m_ospfRouterIdIfindex) .append("ospfAdminStat", Status.getTypeString(m_ospfAdminStat.getValue())) .append("ospfVersionNumber", m_ospfVersionNumber) .append("ospfBdrRtrStatus", TruthValue.getTypeString(m_ospfBdrRtrStatus.getValue())) .append("ospfASBdrRtrStatus", TruthValue.getTypeString(m_ospfASBdrRtrStatus.getValue())) .append("createTime", m_ospfNodeCreateTime) .append("lastPollTime", m_ospfNodeLastPollTime) .toString(); }
/** {@inheritDoc} */ @Transactional public void updateNode(final OnmsNode node) { final OnmsNode dbNode = m_nodeDao.getHierarchy(node.getId()); dbNode.mergeNode(node, m_eventForwarder, false); m_nodeDao.update(dbNode); m_nodeDao.flush(); final EntityVisitor eventAccumlator = new UpdateEventVisitor(m_eventForwarder); node.visit(eventAccumlator); }
@Test @JUnitTemporaryDatabase // Relies on records created in @Before so we need a fresh database @Transactional public void testAddNodeDirectly() throws InterruptedException { OnmsNode node = m_nodeDao.get(NODE_ID); assertNotNull(node); int firstNodeId = node.getId(); m_adapter.doAddNode(firstNodeId); node = m_nodeDao.get(firstNodeId); assertNotNull(node); assertNotNull("AssetRecord comment is null", node.getAssetRecord().getComment()); assertEquals(EXPECTED_COMMENT_FIELD, node.getAssetRecord().getComment()); }
@Test @JUnitTemporaryDatabase // Relies on records created in @Before so we need a fresh database public void testNodeConfigChanged() throws InterruptedException { AdapterOperationChecker verifyOperations = new AdapterOperationChecker(1); m_adapter.getOperationQueue().addListener(verifyOperations); try { OnmsNode node = m_nodeDao.get(NODE_ID); assertNotNull(node); int firstNodeId = node.getId(); m_adapter.nodeConfigChanged(firstNodeId); } finally { m_adapter.getOperationQueue().removeListener(verifyOperations); } }
/** * compareTo * * @param o a {@link org.opennms.netmgt.model.OnmsNode} object. * @return a int. */ @Override public int compareTo(OnmsNode o) { String compareLabel = ""; Integer compareId = 0; if (o != null) { compareLabel = o.getLabel(); compareId = o.getId(); } int returnval = this.getLabel().compareToIgnoreCase(compareLabel); if (returnval == 0) { return this.getId().compareTo(compareId); } else { return returnval; } }
@Override public String toString() { return new ToStringBuilder(this) .append("Nodeid", m_node.getId()) .append("baseBridgeAddress", m_baseBridgeAddress) .append("baseNumPorts", m_baseNumPorts) .append("baseType", BridgeDot1dBaseType.getTypeString(m_baseType.getValue())) .append("stpProtocolSpecification", m_stpProtocolSpecification) .append("stpPriority", m_stpPriority) .append("stpDesignatedRoot", m_stpDesignatedRoot) .append("stpRootCost", m_stpRootCost) .append("m_stpRootPort", m_stpRootPort) .append("vlan", m_vlan) .append("vlanname", m_vlanname) .append("m_bridgeNodeCreateTime", m_bridgeNodeCreateTime) .append("m_bridgeNodeLastPollTime", m_bridgeNodeLastPollTime) .toString(); }
@Override public List<LinkableSnmpNode> getSnmpNodeList() { final List<LinkableSnmpNode> nodes = new ArrayList<LinkableSnmpNode>(); final Criteria criteria = new Criteria(OnmsNode.class); criteria.setAliases( Arrays.asList(new Alias[] {new Alias("ipInterfaces", "iface", JoinType.LEFT_JOIN)})); criteria.addRestriction(new EqRestriction("type", NodeType.ACTIVE)); criteria.addRestriction(new EqRestriction("iface.isSnmpPrimary", PrimaryType.PRIMARY)); for (final OnmsNode node : m_nodeDao.findMatching(criteria)) { nodes.add( new LinkableSnmpNode( node.getId(), node.getPrimaryInterface().getIpAddress(), node.getSysObjectId(), node.getSysName())); } return nodes; }
@Test @Transactional public void testSave() { OnmsEvent event = new OnmsEvent(); event.setEventLog("Y"); event.setEventDisplay("Y"); event.setEventCreateTime(new Date()); event.setDistPoller(m_distPollerDao.load("localhost")); event.setEventTime(new Date()); event.setEventSeverity(new Integer(7)); event.setEventUei("uei://org/opennms/test/EventDaoTest"); event.setEventSource("test"); m_eventDao.save(event); OnmsNode node = m_nodeDao.findAll().iterator().next(); OnmsAlarm alarm = new OnmsAlarm(); alarm.setNode(node); alarm.setUei(event.getEventUei()); alarm.setSeverityId(event.getEventSeverity()); alarm.setFirstEventTime(event.getEventTime()); alarm.setLastEvent(event); alarm.setCounter(1); alarm.setDistPoller(m_distPollerDao.load("localhost")); m_alarmDao.save(alarm); // It works we're so smart! hehe OnmsAlarm newAlarm = m_alarmDao.load(alarm.getId()); assertEquals("uei://org/opennms/test/EventDaoTest", newAlarm.getUei()); assertEquals(alarm.getLastEvent().getId(), newAlarm.getLastEvent().getId()); Collection<OnmsAlarm> alarms; Criteria criteria = new Criteria(OnmsAlarm.class); criteria.addRestriction(new EqRestriction("node.id", node.getId())); alarms = m_alarmDao.findMatching(criteria); assertEquals(1, alarms.size()); newAlarm = alarms.iterator().next(); assertEquals("uei://org/opennms/test/EventDaoTest", newAlarm.getUei()); assertEquals(alarm.getLastEvent().getId(), newAlarm.getLastEvent().getId()); }
@GET @Path("fornode/{nodeCriteria}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML}) @Transactional(readOnly = true) public ResourceDTO getResourceForNode( @PathParam("nodeCriteria") final String nodeCriteria, @DefaultValue("-1") @QueryParam("depth") final int depth) { OnmsNode node = m_nodeDao.get(nodeCriteria); if (node == null) { throw getException(Status.NOT_FOUND, "No node found with criteria '{}'.", nodeCriteria); } OnmsResource resource = m_resourceDao.getResourceForNode(node); if (resource == null) { throw getException( Status.NOT_FOUND, "No resource found for node with id {}.", "" + node.getId()); } return ResourceDTO.fromResource(resource, depth); }
@Test @JUnitTemporaryDatabase // Relies on records created in @Before so we need a fresh database public void testDeleteNode() throws InterruptedException { AdapterOperationChecker verifyOperations = new AdapterOperationChecker(1); m_adapter.getOperationQueue().addListener(verifyOperations); try { OnmsNode node = m_nodeDao.get(NODE_ID); assertNotNull(node); int firstNodeId = node.getId(); m_adapter.deleteNode(firstNodeId); assertTrue(verifyOperations.enqueueLatch.await(4, TimeUnit.SECONDS)); assertTrue(verifyOperations.dequeueLatch.await(4, TimeUnit.SECONDS)); assertTrue(verifyOperations.executeLatch.await(4, TimeUnit.SECONDS)); assertEquals(0, m_adapter.getOperationQueue().getOperationQueueForNode(firstNodeId).size()); } finally { m_adapter.getOperationQueue().removeListener(verifyOperations); } }
@Override public LinkableSnmpNode getSnmpNode(final int nodeid) { final Criteria criteria = new Criteria(OnmsNode.class); criteria.setAliases( Arrays.asList(new Alias[] {new Alias("ipInterfaces", "iface", JoinType.LEFT_JOIN)})); criteria.addRestriction(new EqRestriction("type", NodeType.ACTIVE)); criteria.addRestriction(new EqRestriction("iface.isSnmpPrimary", PrimaryType.PRIMARY)); criteria.addRestriction(new EqRestriction("id", nodeid)); final List<OnmsNode> nodes = m_nodeDao.findMatching(criteria); if (nodes.size() > 0) { final OnmsNode node = nodes.get(0); return new LinkableSnmpNode( node.getId(), node.getPrimaryInterface().getIpAddress(), node.getSysObjectId(), node.getSysName()); } else { return null; } }
@Test @JUnitSnmpAgents( value = { @JUnitSnmpAgent( host = "10.1.1.2", port = 161, resource = "classpath:linkd/10.1.1.2-walk.txt"), @JUnitSnmpAgent( host = "10.1.2.2", port = 161, resource = "classpath:linkd/10.1.2.2-walk.txt"), @JUnitSnmpAgent( host = "10.1.3.2", port = 161, resource = "classpath:linkd/10.1.3.2-walk.txt"), @JUnitSnmpAgent( host = "10.1.4.2", port = 161, resource = "classpath:linkd/10.1.4.2-walk.txt") }) public void testNms4005Network() throws Exception { final OnmsNode cisco1 = m_nodeDao.findByForeignId("linkd", "cisco1"); final OnmsNode cisco2 = m_nodeDao.findByForeignId("linkd", "cisco2"); final OnmsNode cisco3 = m_nodeDao.findByForeignId("linkd", "cisco3"); assertTrue(m_linkd.scheduleNodeCollection(cisco1.getId())); assertTrue(m_linkd.scheduleNodeCollection(cisco2.getId())); assertTrue(m_linkd.scheduleNodeCollection(cisco3.getId())); assertTrue(m_linkd.runSingleCollection(cisco1.getId())); assertTrue(m_linkd.runSingleCollection(cisco2.getId())); assertTrue(m_linkd.runSingleCollection(cisco3.getId())); final List<DataLinkInterface> ifaces = m_dataLinkInterfaceDao.findAll(); assertEquals("we should have found 3 data links", 3, ifaces.size()); }
@Transient @XmlElement(name = "nodeId") public Integer getNodeId() { return m_node == null ? m_nodeId : m_node.getId(); }
/** * This test is the same as {@link #testNms4005Network()} except that it spawns multiple threads * for each scan to ensure that the upsert code is working properly. */ @Test @JUnitSnmpAgents( value = { @JUnitSnmpAgent( host = "10.1.1.2", port = 161, resource = "classpath:linkd/10.1.1.2-walk.txt"), @JUnitSnmpAgent( host = "10.1.2.2", port = 161, resource = "classpath:linkd/10.1.2.2-walk.txt"), @JUnitSnmpAgent( host = "10.1.3.2", port = 161, resource = "classpath:linkd/10.1.3.2-walk.txt"), @JUnitSnmpAgent( host = "10.1.4.2", port = 161, resource = "classpath:linkd/10.1.4.2-walk.txt") }) public void testNms4005NetworkWithThreads() throws Exception { final OnmsNode cisco1 = m_nodeDao.findByForeignId("linkd", "cisco1"); final OnmsNode cisco2 = m_nodeDao.findByForeignId("linkd", "cisco2"); final OnmsNode cisco3 = m_nodeDao.findByForeignId("linkd", "cisco3"); assertTrue(m_linkd.scheduleNodeCollection(cisco1.getId())); assertTrue(m_linkd.scheduleNodeCollection(cisco2.getId())); assertTrue(m_linkd.scheduleNodeCollection(cisco3.getId())); final int NUMBER_OF_THREADS = 20; List<Thread> waitForMe = new ArrayList<Thread>(); for (int i = 0; i < NUMBER_OF_THREADS; i++) { Thread thread = new Thread("NMS-4005-Test-Thread-" + i) { public void run() { assertTrue(m_linkd.runSingleCollection(cisco1.getId())); } }; thread.start(); waitForMe.add(thread); } for (Thread thread : waitForMe) { thread.join(); } waitForMe.clear(); for (int i = 0; i < NUMBER_OF_THREADS; i++) { Thread thread = new Thread("NMS-4005-Test-Thread-" + i) { public void run() { assertTrue(m_linkd.runSingleCollection(cisco2.getId())); } }; thread.start(); waitForMe.add(thread); } for (Thread thread : waitForMe) { thread.join(); } waitForMe.clear(); for (int i = 0; i < NUMBER_OF_THREADS; i++) { Thread thread = new Thread("NMS-4005-Test-Thread-" + i) { public void run() { assertTrue(m_linkd.runSingleCollection(cisco3.getId())); } }; thread.start(); waitForMe.add(thread); } for (Thread thread : waitForMe) { thread.join(); } waitForMe.clear(); final List<DataLinkInterface> ifaces = m_dataLinkInterfaceDao.findAll(); assertEquals("we should have found 3 data links", 3, ifaces.size()); }