Search in sources :

Example 16 with Service

use of org.opennms.netmgt.config.poller.Service in project opennms by OpenNMS.

the class PollableServiceConfigTest method returnsUnknownOnRequestTimedOutException.

/**
     * Verifies that <b>PollStatus.unknown()</b> is returned when the
     * {@link LocationAwarePollerClient} fails with a {@link RequestTimedOutException}.
     *
     * This can happen when no Minions at the given location are available to process
     * the request, or the request was not completed in time, in which case we cannot
     * ascertain that the service is UP or DOWN.
     */
@Test
public void returnsUnknownOnRequestTimedOutException() throws Exception {
    // Create a future that fails with a RequestTimedOutException
    CompletableFuture<PollerResponse> future = new CompletableFuture<>();
    future.completeExceptionally(new RequestTimedOutException(new Exception("Test")));
    // Now mock the client to always return the future we created above
    LocationAwarePollerClient client = mock(LocationAwarePollerClient.class, Mockito.RETURNS_DEEP_STUBS);
    Mockito.when(client.poll().withService(any()).withMonitor(any()).withTimeToLive(any()).withAttributes(any()).withAdaptor(any()).withAdaptor(any()).execute()).thenReturn(future);
    // Mock all of the required objects required to successfully initialize the PollableServiceConfig
    PollableService pollableSvc = mock(PollableService.class);
    when(pollableSvc.getSvcName()).thenReturn("SVC");
    Service configuredSvc = new Service();
    configuredSvc.setName("SVC");
    Package pkg = mock(Package.class);
    when(pkg.getServices()).thenReturn(Lists.newArrayList(configuredSvc));
    PollerConfig pollerConfig = mock(PollerConfig.class);
    PollOutagesConfig pollOutagesConfig = mock(PollOutagesConfig.class);
    Timer timer = mock(Timer.class);
    PersisterFactory persisterFactory = mock(PersisterFactory.class);
    ResourceStorageDao resourceStorageDao = mock(ResourceStorageDao.class);
    final PollableServiceConfig psc = new PollableServiceConfig(pollableSvc, pollerConfig, pollOutagesConfig, pkg, timer, persisterFactory, resourceStorageDao, client);
    // Trigger the poll
    PollStatus pollStatus = psc.poll();
    // Verify
    assertThat(pollStatus.isUnknown(), is(true));
}
Also used : RequestTimedOutException(org.opennms.core.rpc.api.RequestTimedOutException) LocationAwarePollerClient(org.opennms.netmgt.poller.LocationAwarePollerClient) FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) ResourceStorageDao(org.opennms.netmgt.dao.api.ResourceStorageDao) PollStatus(org.opennms.netmgt.poller.PollStatus) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) PersisterFactory(org.opennms.netmgt.collection.api.PersisterFactory) PollerConfig(org.opennms.netmgt.config.PollerConfig) Service(org.opennms.netmgt.config.poller.Service) RequestTimedOutException(org.opennms.core.rpc.api.RequestTimedOutException) CompletableFuture(java.util.concurrent.CompletableFuture) Timer(org.opennms.netmgt.scheduler.Timer) Package(org.opennms.netmgt.config.poller.Package) PollerResponse(org.opennms.netmgt.poller.PollerResponse) PollOutagesConfig(org.opennms.netmgt.config.PollOutagesConfig) Test(org.junit.Test)

Example 17 with Service

use of org.opennms.netmgt.config.poller.Service in project opennms by OpenNMS.

the class PollerConfigWithPSMIT method testPSM.

@Test
public void testPSM() throws Exception {
    InputStream is = new FileInputStream(new File("src/test/resources/etc/psm-poller-configuration.xml"));
    PollerConfigFactory factory = new PollerConfigFactory(0, is, "localhost", false);
    PollerConfigFactory.setInstance(factory);
    IOUtils.closeQuietly(is);
    ServiceMonitor monitor = PollerConfigFactory.getInstance().getServiceMonitor("MQ_API_DirectRte_v2");
    Assert.assertNotNull(monitor);
    Package pkg = PollerConfigFactory.getInstance().getPackage("MapQuest");
    Assert.assertNotNull(pkg);
    Service svc = PollerConfigFactory.getInstance().getServiceInPackage("MQ_API_DirectRte_v2", pkg);
    Assert.assertNotNull(svc);
    Map<String, Object> parameters = new HashMap<String, Object>();
    for (Parameter p : svc.getParameters()) {
        parameters.put(p.getKey(), p.getValue() == null ? p.getAnyObject() : p.getValue());
    }
    PollStatus status = monitor.poll(new MockMonitoredService(1, "www.mapquest.com", InetAddress.getByName("www.mapquest.com"), "MQ_API_DirectRte_v2"), parameters);
    Assert.assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) Service(org.opennms.netmgt.config.poller.Service) FileInputStream(java.io.FileInputStream) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) Parameter(org.opennms.netmgt.config.poller.Parameter) Package(org.opennms.netmgt.config.poller.Package) File(java.io.File) Test(org.junit.Test)

Example 18 with Service

use of org.opennms.netmgt.config.poller.Service in project opennms by OpenNMS.

the class DefaultPollerBackEndTest method canConvertServiceParametersToSerializableMap.

/**
 * Verifies that the parameter map generated for a given
 * service is serializable.
 */
@Test
public void canConvertServiceParametersToSerializableMap() {
    Parameter paramWithStringValue = new Parameter();
    paramWithStringValue.setKey("a");
    paramWithStringValue.setValue("test");
    Parameter paramWithNullValue = new Parameter();
    paramWithNullValue.setKey("b");
    paramWithNullValue.setAnyObject(null);
    Parameter paramWithNonSerializableObject = new Parameter();
    paramWithNonSerializableObject.setKey("c");
    // This can be any object, provided that it does not implement the Serializable interface
    paramWithNonSerializableObject.setAnyObject(new DefaultPollerBackEndTest());
    Service svc = new Service();
    svc.setParameters(Lists.newArrayList(paramWithStringValue, paramWithNullValue, paramWithNonSerializableObject));
    // Expect no exception to be thrown
    SerializationUtils.serialize(DefaultPollerBackEnd.getParameterMap(svc));
}
Also used : Parameter(org.opennms.netmgt.config.poller.Parameter) Service(org.opennms.netmgt.config.poller.Service) Test(org.junit.Test)

Example 19 with Service

use of org.opennms.netmgt.config.poller.Service in project opennms by OpenNMS.

the class DefaultPollerBackEndTest method getParameterMapMarshallsPageSequenceParameters.

/**
 * Verifies that {@link PageSequence} type parameters are marshalled to XML.
 */
@Test
public void getParameterMapMarshallsPageSequenceParameters() {
    final PageSequence ps = new PageSequence();
    Page page = new Page();
    page.setMethod("GET");
    page.setHttpVersion("1.1");
    page.setScheme("http");
    page.setHost("${ipaddr}");
    page.setDisableSslVerification("true");
    page.setPort(7080);
    page.setPath("/Login.do");
    page.setSuccessMatch("w00t");
    page.setResponseRange("100-399");
    ps.addPage(page);
    Parameter paramWithPageSequenceValue = new Parameter();
    paramWithPageSequenceValue.setKey("psm");
    paramWithPageSequenceValue.setAnyObject(ps);
    Service svc = new Service();
    svc.setParameters(Lists.newArrayList(paramWithPageSequenceValue));
    Map<String, Object> params = DefaultPollerBackEnd.getParameterMap(svc);
    PageSequence unmarshalledPs = JaxbUtils.unmarshal(PageSequence.class, (String) params.get("psm"));
    assertEquals(ps, unmarshalledPs);
}
Also used : PageSequence(org.opennms.netmgt.config.pagesequence.PageSequence) Parameter(org.opennms.netmgt.config.poller.Parameter) Service(org.opennms.netmgt.config.poller.Service) Page(org.opennms.netmgt.config.pagesequence.Page) Test(org.junit.Test)

Example 20 with Service

use of org.opennms.netmgt.config.poller.Service in project opennms by OpenNMS.

the class PollableServiceConfigIT method returnsUnknownOnRequestTimedOutException.

/**
 * Verifies that <b>PollStatus.unknown()</b> is returned when the
 * {@link LocationAwarePollerClient} fails with a {@link RequestTimedOutException}.
 *
 * This can happen when no Minions at the given location are available to process
 * the request, or the request was not completed in time, in which case we cannot
 * ascertain that the service is UP or DOWN.
 */
@Test
public void returnsUnknownOnRequestTimedOutException() throws Exception {
    // Create a future that fails with a RequestTimedOutException
    CompletableFuture<PollerResponse> future = new CompletableFuture<>();
    future.completeExceptionally(new RequestTimedOutException(new Exception("Test")));
    // Now mock the client to always return the future we created above
    LocationAwarePollerClient client = mock(LocationAwarePollerClient.class, Mockito.RETURNS_DEEP_STUBS);
    Mockito.when(client.poll().withService(any()).withMonitor(any()).withTimeToLive(any()).withAttributes(any()).withAdaptor(any()).withAdaptor(any()).execute()).thenReturn(future);
    // Mock all of the required objects required to successfully initialize the PollableServiceConfig
    PollableService pollableSvc = mock(PollableService.class);
    when(pollableSvc.getSvcName()).thenReturn("SVC");
    Service configuredSvc = new Service();
    configuredSvc.setName("SVC");
    Package pkg = mock(Package.class);
    when(pkg.getServices()).thenReturn(Lists.newArrayList(configuredSvc));
    PollerConfig pollerConfig = mock(PollerConfig.class);
    PollOutagesConfig pollOutagesConfig = mock(PollOutagesConfig.class);
    Timer timer = mock(Timer.class);
    PersisterFactory persisterFactory = mock(PersisterFactory.class);
    ResourceStorageDao resourceStorageDao = mock(ResourceStorageDao.class);
    final PollableServiceConfig psc = new PollableServiceConfig(pollableSvc, pollerConfig, pollOutagesConfig, pkg, timer, persisterFactory, resourceStorageDao, client);
    // Trigger the poll
    PollStatus pollStatus = psc.poll();
    // Verify
    assertThat(pollStatus.isUnknown(), is(true));
}
Also used : RequestTimedOutException(org.opennms.core.rpc.api.RequestTimedOutException) LocationAwarePollerClient(org.opennms.netmgt.poller.LocationAwarePollerClient) FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) ResourceStorageDao(org.opennms.netmgt.dao.api.ResourceStorageDao) PollStatus(org.opennms.netmgt.poller.PollStatus) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) PersisterFactory(org.opennms.netmgt.collection.api.PersisterFactory) PollerConfig(org.opennms.netmgt.config.PollerConfig) Service(org.opennms.netmgt.config.poller.Service) RequestTimedOutException(org.opennms.core.rpc.api.RequestTimedOutException) CompletableFuture(java.util.concurrent.CompletableFuture) Timer(org.opennms.netmgt.scheduler.Timer) Package(org.opennms.netmgt.config.poller.Package) PollerResponse(org.opennms.netmgt.poller.PollerResponse) PollOutagesConfig(org.opennms.netmgt.config.PollOutagesConfig) Test(org.junit.Test)

Aggregations

Service (org.opennms.netmgt.config.poller.Service)22 Package (org.opennms.netmgt.config.poller.Package)11 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)6 Test (org.junit.Test)5 PollerConfig (org.opennms.netmgt.config.PollerConfig)5 Parameter (org.opennms.netmgt.config.poller.Parameter)5 PollStatus (org.opennms.netmgt.poller.PollStatus)5 File (java.io.File)4 Rrd (org.opennms.netmgt.config.poller.Rrd)4 Downtime (org.opennms.netmgt.config.poller.Downtime)3 Filter (org.opennms.netmgt.config.poller.Filter)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 MonitoredService (org.opennms.netmgt.poller.MonitoredService)3 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 InetAddress (java.net.InetAddress)2 HashMap (java.util.HashMap)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2