use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.
the class DefaultRrdDaoTest method testPrintValueWithBogusLine.
public void testPrintValueWithBogusLine() throws Exception {
long end = System.currentTimeMillis();
long start = end - (24 * 60 * 60 * 1000);
String printLine = "blah blah blah this should be a floating point number blah blah blah";
OnmsResource childResource = preparePrintValueTest(start, end, printLine);
m_mocks.replayAll();
ThrowableAnticipator ta = new ThrowableAnticipator();
ta.anticipate(new DataAccessResourceFailureException("Value of line 1 of output from RRD is not a valid floating point number: '" + printLine + "'"));
try {
m_dao.getPrintValue(childResource.getAttributes().iterator().next(), "AVERAGE", start, end);
} catch (Throwable t) {
ta.throwableReceived(t);
}
m_mocks.verifyAll();
ta.verifyAnticipated();
}
use of org.opennms.netmgt.model.OnmsResource 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.OnmsResource in project opennms by OpenNMS.
the class GenericIndexResourceTypeTest method testGetResourceByNodeAndIndexGetLabelIndexWithSubStringAndDynSubStringAndDynSubStringAndSubStringToEnd.
@Test
public void testGetResourceByNodeAndIndexGetLabelIndexWithSubStringAndDynSubStringAndDynSubStringAndSubStringToEnd() {
GenericIndexResourceType rt = new GenericIndexResourceType(m_resourceStorageDao, "foo", "Foo Resource", "Easy as ${subIndex(0, 1)} and ${subIndex(1, n)} and ${subIndex(n, n)} and ${subIndex(n)}", m_storageStrategy);
touch("snmp", "1", "foo", "3.3.1.2.3.3.4.5.6.0", RRD_FILE_NAME);
m_mocks.replayAll();
OnmsResource resource = rt.getChildByName(getNodeResource(1), "3.3.1.2.3.3.4.5.6.0");
m_mocks.verifyAll();
assertNotNull("resource", resource);
assertEquals("resource label", "Easy as 3 and 1.2.3 and 4.5.6 and 0", resource.getLabel());
}
use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.
the class DefaultRrdDaoTest method testFetchLastValueInRange.
public void testFetchLastValueInRange() throws Exception {
String rrdDir = "snmp" + File.separator + "1" + File.separator + "eth0";
String rrdFile = "ifInOctets.jrb";
OnmsResource topResource = new OnmsResource("1", "Node One", new MockResourceType(), new HashSet<OnmsAttribute>(0), new ResourcePath("foo"));
OnmsAttribute attribute = new RrdGraphAttribute("ifInOctets", rrdDir, rrdFile);
HashSet<OnmsAttribute> attributeSet = new HashSet<OnmsAttribute>(1);
attributeSet.add(attribute);
MockResourceType childResourceType = new MockResourceType();
OnmsResource childResource = new OnmsResource("eth0", "Interface One: eth0", childResourceType, attributeSet, new ResourcePath("foo"));
childResource.setParent(topResource);
int interval = 300000;
int range = 300000;
Double expectedValue = new Double(1.0);
String fullRrdFilePath = m_dao.getRrdBaseDirectory().getAbsolutePath() + File.separator + rrdDir + File.separator + rrdFile;
expect(m_rrdStrategy.fetchLastValueInRange(fullRrdFilePath, attribute.getName(), interval, range)).andReturn(expectedValue);
m_mocks.replayAll();
Double value = m_dao.getLastFetchValue(attribute, interval, range);
m_mocks.verifyAll();
assertNotNull("last fetched value must not be null, but was null", value);
assertEquals("last fetched value", expectedValue, value);
}
use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.
the class DefaultRrdDaoTest method testPrintValueWithnan.
public void testPrintValueWithnan() throws Exception {
long end = System.currentTimeMillis();
long start = end - (24 * 60 * 60 * 1000);
OnmsResource childResource = preparePrintValueTest(start, end, "nan");
m_mocks.replayAll();
Double value = m_dao.getPrintValue(childResource.getAttributes().iterator().next(), "AVERAGE", start, end);
m_mocks.verifyAll();
assertNotNull("value should not be null", value);
assertEquals("value", Double.NaN, value);
}
Aggregations