Search in sources :

Example 36 with ResourcePath

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

the class RrdResourceAttributeUtilsTest method createResource.

private OnmsResource createResource() {
    OnmsResource topResource = new OnmsResource("1", "Node One", new MockResourceType(), new HashSet<OnmsAttribute>(0), new ResourcePath("foo"));
    Set<OnmsAttribute> attributes = new HashSet<OnmsAttribute>(1);
    attributes.add(new RrdGraphAttribute("foo", "1/eth0", "foo.jrb"));
    OnmsResource childResource = new OnmsResource("eth0", "Interface eth0", new MockResourceType(), attributes, new ResourcePath("foo"));
    childResource.setParent(topResource);
    return childResource;
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType) HashSet(java.util.HashSet)

Example 37 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, 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 38 with ResourcePath

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

the class AbstractPersister method persistStringAttribute.

/**
 * {@inheritDoc}
 */
@Override
public void persistStringAttribute(CollectionAttribute attribute) {
    LOG.debug("Persisting {}", attribute);
    CollectionResource resource = attribute.getResource();
    String value = attribute.getStringValue();
    if (value == null) {
        LOG.info("No data collected for attribute {}.  Skipping.", attribute);
        return;
    }
    try {
        ResourcePath path = ResourceTypeUtils.getResourcePathWithRepository(m_repository, resource.getPath());
        persistStringAttribute(path, attribute.getName(), value);
    } catch (PersistException e) {
        LOG.error("Unable to save string attribute {}.", attribute, e);
    }
}
Also used : CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) ResourcePath(org.opennms.netmgt.model.ResourcePath)

Example 39 with ResourcePath

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

the class DefaultCollectionAgentService method getStorageResourcePath.

/**
 * <p>getStorageDir</p>
 *
 * @return a {@link java.io.File} object.
 */
@Override
public final ResourcePath getStorageResourcePath() {
    final String foreignSource = getForeignSource();
    final String foreignId = getForeignId();
    final ResourcePath dir;
    if (isStoreByForeignSource() && foreignSource != null && foreignId != null) {
        dir = ResourcePath.get(ResourceTypeUtils.FOREIGN_SOURCE_DIRECTORY, foreignSource, foreignId);
    } else {
        dir = ResourcePath.get(String.valueOf(getNodeId()));
    }
    LOG.debug("getStorageDir: isStoreByForeignSource = {}, foreignSource = {}, foreignId = {}, dir = {}", isStoreByForeignSource(), foreignSource, foreignId, dir);
    return dir;
}
Also used : ResourcePath(org.opennms.netmgt.model.ResourcePath)

Example 40 with ResourcePath

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

the class GroupPersister method visitGroup.

/**
 * {@inheritDoc}
 */
@Override
public void visitGroup(AttributeGroup group) {
    pushShouldPersist(group);
    if (shouldPersist()) {
        Map<String, String> dsNamesToRrdNames = new LinkedHashMap<String, String>();
        for (CollectionAttribute a : group.getAttributes()) {
            if (a.getType().isNumeric()) {
                dsNamesToRrdNames.put(a.getName(), group.getName());
            }
        }
        setBuilder(createBuilder(group.getResource(), group.getName(), group.getGroupType().getAttributeTypes()));
        ResourcePath path = ResourceTypeUtils.getResourcePathWithRepository(getRepository(), group.getResource().getPath());
        m_resourceStorageDao.updateMetricToResourceMappings(path, dsNamesToRrdNames);
    }
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) ResourcePath(org.opennms.netmgt.model.ResourcePath) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ResourcePath (org.opennms.netmgt.model.ResourcePath)57 OnmsResource (org.opennms.netmgt.model.OnmsResource)19 OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)14 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)9 MockResourceType (org.opennms.netmgt.mock.MockResourceType)9 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)8 HashSet (java.util.HashSet)6 Map (java.util.Map)6 CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)6 Parameter (org.opennms.netmgt.config.datacollection.Parameter)6 Resource (org.opennms.newts.api.Resource)6 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)5 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)5 Sample (org.opennms.newts.api.Sample)5 Path (java.nio.file.Path)4 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)4 IOException (java.io.IOException)3 ObjectNameStorageStrategy (org.opennms.netmgt.collection.support.ObjectNameStorageStrategy)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)3