Search in sources :

Example 31 with OnmsAttribute

use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.

the class InterfaceSnmpResourceType method getResourceByParentPathAndInterface.

private OnmsResource getResourceByParentPathAndInterface(ResourcePath parent, String intf, String label, Long ifSpeed, String ifSpeedFriendly) throws DataAccessException {
    final ResourcePath path = ResourcePath.get(parent, intf);
    final AttributeLoader loader = new AttributeLoader(m_resourceStorageDao, path, ifSpeed, ifSpeedFriendly);
    final Set<OnmsAttribute> set = new LazySet<OnmsAttribute>(loader);
    return new OnmsResource(intf, label, this, set, path);
}
Also used : LazySet(org.opennms.core.collections.LazySet) ResourcePath(org.opennms.netmgt.model.ResourcePath) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute)

Example 32 with OnmsAttribute

use of org.opennms.netmgt.model.OnmsAttribute 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(attributes::add);
    } 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) 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 33 with OnmsAttribute

use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.

the class NewtsFetchStrategyTest method createMockResource.

public Source createMockResource(final String label, final String attr, final String node, boolean expect) {
    OnmsResourceType type = EasyMock.createNiceMock(OnmsResourceType.class);
    final int nodeId = node.hashCode();
    final String newtsResourceId = "response:" + node + ":" + attr;
    final ResourceId resourceId = ResourceId.get("nodeSource", "NODES:" + nodeId).resolve("responseTime", node);
    OnmsResource resource = m_resources.get(resourceId);
    if (resource == null) {
        resource = new OnmsResource(attr, label, type, Sets.newHashSet(), ResourcePath.get("foo"));
        m_resources.put(resourceId, resource);
    }
    Set<OnmsAttribute> attributes = resource.getAttributes();
    attributes.add(new RrdGraphAttribute(attr, "", newtsResourceId));
    Results<Measurement> results = new Results<>();
    Resource res = new Resource(newtsResourceId);
    Row<Measurement> row = new Row<Measurement>(Timestamp.fromEpochSeconds(0), res);
    Measurement measurement = new Measurement(Timestamp.fromEpochSeconds(0), res, label, 0.0d);
    row.addElement(measurement);
    results.addRow(row);
    if (expect) {
        EasyMock.expect(m_sampleRepository.select(EasyMock.eq(m_context), EasyMock.eq(res), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(results);
    }
    final Source source = new Source();
    source.setAggregation("AVERAGE");
    source.setAttribute(attr);
    source.setLabel(label);
    source.setResourceId(resourceId.toString());
    source.setTransient(false);
    return source;
}
Also used : Measurement(org.opennms.newts.api.Measurement) OnmsResource(org.opennms.netmgt.model.OnmsResource) Resource(org.opennms.newts.api.Resource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) Source(org.opennms.netmgt.measurements.model.Source) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsResourceType(org.opennms.netmgt.model.OnmsResourceType) ResourceId(org.opennms.netmgt.model.ResourceId) FetchResults(org.opennms.netmgt.measurements.api.FetchResults) Results(org.opennms.newts.api.Results) Row(org.opennms.newts.api.Results.Row)

Example 34 with OnmsAttribute

use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.

the class ReportDefinitionTest method testUnfilteredResourceAttributeFilteringWithMatch.

public void testUnfilteredResourceAttributeFilteringWithMatch() throws Exception {
    OnmsAttribute rrdAttribute = new RrdGraphAttribute("IfInOctets", "something", "something else");
    ExternalValueAttribute externalValueAttribute = new ExternalValueAttribute("ifSpeed", "100000000");
    Set<OnmsAttribute> attributes = new HashSet<>();
    attributes.add(rrdAttribute);
    attributes.add(externalValueAttribute);
    MockResourceType resourceType = new MockResourceType();
    resourceType.setName("interfaceSnmp");
    OnmsResource resource = new OnmsResource("1", "Node One", resourceType, attributes, ResourcePath.get("foo"));
    EasyMock.expect(m_resourceDao.findTopLevelResources()).andReturn(Collections.singletonList(resource));
    ReportDefinition def = createReportDefinition();
    def.setResourceAttributeKey(externalValueAttribute.getName());
    def.setResourceAttributeValueMatch(externalValueAttribute.getValue());
    ReportInstance report = def.createReport(m_nodeDao, m_resourceDao, m_fetchStrategy, m_filterDao);
    rrdAttribute.setResource(new OnmsResource("1", "Node One", resourceType, Collections.singleton(rrdAttribute), ResourcePath.get("foo")));
    Source source = new Source();
    source.setLabel("result");
    source.setResourceId(rrdAttribute.getResource().getId().toString());
    source.setAttribute(rrdAttribute.getName());
    source.setAggregation("AVERAGE");
    FetchResults results = new FetchResults(new long[] { report.getStartTime() }, Collections.singletonMap("result", new double[] { 100.0 }), report.getEndTime() - report.getStartTime(), Collections.emptyMap());
    EasyMock.expect(m_fetchStrategy.fetch(report.getStartTime(), report.getEndTime(), 1, 0, null, null, Collections.singletonList(source), false)).andReturn(results);
    m_mocks.replayAll();
    report.walk();
    m_mocks.verifyAll();
    assertEquals("results size", 1, report.getResults().size());
    m_mocks.replayAll();
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) FetchResults(org.opennms.netmgt.measurements.api.FetchResults) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) ExternalValueAttribute(org.opennms.netmgt.model.ExternalValueAttribute) Source(org.opennms.netmgt.measurements.model.Source) HashSet(java.util.HashSet) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 35 with OnmsAttribute

use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.

the class AttributeMatchingResourceVisitorTest method testVisitWithoutMatch.

public void testVisitWithoutMatch() throws Exception {
    AttributeMatchingResourceVisitor resourceVisitor = new AttributeMatchingResourceVisitor();
    resourceVisitor.setAttributeVisitor(m_attributeVisitor);
    resourceVisitor.setAttributeMatch("ifInOctets");
    resourceVisitor.afterPropertiesSet();
    MockResourceType resourceType = new MockResourceType();
    resourceType.setName("something other than interfaceSnmp");
    OnmsResource resource = new OnmsResource("1", "Node One", resourceType, new HashSet<OnmsAttribute>(0), ResourcePath.get("foo"));
    m_mocks.replayAll();
    resourceVisitor.visit(resource);
    m_mocks.verifyAll();
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Aggregations

OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)45 OnmsResource (org.opennms.netmgt.model.OnmsResource)40 MockResourceType (org.opennms.netmgt.mock.MockResourceType)30 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)21 HashSet (java.util.HashSet)13 ResourcePath (org.opennms.netmgt.model.ResourcePath)13 Test (org.junit.Test)7 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)7 Source (org.opennms.netmgt.measurements.model.Source)7 ExternalValueAttribute (org.opennms.netmgt.model.ExternalValueAttribute)7 LazySet (org.opennms.core.collections.LazySet)6 HashMap (java.util.HashMap)5 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)5 AttributeStatistic (org.opennms.netmgt.model.AttributeStatistic)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 OnmsResourceType (org.opennms.netmgt.model.OnmsResourceType)3 ResourceId (org.opennms.netmgt.model.ResourceId)3 StringPropertyAttribute (org.opennms.netmgt.model.StringPropertyAttribute)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2