Search in sources :

Example 1 with ResourceType

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

the class CollectionSetDTOTest method data.

@Parameters
public static Collection<Object[]> data() throws ParseException {
    CollectionAgent collectionAgent = mock(CollectionAgent.class);
    NodeLevelResource nodeLevelResource = new NodeLevelResource(1);
    InterfaceLevelResource interfaceLevelResource = new InterfaceLevelResource(nodeLevelResource, "eth0");
    ResourceType rt = mock(ResourceType.class, RETURNS_DEEP_STUBS);
    when(rt.getName()).thenReturn("Charles");
    when(rt.getStorageStrategy().getClazz()).thenReturn(MockStorageStrategy.class.getCanonicalName());
    when(rt.getPersistenceSelectorStrategy().getClazz()).thenReturn(MockPersistenceSelectorStrategy.class.getCanonicalName());
    DeferredGenericTypeResource deferredGenericTypeResource = new DeferredGenericTypeResource(nodeLevelResource, "Charles", "id");
    GenericTypeResource genericTypeResource = new GenericTypeResource(nodeLevelResource, rt, "idx");
    genericTypeResource.setTimestamp(new Date(0));
    ResourceTypeMapper.getInstance().setResourceTypeMapper((name) -> rt);
    // For complete coverage make sure that there is at least one attribute
    // for every different resource type, and that every different type
    // of attribute is represented at least once
    CollectionSet collectionSet = new CollectionSetBuilder(collectionAgent).withTimestamp(new Date(0)).withNumericAttribute(nodeLevelResource, "ucd-sysstat", "CpuRawIdle", 99, AttributeType.GAUGE).withNumericAttribute(interfaceLevelResource, "mib2-X-interfaces", "ifHCInOctets", 1001, AttributeType.COUNTER).withStringAttribute(interfaceLevelResource, "mib2-X-interfaces", "ifDescr", "LAN").withIdentifiedNumericAttribute(deferredGenericTypeResource, "net-snmp-disk", "ns-dsk1", 1024, AttributeType.GAUGE, "some-oid").withIdentifiedNumericAttribute(genericTypeResource, "net-snmp-disk", "ns-dskTotal", 1024, AttributeType.GAUGE, "some-oid").build();
    return Arrays.asList(new Object[][] { { collectionSet, "<collection-set status=\"SUCCEEDED\" timestamp=\"" + StringUtils.iso8601OffsetString(new Date(0), ZoneId.systemDefault(), ChronoUnit.SECONDS) + "\">\n" + "   <agent type=\"0\" store-by-fs=\"false\" node-id=\"0\" sys-up-time=\"0\"/>\n" + "   <collection-resource>\n" + "      <node-level-resource node-id=\"1\"/>\n" + "      <numeric-attribute group=\"ucd-sysstat\" name=\"CpuRawIdle\" type=\"gauge\" value=\"99\"/>\n" + "   </collection-resource>\n" + "   <collection-resource>\n" + "      <interface-level-resource if-name=\"eth0\">\n" + "         <node-level-resource node-id=\"1\"/>\n" + "      </interface-level-resource>\n" + "      <numeric-attribute group=\"mib2-X-interfaces\" name=\"ifHCInOctets\" type=\"counter\" value=\"1001\"/>\n" + "      <string-attribute group=\"mib2-X-interfaces\" name=\"ifDescr\" type=\"string\" value=\"LAN\"/>\n" + "   </collection-resource>\n" + "   <collection-resource>\n" + "      <generic-type-resource name=\"Charles\" instance=\"id\">\n" + "         <node-level-resource node-id=\"1\"/>\n" + "      </generic-type-resource>\n" + "      <numeric-attribute group=\"net-snmp-disk\" name=\"ns-dsk1\" type=\"gauge\" identifier=\"some-oid\" value=\"1024\"/>\n" + "   </collection-resource>\n" + "   <collection-resource>\n" + "      <generic-type-resource name=\"Charles\" instance=\"idx\" timestamp=\"" + StringUtils.iso8601OffsetString(new Date(0), ZoneId.systemDefault(), ChronoUnit.SECONDS) + "\">\n" + "         <node-level-resource node-id=\"1\"/>\n" + "      </generic-type-resource>\n" + "      <numeric-attribute group=\"net-snmp-disk\" name=\"ns-dskTotal\" type=\"gauge\" identifier=\"some-oid\" value=\"1024\"/>\n" + "   </collection-resource>\n" + "</collection-set>" } });
}
Also used : DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) InterfaceLevelResource(org.opennms.netmgt.collection.support.builder.InterfaceLevelResource) ResourceType(org.opennms.netmgt.collection.api.ResourceType) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) Date(java.util.Date) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) Parameters(org.junit.runners.Parameterized.Parameters)

Example 2 with ResourceType

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

the class GenericTypeResourceTest method getInstanceInResourcePath.

private String getInstanceInResourcePath(String instance) {
    // Mock the ResourceType
    ResourceType rt = mock(ResourceType.class, RETURNS_DEEP_STUBS);
    when(rt.getName()).thenReturn("type");
    when(rt.getStorageStrategy().getClazz()).thenReturn(IndexStorageStrategy.class.getCanonicalName());
    when(rt.getStorageStrategy().getParameters()).thenReturn(Collections.emptyList());
    when(rt.getPersistenceSelectorStrategy().getClazz()).thenReturn(PersistAllSelectorStrategy.class.getCanonicalName());
    when(rt.getPersistenceSelectorStrategy().getParameters()).thenReturn(Collections.emptyList());
    // Create the GenericTypeResource
    NodeLevelResource nlr = new NodeLevelResource(1);
    GenericTypeResource gtr = new GenericTypeResource(nlr, rt, instance);
    // Mock the CollectionResource
    CollectionResource resource = mock(CollectionResource.class);
    when(resource.getInstance()).thenReturn(gtr.getInstance());
    // Build the resource path, and extract the instance (the last element of the path)
    ResourcePath path = gtr.getPath(resource);
    String[] elements = path.elements();
    return elements[elements.length - 1];
}
Also used : CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) ResourceType(org.opennms.netmgt.collection.api.ResourceType) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource)

Example 3 with ResourceType

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

the class CollectionSetDTOTest method getCollectionSetWithAllResourceTypes.

private static CollectionSet getCollectionSetWithAllResourceTypes() {
    CollectionAgent collectionAgent = mock(CollectionAgent.class);
    NodeLevelResource nodeLevelResource = new NodeLevelResource(1);
    NodeLevelResource jmxNodeLevelResource = new NodeLevelResource(1, "opennns-jvm");
    InterfaceLevelResource interfaceLevelResource = new InterfaceLevelResource(nodeLevelResource, "eth0");
    ResourceType rt = mock(ResourceType.class, RETURNS_DEEP_STUBS);
    when(rt.getName()).thenReturn("Charles");
    when(rt.getStorageStrategy().getClazz()).thenReturn(MockStorageStrategy.class.getCanonicalName());
    when(rt.getPersistenceSelectorStrategy().getClazz()).thenReturn(MockPersistenceSelectorStrategy.class.getCanonicalName());
    DeferredGenericTypeResource deferredGenericTypeResource = new DeferredGenericTypeResource(nodeLevelResource, "Charles", "id");
    GenericTypeResource genericTypeResource = new GenericTypeResource(nodeLevelResource, rt, "idx");
    genericTypeResource.setTimestamp(new Date(0));
    ResourceTypeMapper.getInstance().setResourceTypeMapper((name) -> rt);
    // of attribute is represented at least once
    return new CollectionSetBuilder(collectionAgent).withTimestamp(new Date(0)).withNumericAttribute(nodeLevelResource, "ucd-sysstat", "CpuRawIdle", 99, AttributeType.GAUGE).withNumericAttribute(jmxNodeLevelResource, "opennms-jvm", "heap", 2048, AttributeType.GAUGE).withNumericAttribute(interfaceLevelResource, "mib2-X-interfaces", "ifHCInOctets", 1001, AttributeType.COUNTER).withStringAttribute(interfaceLevelResource, "mib2-X-interfaces", "ifDescr", "LAN").withIdentifiedNumericAttribute(deferredGenericTypeResource, "net-snmp-disk", "ns-dsk1", 1024, AttributeType.GAUGE, "some-oid").withIdentifiedNumericAttribute(genericTypeResource, "net-snmp-disk", "ns-dskTotal", 1024, AttributeType.GAUGE, "some-oid").build();
}
Also used : DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) InterfaceLevelResource(org.opennms.netmgt.collection.support.builder.InterfaceLevelResource) ResourceType(org.opennms.netmgt.collection.api.ResourceType) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) Date(java.util.Date)

Example 4 with ResourceType

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

the class GenericTypeResourceDTO method toResource.

public GenericTypeResource toResource() {
    final ResourceType resourceType = ResourceTypeMapper.getInstance().getResourceTypeWithFallback(name, fallback);
    if (resourceType == null) {
        throw new IllegalArgumentException(String.format("No resource type found with name '%s'!", name));
    }
    final GenericTypeResource resource = new GenericTypeResource(parent.toResource(), resourceType, instance);
    resource.setTimestamp(timestamp);
    return resource;
}
Also used : GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) ResourceType(org.opennms.netmgt.collection.api.ResourceType)

Example 5 with ResourceType

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

the class DeferredGenericTypeResource method resolve.

@Override
public Resource resolve() {
    final ResourceType resourceType = ResourceTypeMapper.getInstance().getResourceTypeWithFallback(m_resourceTypeName, m_fallbackResourceTypeName);
    if (resourceType == null) {
        throw new IllegalArgumentException(String.format("No resource type found with name '%s'!", m_resourceTypeName));
    }
    final GenericTypeResource resource = new GenericTypeResource(m_node, resourceType, m_instance);
    resource.setTimestamp(getTimestamp());
    return resource;
}
Also used : ResourceType(org.opennms.netmgt.collection.api.ResourceType)

Aggregations

ResourceType (org.opennms.netmgt.collection.api.ResourceType)6 GenericTypeResource (org.opennms.netmgt.collection.support.builder.GenericTypeResource)4 DeferredGenericTypeResource (org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource)3 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)3 Date (java.util.Date)2 CollectionAgent (org.opennms.netmgt.collection.api.CollectionAgent)2 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)2 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)2 InterfaceLevelResource (org.opennms.netmgt.collection.support.builder.InterfaceLevelResource)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1 Parameters (org.junit.runners.Parameterized.Parameters)1 JmxTest (org.opennms.netmgt.collectd.jmxhelper.JmxTest)1 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)1 CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)1 ResourcePath (org.opennms.netmgt.model.ResourcePath)1