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;
}
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);
}
Aggregations