use of org.opennms.netmgt.config.datacollection.ResourceType in project opennms by OpenNMS.
the class FindTopLevelResourcesTest method execute_testFindTopLevelResources_discoveredNodes.
/*
* On environments where all the nodes have been discovered (i.e. they are not part of a requisition),
* the top level resources are always going to be built using NodeResourceType.
* no matter if storeByForeignSource is enabled or not.
*/
private void execute_testFindTopLevelResources_discoveredNodes() throws Exception {
final List<OnmsNode> nodes = new ArrayList<>();
// Node on the DB with RRD Data
OnmsNode n1 = createNode(1, "node1", null, null, "10.0.0.1");
nodes.add(n1);
// Node on the DB with No RRD Data
OnmsNode n2 = createNode(2, "node2", null, null, "10.0.0.2");
nodes.add(n2);
expect(m_resourceTypesDao.getLastUpdate()).andReturn(new Date(System.currentTimeMillis())).atLeastOnce();
expect(m_resourceTypesDao.getResourceTypes()).andReturn(new HashMap<String, ResourceType>());
expect(m_nodeDao.findAll()).andReturn(nodes);
expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(n1.getId())).andReturn(new ArrayList<LocationMonitorIpInterface>(0));
expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(n2.getId())).andReturn(new ArrayList<LocationMonitorIpInterface>(0));
// Common directories
File snmpDir = m_fileAnticipator.tempDir(ResourceTypeUtils.SNMP_DIRECTORY);
File responseDir = m_fileAnticipator.tempDir(ResourceTypeUtils.RESPONSE_DIRECTORY);
// RRD Directory for n1
File nodeDir = m_fileAnticipator.tempDir(snmpDir, n1.getId().toString());
m_fileAnticipator.tempFile(nodeDir, "data" + m_rrdFileExtension);
// RRD Directory for an orphan node
File orphanDir = m_fileAnticipator.tempDir(snmpDir, "100");
m_fileAnticipator.tempFile(orphanDir, "data" + m_rrdFileExtension);
// Response Time RRD Directory for n1
File ipDir = m_fileAnticipator.tempDir(responseDir, n1.getIpInterfaces().iterator().next().getIpAddress().getHostAddress());
m_fileAnticipator.tempFile(ipDir, "icmp" + m_rrdFileExtension);
m_easyMockUtils.replayAll();
m_resourceDao.afterPropertiesSet();
// Verify node1
List<OnmsResource> resources = m_resourceDao.findTopLevelResources();
Assert.assertNotNull(resources);
Collections.sort(resources);
Assert.assertEquals(1, resources.size());
List<OnmsResource> children = resources.get(0).getChildResources();
Collections.sort(children);
Assert.assertEquals(2, children.size());
Assert.assertEquals("node[1].responseTime[10.0.0.1]", children.get(0).getId().toString());
Assert.assertEquals("node[1].nodeSnmp[]", children.get(1).getId().toString());
m_easyMockUtils.verifyAll();
}
use of org.opennms.netmgt.config.datacollection.ResourceType in project opennms by OpenNMS.
the class FindTopLevelResourcesTest method execute_testFindTopLevelResources_hybridNodes.
/*
* On hybrid environments where some nodes have been discovered and other nodes are part of a requisition,
* the top level resources are always going to be built using NodeResourceType only if storeByForeignSource
* is disabled.
* But, if storeByForeignSource is enabled, the resources associated with discovered nodes are going to be
* built by NodeResourceType, and the resources associated with requisitioned nodes are going to be built by
* NodeSourceResourceType.
*/
private void execute_testFindTopLevelResources_hybridNodes(boolean storeByForeignSource) throws Exception {
setStoreByForeignSource(storeByForeignSource);
final String foreignSource = "Junit";
final List<OnmsNode> nodes = new ArrayList<>();
// Discovered node on the DB with RRD Data
OnmsNode n1 = createNode(1, "node1", null, null, "10.0.0.1");
nodes.add(n1);
// Requisitioned node on the DB with RRD Data
OnmsNode n2 = createNode(2, "node2", foreignSource, "node2", "10.0.0.2");
nodes.add(n2);
// Discovered node on the DB with No RRD Data
OnmsNode n3 = createNode(3, "node3", null, null, "10.0.0.3");
nodes.add(n3);
// Requisitioned node on the DB with RRD Data
OnmsNode n4 = createNode(4, "node4", foreignSource, "node4", "10.0.0.4");
nodes.add(n4);
expect(m_resourceTypesDao.getLastUpdate()).andReturn(new Date(System.currentTimeMillis())).atLeastOnce();
expect(m_resourceTypesDao.getResourceTypes()).andReturn(new HashMap<String, ResourceType>());
expect(m_nodeDao.findAll()).andReturn(nodes);
expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(n1.getId())).andReturn(new ArrayList<LocationMonitorIpInterface>(0));
expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(n2.getId())).andReturn(new ArrayList<LocationMonitorIpInterface>(0));
expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(n3.getId())).andReturn(new ArrayList<LocationMonitorIpInterface>(0));
expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(n4.getId())).andReturn(new ArrayList<LocationMonitorIpInterface>(0));
// Common directories
File snmpDir = m_fileAnticipator.tempDir(ResourceTypeUtils.SNMP_DIRECTORY);
File responseDir = m_fileAnticipator.tempDir(ResourceTypeUtils.RESPONSE_DIRECTORY);
File featureDir = m_fileAnticipator.tempDir(snmpDir, ResourceTypeUtils.FOREIGN_SOURCE_DIRECTORY);
File fsDir = m_fileAnticipator.tempDir(featureDir, foreignSource);
// RRD Directory for n1
File node1Dir = m_fileAnticipator.tempDir(snmpDir, n1.getId().toString());
m_fileAnticipator.tempFile(node1Dir, "data" + m_rrdFileExtension);
// RRD Directory for n2
File node2Dir = null;
if (storeByForeignSource) {
node2Dir = m_fileAnticipator.tempDir(fsDir, n2.getForeignId());
} else {
node2Dir = m_fileAnticipator.tempDir(snmpDir, n2.getId().toString());
}
m_fileAnticipator.tempFile(node2Dir, "data" + m_rrdFileExtension);
// RRD Directory for an orphan discovered node
m_fileAnticipator.tempFile(m_fileAnticipator.tempDir(snmpDir, "100"), "data" + m_rrdFileExtension);
// RRD Directory for an orphan requisitioned node
File orphanDir = null;
if (storeByForeignSource) {
orphanDir = m_fileAnticipator.tempDir(fsDir, "orphan_node");
} else {
orphanDir = m_fileAnticipator.tempDir(snmpDir, "101");
}
m_fileAnticipator.tempFile(orphanDir, "data" + m_rrdFileExtension);
// Response Time RRD Directory for n1
File ip1Dir = m_fileAnticipator.tempDir(responseDir, n1.getIpInterfaces().iterator().next().getIpAddress().getHostAddress());
m_fileAnticipator.tempFile(ip1Dir, "icmp" + m_rrdFileExtension);
// Response Time RRD Directory for n2
File ip2Dir = m_fileAnticipator.tempDir(responseDir, n2.getIpInterfaces().iterator().next().getIpAddress().getHostAddress());
m_fileAnticipator.tempFile(ip2Dir, "icmp" + m_rrdFileExtension);
m_easyMockUtils.replayAll();
m_resourceDao.afterPropertiesSet();
List<OnmsResource> resources = m_resourceDao.findTopLevelResources();
Assert.assertNotNull(resources);
Collections.sort(resources);
Assert.assertEquals(2, resources.size());
// parent resource for the discovered node
OnmsResource r1 = resources.get(0);
Assert.assertEquals("node[1]", r1.getId().toString());
List<OnmsResource> children2 = r1.getChildResources();
Collections.sort(children2);
Assert.assertEquals(2, children2.size());
Assert.assertEquals("node[1].responseTime[10.0.0.1]", children2.get(0).getId().toString());
Assert.assertEquals("node[1].nodeSnmp[]", children2.get(1).getId().toString());
// parent resource for the provisioned node
OnmsResource r2 = resources.get(1);
List<OnmsResource> children1 = r2.getChildResources();
Collections.sort(children1);
Assert.assertEquals("node[Junit:node2]", r2.getId().toString());
Assert.assertEquals("node[Junit:node2].responseTime[10.0.0.2]", children1.get(0).getId().toString());
Assert.assertEquals("node[Junit:node2].nodeSnmp[]", children1.get(1).getId().toString());
m_easyMockUtils.verifyAll();
}
use of org.opennms.netmgt.config.datacollection.ResourceType in project opennms by OpenNMS.
the class GenericIndexResourceType method createTypes.
protected static Map<String, GenericIndexResourceType> createTypes(Map<String, ResourceType> configuredResourceTypes, ResourceStorageDao resourceStorageDao) {
Map<String, GenericIndexResourceType> resourceTypes = Maps.newLinkedHashMap();
List<ResourceType> resourceTypeList = new LinkedList<ResourceType>(configuredResourceTypes.values());
Collections.sort(resourceTypeList, new Comparator<ResourceType>() {
@Override
public int compare(ResourceType r0, ResourceType r1) {
// Sort by resource label, allowing the resource label to be null
final Comparator<? super String> comparator = (a, b) -> a.compareTo(b);
return Objects.compare(r0.getLabel(), r1.getLabel(), Comparator.nullsLast(comparator));
}
});
for (ResourceType resourceType : resourceTypeList) {
String className = resourceType.getStorageStrategy().getClazz();
Class<?> cinst;
try {
cinst = Class.forName(className);
} catch (ClassNotFoundException e) {
throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not load class '" + className + "' for resource type '" + resourceType.getName() + "'", e);
}
StorageStrategy storageStrategy;
try {
storageStrategy = (StorageStrategy) cinst.newInstance();
} catch (InstantiationException e) {
throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not instantiate class '" + className + "' for resource type '" + resourceType.getName() + "'", e);
} catch (IllegalAccessException e) {
throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not instantiate class '" + className + "' for resource type '" + resourceType.getName() + "'", e);
}
storageStrategy.setResourceTypeName(resourceType.getName());
GenericIndexResourceType genericIndexResourceType = new GenericIndexResourceType(resourceStorageDao, resourceType.getName(), resourceType.getLabel(), resourceType.getResourceLabel(), storageStrategy);
resourceTypes.put(genericIndexResourceType.getName(), genericIndexResourceType);
}
return resourceTypes;
}
use of org.opennms.netmgt.config.datacollection.ResourceType in project opennms by OpenNMS.
the class DefaultResourceDaoTest method setUp.
@Before
public void setUp() throws Exception {
m_fileAnticipator = new FileAnticipator();
m_easyMockUtils = new EasyMockUtils();
m_nodeDao = m_easyMockUtils.createMock(NodeDao.class);
m_locationMonitorDao = m_easyMockUtils.createMock(LocationMonitorDao.class);
m_resourceTypesDao = m_easyMockUtils.createMock(ResourceTypesDao.class);
m_filterDao = m_easyMockUtils.createMock(FilterDao.class);
m_ipInterfaceDao = m_easyMockUtils.createMock(IpInterfaceDao.class);
FilterDaoFactory.setInstance(m_filterDao);
expect(m_filterDao.getActiveIPAddressList("IPADDR IPLIKE *.*.*.*")).andReturn(new ArrayList<InetAddress>(0)).anyTimes();
m_easyMockUtils.replayAll();
setUpCollectdConfigFactory();
m_easyMockUtils.verifyAll();
RrdStrategy<?, ?> rrdStrategy = new JRobinRrdStrategy();
m_rrdFileExtension = rrdStrategy.getDefaultFileExtension();
m_resourceStorageDao.setRrdDirectory(m_fileAnticipator.getTempDir());
m_resourceStorageDao.setRrdStrategy(rrdStrategy);
m_resourceDao = new DefaultResourceDao();
m_resourceDao.setNodeDao(m_nodeDao);
m_resourceDao.setLocationMonitorDao(m_locationMonitorDao);
m_resourceDao.setIpInterfaceDao(m_ipInterfaceDao);
m_resourceDao.setCollectdConfig(m_collectdConfig);
m_resourceDao.setResourceTypesDao(m_resourceTypesDao);
m_resourceDao.setResourceStorageDao(m_resourceStorageDao);
expect(m_resourceTypesDao.getResourceTypes()).andReturn(new HashMap<String, ResourceType>());
expect(m_resourceTypesDao.getLastUpdate()).andReturn(m_lastUpdateTime);
m_easyMockUtils.replayAll();
m_resourceDao.afterPropertiesSet();
m_easyMockUtils.verifyAll();
}
use of org.opennms.netmgt.config.datacollection.ResourceType in project opennms by OpenNMS.
the class CollectionResourceWrapperIT method testGenericResource.
@Test
public void testGenericResource() throws Exception {
SnmpCollectionAgent agent = createCollectionAgent();
MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
ResourceType rt = new ResourceType();
rt.setName("hrStorageIndex");
rt.setLabel("host-resources storage");
StorageStrategy strategy = new StorageStrategy();
strategy.setClazz("org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy");
strategy.addParameter(new Parameter("sibling-column-name", "hrStorageLabel"));
strategy.addParameter(new Parameter("replace-all", "s/^-//"));
rt.setStorageStrategy(strategy);
PersistenceSelectorStrategy pstrategy = new PersistenceSelectorStrategy();
pstrategy.setClazz("org.opennms.netmgt.collection.support.PersistAllSelectorStrategy");
rt.setPersistenceSelectorStrategy(pstrategy);
GenericIndexResourceType resourceType = new GenericIndexResourceType(agent, collection, rt);
SnmpCollectionResource resource = new GenericIndexResource(resourceType, resourceType.getName(), new SnmpInstId(100));
SnmpAttribute used = addAttributeToCollectionResource(resource, "hrStorageUsed", AttributeType.GAUGE, "hrStorageIndex", "5000");
SnmpAttribute label = addAttributeToCollectionResource(resource, "hrStorageLabel", AttributeType.STRING, "hrStorageIndex", "/opt");
Map<String, CollectionAttribute> attributes = new HashMap<String, CollectionAttribute>();
attributes.put(used.getName(), used);
attributes.put(label.getName(), label);
CollectionResourceWrapper wrapper = createWrapper(resource, attributes);
Assert.assertEquals("opt", wrapper.getInstanceLabel());
}
Aggregations