Search in sources :

Example 16 with CollectionAgent

use of org.opennms.netmgt.collection.api.CollectionAgent in project opennms by OpenNMS.

the class WsManCollector method collect.

@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(g -> g.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) {
            // 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();
}
Also used : CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) WSManDataCollectionConfigDao(org.opennms.netmgt.dao.WSManDataCollectionConfigDao) ListMultimap(com.google.common.collect.ListMultimap) LoggerFactory(org.slf4j.LoggerFactory) WSManException(org.opennms.core.wsman.exceptions.WSManException) CollectionException(org.opennms.netmgt.collection.api.CollectionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ParameterMap(org.opennms.core.utils.ParameterMap) NodeDao(org.opennms.netmgt.dao.api.NodeDao) WsmanAgentConfig(org.opennms.netmgt.config.wsman.WsmanAgentConfig) RetryNTimesLoop(org.opennms.core.wsman.utils.RetryNTimesLoop) WSManEndpoint(org.opennms.core.wsman.WSManEndpoint) Group(org.opennms.netmgt.config.wsman.Group) Collectors(java.util.stream.Collectors) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) BeanUtils(org.opennms.core.spring.BeanUtils) Definition(org.opennms.netmgt.config.wsman.Definition) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) WSManClient(org.opennms.core.wsman.WSManClient) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) Groups(org.opennms.netmgt.config.wsman.Groups) Iterables(com.google.common.collect.Iterables) HashMap(java.util.HashMap) WSManConfigDao(org.opennms.netmgt.dao.WSManConfigDao) Supplier(java.util.function.Supplier) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) WsmanDatacollectionConfig(org.opennms.netmgt.config.wsman.WsmanDatacollectionConfig) Lists(com.google.common.collect.Lists) Node(org.w3c.dom.Node) Collection(org.opennms.netmgt.config.wsman.Collection) Attrib(org.opennms.netmgt.config.wsman.Attrib) NoSuchElementException(java.util.NoSuchElementException) InvalidResourceURI(org.opennms.core.wsman.exceptions.InvalidResourceURI) SimpleEntry(java.util.AbstractMap.SimpleEntry) OnmsNode(org.opennms.netmgt.model.OnmsNode) ResponseHandlingUtils(org.opennms.core.wsman.utils.ResponseHandlingUtils) Resource(org.opennms.netmgt.collection.support.builder.Resource) Logger(org.slf4j.Logger) WSManClientFactory(org.opennms.core.wsman.WSManClientFactory) AbstractRemoteServiceCollector(org.opennms.netmgt.collection.api.AbstractRemoteServiceCollector) CXFWSManClientFactory(org.opennms.core.wsman.cxf.CXFWSManClientFactory) File(java.io.File) CollectionInitializationException(org.opennms.netmgt.collection.api.CollectionInitializationException) Collections(java.util.Collections) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) WSManException(org.opennms.core.wsman.exceptions.WSManException) Group(org.opennms.netmgt.config.wsman.Group) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) WSManEndpoint(org.opennms.core.wsman.WSManEndpoint) Groups(org.opennms.netmgt.config.wsman.Groups) CollectionException(org.opennms.netmgt.collection.api.CollectionException) WsmanAgentConfig(org.opennms.netmgt.config.wsman.WsmanAgentConfig) WSManClient(org.opennms.core.wsman.WSManClient) InvalidResourceURI(org.opennms.core.wsman.exceptions.InvalidResourceURI)

Aggregations

CollectionAgent (org.opennms.netmgt.collection.api.CollectionAgent)16 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)13 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)9 Test (org.junit.Test)8 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)8 Definition (org.opennms.netmgt.config.wsman.Definition)7 OnmsNode (org.opennms.netmgt.model.OnmsNode)7 Map (java.util.Map)6 WSManClientFactory (org.opennms.core.wsman.WSManClientFactory)6 CollectionInitializationException (org.opennms.netmgt.collection.api.CollectionInitializationException)6 Collection (org.opennms.netmgt.config.wsman.Collection)6 WSManConfigDao (org.opennms.netmgt.dao.WSManConfigDao)6 WSManDataCollectionConfigDao (org.opennms.netmgt.dao.WSManDataCollectionConfigDao)6 NodeDao (org.opennms.netmgt.dao.api.NodeDao)6 List (java.util.List)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Supplier (java.util.function.Supplier)5 Collectors (java.util.stream.Collectors)5 CollectionException (org.opennms.netmgt.collection.api.CollectionException)5 GenericTypeResource (org.opennms.netmgt.collection.support.builder.GenericTypeResource)5