Search in sources :

Example 11 with EventAnticipator

use of org.opennms.netmgt.dao.mock.EventAnticipator in project opennms by OpenNMS.

the class DragonWaveNodeSwitchingIT method testASetup.

@Test
@JUnitSnmpAgents({ @JUnitSnmpAgent(host = "192.168.255.22", resource = "classpath:/dw/walks/node3-walk.properties") })
public void testASetup() throws Exception {
    final int nextNodeId = m_nodeDao.getNextNodeId();
    final InetAddress iface = InetAddressUtils.addr("192.168.255.22");
    final EventAnticipator anticipator = m_eventSubscriber.getEventAnticipator();
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_ADDED_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(iface).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_SERVICE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(iface).setService("SNMP").getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_SERVICE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(iface).setService("ICMP").getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.REINITIALIZE_PRIMARY_SNMP_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(iface).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.PROVISION_SCAN_COMPLETE_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
    importResource("classpath:/dw/import/dw_test_import.xml");
    anticipator.verifyAnticipated(200000, 0, 0, 0, 0);
    final OnmsNode onmsNode = m_nodeDao.findAll().get(0);
    assertEquals(".1.3.6.1.4.1.7262.1", onmsNode.getSysObjectId());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) InetAddress(java.net.InetAddress) EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 12 with EventAnticipator

use of org.opennms.netmgt.dao.mock.EventAnticipator in project opennms by OpenNMS.

the class MockNetworkTest method testWaitForEvent.

public void testWaitForEvent() throws Throwable {
    MockNode node = m_network.getNode(1);
    final Event event1 = MockEventUtil.createNodeDownEvent("Test", node);
    final Event event2 = MockEventUtil.createNodeDownEvent("Test", node);
    final Event event3 = MockEventUtil.createNodeDownEvent("Test", m_network.getNode(2));
    EventAnticipator anticipator = m_eventMgr.getEventAnticipator();
    anticipator.anticipateEvent(event1);
    anticipator.anticipateEvent(event3);
    class EventSender extends Thread {

        Throwable m_t = null;

        public void assertSuccess() throws Throwable {
            if (m_t != null)
                throw m_t;
        }

        @Override
        public void run() {
            try {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                }
                m_eventMgr.sendNow(event2);
                m_eventMgr.sendNow(event2);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                }
                m_eventMgr.sendNow(event3);
            } catch (Throwable t) {
                m_t = t;
            }
        }
    }
    ;
    EventSender eventSender = new EventSender();
    eventSender.start();
    eventSender.assertSuccess();
    assertEquals(1, anticipator.waitForAnticipated(1500).size());
    assertEquals(0, anticipator.waitForAnticipated(1000).size());
    assertEquals(1, anticipator.getUnanticipatedEvents().size());
}
Also used : Event(org.opennms.netmgt.xml.event.Event) EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator)

Example 13 with EventAnticipator

use of org.opennms.netmgt.dao.mock.EventAnticipator in project opennms by OpenNMS.

the class DiscoveryIntegrationIT method testDiscoveryTaskExecutor.

@Test
public void testDiscoveryTaskExecutor() throws Exception {
    // Add a range of localhost IP addresses to ping
    IncludeRange range = new IncludeRange();
    //range.setBegin("127.0.5.1");
    //range.setEnd("127.0.5.254");
    range.setBegin("192.168.99.1");
    range.setEnd("192.168.99.100");
    range.setTimeout(5000l);
    range.setRetries(0);
    DiscoveryConfiguration config = new DiscoveryConfiguration();
    config.setInitialSleepTime(0l);
    // 100 addresses at 10 per second should take at least 10 seconds
    config.setPacketsPerSecond(10d);
    config.clearIncludeRanges();
    config.addIncludeRange(range);
    // Anticipate newSuspect events for all of the addresses
    EventAnticipator anticipator = m_eventIpcManager.getEventAnticipator();
    StreamSupport.stream(new DiscoveryConfigFactory(config).getConfiguredAddresses().spliterator(), false).forEach(addr -> {
        System.out.println("ANTICIPATING: " + str(addr.getAddress()));
        Event event = new Event();
        event.setUei(EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI);
        event.setInterfaceAddress(addr.getAddress());
        anticipator.anticipateEvent(event);
    });
    Date beforeTime = new Date();
    // Invoke a one-time scan via the DiscoveryTaskExecutor service
    m_taskExecutor.handleDiscoveryTask(config);
    Date afterTime = new Date();
    // Make sure that this call returns quickly as an async. call
    long timespan = (afterTime.getTime() - beforeTime.getTime());
    System.out.println("Task executor invocation took " + timespan + "ms");
    assertTrue("Timespan was not less than 8 seconds: " + timespan, timespan < 8000L);
    anticipator.waitForAnticipated(60000);
    anticipator.verifyAnticipated();
}
Also used : IncludeRange(org.opennms.netmgt.config.discovery.IncludeRange) DiscoveryConfiguration(org.opennms.netmgt.config.discovery.DiscoveryConfiguration) Event(org.opennms.netmgt.xml.event.Event) DiscoveryConfigFactory(org.opennms.netmgt.config.DiscoveryConfigFactory) Date(java.util.Date) EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator) Test(org.junit.Test)

Example 14 with EventAnticipator

use of org.opennms.netmgt.dao.mock.EventAnticipator in project opennms by OpenNMS.

the class RequisitionRestServiceJsonIT method testImportNoRescan.

@Test
public void testImportNoRescan() throws Exception {
    createRequisition();
    EventAnticipator anticipator = m_eventProxy.getEventAnticipator();
    sendRequest(PUT, "/requisitions/test/import", parseParamData("rescanExisting=false"), 202);
    assertEquals(1, anticipator.getUnanticipatedEvents().size());
    final Event event = anticipator.getUnanticipatedEvents().iterator().next();
    final List<Parm> parms = event.getParmCollection();
    assertEquals(2, parms.size());
    assertEquals("false", parms.get(1).getValue().getContent());
}
Also used : Event(org.opennms.netmgt.xml.event.Event) Parm(org.opennms.netmgt.xml.event.Parm) EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator) Test(org.junit.Test)

Example 15 with EventAnticipator

use of org.opennms.netmgt.dao.mock.EventAnticipator in project opennms by OpenNMS.

the class NewSuspectScanIT method runDuplicateIpScan.

private void runDuplicateIpScan(final String firstForeignSource, final String secondForeignSource, final String firstLocation, final String secondLocation) throws InterruptedException, ExecutionException {
    int nextNodeId = m_nodeDao.getNextNodeId();
    //Verify empty database
    assertEquals(1, getDistPollerDao().countAll());
    assertEquals(0, getNodeDao().countAll());
    assertEquals(0, getInterfaceDao().countAll());
    assertEquals(0, getMonitoredServiceDao().countAll());
    assertEquals(0, getServiceTypeDao().countAll());
    assertEquals(0, getSnmpInterfaceDao().countAll());
    InetAddress ip = addr("192.0.2.123");
    EventAnticipator anticipator = m_eventSubscriber.getEventAnticipator();
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_ADDED_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(ip).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.PROVISION_SCAN_COMPLETE_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
    NewSuspectScan scan = m_provisioner.createNewSuspectScan(ip, firstForeignSource, firstLocation);
    runScan(scan);
    anticipator.verifyAnticipated(20000, 0, 2000, 0, 0);
    //Verify distpoller count
    assertEquals(1, getDistPollerDao().countAll());
    //Verify node count
    assertEquals(1, getNodeDao().countAll());
    //Verify ipinterface count
    assertEquals("Unexpected number of interfaces found: " + getInterfaceDao().findAll(), 1, getInterfaceDao().countAll());
    // Now do it again, with a different location
    nextNodeId = m_nodeDao.getNextNodeId();
    anticipator = m_eventSubscriber.getEventAnticipator();
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_ADDED_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(ip).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.PROVISION_SCAN_COMPLETE_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
    scan = m_provisioner.createNewSuspectScan(ip, secondForeignSource, secondLocation);
    runScan(scan);
    anticipator.verifyAnticipated(20000, 0, 2000, 0, 0);
    //Verify distpoller count
    assertEquals(1, getDistPollerDao().countAll());
    //Verify node count
    assertEquals(2, getNodeDao().countAll());
    //Verify ipinterface count
    assertEquals("Unexpected number of interfaces found: " + getInterfaceDao().findAll(), 2, getInterfaceDao().countAll());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) InetAddress(java.net.InetAddress) EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator)

Aggregations

EventAnticipator (org.opennms.netmgt.dao.mock.EventAnticipator)21 Test (org.junit.Test)17 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)11 Event (org.opennms.netmgt.xml.event.Event)8 OnmsNode (org.opennms.netmgt.model.OnmsNode)7 InetAddress (java.net.InetAddress)6 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)4 Date (java.util.Date)2 DiscoveryConfiguration (org.opennms.netmgt.config.discovery.DiscoveryConfiguration)2 IncludeRange (org.opennms.netmgt.config.discovery.IncludeRange)2 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)2 Parm (org.opennms.netmgt.xml.event.Parm)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 BigInteger (java.math.BigInteger)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Before (org.junit.Before)1 JUnitSnmpAgent (org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)1 DiscoveryConfigFactory (org.opennms.netmgt.config.DiscoveryConfigFactory)1