use of org.opennms.netmgt.model.LocationMonitorIpInterface in project opennms by OpenNMS.
the class LocationMonitorDaoHibernate method findStatusChangesForNodeForUniqueMonitorAndInterface.
/** {@inheritDoc} */
@Override
public Collection<LocationMonitorIpInterface> findStatusChangesForNodeForUniqueMonitorAndInterface(final int nodeId) {
@SuppressWarnings("unchecked") final List<Object[]> l = (List<Object[]>) getHibernateTemplate().find("select distinct status.locationMonitor, status.monitoredService.ipInterface from OnmsLocationSpecificStatus as status " + "where status.monitoredService.ipInterface.node.id = ?", nodeId);
final HashSet<LocationMonitorIpInterface> ret = new HashSet<LocationMonitorIpInterface>();
for (Object[] tuple : l) {
OnmsLocationMonitor mon = (OnmsLocationMonitor) tuple[0];
OnmsIpInterface ip = (OnmsIpInterface) tuple[1];
ret.add(new LocationMonitorIpInterface(mon, ip));
}
return ret;
}
use of org.opennms.netmgt.model.LocationMonitorIpInterface in project opennms by OpenNMS.
the class FindTopLevelResourcesTest method execute_testFindTopLevelResources_provisionedNodes.
/*
* On environments where all the nodes are part of a requisition (i.e. they have been provisioned)
* the top level resources are always going to be built using NodeSourceResourceType only
* if storeByForeignSource is enabled, otherwise they are all going to built using NodeResourceType.
*/
private void execute_testFindTopLevelResources_provisionedNodes(boolean storeByForeignSource) throws Exception {
setStoreByForeignSource(storeByForeignSource);
final List<OnmsNode> nodes = new ArrayList<OnmsNode>();
final String foreignSource = "Junit";
// Node on the DB with RRD Data with Response Time
OnmsNode n1 = createNode(1, "node1", foreignSource, "node1", "10.0.0.1");
nodes.add(n1);
// Node on the DB with RRD Data without Response Time
OnmsNode n2 = createNode(2, "node2", foreignSource, "node2", "10.0.0.2");
nodes.add(n2);
// Node on the DB with No RRD Data or Response Time
OnmsNode n3 = createNode(3, "node3", foreignSource, "node3", "10.0.0.3");
nodes.add(n3);
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));
// Common directories
File snmpDir = m_fileAnticipator.tempDir(ResourceTypeUtils.SNMP_DIRECTORY);
File responseDir = m_fileAnticipator.tempDir(ResourceTypeUtils.RESPONSE_DIRECTORY);
File fsDir = m_fileAnticipator.tempDir(snmpDir, ResourceTypeUtils.FOREIGN_SOURCE_DIRECTORY);
File foreignSourceDir = m_fileAnticipator.tempDir(fsDir, foreignSource);
// RRD Directory for n1
File nodeDir = null;
if (storeByForeignSource) {
nodeDir = m_fileAnticipator.tempDir(foreignSourceDir, n1.getForeignId());
} else {
nodeDir = m_fileAnticipator.tempDir(snmpDir, n1.getId().toString());
}
m_fileAnticipator.tempFile(nodeDir, "data" + m_rrdFileExtension);
// RRD Directory for n2
if (storeByForeignSource) {
nodeDir = m_fileAnticipator.tempDir(foreignSourceDir, n2.getForeignId());
} else {
nodeDir = m_fileAnticipator.tempDir(snmpDir, n2.getId().toString());
}
m_fileAnticipator.tempFile(nodeDir, "data" + m_rrdFileExtension);
// RRD Directory for an orphan node
if (storeByForeignSource) {
nodeDir = m_fileAnticipator.tempDir(foreignSourceDir, "orphan_node");
} else {
nodeDir = m_fileAnticipator.tempDir(snmpDir, "100");
}
m_fileAnticipator.tempFile(nodeDir, "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);
walkin(m_fileAnticipator.getTempDir());
m_easyMockUtils.replayAll();
m_resourceDao.afterPropertiesSet();
List<OnmsResource> resources = m_resourceDao.findTopLevelResources();
Assert.assertNotNull(resources);
Collections.sort(resources);
Assert.assertEquals(2, resources.size());
// Node 1
List<OnmsResource> children = resources.get(0).getChildResources();
Collections.sort(children);
Assert.assertEquals(2, children.size());
Assert.assertEquals("node[Junit:node1].responseTime[10.0.0.1]", children.get(0).getId().toString());
Assert.assertEquals("node[Junit:node1].nodeSnmp[]", children.get(1).getId().toString());
// Node 2
children = resources.get(1).getChildResources();
Collections.sort(children);
Assert.assertEquals(1, children.size());
Assert.assertEquals("node[Junit:node2].nodeSnmp[]", children.get(0).getId().toString());
m_easyMockUtils.verifyAll();
}
use of org.opennms.netmgt.model.LocationMonitorIpInterface in project opennms by OpenNMS.
the class DistributedStatusResourceType method getResourcesForParent.
/** {@inheritDoc} */
@Override
public List<OnmsResource> getResourcesForParent(OnmsResource parent) {
if (!NodeResourceType.isNode(parent)) {
return Collections.emptyList();
}
final OnmsNode node = ResourceTypeUtils.getNodeFromResource(parent);
final List<OnmsResource> resources = Lists.newLinkedList();
final Collection<LocationMonitorIpInterface> statuses = m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(node.getId());
for (LocationMonitorIpInterface status : statuses) {
String definitionName = status.getLocationMonitor().getLocation();
String id = status.getLocationMonitor().getId();
final OnmsIpInterface ipInterface = status.getIpInterface();
String ipAddr = InetAddressUtils.str(ipInterface.getIpAddress());
if (m_resourceStorageDao.exists(getRelativeInterfacePath(id, ipAddr), 0)) {
resources.add(createResource(definitionName, id, ipAddr));
}
}
return OnmsResource.sortIntoResourceList(resources);
}
use of org.opennms.netmgt.model.LocationMonitorIpInterface in project opennms by OpenNMS.
the class LocationMonitorDaoHibernateIT method testFindStatusChangesForNodeForUniqueMonitorAndInterface.
@Test
@Transactional
public void testFindStatusChangesForNodeForUniqueMonitorAndInterface() {
m_databasePopulator.populateDatabase();
OnmsLocationMonitor monitor1 = new OnmsLocationMonitor();
monitor1.setId(UUID.randomUUID().toString());
monitor1.setLocation("Outer Space");
m_locationMonitorDao.save(monitor1);
OnmsLocationMonitor monitor2 = new OnmsLocationMonitor();
monitor2.setId(UUID.randomUUID().toString());
monitor2.setLocation("Really Outer Space");
m_locationMonitorDao.save(monitor2);
OnmsNode node1 = m_nodeDao.get(1);
assertNotNull("node 1 should not be null", node1);
OnmsNode node2 = m_nodeDao.get(2);
assertNotNull("node 2 should not be null", node2);
// Add node1/192.168.1.1 on monitor1
addStatusChangesForMonitorAndService(monitor1, node1.getIpInterfaceByIpAddress("192.168.1.1").getMonitoredServices());
// Add node1/192.168.1.2 on monitor1
addStatusChangesForMonitorAndService(monitor1, node1.getIpInterfaceByIpAddress("192.168.1.2").getMonitoredServices());
// Add node1/192.168.1.1 on monitor2
addStatusChangesForMonitorAndService(monitor2, node1.getIpInterfaceByIpAddress("192.168.1.1").getMonitoredServices());
// Add node1/fe80:0000:0000:0000:aaaa:bbbb:cccc:dddd%5 on monitor1
addStatusChangesForMonitorAndService(monitor1, node1.getIpInterfaceByIpAddress("fe80::aaaa:bbbb:cccc:dddd%5").getMonitoredServices());
// Add node2/192.168.2.1 on monitor1 to test filtering on a specific node (this shouldn't show up in the results)
addStatusChangesForMonitorAndService(monitor1, node2.getIpInterfaceByIpAddress("192.168.2.1").getMonitoredServices());
// Add another copy for node1/192.168.1.1 on monitor1 to test distinct
addStatusChangesForMonitorAndService(monitor1, node1.getIpInterfaceByIpAddress("192.168.1.1").getMonitoredServices());
Collection<LocationMonitorIpInterface> statuses = m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(1);
assertEquals("number of statuses found", 4, statuses.size());
/*
for (LocationMonitorIpInterface status : statuses) {
OnmsLocationMonitor m = status.getLocationMonitor();
OnmsIpInterface i = status.getIpInterface();
System.err.println("monitor " + m.getId() + " " + m.getDefinitionName() + ", IP " + i.getIpAddress());
}
*/
}
use of org.opennms.netmgt.model.LocationMonitorIpInterface in project opennms by OpenNMS.
the class DefaultResourceDaoTest method testFindNodeResourcesWithDistributedResponseTime.
@Test
public void testFindNodeResourcesWithDistributedResponseTime() throws Exception {
List<OnmsNode> nodes = new LinkedList<OnmsNode>();
OnmsNode node = createNode();
OnmsIpInterface ip = createIpInterface();
node.addIpInterface(ip);
nodes.add(node);
expect(m_nodeDao.findAll()).andReturn(nodes);
File response = m_fileAnticipator.tempDir("response");
File distributed = m_fileAnticipator.tempDir(response, "distributed");
File monitor = m_fileAnticipator.tempDir(distributed, LOCATION_MONITOR_ID);
File ipDir = m_fileAnticipator.tempDir(monitor, "192.168.1.1");
m_fileAnticipator.tempFile(ipDir, "icmp" + m_rrdFileExtension);
expect(m_resourceTypesDao.getLastUpdate()).andReturn(m_lastUpdateTime);
// Setup the status to match the path on disk
OnmsLocationMonitor locMon = new OnmsLocationMonitor();
locMon.setId(LOCATION_MONITOR_ID);
OnmsIpInterface ipIntf = new OnmsIpInterface();
ipIntf.setIpAddress(InetAddress.getByName("192.168.1.1"));
LocationMonitorIpInterface locMonIpIntf = new LocationMonitorIpInterface(locMon, ipIntf);
expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(node.getId())).andReturn(Collections.singleton(locMonIpIntf)).anyTimes();
m_easyMockUtils.replayAll();
List<OnmsResource> resources = m_resourceDao.findTopLevelResources();
m_easyMockUtils.verifyAll();
assertNotNull("Resource list should not be null", resources);
assertEquals("Resource list size", 1, resources.size());
}
Aggregations