use of org.opennms.core.rpc.api.RpcExceptionHandler in project opennms by OpenNMS.
the class PollableServiceConfig method poll.
/**
* <p>poll</p>
*
* @return a {@link org.opennms.netmgt.poller.PollStatus} object.
*/
@Override
public PollStatus poll() {
try {
final String packageName = getPackageName();
// Use the service's configured interval as the TTL for this request
final Long ttlInMs = m_configService.getInterval();
LOG.debug("Polling {} with TTL {} using pkg {}", m_service, ttlInMs, packageName);
PollStatus result = m_locationAwarePollerClient.poll().withService(m_service).withMonitor(m_serviceMonitor).withTimeToLive(ttlInMs).withAttributes(getParameters()).withAdaptor(m_latencyStoringServiceMonitorAdaptor).withAdaptor(m_invertedStatusServiceMonitorAdaptor).execute().get().getPollStatus();
LOG.debug("Finish polling {} using pkg {} result = {}", m_service, packageName, result);
return result;
} catch (Throwable e) {
return RpcExceptionUtils.handleException(e, new RpcExceptionHandler<PollStatus>() {
@Override
public PollStatus onInterrupted(Throwable cause) {
LOG.warn("Interrupted while invoking the poll for {}." + " Marking the service as UNKNOWN.", m_service);
return PollStatus.unknown("Interrupted while invoking the poll for" + m_service + ". " + e);
}
@Override
public PollStatus onTimedOut(Throwable cause) {
LOG.warn("No response was received when remotely invoking the poll for {}." + " Marking the service as UNKNOWN.", m_service);
return PollStatus.unknown(String.format("No response received for %s. %s", m_service, cause));
}
@Override
public PollStatus onRejected(Throwable cause) {
LOG.warn("The request to remotely invoke the poll for {} was rejected." + " Marking the service as UNKNOWN.", m_service);
return PollStatus.unknown(String.format("Remote poll request rejected for %s. %s", m_service, cause));
}
@Override
public PollStatus onUnknown(Throwable cause) {
LOG.error("Unexpected exception while polling {}. Marking service as DOWN", m_service, e);
return PollStatus.down("Unexpected exception while polling " + m_service + ". " + e);
}
});
}
}
use of org.opennms.core.rpc.api.RpcExceptionHandler in project opennms by OpenNMS.
the class SnmpCollectionSet method collect.
void collect() throws CollectionException {
// XXX Should we have a call to hasDataToCollect here?
try {
// now collect the data
CollectionAgent agent = getCollectionAgent();
logStartedWalker();
CompletableFuture<CollectionTracker> future = m_client.walk(getAgentConfig(), getTracker()).withDescription("SnmpCollectors for " + agent.getHostAddress()).withLocation(getCollectionAgent().getLocationName()).withTimeToLive(m_snmpCollection.getServiceParameters().getServiceInterval()).execute();
// wait for collection to finish
try {
future.get();
} finally {
logFinishedWalker();
}
// Execute POST Updates (add custom parameters)
SnmpPropertyExtenderProcessor processor = new SnmpPropertyExtenderProcessor();
processor.process(this, m_snmpCollection.getName(), m_agent.getSysObjectId(), m_agent.getHostAddress());
m_status = CollectionStatus.SUCCEEDED;
} catch (InterruptedException | ExecutionException e) {
throw RpcExceptionUtils.handleException(e, new RpcExceptionHandler<CollectionException>() {
@Override
public CollectionException onInterrupted(Throwable t) {
Thread.currentThread().interrupt();
return new CollectionUnknown(String.format("Collection of SNMP data for interface %s at location %s was interrupted.", getCollectionAgent().getHostAddress(), getCollectionAgent().getLocationName()), t);
}
@Override
public CollectionException onTimedOut(Throwable t) {
return new CollectionUnknown(String.format("No response received when remotely collecting SNMP data" + " for interface %s at location %s.", getCollectionAgent().getHostAddress(), getCollectionAgent().getLocationName()), t);
}
@Override
public CollectionException onRejected(Throwable t) {
return new CollectionUnknown(String.format("The request to remotely collect SNMP data" + " for interface %s at location %s was rejected.", getCollectionAgent().getHostAddress(), getCollectionAgent().getLocationName()), t);
}
@Override
public CollectionException onUnknown(Throwable t) {
if (t instanceof SnmpAgentTimeoutException) {
return new CollectionTimedOut(t.getMessage());
} else if (t.getCause() != null && t.getCause() instanceof SnmpAgentTimeoutException) {
return new CollectionTimedOut(t.getCause().getMessage());
}
return new CollectionWarning(String.format("Unexpected exception when collecting SNMP data for interface %s at location %s.", getCollectionAgent().getHostAddress(), getCollectionAgent().getLocationName()), t);
}
});
}
}
Aggregations