Search in sources :

Example 1 with DefaultDataCollectionConfigDao

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;
}
Also used : File(java.io.File) DefaultDataCollectionConfigDao(org.opennms.netmgt.config.DefaultDataCollectionConfigDao) FileInputStream(java.io.FileInputStream) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 2 with DefaultDataCollectionConfigDao

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);
}
Also used : FileWriter(java.io.FileWriter) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Date(java.util.Date) DefaultDataCollectionConfigDao(org.opennms.netmgt.config.DefaultDataCollectionConfigDao) Test(org.junit.Test)

Example 3 with DefaultDataCollectionConfigDao

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());
}
Also used : SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) DefaultDataCollectionConfigDao(org.opennms.netmgt.config.DefaultDataCollectionConfigDao) Test(org.junit.Test)

Example 4 with DefaultDataCollectionConfigDao

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);
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAssetRecord(org.opennms.netmgt.model.OnmsAssetRecord) FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) RrdPersisterFactory(org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory) MockCollectionAgent(org.opennms.core.collection.test.MockCollectionAgent) FileSystemResource(org.springframework.core.io.FileSystemResource) JRobinRrdStrategy(org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy) DefaultDataCollectionConfigDao(org.opennms.netmgt.config.DefaultDataCollectionConfigDao) Before(org.junit.Before)

Example 5 with DefaultDataCollectionConfigDao

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);
}
Also used : HttpCollectionConfigFactory(org.opennms.netmgt.config.HttpCollectionConfigFactory) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) DatabaseSchemaConfigFactory(org.opennms.netmgt.config.DatabaseSchemaConfigFactory) FileAnticipator(org.opennms.test.FileAnticipator) DefaultDataCollectionConfigDao(org.opennms.netmgt.config.DefaultDataCollectionConfigDao)

Aggregations

DefaultDataCollectionConfigDao (org.opennms.netmgt.config.DefaultDataCollectionConfigDao)12 FileSystemResource (org.springframework.core.io.FileSystemResource)6 File (java.io.File)5 Test (org.junit.Test)4 Before (org.junit.Before)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 MockCollectionAgent (org.opennms.core.collection.test.MockCollectionAgent)2 RrdPersisterFactory (org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory)2 DatabaseSchemaConfigFactory (org.opennms.netmgt.config.DatabaseSchemaConfigFactory)2 NodeDao (org.opennms.netmgt.dao.api.NodeDao)2 FilesystemResourceStorageDao (org.opennms.netmgt.dao.support.FilesystemResourceStorageDao)2 OnmsAssetRecord (org.opennms.netmgt.model.OnmsAssetRecord)2 OnmsNode (org.opennms.netmgt.model.OnmsNode)2 JRobinRrdStrategy (org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy)2 OnmsUpgradeException (org.opennms.upgrade.api.OnmsUpgradeException)2 InputStreamResource (org.springframework.core.io.InputStreamResource)2 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 Date (java.util.Date)1