Search in sources :

Example 6 with RequestTimedOutException

use of org.opennms.core.rpc.api.RequestTimedOutException in project opennms by OpenNMS.

the class TcaCollectionHandler method collect.

/**
 * Collect.
 *
 * @throws CollectionException the collection exception
 */
protected CollectionSet collect() throws CollectionException {
    try {
        CollectionSetBuilder builder = new CollectionSetBuilder(m_agent);
        TcaData tracker = new TcaData(m_agent.getAddress());
        CompletableFuture<TcaData> future = m_locationAwareSnmpClient.walk(m_agent.getAgentConfig(), tracker).withDescription("TcaCollector for " + m_agent.getHostAddress()).withLocation(m_agent.getLocationName()).execute();
        LOG.debug("collect: successfully instantiated TCA Collector for {}", m_agent.getHostAddress());
        future.get();
        LOG.info("collect: node TCA query for address {} complete.", m_agent.getHostAddress());
        process(tracker, builder);
        return builder.build();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new CollectionUnknown("Collection of node TCA data for interface " + m_agent.getHostAddress() + " interrupted: " + e, e);
    } catch (ExecutionException e) {
        final Throwable cause = e.getCause();
        if (cause != null && cause instanceof RequestTimedOutException) {
            throw new CollectionUnknown(String.format("No response received when remotely collecting TCA data" + " for interface %s at location %s interrupted.", m_agent.getHostAddress(), m_agent.getLocationName()), e);
        } else if (cause != null && cause instanceof RequestRejectedException) {
            throw new CollectionUnknown(String.format("The request to remotely collect TCA data" + " for interface %s at location %s was rejected.", m_agent.getHostAddress(), m_agent.getLocationName()), e);
        }
        throw new CollectionException(String.format("Unexpected exception when collecting TCA data for interface %s at location %s.", m_agent.getHostAddress(), m_agent.getLocationName()), e);
    }
}
Also used : RequestTimedOutException(org.opennms.core.rpc.api.RequestTimedOutException) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) RequestRejectedException(org.opennms.core.rpc.api.RequestRejectedException) CollectionException(org.opennms.netmgt.collection.api.CollectionException) CollectionUnknown(org.opennms.netmgt.collection.api.CollectionUnknown) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with RequestTimedOutException

use of org.opennms.core.rpc.api.RequestTimedOutException 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

RequestTimedOutException (org.opennms.core.rpc.api.RequestTimedOutException)7 Test (org.junit.Test)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 ExecutionException (java.util.concurrent.ExecutionException)3 RemoteExecutionException (org.opennms.core.rpc.api.RemoteExecutionException)3 RequestRejectedException (org.opennms.core.rpc.api.RequestRejectedException)3 CamelContext (org.apache.camel.CamelContext)2 EchoRequest (org.opennms.core.rpc.echo.EchoRequest)2 EchoRpcModule (org.opennms.core.rpc.echo.EchoRpcModule)2 PersisterFactory (org.opennms.netmgt.collection.api.PersisterFactory)2 PollOutagesConfig (org.opennms.netmgt.config.PollOutagesConfig)2 PollerConfig (org.opennms.netmgt.config.PollerConfig)2 Package (org.opennms.netmgt.config.poller.Package)2 Service (org.opennms.netmgt.config.poller.Service)2 ResourceStorageDao (org.opennms.netmgt.dao.api.ResourceStorageDao)2 FilesystemResourceStorageDao (org.opennms.netmgt.dao.support.FilesystemResourceStorageDao)2 MockPersisterFactory (org.opennms.netmgt.mock.MockPersisterFactory)2 LocationAwarePollerClient (org.opennms.netmgt.poller.LocationAwarePollerClient)2 PollStatus (org.opennms.netmgt.poller.PollStatus)2 PollerResponse (org.opennms.netmgt.poller.PollerResponse)2