use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.
the class DefaultSurveillanceViewService method checkLabelForQuotes.
/**
* Checks a label for quotes and returns a safe resource instance.
*
* @param childResource the resource to check
* @return a new constructed resource instance
*/
private static OnmsResource checkLabelForQuotes(OnmsResource childResource) {
String lbl = Util.convertToJsSafeString(childResource.getLabel());
OnmsResource resource = new OnmsResource(childResource.getName(), lbl, childResource.getResourceType(), childResource.getAttributes(), childResource.getPath());
resource.setParent(childResource.getParent());
resource.setEntity(childResource.getEntity());
resource.setLink(childResource.getLink());
return resource;
}
use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.
the class DefaultResourceDaoTest method testFindNodeResourcesWithNodeInterface.
@Test
public void testFindNodeResourcesWithNodeInterface() throws Exception {
List<OnmsNode> nodes = new LinkedList<>();
OnmsNode node = createNode();
OnmsIpInterface ip = createIpInterface();
node.addIpInterface(ip);
nodes.add(node);
expect(m_nodeDao.findAll()).andReturn(nodes);
File snmp = m_fileAnticipator.tempDir("snmp");
File nodeDir = m_fileAnticipator.tempDir(snmp, "1");
File intfDir = m_fileAnticipator.tempDir(nodeDir, "eth0");
m_fileAnticipator.tempFile(intfDir, "foo" + m_rrdFileExtension);
expect(m_resourceTypesDao.getLastUpdate()).andReturn(m_lastUpdateTime);
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());
}
use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.
the class DefaultResourceDaoTest method testFindNodeResourcesWithDistributedResponseTime.
@Test
public void testFindNodeResourcesWithDistributedResponseTime() throws Exception {
List<OnmsNode> nodes = new LinkedList<>();
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());
}
use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.
the class DefaultResourceDaoTest method testGetResourceForIpInterfaceWithLocationMonitor.
@Test
public void testGetResourceForIpInterfaceWithLocationMonitor() throws Exception {
OnmsIpInterface ip = createIpInterfaceOnNode();
OnmsLocationMonitor locMon = new OnmsLocationMonitor();
locMon.setId(LOCATION_MONITOR_ID);
// Create distributed/9850/209.61.128.9
File response = m_fileAnticipator.tempDir("response");
File distributed = m_fileAnticipator.tempDir(response, "distributed");
File locMonDir = m_fileAnticipator.tempDir(distributed, locMon.getId().toString());
File ipDir = m_fileAnticipator.tempDir(locMonDir, InetAddressUtils.str(ip.getIpAddress()));
m_fileAnticipator.tempFile(ipDir, "http" + m_rrdFileExtension);
ArrayList<LocationMonitorIpInterface> locationMonitorInterfaces = new ArrayList<>();
locationMonitorInterfaces.add(new LocationMonitorIpInterface(locMon, ip));
expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(ip.getNode().getId())).andReturn(locationMonitorInterfaces);
expect(m_resourceTypesDao.getLastUpdate()).andReturn(new Date(System.currentTimeMillis() - 86400000l)).anyTimes();
m_easyMockUtils.replayAll();
OnmsResource resource = m_resourceDao.getResourceForIpInterface(ip, locMon);
m_easyMockUtils.verifyAll();
assertNotNull("Resource should not be null", resource);
}
use of org.opennms.netmgt.model.OnmsResource 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();
}
Aggregations