Search in sources :

Example 1 with DemandPoll

use of org.opennms.netmgt.model.DemandPoll in project opennms by OpenNMS.

the class DefaultDemandPollService method pollMonitoredService.

@Override
public DemandPoll pollMonitoredService(final int nodeId, final InetAddress ipAddr, final int ifIndex, final int serviceId) {
    final DemandPoll demandPoll = new DemandPoll();
    demandPoll.setRequestTime(new Date());
    m_demandPollDao.save(demandPoll);
    final OnmsMonitoredService monSvc = m_monitoredServiceDao.get(nodeId, ipAddr, ifIndex, serviceId);
    if (monSvc == null) {
        throw new RuntimeException("Service doesn't exist: " + monSvc);
    }
    m_pollerService.poll(monSvc, demandPoll.getId());
    return demandPoll;
}
Also used : DemandPoll(org.opennms.netmgt.model.DemandPoll) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 2 with DemandPoll

use of org.opennms.netmgt.model.DemandPoll in project opennms by OpenNMS.

the class DemandPollServiceTest method testPollMonitoredService.

public void testPollMonitoredService() throws EventProxyException {
    final int expectedResultId = m_pollStore.getExpectedId();
    // anticipate a call to the dao save with a pollResult
    m_demandPollDao.save(isA(DemandPoll.class));
    expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            DemandPoll poll = (DemandPoll) getCurrentArguments()[0];
            m_pollStore.save(poll);
            return null;
        }
    });
    OnmsServiceType svcType = new OnmsServiceType();
    svcType.setId(3);
    svcType.setName("HTTP");
    OnmsNode node = new OnmsNode();
    node.setId(1);
    OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(node, 1);
    OnmsIpInterface iface = new OnmsIpInterface("192.168.1.1", node);
    iface.setSnmpInterface(snmpIface);
    OnmsMonitoredService monSvc = new OnmsMonitoredService(iface, svcType);
    expect(m_monitoredServiceDao.get(1, addr("192.168.1.1"), 1, 3)).andReturn(monSvc);
    m_pollerService.poll(monSvc, expectedResultId);
    replay(m_demandPollDao);
    replay(m_monitoredServiceDao);
    replay(m_pollerService);
    DemandPoll result = m_demandPollService.pollMonitoredService(1, addr("192.168.1.1"), 1, 3);
    verify(m_demandPollDao);
    verify(m_monitoredServiceDao);
    verify(m_pollerService);
    assertNotNull("Null is an invalid response from pollMonitoredService", result);
    assertEquals("Expected Id to be set by dao", expectedResultId, result.getId().intValue());
}
Also used : DemandPoll(org.opennms.netmgt.model.DemandPoll) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 3 with DemandPoll

use of org.opennms.netmgt.model.DemandPoll in project opennms by OpenNMS.

the class DefaultPollServiceIntegrationIT method testPollMonitoredService.

/**
     * this is a feature that has not been written yet
     */
@Test
@Ignore
public void testPollMonitoredService() {
    final PollerService api = createMock(PollerService.class);
    ((DefaultDemandPollService) m_demandPollService).setPollerAPI(api);
    final DemandPoll poll = m_demandPollService.pollMonitoredService(1, addr("192.168.2.100"), 1, 1);
    assertNotNull("DemandPoll should not be null", poll);
    assertTrue("Polled service addr doesn't match...", poll.getId() >= 1);
}
Also used : DemandPoll(org.opennms.netmgt.model.DemandPoll) DefaultDemandPollService(org.opennms.web.svclayer.support.DefaultDemandPollService) PollerService(org.opennms.web.svclayer.api.PollerService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with DemandPoll

use of org.opennms.netmgt.model.DemandPoll in project opennms by OpenNMS.

the class DemandPollServiceTest method testGetUpdatedResults.

public void testGetUpdatedResults() {
    final int resultId = 3;
    DemandPoll expectedResult = new DemandPoll();
    expect(m_demandPollDao.get(resultId)).andReturn(expectedResult);
    replay(m_demandPollDao);
    DemandPoll result = m_demandPollService.getUpdatedResults(resultId);
    verify(m_demandPollDao);
    assertEquals(expectedResult, result);
}
Also used : DemandPoll(org.opennms.netmgt.model.DemandPoll)

Aggregations

DemandPoll (org.opennms.netmgt.model.DemandPoll)4 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)2 Date (java.util.Date)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)1 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)1 PollerService (org.opennms.web.svclayer.api.PollerService)1 DefaultDemandPollService (org.opennms.web.svclayer.support.DefaultDemandPollService)1