Search in sources :

Example 11 with StorageStrategy

use of org.opennms.netmgt.config.datacollection.StorageStrategy in project opennms by OpenNMS.

the class GenericIndexResourceTypeTest method instantiate.

private GenericIndexResourceType instantiate() {
    org.opennms.netmgt.config.datacollection.ResourceType rt = new org.opennms.netmgt.config.datacollection.ResourceType();
    PersistenceSelectorStrategy ps = new PersistenceSelectorStrategy();
    ps.setClazz("org.opennms.netmgt.collection.support.PersistAllSelectorStrategy");
    rt.setPersistenceSelectorStrategy(ps);
    StorageStrategy ss = new StorageStrategy();
    ss.setClazz("org.opennms.netmgt.collection.support.IndexStorageStrategy");
    rt.setStorageStrategy(ss);
    return new GenericIndexResourceType(null, null, rt);
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)

Example 12 with StorageStrategy

use of org.opennms.netmgt.config.datacollection.StorageStrategy in project opennms by OpenNMS.

the class XmpCollectorTest method canDetermineAppropriateResourceType.

@Test
public void canDetermineAppropriateResourceType() throws CollectionException {
    NodeLevelResource nodeLevelResource = new NodeLevelResource(1);
    // Define the resource type
    ResourceType resourceType = new ResourceType();
    resourceType.setName("rt");
    resourceType.setLabel("rt label");
    resourceType.setResourceLabel("${instance}");
    StorageStrategy storageStrategy = new StorageStrategy();
    storageStrategy.setClazz(IndexStorageStrategy.class.getCanonicalName());
    resourceType.setStorageStrategy(storageStrategy);
    PersistenceSelectorStrategy persistenceSelectorStrategy = new PersistenceSelectorStrategy();
    persistenceSelectorStrategy.setClazz(PersistAllSelectorStrategy.class.getCanonicalName());
    resourceType.setPersistenceSelectorStrategy(persistenceSelectorStrategy);
    ResourceTypesDao resourceTypesDao = mock(ResourceTypesDao.class);
    when(resourceTypesDao.getResourceTypeByName(resourceType.getName())).thenReturn(resourceType);
    xmpCollector.setResourceTypesDao(resourceTypesDao);
    // If the nodeTypeName is set to "node" it should always return a node level resource
    assertThat(xmpCollector.getResource(nodeLevelResource, CollectionResource.RESOURCE_TYPE_NODE, null, "instance"), instanceOf(NodeLevelResource.class));
    assertThat(xmpCollector.getResource(nodeLevelResource, CollectionResource.RESOURCE_TYPE_NODE, "some-resource", "instance"), instanceOf(NodeLevelResource.class));
    // If a resource-type is set, it should always return a generic type resource
    assertThat(xmpCollector.getResource(nodeLevelResource, null, "rt", "instance"), instanceOf(GenericTypeResource.class));
    // Otherwise, falls back to an instance level resource
    assertThat(xmpCollector.getResource(nodeLevelResource, null, null, "instance"), instanceOf(InterfaceLevelResource.class));
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) IndexStorageStrategy(org.opennms.netmgt.collection.support.IndexStorageStrategy) PersistAllSelectorStrategy(org.opennms.netmgt.collection.support.PersistAllSelectorStrategy) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) IndexStorageStrategy(org.opennms.netmgt.collection.support.IndexStorageStrategy) ResourceTypesDao(org.opennms.netmgt.config.api.ResourceTypesDao) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) InterfaceLevelResource(org.opennms.netmgt.collection.support.builder.InterfaceLevelResource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy) Test(org.junit.Test)

Example 13 with StorageStrategy

use of org.opennms.netmgt.config.datacollection.StorageStrategy in project opennms by OpenNMS.

the class WSManCollectorTest method canGenerateManyResources.

/**
 * NMS-8924: Verifies that the generated collection set includes a resource
 * for every node (XML) in the response.
 */
@Test
public void canGenerateManyResources() {
    // Define our resource type, and create a supplier that returns a new instance on every call
    NodeLevelResource node = mock(NodeLevelResource.class);
    ResourceType rt = new ResourceType();
    rt.setName("wsProcIndex");
    rt.setLabel("Processor (wsman)");
    rt.setResourceLabel("Processor (${wmiOSCpuName})");
    StorageStrategy strategy = new StorageStrategy();
    strategy.setClazz(SiblingColumnStorageStrategy.class.getCanonicalName());
    strategy.addParameter(new Parameter("sibling-column-name", "wmiOSCpuName"));
    rt.setStorageStrategy(strategy);
    PersistenceSelectorStrategy pstrategy = new PersistenceSelectorStrategy();
    pstrategy.setClazz(PersistAllSelectorStrategy.class.getCanonicalName());
    rt.setPersistenceSelectorStrategy(pstrategy);
    final AtomicInteger instanceId = new AtomicInteger();
    Supplier<Resource> resourceSupplier = () -> {
        return new GenericTypeResource(node, rt, Integer.toString(instanceId.getAndIncrement()));
    };
    // Define our group
    Group group = new Group();
    group.setName("windows-os-wmi-processor");
    addAttribute(group, "Name", "wmiOSCpuName", AttributeType.STRING);
    addAttribute(group, "InterruptsPersec", "wmiOSCpuIntsPerSec", AttributeType.GAUGE);
    addAttribute(group, "PercentProcessorTime", "wmiOSCpuPctProcTime", AttributeType.GAUGE);
    addAttribute(group, "PercentDPCTime", "wmiOSCpuPctDPCTime", AttributeType.GAUGE);
    addAttribute(group, "PercentInterruptTime", "wmiOSCpuPctIntrTime", AttributeType.GAUGE);
    addAttribute(group, "PercentUserTime", "wmiOSCpuPctUserTime", AttributeType.GAUGE);
    // Mock the agent
    CollectionAgent agent = mock(CollectionAgent.class);
    when(agent.getStorageResourcePath()).thenReturn(ResourcePath.get());
    CollectionSetBuilder builder = new CollectionSetBuilder(agent);
    // Sample data
    XMLTag xmlTag = XMLDoc.newDocument(true).addRoot("body").addTag("Win32_PerfFormattedData_PerfOS_Processor").addTag("Name").setText("c0").addTag("InterruptsPersec").setText("95").gotoRoot().addTag("Win32_PerfFormattedData_PerfOS_Processor").addTag("Name").setText("c1").addTag("InterruptsPersec").setText("100");
    List<Node> nodes = xmlTag.gotoRoot().getChildElement().stream().map(el -> (Node) el).collect(Collectors.toList());
    // Process the data and generate the collection set
    WsManCollector.processEnumerationResults(group, builder, resourceSupplier, nodes);
    // Verify the result
    CollectionSet collectionSet = builder.build();
    assertEquals(Arrays.asList("wsProcIndex/c0/windows-os-wmi-processor/wmiOSCpuName[c0,null]", "wsProcIndex/c0/windows-os-wmi-processor/wmiOSCpuIntsPerSec[null,95.0]", "wsProcIndex/c1/windows-os-wmi-processor/wmiOSCpuName[c1,null]", "wsProcIndex/c1/windows-os-wmi-processor/wmiOSCpuIntsPerSec[null,100.0]"), CollectionSetUtils.flatten(collectionSet));
    assertEquals(Sets.newHashSet("c0", "c1"), CollectionSetUtils.getResourcesByLabel(collectionSet).keySet());
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) WSManDataCollectionConfigDao(org.opennms.netmgt.dao.WSManDataCollectionConfigDao) Arrays(java.util.Arrays) CollectionStatus(org.opennms.netmgt.collection.api.CollectionStatus) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) WSManConfigDao(org.opennms.netmgt.dao.WSManConfigDao) Supplier(java.util.function.Supplier) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) XMLDoc(com.mycila.xmltool.XMLDoc) SiblingColumnStorageStrategy(org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy) CollectionException(org.opennms.netmgt.collection.api.CollectionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Node(org.w3c.dom.Node) AttributeType(org.opennms.netmgt.collection.api.AttributeType) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) Collection(org.opennms.netmgt.config.wsman.Collection) Attrib(org.opennms.netmgt.config.wsman.Attrib) OnmsNode(org.opennms.netmgt.model.OnmsNode) Resource(org.opennms.netmgt.collection.support.builder.Resource) NodeDao(org.opennms.netmgt.dao.api.NodeDao) InetAddressUtils(org.opennms.core.utils.InetAddressUtils) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) WSManClientFactory(org.opennms.core.wsman.WSManClientFactory) XMLTag(com.mycila.xmltool.XMLTag) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Group(org.opennms.netmgt.config.wsman.Group) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) Sets(com.google.common.collect.Sets) Definition(org.opennms.netmgt.config.wsman.Definition) Matchers.any(org.mockito.Matchers.any) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy) CollectionInitializationException(org.opennms.netmgt.collection.api.CollectionInitializationException) List(java.util.List) PersistAllSelectorStrategy(org.opennms.netmgt.collection.support.PersistAllSelectorStrategy) Assert.assertFalse(org.junit.Assert.assertFalse) CollectionSetUtils(org.opennms.core.collection.test.CollectionSetUtils) ResourcePath(org.opennms.netmgt.model.ResourcePath) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) Parameter(org.opennms.netmgt.config.datacollection.Parameter) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) Group(org.opennms.netmgt.config.wsman.Group) StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) SiblingColumnStorageStrategy(org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy) PersistAllSelectorStrategy(org.opennms.netmgt.collection.support.PersistAllSelectorStrategy) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) Node(org.w3c.dom.Node) OnmsNode(org.opennms.netmgt.model.OnmsNode) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) Resource(org.opennms.netmgt.collection.support.builder.Resource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) XMLTag(com.mycila.xmltool.XMLTag) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Parameter(org.opennms.netmgt.config.datacollection.Parameter) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) SiblingColumnStorageStrategy(org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy) Test(org.junit.Test)

Example 14 with StorageStrategy

use of org.opennms.netmgt.config.datacollection.StorageStrategy in project opennms by OpenNMS.

the class ThresholdingVisitorIT method createWmiLogicalDiskResourceType.

private static org.opennms.netmgt.config.datacollection.ResourceType createWmiLogicalDiskResourceType() {
    org.opennms.netmgt.config.datacollection.ResourceType wmiLogicalDisk = new org.opennms.netmgt.config.datacollection.ResourceType();
    wmiLogicalDisk.setName("wmiLogicalDisk");
    wmiLogicalDisk.setLabel("(wsman) Logical Storage");
    wmiLogicalDisk.setResourceLabel("Logical Disk (${wmiLDName})");
    PersistenceSelectorStrategy pss = new PersistenceSelectorStrategy();
    pss.setClazz(PersistAllSelectorStrategy.class.getCanonicalName());
    wmiLogicalDisk.setPersistenceSelectorStrategy(pss);
    StorageStrategy ss = new StorageStrategy();
    ss.setClazz(SiblingColumnStorageStrategy.class.getCanonicalName());
    org.opennms.netmgt.config.datacollection.Parameter siblingColumnName = new org.opennms.netmgt.config.datacollection.Parameter();
    siblingColumnName.setKey("sibling-column-name");
    siblingColumnName.setValue("wmiLDName");
    ss.addParameter(siblingColumnName);
    wmiLogicalDisk.setStorageStrategy(ss);
    return wmiLogicalDisk;
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) IndexStorageStrategy(org.opennms.netmgt.collection.support.IndexStorageStrategy) SiblingColumnStorageStrategy(org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy) PersistAllSelectorStrategy(org.opennms.netmgt.collection.support.PersistAllSelectorStrategy) GenericIndexResourceType(org.opennms.netmgt.collectd.GenericIndexResourceType) NodeResourceType(org.opennms.netmgt.collectd.NodeResourceType) ResourceType(org.opennms.netmgt.collectd.ResourceType) IfResourceType(org.opennms.netmgt.collectd.IfResourceType) Parameter(org.opennms.netmgt.config.threshd.Parameter) SiblingColumnStorageStrategy(org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)

Aggregations

PersistenceSelectorStrategy (org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)14 StorageStrategy (org.opennms.netmgt.config.datacollection.StorageStrategy)14 ResourceType (org.opennms.netmgt.config.datacollection.ResourceType)11 IndexStorageStrategy (org.opennms.netmgt.collection.support.IndexStorageStrategy)7 PersistAllSelectorStrategy (org.opennms.netmgt.collection.support.PersistAllSelectorStrategy)7 Test (org.junit.Test)5 Parameter (org.opennms.netmgt.config.datacollection.Parameter)5 HashMap (java.util.HashMap)3 GenericIndexResourceType (org.opennms.netmgt.collectd.GenericIndexResourceType)3 IfResourceType (org.opennms.netmgt.collectd.IfResourceType)3 NodeResourceType (org.opennms.netmgt.collectd.NodeResourceType)3 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)3 GenericTypeResource (org.opennms.netmgt.collection.support.builder.GenericTypeResource)3 GenericIndexResource (org.opennms.netmgt.collectd.GenericIndexResource)2 OnmsSnmpCollection (org.opennms.netmgt.collectd.OnmsSnmpCollection)2 SnmpAttribute (org.opennms.netmgt.collectd.SnmpAttribute)2 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)2 SnmpCollectionResource (org.opennms.netmgt.collectd.SnmpCollectionResource)2 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)2 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)2