Search in sources :

Example 16 with ResourcePath

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

the class NewtsResourceStorageDao method children.

@Override
public Set<ResourcePath> children(ResourcePath path, int depth) {
    Preconditions.checkArgument(depth >= 0, "depth must be non-negative");
    Set<ResourcePath> matches = Sets.newTreeSet();
    SearchResults results = searchFor(path, depth, false);
    for (Result result : results) {
        // Relativize the path
        ResourcePath child = toChildResourcePath(path, result.getResource().getId());
        if (child == null) {
            // This shouldn't happen
            LOG.warn("Encountered non-child resource {} when searching for {} with depth {}. Ignoring resource.", result.getResource(), path, depth);
            continue;
        }
        matches.add(child);
    }
    return matches;
}
Also used : NewtsUtils.toResourcePath(org.opennms.netmgt.newts.support.NewtsUtils.toResourcePath) ResourcePath(org.opennms.netmgt.model.ResourcePath) SearchResults(org.opennms.newts.api.search.SearchResults) Result(org.opennms.newts.api.search.SearchResults.Result)

Example 17 with ResourcePath

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

the class NewtsResourceStorageDao method toChildResourcePath.

protected static ResourcePath toChildResourcePath(ResourcePath parent, String resourceId) {
    final ResourcePath child = toResourcePath(resourceId);
    final String[] childEls = child.elements();
    final String[] parentEls = parent.elements();
    if (childEls.length <= parentEls.length) {
        return null;
    }
    String[] els = new String[parentEls.length + 1];
    for (int i = 0; i <= parentEls.length; i++) {
        els[i] = childEls[i];
    }
    return ResourcePath.get(els);
}
Also used : NewtsUtils.toResourcePath(org.opennms.netmgt.newts.support.NewtsUtils.toResourcePath) ResourcePath(org.opennms.netmgt.model.ResourcePath)

Example 18 with ResourcePath

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

the class NewtsResourceStorageDaoTest method replay.

private void replay() {
    EasyMock.expect(m_searcher.search(EasyMock.eq(m_context), EasyMock.anyObject(), EasyMock.anyBoolean())).andAnswer(new IAnswer<SearchResults>() {

        public SearchResults answer() throws Throwable {
            // Assume there is a single term query
            Query q = (Query) EasyMock.getCurrentArguments()[1];
            BooleanQuery bq = (BooleanQuery) q;
            TermQuery tq = (TermQuery) bq.getClauses().get(0).getQuery();
            String field = tq.getTerm().getField("");
            String value = tq.getTerm().getValue();
            SearchResults searchResults = new SearchResults();
            for (Entry<ResourcePath, Set<String>> entry : m_indexedPaths.entrySet()) {
                Map<String, String> attributes = Maps.newHashMap();
                // Build the indexed attributes and attempt to match them against the given query
                NewtsUtils.addIndicesToAttributes(entry.getKey(), attributes);
                if (value.equals(attributes.get(field))) {
                    searchResults.addResult(new Resource(NewtsUtils.toResourceId(entry.getKey())), entry.getValue());
                }
            }
            return searchResults;
        }
    }).atLeastOnce();
    EasyMock.expect(m_searcher.getResourceAttributes(EasyMock.eq(m_context), EasyMock.anyObject())).andReturn(Maps.newHashMap()).anyTimes();
    EasyMock.replay(m_searcher);
}
Also used : IAnswer(org.easymock.IAnswer) BooleanQuery(org.opennms.newts.api.search.BooleanQuery) TermQuery(org.opennms.newts.api.search.TermQuery) ResourcePath(org.opennms.netmgt.model.ResourcePath) Set(java.util.Set) TermQuery(org.opennms.newts.api.search.TermQuery) BooleanQuery(org.opennms.newts.api.search.BooleanQuery) Query(org.opennms.newts.api.search.Query) Resource(org.opennms.newts.api.Resource) SearchResults(org.opennms.newts.api.search.SearchResults)

Example 19 with ResourcePath

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

the class GenericIndexResourceType method getResourcesForParent.

/** {@inheritDoc} */
@Override
public List<OnmsResource> getResourcesForParent(OnmsResource parent) {
    if (parent == null) {
        return Collections.emptyList();
    }
    List<OnmsResource> resources = Lists.newArrayList();
    List<String> indexes = getQueryableIndexes(new ResourcePath(parent.getPath(), m_name));
    for (String index : indexes) {
        resources.add(getResourceByPath(new ResourcePath(parent.getPath(), m_name, index), parent));
    }
    return OnmsResource.sortIntoResourceList(resources);
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourcePath(org.opennms.netmgt.model.ResourcePath)

Example 20 with ResourcePath

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

the class InterfaceSnmpResourceType method getResourceByParentPathAndInterface.

private OnmsResource getResourceByParentPathAndInterface(ResourcePath parent, String intf) {
    final ResourcePath path = ResourcePath.get(parent, intf);
    final LazyResourceAttributeLoader loader = new LazyResourceAttributeLoader(m_resourceStorageDao, path);
    final Set<OnmsAttribute> set = new LazySet<OnmsAttribute>(loader);
    return new OnmsResource(intf, intf, this, set, path);
}
Also used : LazySet(org.opennms.core.utils.LazySet) ResourcePath(org.opennms.netmgt.model.ResourcePath) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute)

Aggregations

ResourcePath (org.opennms.netmgt.model.ResourcePath)51 OnmsResource (org.opennms.netmgt.model.OnmsResource)19 OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)14 MockResourceType (org.opennms.netmgt.mock.MockResourceType)9 Test (org.junit.Test)8 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)8 HashSet (java.util.HashSet)6 Map (java.util.Map)6 Resource (org.opennms.newts.api.Resource)6 Path (java.nio.file.Path)5 ArrayList (java.util.ArrayList)5 Sample (org.opennms.newts.api.Sample)5 IOException (java.io.IOException)3 List (java.util.List)3 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)3 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 Timestamp (org.opennms.newts.api.Timestamp)3 Optional (com.google.common.base.Optional)2 Preconditions (com.google.common.base.Preconditions)2