コード例 #1
0
ファイル: DatabasePopulator.java プロジェクト: Eising/opennms
  private void doPopulateDatabase() {
    LOG.debug("==== DatabasePopulator Starting ====");

    final OnmsDistPoller distPoller = getDistPoller("localhost", "127.0.0.1");
    final NetworkBuilder builder = new NetworkBuilder(distPoller);

    final OnmsNode node1 = buildNode1(builder);
    getNodeDao().save(node1);
    getNodeDao().flush();

    OnmsNode node2 = buildNode2(builder);
    getNodeDao().save(node2);
    getNodeDao().flush();
    setNode2(node2);

    OnmsNode node3 = buildNode3(builder);
    getNodeDao().save(node3);
    getNodeDao().flush();
    setNode3(node3);

    OnmsNode node4 = buildNode4(builder);
    getNodeDao().save(node4);
    getNodeDao().flush();
    setNode4(node4);

    OnmsNode node5 = buildNode5(builder);
    getNodeDao().save(node5);
    getNodeDao().flush();
    setNode5(node5);

    OnmsNode node6 = buildNode6(builder);
    getNodeDao().save(node6);
    getNodeDao().flush();
    setNode6(node6);

    final OnmsEvent event = buildEvent(distPoller);
    getEventDao().save(event);
    getEventDao().flush();

    final OnmsNotification notif = buildTestNotification(builder, event);
    getNotificationDao().save(notif);
    getNotificationDao().flush();

    final OnmsUserNotification userNotif = buildTestUserNotification(notif);
    getUserNotificationDao().save(userNotif);
    getUserNotificationDao().flush();

    final OnmsUserNotification userNotif2 = buildTestUser2Notification(notif);
    getUserNotificationDao().save(userNotif2);
    getUserNotificationDao().flush();

    final OnmsMonitoredService svc =
        getMonitoredServiceDao().get(node1.getId(), InetAddressUtils.addr("192.168.1.1"), "SNMP");
    final OnmsOutage resolved =
        new OnmsOutage(new Date(), new Date(), event, event, svc, null, null);
    getOutageDao().save(resolved);
    getOutageDao().flush();

    final OnmsOutage unresolved = new OnmsOutage(new Date(), event, svc);
    getOutageDao().save(unresolved);
    getOutageDao().flush();

    final OnmsAlarm alarm = buildAlarm(event);
    getAlarmDao().save(alarm);
    getAlarmDao().flush();

    final OnmsMap map = new OnmsMap("DB_Pop_Test_Map", "admin");
    map.setBackground("fake_background.jpg");
    map.setAccessMode(OnmsMap.ACCESS_MODE_ADMIN);
    map.setType(OnmsMap.USER_GENERATED_MAP);
    map.setMapGroup("admin");
    getOnmsMapDao().save(map);
    getOnmsMapDao().flush();

    final OnmsMapElement mapElement =
        new OnmsMapElement(
            map, 1, OnmsMapElement.NODE_TYPE, "Test Node", OnmsMapElement.defaultNodeIcon, 0, 10);
    getOnmsMapElementDao().save(mapElement);
    getOnmsMapElementDao().flush();

    final DataLinkInterface dli =
        new DataLinkInterface(node1, 1, node1.getId(), 1, StatusType.ACTIVE, new Date());
    getDataLinkInterfaceDao().save(dli);
    getDataLinkInterfaceDao().flush();

    final DataLinkInterface dli2 =
        new DataLinkInterface(node1, 2, node1.getId(), 1, StatusType.ACTIVE, new Date());
    getDataLinkInterfaceDao().save(dli2);
    getDataLinkInterfaceDao().flush();

    final DataLinkInterface dli3 =
        new DataLinkInterface(node2, 1, node1.getId(), 1, StatusType.ACTIVE, new Date());
    getDataLinkInterfaceDao().save(dli3);
    getDataLinkInterfaceDao().flush();

    final OnmsAcknowledgment ack = new OnmsAcknowledgment();
    ack.setAckTime(new Date());
    ack.setAckType(AckType.UNSPECIFIED);
    ack.setAckAction(AckAction.UNSPECIFIED);
    ack.setAckUser("admin");
    getAcknowledgmentDao().save(ack);
    getAcknowledgmentDao().flush();

    final OnmsMonitoringLocationDefinition def = new OnmsMonitoringLocationDefinition();
    def.setName("RDU");
    def.setArea("East Coast");
    def.setPollingPackageName("example1");
    def.setGeolocation("Research Triangle Park, NC");
    def.setCoordinates("35.715751,-79.16262");
    def.setPriority(1L);
    m_locationMonitorDao.saveMonitoringLocationDefinition(def);

    LOG.debug("= DatabasePopulatorExtension Populate Starting =");
    for (Extension eachExtension : extensions) {
      DaoSupport daoSupport = eachExtension.getDaoSupport();
      OnmsDao dao = daoSupport != null ? daoSupport.getDao() : null;
      Class<? super OnmsDao> daoClass = daoSupport != null ? daoSupport.getDaoClass() : null;
      registerDao(daoClass, dao);

      dao = lookupDao(daoClass);
      eachExtension.onPopulate(this, dao);
      if (dao != null) {
        dao.flush();
      }
    }
    LOG.debug("= DatabasePopulatorExtension Populate Finished =");

    LOG.debug("==== DatabasePopulator Finished ====");
  }
コード例 #2
0
ファイル: DatabasePopulator.java プロジェクト: Eising/opennms
  public void resetDatabase() {
    LOG.debug("==== DatabasePopulator Reset ====");
    for (final DataLinkInterface iface : m_dataLinkInterfaceDao.findAll()) {
      m_dataLinkInterfaceDao.delete(iface);
    }
    for (final OnmsOutage outage : m_outageDao.findAll()) {
      m_outageDao.delete(outage);
    }
    for (final OnmsUserNotification not : m_userNotificationDao.findAll()) {
      m_userNotificationDao.delete(not);
    }
    for (final OnmsNotification not : m_notificationDao.findAll()) {
      m_notificationDao.delete(not);
    }
    for (final OnmsAlarm alarm : m_alarmDao.findAll()) {
      m_alarmDao.delete(alarm);
    }
    for (final OnmsEvent event : m_eventDao.findAll()) {
      m_eventDao.delete(event);
    }
    for (final OnmsSnmpInterface iface : m_snmpInterfaceDao.findAll()) {
      m_snmpInterfaceDao.delete(iface);
    }
    for (final OnmsIpInterface iface : m_ipInterfaceDao.findAll()) {
      m_ipInterfaceDao.delete(iface);
    }
    for (final OnmsNode node : m_nodeDao.findAll()) {
      m_nodeDao.delete(node);
    }
    for (final OnmsServiceType service : m_serviceTypeDao.findAll()) {
      m_serviceTypeDao.delete(service);
    }

    LOG.debug("= DatabasePopulatorExtension Reset Starting =");
    for (Extension eachExtension : extensions) {
      DaoSupport daoSupport = eachExtension.getDaoSupport();
      OnmsDao dao =
          daoSupport != null && daoSupport.getDaoClass() != null
              ? lookupDao(daoSupport.getDaoClass())
              : null;

      eachExtension.onShutdown(this, dao);
      if (dao != null) {
        dao.flush();
      }
    }
    LOG.debug("= DatabasePopulatorExtension Reset Finished =");

    m_dataLinkInterfaceDao.flush();
    m_outageDao.flush();
    m_userNotificationDao.flush();
    m_notificationDao.flush();
    m_alarmDao.flush();
    m_eventDao.flush();
    m_snmpInterfaceDao.flush();
    m_ipInterfaceDao.flush();
    m_nodeDao.flush();
    m_serviceTypeDao.flush();

    LOG.debug("==== DatabasePopulator Reset Finished ====");
  }