use of org.opennms.netmgt.config.DefaultDataCollectionConfigDao in project opennms by OpenNMS.
the class DefaultDataCollectionConfigDaoIT method instantiateDao.
private DefaultDataCollectionConfigDao instantiateDao(String fileName, boolean setConfigDirectory) throws Exception {
DefaultDataCollectionConfigDao dao = new DefaultDataCollectionConfigDao();
File configFile = new File("src/test/opennms-home/etc", fileName);
if (setConfigDirectory) {
File configFolder = new File(configFile.getParentFile(), "datacollection");
Assert.assertTrue(configFolder.isDirectory());
dao.setConfigDirectory(configFolder.getAbsolutePath());
}
dao.setConfigResource(new InputStreamResource(new FileInputStream(configFile)));
dao.afterPropertiesSet();
return dao;
}
use of org.opennms.netmgt.config.DefaultDataCollectionConfigDao in project opennms by OpenNMS.
the class DefaultDataCollectionConfigDaoIT method testReload.
@Test
public void testReload() throws Exception {
File source = new File("src/test/opennms-home/etc");
File dest = new File("src/target/opennms-home-test/etc");
dest.mkdirs();
FileUtils.copyDirectory(source, dest, true);
File target = new File(dest, "datacollection-config.xml");
Date currentDate = new Date(target.lastModified());
// Initialize the DAO with auto-reload
DefaultDataCollectionConfigDao dao = new DefaultDataCollectionConfigDao();
dao.setConfigDirectory(new File(dest, "datacollection").getAbsolutePath());
dao.setConfigResource(new FileSystemResource(target));
dao.setReloadCheckInterval(1000l);
dao.afterPropertiesSet();
// Verify that it has not been reloaded
Assert.assertTrue(currentDate.after(dao.getLastUpdate()));
// Modify the file to trigger the reload.
FileWriter w = new FileWriter(target, true);
w.write("<!-- Adding a comment to make it different. -->");
w.close();
currentDate = new Date(target.lastModified());
// Wait and check if the data was changed.
Thread.sleep(2000l);
Assert.assertFalse(currentDate.after(dao.getLastUpdate()));
FileUtils.deleteDirectory(dest);
}
use of org.opennms.netmgt.config.DefaultDataCollectionConfigDao in project opennms by OpenNMS.
the class DefaultDataCollectionConfigDaoIT method testNewStyle.
@Test
public void testNewStyle() throws Exception {
DefaultDataCollectionConfigDao dao = instantiateDao("datacollection-config.xml", true);
executeTests(dao, 86);
SnmpCollection def = dao.getContainer().getObject().getSnmpCollection("default");
Assert.assertEquals(0, def.getResourceTypes().size());
SnmpCollection rt = dao.getContainer().getObject().getSnmpCollection("__resource_type_collection");
Assert.assertEquals(86, rt.getResourceTypes().size());
Assert.assertEquals(0, rt.getSystems().getSystemDefs().size());
Assert.assertEquals(0, rt.getGroups().getGroups().size());
}
use of org.opennms.netmgt.config.DefaultDataCollectionConfigDao in project opennms by OpenNMS.
the class NMS7963IT method setUp.
/**
* Sets the up.
*
* @throws Exception the exception
*/
@Before
public void setUp() throws Exception {
MockLogAppender.setupLogging();
DefaultDataCollectionConfigDao dao = new DefaultDataCollectionConfigDao();
dao.setConfigDirectory("src/test/resources/etc/datacollection");
dao.setConfigResource(new FileSystemResource("src/test/resources/etc/datacollection-config.xml"));
dao.afterPropertiesSet();
DataCollectionConfigFactory.setInstance(dao);
m_rrdStrategy = new JRobinRrdStrategy();
m_resourceStorageDao = new FilesystemResourceStorageDao();
m_resourceStorageDao.setRrdDirectory(m_temporaryFolder.getRoot());
m_temporaryFolder.newFolder("snmp");
m_persisterFactory = new RrdPersisterFactory();
m_persisterFactory.setResourceStorageDao(m_resourceStorageDao);
m_persisterFactory.setRrdStrategy(m_rrdStrategy);
m_collectionAgent = new MockCollectionAgent(1, "mynode.local", InetAddrUtils.addr("127.0.0.1"));
m_nodeDao = EasyMock.createMock(NodeDao.class);
OnmsNode node = new OnmsNode();
node.setId(1);
node.setLabel("mynode.local");
node.setAssetRecord(new OnmsAssetRecord());
EasyMock.expect(m_nodeDao.get(1)).andReturn(node).anyTimes();
EasyMock.replay(m_nodeDao);
}
use of org.opennms.netmgt.config.DefaultDataCollectionConfigDao in project opennms by OpenNMS.
the class JUnitCollectorExecutionListener method beforeTestMethod.
@Override
public void beforeTestMethod(TestContext testContext) throws Exception {
m_fileAnticipator = new FileAnticipator();
JUnitCollector config = findCollectorAnnotation(testContext);
if (config == null) {
return;
}
// make a fake database schema with hibernate
InputStream is = ConfigurationTestUtils.getInputStreamForResource(testContext.getTestInstance(), config.schemaConfig());
DatabaseSchemaConfigFactory.setInstance(new DatabaseSchemaConfigFactory(is));
is.close();
// set up temporary directories for RRD files
m_snmpRrdDirectory = m_fileAnticipator.tempDir("snmp");
m_snmpRrdDirectory.mkdirs();
testContext.setAttribute("fileAnticipator", m_fileAnticipator);
testContext.setAttribute("rrdDirectory", m_snmpRrdDirectory);
// set up the collection configuration factory
if ("http".equalsIgnoreCase(config.datacollectionType()) || "https".equalsIgnoreCase(config.datacollectionType())) {
is = ConfigurationTestUtils.getInputStreamForResourceWithReplacements(testContext.getTestInstance(), config.datacollectionConfig(), new String[] { "%rrdRepository%", m_snmpRrdDirectory.getAbsolutePath() });
HttpCollectionConfigFactory factory = new HttpCollectionConfigFactory(is);
HttpCollectionConfigFactory.setInstance(factory);
HttpCollectionConfigFactory.init();
} else if ("snmp".equalsIgnoreCase(config.datacollectionType())) {
Resource r = ConfigurationTestUtils.getSpringResourceForResourceWithReplacements(testContext.getTestInstance(), config.datacollectionConfig(), new String[] { "%rrdRepository%", m_snmpRrdDirectory.getAbsolutePath() });
DefaultDataCollectionConfigDao dataCollectionDao = new DefaultDataCollectionConfigDao();
dataCollectionDao.setConfigResource(r);
dataCollectionDao.afterPropertiesSet();
DataCollectionConfigFactory.setInstance(dataCollectionDao);
} else {
throw new UnsupportedOperationException("data collection type '" + config.datacollectionType() + "' not supported");
}
IOUtils.closeQuietly(is);
}
Aggregations