Search in sources :

Example 6 with Result

use of org.opennms.newts.api.search.SearchResults.Result in project opennms by OpenNMS.

the class NewtsResourceStorageDao method getAttributes.

@Override
public Set<OnmsAttribute> getAttributes(ResourcePath path) {
    Set<OnmsAttribute> attributes = Sets.newHashSet();
    // Fetch the resource-level attributes in parallel
    Future<Map<String, String>> stringAttributes = ForkJoinPool.commonPool().submit(getResourceAttributesCallable(path));
    // Gather the list of metrics available under the resource path
    SearchResults results = searchFor(path, 0, true);
    for (Result result : results) {
        final String resourceId = result.getResource().getId();
        final ResourcePath resultPath = toResourcePath(resourceId);
        if (!path.equals(resultPath)) {
            // This shouldn't happen
            LOG.warn("Encountered non-child resource {} when searching for {} with depth {}. Ignoring resource.", result.getResource(), path, 0);
            continue;
        }
        for (String metric : result.getMetrics()) {
            // Use the metric name as the dsName
            // Store the resource id in the rrdFile field
            attributes.add(new RrdGraphAttribute(metric, "", resourceId));
        }
    }
    // Add the resource level attributes to the result set
    try {
        stringAttributes.get().entrySet().stream().map(e -> new StringPropertyAttribute(e.getKey(), e.getValue())).forEach(attr -> attributes.add(attr));
    } catch (InterruptedException | ExecutionException e) {
        throw Throwables.propagate(e);
    }
    return attributes;
}
Also used : NewtsUtils.toResourcePath(org.opennms.netmgt.newts.support.NewtsUtils.toResourcePath) IntStream(java.util.stream.IntStream) Context(org.opennms.newts.api.Context) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Callable(java.util.concurrent.Callable) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) CassandraIndexer(org.opennms.newts.cassandra.search.CassandraIndexer) StringPropertyAttribute(org.opennms.netmgt.model.StringPropertyAttribute) NewtsUtils(org.opennms.netmgt.newts.support.NewtsUtils) NewtsUtils.toResourceId(org.opennms.netmgt.newts.support.NewtsUtils.toResourceId) Future(java.util.concurrent.Future) Lists(com.google.common.collect.Lists) Optional(com.google.common.base.Optional) Map(java.util.Map) Sample(org.opennms.newts.api.Sample) NewtsWriter(org.opennms.netmgt.newts.NewtsWriter) Path(java.nio.file.Path) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) Query(org.opennms.newts.api.search.Query) CassandraSampleRepository(org.opennms.newts.persistence.cassandra.CassandraSampleRepository) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) Resource(org.opennms.newts.api.Resource) Set(java.util.Set) Throwables(com.google.common.base.Throwables) CassandraSearcher(org.opennms.newts.cassandra.search.CassandraSearcher) ResourceStorageDao(org.opennms.netmgt.dao.api.ResourceStorageDao) Result(org.opennms.newts.api.search.SearchResults.Result) SearchableResourceMetadataCache(org.opennms.netmgt.newts.support.SearchableResourceMetadataCache) Sets(com.google.common.collect.Sets) ExecutionException(java.util.concurrent.ExecutionException) NewtsUtils.findResourcesWithMetricsAtDepth(org.opennms.netmgt.newts.support.NewtsUtils.findResourcesWithMetricsAtDepth) List(java.util.List) SearchResults(org.opennms.newts.api.search.SearchResults) ForkJoinPool(java.util.concurrent.ForkJoinPool) ResourcePath(org.opennms.netmgt.model.ResourcePath) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) SearchResults(org.opennms.newts.api.search.SearchResults) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) Result(org.opennms.newts.api.search.SearchResults.Result) StringPropertyAttribute(org.opennms.netmgt.model.StringPropertyAttribute) NewtsUtils.toResourcePath(org.opennms.netmgt.newts.support.NewtsUtils.toResourcePath) ResourcePath(org.opennms.netmgt.model.ResourcePath) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 7 with Result

use of org.opennms.newts.api.search.SearchResults.Result in project opennms by OpenNMS.

the class NewtsResourceStorageDao method delete.

@Override
public boolean delete(ResourcePath path) {
    final SearchResults results = searchFor(path, 0, true);
    if (results.isEmpty()) {
        return false;
    }
    for (final Result result : results) {
        m_sampleRepository.delete(m_context, result.getResource());
        m_indexer.delete(m_context, result.getResource());
    }
    return true;
}
Also used : SearchResults(org.opennms.newts.api.search.SearchResults) Result(org.opennms.newts.api.search.SearchResults.Result)

Aggregations

Result (org.opennms.newts.api.search.SearchResults.Result)7 SearchResults (org.opennms.newts.api.search.SearchResults)6 Resource (org.opennms.newts.api.Resource)4 Context (org.opennms.newts.api.Context)3 Sample (org.opennms.newts.api.Sample)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 Test (org.junit.Test)2 ResourcePath (org.opennms.netmgt.model.ResourcePath)2 NewtsUtils.toResourcePath (org.opennms.netmgt.newts.support.NewtsUtils.toResourcePath)2 Indexer (org.opennms.newts.api.search.Indexer)2 QueryBuilder (org.opennms.newts.api.search.QueryBuilder)2 CassandraSession (org.opennms.newts.cassandra.CassandraSession)2 ContextConfigurations (org.opennms.newts.cassandra.ContextConfigurations)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Optional (com.google.common.base.Optional)1 Preconditions (com.google.common.base.Preconditions)1 Throwables (com.google.common.base.Throwables)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1