@Override public CollectionException onUnknown(Throwable t) { if (t instanceof CollectionException) { return (CollectionException)t; } else if (t.getCause() != null && t.getCause() instanceof CollectionException) { return (CollectionException)t.getCause(); } return new CollectionException("Collection failed.", t); } });
@Override public void reportCollectionException(final String packageName, final int nodeId, final String ipAddress, final String svcName, final CollectionException e) { log("collector.collect: error: {}/{}/{}/{}: {}", packageName, nodeId, ipAddress, svcName, e.getMessage()); }
LOG.error(e.getMessage(), e); updateStatus(CollectionStatus.FAILED, e); } catch (Throwable e) { LOG.error(e.getMessage(), e); updateStatus(CollectionStatus.FAILED, new CollectionException("Collection failed unexpectedly: " + e.getClass().getSimpleName() + ": " + e.getMessage(), e));
@Transactional @JUnitCollector( datacollectionConfig = "/org/opennms/netmgt/config/datacollection-persistTest-config.xml", datacollectionType = "snmp" ) public void collectionTimedOutExceptionOnAgentTimeout() throws CollectionInitializationException, CollectionException { // There is no @JUnitSnmpAgent annotation on this method, so // we don't actually start the SNMP agent, which should // generate a CollectionTimedOut exception CollectionException caught = null; try { m_collectionSpecification.collect(m_collectionAgent); } catch (final CollectionException e) { caught = e; } assertNotNull(caught); assertEquals(CollectionTimedOut.class, caught.getCause().getClass()); }
@Override public CollectionException onUnknown(Throwable t) { if (t instanceof CollectionException) { return (CollectionException)t; } else if (t.getCause() != null && t.getCause() instanceof CollectionException) { return (CollectionException)t.getCause(); } return new CollectionException("Collection failed.", t); } });
@Override public void reportCollectionException(final String packageName, final int nodeId, final String ipAddress, final String svcName, final CollectionException e) { log("collector.collect: error: {}/{}/{}/{}: {}", packageName, nodeId, ipAddress, svcName, e.getMessage()); }
public XmlCollectionHandler load(XmlCollectionHandlerKey key) throws Exception { try { LOG.debug("initialize: instantiating XML collection handler {}", key.getHandlerClass()); final Class<?> clazz = Class.forName(key.getHandlerClass()); final XmlCollectionHandler handler = (XmlCollectionHandler) clazz.newInstance(); handler.setServiceName(key.getServiceName()); return handler; } catch (Exception e) { throw new CollectionException("Unable to instantiate XML Collection Handler " + key.getHandlerClass() + " because: " + e.getMessage(), e); } } });
private void updateStatus(CollectionStatus status, CollectionException e) { // Any change in status? if (!status.equals(m_status)) { // Generate data collection transition events LOG.debug("run: change in collection status, generating event."); String reason = null; if (e != null) { reason = e.getMessage(); } // Send the appropriate event switch (status) { case SUCCEEDED: sendEvent(EventConstants.DATA_COLLECTION_SUCCEEDED_EVENT_UEI, null); break; case FAILED: sendEvent(EventConstants.DATA_COLLECTION_FAILED_EVENT_UEI, reason); break; default: break; } } // Set the new status m_status = status; }
public XmlCollectionHandler load(XmlCollectionHandlerKey key) throws Exception { try { LOG.debug("initialize: instantiating XML collection handler {}", key.getHandlerClass()); final Class<?> clazz = Class.forName(key.getHandlerClass()); final XmlCollectionHandler handler = (XmlCollectionHandler) clazz.newInstance(); handler.setServiceName(key.getServiceName()); return handler; } catch (Exception e) { throw new CollectionException("Unable to instantiate XML Collection Handler " + key.getHandlerClass() + " because: " + e.getMessage(), e); } } });
@Override public CollectionSet collect(CollectionAgent agent, XmlDataCollection collection, Map<String, Object> parameters) throws CollectionException { String status = "finished"; CollectionSetBuilder builder = new CollectionSetBuilder(agent); DateTime startTime = new DateTime(); try { LOG.debug("collect: looping sources for collection {}", collection.getName()); for (XmlSource source : collection.getXmlSources()) { final String urlStr = source.getUrl(); final Request request = source.getRequest(); LOG.debug("collect: starting source url '{}' collection with request: {}", urlStr, request); fillCollectionSet(urlStr, request, agent, builder, source); LOG.debug("collect: finished source url '{}' collection with {} resources", urlStr, builder.getNumResources()); } return builder.build(); } catch (Exception e) { status = "failed"; throw new CollectionException(e.getMessage(), e); } finally { DateTime endTime = new DateTime(); LOG.debug("collect: {} collection {}: duration: {} ms", status, collection.getName(), endTime.getMillis()-startTime.getMillis()); } }
@Override public CollectionSet collect(CollectionAgent agent, XmlDataCollection collection, Map<String, Object> parameters) throws CollectionException { String status = "finished"; CollectionSetBuilder builder = new CollectionSetBuilder(agent); DateTime startTime = new DateTime(); try { LOG.debug("collect: looping sources for collection {}", collection.getName()); for (XmlSource source : collection.getXmlSources()) { final String urlStr = source.getUrl(); final Request request = source.getRequest(); LOG.debug("collect: starting source url '{}' collection with request: {}", urlStr, request); fillCollectionSet(urlStr, request, agent, builder, source); LOG.debug("collect: finished source url '{}' collection with {} resources", urlStr, builder.getNumResources()); } return builder.build(); } catch (Exception e) { status = "failed"; throw new CollectionException(e.getMessage(), e); } finally { DateTime endTime = new DateTime(); LOG.debug("collect: {} collection {}: duration: {} ms", status, collection.getName(), endTime.getMillis()-startTime.getMillis()); } }
protected Resource getResource(NodeLevelResource nodeLevelResource, String nodeTypeName, String resourceType, String instance) throws CollectionException { if (CollectionResource.RESOURCE_TYPE_NODE.equalsIgnoreCase(nodeTypeName)) { return nodeLevelResource; } final String effectiveResourceType; if ((resourceType == null) || (resourceType.length() == 0)) { effectiveResourceType = null; } else { effectiveResourceType = resourceType; } final String effectiveInstance; if (instance != null) { effectiveInstance = XmpCollector.sanitizeInstance(instance); } else { effectiveInstance = null; } if (effectiveResourceType != null) { final ResourceType resourceTypeDef = m_resourceTypesDao.getResourceTypeByName(effectiveResourceType); if (resourceType == null) { throw new CollectionException("No resource type found with name '" + effectiveResourceType + "'."); } return new GenericTypeResource(nodeLevelResource, resourceTypeDef, effectiveInstance); } else { return new InterfaceLevelResource(nodeLevelResource, effectiveInstance); } }
@Override public CollectionSet collect(CollectionAgent agent, Map<String, Object> parameters) throws CollectionException { try { String collectionName = ParameterMap.getKeyedString(parameters, "collection", null); if (collectionName == null) { collectionName = ParameterMap.getKeyedString(parameters, "tca-collection", null); } if (collectionName == null) { throw new CollectionException("Parameter collection is required for the TCA Collector!"); } TcaCollectionHandler collectionHandler = new TcaCollectionHandler((SnmpCollectionAgent)agent, getRrdRepository(collectionName), m_resourceStorageDao, m_resourceTypesDao, m_locationAwareSnmpClient); return collectionHandler.collect(); } catch (CollectionException e) { throw e; } catch (Throwable t) { LOG.error("Unexpected error during node TCA collection for: {}", agent.getHostAddress(), t); throw new CollectionException("Unexpected error during node TCA collection for: " + agent.getHostAddress() + ": " + t, t); } }
@Override public CollectionSet collect(CollectionAgent agent, Map<String, Object> parameters) throws CollectionException { final String rrdRepositoryPath = ParameterMap.getKeyedString(parameters, RRD_REPOSITORY_PATH_KEY, null); final XmlDataCollection collection = (XmlDataCollection) parameters.get(XML_DATACOLLECTION_KEY); final String serviceName = ParameterMap.getKeyedString(parameters, "SERVICE", "XML"); final String handlerClass = ParameterMap.getKeyedString(parameters, "handler-class", "org.opennms.protocols.xml.collector.DefaultXmlCollectionHandler"); final XmlCollectionHandlerKey key = new XmlCollectionHandlerKey(serviceName, handlerClass); try { // Filling XML CollectionSet RrdRepository rrdRepository = XmlDataCollectionConfig.buildRrdRepository(rrdRepositoryPath, collection); XmlCollectionHandler handler = m_handlers.get(key); handler.setRrdRepository(rrdRepository); return handler.collect(agent, collection, parameters); } catch (Exception e) { throw new CollectionException("Can't collect XML data because " + e.getMessage(), e); } }
@Override public CollectionSet collect(CollectionAgent agent, Map<String, Object> parameters) throws CollectionException { final String rrdRepositoryPath = ParameterMap.getKeyedString(parameters, RRD_REPOSITORY_PATH_KEY, null); final XmlDataCollection collection = (XmlDataCollection) parameters.get(XML_DATACOLLECTION_KEY); final String serviceName = ParameterMap.getKeyedString(parameters, "SERVICE", "XML"); final String handlerClass = ParameterMap.getKeyedString(parameters, "handler-class", "org.opennms.protocols.xml.collector.DefaultXmlCollectionHandler"); final XmlCollectionHandlerKey key = new XmlCollectionHandlerKey(serviceName, handlerClass); try { // Filling XML CollectionSet RrdRepository rrdRepository = XmlDataCollectionConfig.buildRrdRepository(rrdRepositoryPath, collection); XmlCollectionHandler handler = m_handlers.get(key); handler.setRrdRepository(rrdRepository); return handler.collect(agent, collection, parameters); } catch (Exception e) { throw new CollectionException("Can't collect XML data because " + e.getMessage(), e); } }
@Override public CollectionSet collect(CollectionAgent agent, Map<String, Object> parameters) throws CollectionException { LOG.debug("collect({}, {}, {})", agent, parameters); final WsmanAgentConfig config = (WsmanAgentConfig)parameters.get(WSMAN_AGENT_CONFIG_KEY); final Groups groups = (Groups)parameters.get(WSMAN_GROUPS_KEY); final WSManEndpoint endpoint = WSManConfigDao.getEndpoint(config, agent.getAddress()); final WSManClient client = m_factory.getClient(endpoint); final CollectionSetBuilder collectionSetBuilder = new CollectionSetBuilder(agent); if (LOG.isDebugEnabled()) { String groupNames = groups.getGroups().stream().map(Group::getName).collect(Collectors.joining(", ")); LOG.debug("Collecting attributes on {} from groups: {}", agent, groupNames); } for (Group group : groups.getGroups()) { try { collectGroupUsing(group, agent, client, config.getRetry() != null ? config.getRetry() : 0, collectionSetBuilder); } catch (InvalidResourceURI e) { LOG.info("Resource URI {} in group named {} is not available on {}.", group.getResourceUri(), group.getName(), agent); } catch (WSManException e) { // If collecting any individual group fails, mark the collection set as // failed, and abort trying to collect any other groups throw new CollectionException(String.format("Collecting group '%s' on %s failed with '%s'. See logs for details.", group.getName(), agent, e.getMessage()), e); } } return collectionSetBuilder.build(); }
@Override public CollectionSet collect(CollectionAgent agent, Map<String, Object> parameters) throws CollectionException { LOG.debug("collect({}, {}, {})", agent, parameters); final WsmanAgentConfig config = (WsmanAgentConfig)parameters.get(WSMAN_AGENT_CONFIG_KEY); final Groups groups = (Groups)parameters.get(WSMAN_GROUPS_KEY); final WSManEndpoint endpoint = WSManConfigDao.getEndpoint(config, agent.getAddress()); final WSManClient client = m_factory.getClient(endpoint); final CollectionSetBuilder collectionSetBuilder = new CollectionSetBuilder(agent); if (LOG.isDebugEnabled()) { String groupNames = groups.getGroups().stream().map(Group::getName).collect(Collectors.joining(", ")); LOG.debug("Collecting attributes on {} from groups: {}", agent, groupNames); } for (Group group : groups.getGroups()) { try { collectGroupUsing(group, agent, client, config.getRetry() != null ? config.getRetry() : 0, collectionSetBuilder); } catch (InvalidResourceURI e) { LOG.info("Resource URI {} in group named {} is not available on {}.", group.getResourceUri(), group.getName(), agent); } catch (WSManException e) { // If collecting any individual group fails, mark the collection set as // failed, and abort trying to collect any other groups throw new CollectionException(String.format("Collecting group '%s' on %s failed with '%s'. See logs for details.", group.getName(), agent, e.getMessage()), e); } } return collectionSetBuilder.build(); }
throw e; } catch (Throwable t) { throw new CollectionException("Unexpected error during node SNMP collection for: " + agent.getHostAddress(), t);
for (XmlSource source : collection.getXmlSources()) { if (!source.getUrl().startsWith(Sftp3gppUrlHandler.PROTOCOL)) { throw new CollectionException("The 3GPP SFTP Collection Handler can only use the protocol " + Sftp3gppUrlHandler.PROTOCOL); } catch (Exception e) { status = "failed"; throw new CollectionException(e.getMessage(), e); } finally { DateTime endTime = new DateTime();
throw e; } catch (Throwable t) { throw new CollectionException("Unexpected error during node SNMP collection for: " + agent.getHostAddress(), t);