use of org.opennms.netmgt.config.DatabaseSchemaConfigFactory in project opennms by OpenNMS.
the class JdbcFilterDaoIT method testAfterPropertiesSetNoNodeDao.
@Test
public void testAfterPropertiesSetNoNodeDao() throws Exception {
JdbcFilterDao dao = new JdbcFilterDao();
dao.setDataSource(m_dataSource);
InputStream is = ConfigurationTestUtils.getInputStreamForConfigFile("database-schema.xml");
dao.setDatabaseSchemaConfigFactory(new DatabaseSchemaConfigFactory(is));
is.close();
// The nodeDao isn't required because this ends up getting used outside of a Spring context quite a bit
dao.afterPropertiesSet();
}
use of org.opennms.netmgt.config.DatabaseSchemaConfigFactory in project opennms by OpenNMS.
the class AvailabilityCalculatorIT method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
// Reset the FilterDaoFactory so we don't get screwed by having the JdbcFilterDao be connected to an older database
FilterDaoFactory.setInstance(null);
Locale.setDefault(Locale.US);
m_calendar = new GregorianCalendar();
// date for report run is 18th May 2005
m_calendar.set(2005, Calendar.MAY, 18);
MockLogAppender.setupLogging();
m_categories = new Categories();
m_db = new MockDatabase();
DataSourceFactory.setInstance(m_db);
InputStream is = ConfigurationTestUtils.getInputStreamForConfigFile("database-schema.xml");
DatabaseSchemaConfigFactory.setInstance(new DatabaseSchemaConfigFactory(is));
is.close();
m_catFactory = new MockCategoryFactory();
CategoryFactory.setInstance(m_catFactory);
m_db.update("insert into node (location, nodeID, nodelabel, nodeCreateTime, nodeType) values ('" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID + "', 1,'test1.availability.opennms.org','2004-03-01 09:00:00','A')");
m_db.update("insert into node (location, nodeID, nodelabel, nodeCreateTime, nodeType) values ('" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID + "', 2,'test2.availability.opennms.org','2004-03-01 09:00:00','A')");
m_db.update("insert into service (serviceid, servicename) values\n" + "(1, 'ICMP');");
m_db.update("insert into service (serviceid, servicename) values\n" + "(2, 'HTTP');");
m_db.update("insert into service (serviceid, servicename) values\n" + "(3, 'SNMP');");
m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n" + "(1, 1,'192.168.100.1','M');");
m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n" + "(2, 2,'192.168.100.2','M');");
m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n" + "(3, 2,'192.168.100.3','M');");
m_db.update("insert into ifservices (id, serviceid, status, ipInterfaceId) values " + // 1:192.168.100.1:1
"(1, 1,'A', 1);");
m_db.update("insert into ifservices (id, serviceid, status, ipInterfaceId) values " + // 2:192.168.100.2:1
"(2, 1,'A', 2);");
/*
* m_db.update("insert into ifservices (serviceid, status, ipInterfaceId) values " + "(2,'A', 2);"); //2:192.168.100.2:2
*/
m_db.update("insert into ifservices (id, serviceid, status, ipInterfaceId) values " + // 2:192.168.100.3:1
"(3, 1,'A', 3);");
m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(1,1,'2005-05-01 09:00:00','2005-05-01 09:30:00');");
m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(2,2,'2005-05-01 10:00:00','2005-05-02 10:00:00');");
// test data for LastMonthsDailyAvailability report
// insert 30 minute outage on one node - 99.3056% availability
m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(3,1,'2005-04-02 10:00:00','2005-04-02 10:30:00');");
// insert 60 minute outage on one interface and 59 minute outages on
// another - 97.2454
m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(4,1,'2005-04-03 11:30:00','2005-04-03 12:30:00');");
m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(5,2,'2005-04-03 23:00:00','2005-04-03 23:59:00');");
// test an outage that spans 60 minutes across midnight - 99.3056% on
// each day, well, not exactly
// its 29 minutes 99.3059 on the fist day and 31 minutes 99.3052 on
// the second.
m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(6,3,'2005-04-04 23:30:00','2005-04-05 00:30:00');");
}
use of org.opennms.netmgt.config.DatabaseSchemaConfigFactory in project opennms by OpenNMS.
the class AvailabilityReportIT method setUp.
@Override
protected void setUp() throws Exception {
System.err.println("------------------- begin " + getName() + " ---------------------");
// Reset the FilterDaoFactory so we don't get screwed by having the JdbcFilterDao be connected to an older database
FilterDaoFactory.setInstance(null);
super.setUp();
Locale.setDefault(Locale.US);
calendar = new GregorianCalendar();
// date for report run is 18th May 2005
calendar.set(2005, 4, 18);
MockLogAppender.setupLogging();
m_categories = new Categories();
m_db = new MockDatabase();
DataSourceFactory.setInstance(m_db);
InputStream is = ConfigurationTestUtils.getInputStreamForConfigFile("database-schema.xml");
DatabaseSchemaConfigFactory.setInstance(new DatabaseSchemaConfigFactory(is));
is.close();
m_catFactory = new MockCategoryFactory();
CategoryFactory.setInstance(m_catFactory);
m_db.update("insert into node (location, nodeID, nodelabel, nodeCreateTime, nodeType) values ('" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID + "', 1,'test1.availability.opennms.org','2004-03-01 09:00:00','A')");
m_db.update("insert into node (location, nodeID, nodelabel, nodeCreateTime, nodeType) values ('" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID + "', 2,'test2.availability.opennms.org','2004-03-01 09:00:00','A')");
m_db.update("insert into service (serviceid, servicename) values\n" + "(1, 'ICMP');");
m_db.update("insert into service (serviceid, servicename) values\n" + "(2, 'HTTP');");
m_db.update("insert into service (serviceid, servicename) values\n" + "(3, 'SNMP');");
m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n" + "(1, 1,'192.168.100.1','M');");
m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n" + "(2, 2,'192.168.100.2','M');");
m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n" + "(3, 2,'192.168.100.3','M');");
m_db.update("insert into ifservices (id, serviceid, status, ipInterfaceId) values " + // 1:192.168.100.1:1
"(1,1,'A',1);");
m_db.update("insert into ifservices (id, serviceid, status, ipInterfaceId) values " + // 2:192.168.100.2:1
"(2,1,'A',2);");
/*
m_db.update("insert into ifservices (id, serviceid, status, ipInterfaceId) values " +
"(3,2,'A',2);"); // 2:192.168.100.2:2
*/
m_db.update("insert into ifservices (id, serviceid, status, ipInterfaceId) values " + // 2:192.168.100.3:1
"(4,1,'A',3);");
m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(1,1,'2005-05-01 09:00:00','2005-05-01 09:30:00');");
m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(2,2,'2005-05-01 10:00:00','2005-05-02 10:00:00');");
// test data for LastMonthsDailyAvailability report
// insert 30 minute outage on one node - 99.3056% availability
m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(3,1,'2005-04-02 10:00:00','2005-04-02 10:30:00');");
// insert 60 minute outage on one interface and 59 minute outages on another - 97.2454
m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(4,1,'2005-04-03 11:30:00','2005-04-03 12:30:00');");
m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(5,2,'2005-04-03 23:00:00','2005-04-03 23:59:00');");
// test an outage that spans 60 minutes across midnight - 99.3056% on each day, well, not exactly
// its 29 minutes 99.3059 on the fist day and 31 minutes 99.3052 on the second.
m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(6,4,'2005-04-04 23:30:00','2005-04-05 00:30:00');");
}
use of org.opennms.netmgt.config.DatabaseSchemaConfigFactory in project opennms by OpenNMS.
the class DataSenderTest method testSendData.
/*
* This doesn't work unless we have a receiver on the other end.... more of an integration test
*/
@Test
@Ignore
public void testSendData() throws IOException, FilterParseException, SAXException, SQLException, RTCException {
InputStream stream = ConfigurationTestUtils.getInputStreamForResource(this, "/org/opennms/netmgt/config/rtc-configuration.xml");
RTCConfigFactory configFactory = new RTCConfigFactory(stream);
stream.close();
Resource categoryResource = ConfigurationTestUtils.getSpringResourceForResource(this, "/org/opennms/netmgt/config/categories.xml");
CategoryFactory.setInstance(new CategoryFactory(categoryResource));
stream = ConfigurationTestUtils.getInputStreamForResource(this, "/org/opennms/netmgt/config/test-database-schema.xml");
DatabaseSchemaConfigFactory.setInstance(new DatabaseSchemaConfigFactory(stream));
stream.close();
DataManager dataManager = new DataManager();
String categoryName = "Database Servers";
String categoryNameUrl = "Database+Servers";
Category category = new Category();
category.setLabel(categoryName);
category.setComment("Some database servers. Exciting, eh?");
category.setNormalThreshold(99.0);
category.setWarningThreshold(97.0);
RTCCategory rtcCategory = new RTCCategory(category, categoryName);
Map<String, RTCCategory> rtcCategories = new HashMap<String, RTCCategory>();
rtcCategories.put(categoryName, rtcCategory);
DataSender sender = new DataSender(dataManager, configFactory);
sender.subscribe("http://localhost:8080/opennms-webapp/rtc/post/" + categoryNameUrl, categoryName, "rtc", "rtc");
sender.sendData();
}
use of org.opennms.netmgt.config.DatabaseSchemaConfigFactory 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