Search in sources :

Example 1 with DatabaseSchemaConfigFactory

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();
}
Also used : InputStream(java.io.InputStream) DatabaseSchemaConfigFactory(org.opennms.netmgt.config.DatabaseSchemaConfigFactory) JdbcFilterDao(org.opennms.netmgt.filter.JdbcFilterDao) Test(org.junit.Test)

Example 2 with DatabaseSchemaConfigFactory

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');");
}
Also used : InputStream(java.io.InputStream) GregorianCalendar(java.util.GregorianCalendar) MockDatabase(org.opennms.core.test.db.MockDatabase) MockCategoryFactory(org.opennms.netmgt.mock.MockCategoryFactory) DatabaseSchemaConfigFactory(org.opennms.netmgt.config.DatabaseSchemaConfigFactory)

Example 3 with DatabaseSchemaConfigFactory

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');");
}
Also used : InputStream(java.io.InputStream) GregorianCalendar(java.util.GregorianCalendar) MockDatabase(org.opennms.core.test.db.MockDatabase) MockCategoryFactory(org.opennms.netmgt.mock.MockCategoryFactory) DatabaseSchemaConfigFactory(org.opennms.netmgt.config.DatabaseSchemaConfigFactory)

Example 4 with DatabaseSchemaConfigFactory

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();
}
Also used : Category(org.opennms.netmgt.config.categories.Category) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) DatabaseSchemaConfigFactory(org.opennms.netmgt.config.DatabaseSchemaConfigFactory) RTCConfigFactory(org.opennms.netmgt.config.RTCConfigFactory) CategoryFactory(org.opennms.netmgt.config.CategoryFactory) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with DatabaseSchemaConfigFactory

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

InputStream (java.io.InputStream)8 DatabaseSchemaConfigFactory (org.opennms.netmgt.config.DatabaseSchemaConfigFactory)8 Test (org.junit.Test)4 JdbcFilterDao (org.opennms.netmgt.filter.JdbcFilterDao)3 GregorianCalendar (java.util.GregorianCalendar)2 MockDatabase (org.opennms.core.test.db.MockDatabase)2 DefaultDataCollectionConfigDao (org.opennms.netmgt.config.DefaultDataCollectionConfigDao)2 MockCategoryFactory (org.opennms.netmgt.mock.MockCategoryFactory)2 Resource (org.springframework.core.io.Resource)2 HashMap (java.util.HashMap)1 Ignore (org.junit.Ignore)1 CategoryFactory (org.opennms.netmgt.config.CategoryFactory)1 CollectdConfigFactory (org.opennms.netmgt.config.CollectdConfigFactory)1 HttpCollectionConfigFactory (org.opennms.netmgt.config.HttpCollectionConfigFactory)1 RTCConfigFactory (org.opennms.netmgt.config.RTCConfigFactory)1 SnmpPeerFactory (org.opennms.netmgt.config.SnmpPeerFactory)1 Category (org.opennms.netmgt.config.categories.Category)1 RTCCategory (org.opennms.netmgt.rtc.datablock.RTCCategory)1 FileAnticipator (org.opennms.test.FileAnticipator)1 ThrowableAnticipator (org.opennms.test.ThrowableAnticipator)1