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);
}
}
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));
}
Aggregations