Search in sources :

Example 11 with DefaultDataCollectionConfigDao

use of org.opennms.netmgt.config.DefaultDataCollectionConfigDao in project opennms by OpenNMS.

the class DataCollectionConfigMigrator17Offline method isConfigValid.

/**
 * Checks if is configuration valid.
 *
 * @return true, if is configuration valid
 * @throws OnmsUpgradeException the OpenNMS upgrade exception
 */
private boolean isConfigValid() throws OnmsUpgradeException {
    File configDirectory = new File(sourceFile.getParentFile().getAbsolutePath(), "datacollection");
    try {
        DefaultDataCollectionConfigDao dao = new DefaultDataCollectionConfigDao();
        dao.setConfigDirectory(configDirectory.getAbsolutePath());
        dao.setConfigResource(new FileSystemResource(sourceFile));
        dao.setReloadCheckInterval(new Long(0));
        dao.afterPropertiesSet();
    } catch (IllegalArgumentException e) {
        log("Found a problem: %s\n", e.getMessage());
        Matcher m = pattern.matcher(e.getMessage());
        if (m.find()) {
            try {
                Iterator<Path> paths = Files.list(configDirectory.toPath()).filter(f -> f.getFileName().toString().toLowerCase().endsWith(".xml")).iterator();
                for (; paths.hasNext(); ) {
                    String group = getGroupForResourceType(paths.next().toFile(), m.group(1));
                    if (group != null) {
                        updateDataCollectionConfig(m.group(2), group);
                        return false;
                    }
                }
            } catch (Exception ex) {
                throw new OnmsUpgradeException("Can't get datacollection-group files", ex);
            }
        }
    } catch (Exception e) {
        throw new OnmsUpgradeException("Can't process " + sourceFile, e);
    }
    return true;
}
Also used : Matcher(java.util.regex.Matcher) Iterator(java.util.Iterator) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) DefaultDataCollectionConfigDao(org.opennms.netmgt.config.DefaultDataCollectionConfigDao) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException) IOException(java.io.IOException) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException)

Example 12 with DefaultDataCollectionConfigDao

use of org.opennms.netmgt.config.DefaultDataCollectionConfigDao in project opennms by OpenNMS.

the class HttpDataCollectionIT 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)

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