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>" } });
}
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];
}
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();
}
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;
}
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;
}
Aggregations