Exemplo n.º 1
0
  /**
   * Stop method of fiber, called by OpenNMS when fiber execution is to finish. Its purpose is to
   * clean everything up, e.g. close any JNDI or database connections, before the fiber's execution
   * is ended.
   */
  @Override
  protected void onStop() {
    // Get a reference to the QoSD logger

    LOG.info("Stopping QosD");

    try {
      unregisterListener(); // unregister the OpenNMS event listener
    } catch (Throwable ex) {
      LOG.error("stop() Error unregistering the OpenNMS event listener. Error:", ex);
    }

    try {
      openNMSEventHandlerThread.kill();
    } catch (Throwable ex) {
      LOG.error("stop() Error killing openNMSEventHandlerThread. Error:", ex);
    }

    try {
      alarmListConnectionManager.kill(); // kill the connection thread
    } catch (Throwable ex) {
      LOG.error("stop() Error killing alarmListConnectionManager. Error:", ex);
    }

    LOG.info("QosD Stopped");
  }
Exemplo n.º 2
0
  /**
   * A method to request an alarm list from the OpenNMS database using the ossDao, convert them to
   * OSS/J alarms using the onmsAlarmOssjMapper and send the OSS/J alarms using the alarm list
   * connection manager (alcm) to update the the AlarmMonitor bean. This is called from ossDao every
   * time there is an update to the database.
   */
  @Override
  public void sendAlarms() {
    Hashtable<AlarmKey, AlarmValue> ossjAlarmUpdateList = new Hashtable<AlarmKey, AlarmValue>();
    OnmsAlarm[] onmsAlarmUpdateList = null;
    AlarmValue ossjAlarm;

    try {
      LOG.debug("sendAlarms() using ossDao to get current alarm list");
      onmsAlarmUpdateList = ossDao.getAlarmCache();
    } catch (Throwable ex) {
      // problems contacting the PostgreSQL database
      LOG.error("sendAlarms() Cannot retrieve alarms from ossDao.getAlarmCache()", ex);
      throw new UndeclaredThrowableException(
          ex, "sendAlarms() Cannot retrieve alarms from ossDao.getAlarmCache()");
    }

    LOG.debug("sendAlarms() Alarms fetched. Processing each alarm in list.");
    // Convert the OnmsAlarm array alarmBuf to a hashtable using the alarmid as the key.
    try {
      for (int i = 0; i < onmsAlarmUpdateList.length; i++) {
        LOG.debug("sendAlarms() processing an OpenNMS alarm:");

        // if useUeiList is true only the alarms whose UEI's are listed in the
        // QosD-configuration.xml file will be included in the list.
        if (useUeiList) {
          LOG.debug("sendAlarms() useUeiList= true: using UeiList to determine alarms to send");
          if (null == triggerUeiList.get(onmsAlarmUpdateList[i].getUei())) {
            LOG.debug(
                "sendAlarms() alarm UEI not in QosD-configuration.xml. Not sending. alarmID:{} alarmUEI:{}",
                onmsAlarmUpdateList[i].getId(),
                onmsAlarmUpdateList[i].getUei());
            continue; // ignore this event and return
          }
          LOG.debug(
              "sendAlarms() alarm UEI is in QosD-configuration.xml. Trying to send alarmID:{} alarmUEI:{}",
              onmsAlarmUpdateList[i].getId(),
              onmsAlarmUpdateList[i].getUei());
        }

        if (onmsAlarmUpdateList[i].getAlarmType() != 1) {
          LOG.debug(
              "sendAlarms() Alarm AlarmType !=1 ( not raise alarm ) Not sending alarmID:{} :alarmBuf[i].getQosAlarmState()=: {}",
              onmsAlarmUpdateList[i].getId(),
              onmsAlarmUpdateList[i].getQosAlarmState());
          continue;
        } else {
          LOG.debug(
              "sendAlarms() Alarm AlarmType==1 ( raise alarm ) Sending alarmID:{} :alarmBuf[i].getQosAlarmState()=: {}",
              onmsAlarmUpdateList[i].getId(),
              onmsAlarmUpdateList[i].getQosAlarmState());
          try {

            // Code which creates the OSSJ AlarmValue from the Spring OSS?J AlarmValue Specification
            LOG.debug("sendAlarms(): generating the OSS/J alarm specification:");
            ossjAlarm = alarmListConnectionManager.makeAlarmValueFromSpec();
            LOG.debug(
                "sendAlarms(): OSS/J alarm specification:{}",
                OOSSAlarmValue.converttoString(ossjAlarm));

            // Code which creates the OSSJ AlarmValue from the Spring OSS/J AlarmValue Specification
            LOG.debug("sendAlarms(): onmsAlarmOssjMapper.populateOssjAlarmFromOpenNMSAlarm:");
            ossjAlarm =
                onmsAlarmOssjMapper.populateOssjAlarmFromOpenNMSAlarm(
                    ossjAlarm, onmsAlarmUpdateList[i]);
            LOG.debug(
                "buildList(): alarm specifcation: {}", OOSSAlarmValue.converttoString(ossjAlarm));

            // TODO selector on ACKNOWLEDGED and CLEARED - currently always sends all alarms in list
            if (true)
              try {
                // alarms which are ACKNOWLEDGED and CLEARED are included in this current alarm list
                LOG.debug(
                    "sendAlarms() including ACKNOWLEDGED and CLEARED alarms in alarm in list");
                ossjAlarmUpdateList.put(ossjAlarm.getAlarmKey(), ossjAlarm);
              } catch (Throwable e) {
                LOG.error("sendAlarms() error putting alarm in alarmList", e);
              }

            // TODO - THIS CODE NEVER RUN
            /*
            else try {
            	// no alarms which are ACKNOWLEDGED and CLEARED are included in this current alarm list
            	if (ossjAlarm.getAlarmAckState() == javax.oss.fm.monitor.AlarmAckState.UNACKNOWLEDGED ) {
            		ossjAlarmUpdateList.put(ossjAlarm.getAlarmKey(), ossjAlarm); // put all unacknowledged alarms in list
            	}
            	else if (ossjAlarm.getPerceivedSeverity() != javax.oss.fm.monitor.PerceivedSeverity.CLEARED ){
            		ossjAlarmUpdateList.put(ossjAlarm.getAlarmKey(), ossjAlarm);	// put all uncleared acknowledged alarms in list
            	}
            } catch (Throwable e) {
            	log.error("sendAlarms() error in alarmACKState or PercievedSeverity - check alarm definitons", e);
            }*/
          } catch (Throwable ex) {
            LOG.error(
                "sendAlarms() error trying to populate alarm - alarm disguarded - check alarm definitons",
                ex);
          }
        }
      }
    } catch (Throwable ex) {
      LOG.error("Qosd.sendAlarms(): Problem when building alarm list:", ex);
      throw new UndeclaredThrowableException(
          ex, "Qosd.sendAlarms(): Problem when building alarm list");
    }
    try {
      // debug code prints out alarm list to be sent if enabled
      if (LOG.isDebugEnabled()) {
        LOG.debug("QosD sendAlarms() - Alarm list built:");
        LOG.debug("QosD sendAlarms() - ******* Alarm List to be sent : primary keys");
        for (Entry<AlarmKey, AlarmValue> entry : ossjAlarmUpdateList.entrySet()) {
          LOG.debug(
              "QosD sendAlarms() key:{}  AlarmValue.getAlarmChangedTime: {}",
              entry.getKey().getPrimaryKey(),
              entry.getValue().getAlarmChangedTime());
        }
        LOG.debug("QosD sendAlarms() - ******* END OF LIST");
        LOG.debug("QosD sendAlarms() Sending alarm list to bean");
      }
      // send the alarmList to Ossbeans EJB or local runner via the connection manager thread.

      alarmListConnectionManager.send(ossjAlarmUpdateList);
    } catch (Throwable ex) {
      LOG.error("Qosd.sendAlarms(): Problem when sending alarm list:", ex);
      throw new UndeclaredThrowableException(
          ex, "Qosd.sendAlarms(): Problem when sending alarm list");
    }
  }
Exemplo n.º 3
0
  /** The start() method loads the configuration for the QosD daemon and registers for events */
  @Override
  protected void onStart() {
    String jnp_host;
    // Get a reference to the QosD logger instance assigned by OpenNMS

    LOG.info("Qosd.start(): Preparing to load configuration");

    // set application context for AlarmListConnectionManager
    try {
      LOG.debug(
          "Qosd.start():setting application context for alarmListConnectionManager: m.context.toString:{}",
          m_context.toString());
      alarmListConnectionManager.setApplicationContext(m_context);
    } catch (Exception ex) {
      throw new IllegalArgumentException(
          "Qosd.start(): Error setting spring application context: " + ex);
    }

    // Load the configuration file QosD-Configuration.xml This file contains
    // all the UEIs that will be sent as alarms if useUeiList = true.
    try {
      config = QoSDConfigFactory.getConfig();
      LOG.info("QoSD QoSD-configuration.xml - Configuration Loaded Successfully");

      // loading list of UEI's which trigger this daemon
      triggerUeiList = new Hashtable<String, String>();
      String[] temp = config.getEventlist().getUei();
      for (int i = 0; i < temp.length; i++) triggerUeiList.put(temp[i], "1");

    } catch (MarshalException mrshl_ex) {
      // write an error message to the log file
      LOG.error(
          "Qosd.start(): Marshal Exception thrown whilst getting QoSD configuration\n\t\t\t\tEnsure tags have correct names",
          mrshl_ex);
      throw new UndeclaredThrowableException(mrshl_ex);
    } catch (ValidationException vldtn_ex) {
      LOG.error(
          "Qosd.start(): Validation Exception thrown whilst getting QoSD configuration\n\t\t\t\tMake sure all the tags are formatted correctly within QoSD-configuration.xml",
          vldtn_ex);
      throw new UndeclaredThrowableException(vldtn_ex);
    } catch (IOException io_ex) {
      // Get the OpenNMS home directory
      String configFile = System.getProperty("opennms.home");
      // if there is '/' at the end...
      if (configFile.endsWith(java.io.File.separator)) {
        // ... remove it so that we can compose a valid filename
        configFile = configFile.substring(0, configFile.length() - 1);
      }
      configFile +=
          java.io.File.separator + "etc" + java.io.File.separator + "QoSD-configuration.xml";
      LOG.error(
          "Qosd.start(): Failed to load configuration file: {}\n\t\t\t\tMake sure that it exists",
          configFile,
          io_ex);
      throw new UndeclaredThrowableException(io_ex);
    }

    if (useUeiList)
      LOG.info(
          "Qosd.start(): useUeiList = true = using QoSD QoSD-configuration.xml UEI list selects which alarms are sent");

    try {
      // Load the properties file containing the JNDI connection address etc.
      props = PropertiesLoader.getInstance();
    } catch (FileNotFoundException fnf_ex) {
      // record in log that the properties file could not be found
      String propertiesFilename = System.getProperty("propertiesFile");
      LOG.error("Qosd.start(): Could not find properties file: {}", propertiesFilename, fnf_ex);
      throw new UndeclaredThrowableException(fnf_ex);
    } catch (IOException io_ex) {
      // record in log that the properties file could not be read
      String propertiesFilename = System.getProperty("propertiesFile");
      LOG.error(
          "Qosd.start(): Could not read from properties file: {}\n\t\t\t\tPlease check the file permissions",
          propertiesFilename,
          io_ex);
      throw new UndeclaredThrowableException(io_ex);
    }

    LOG.info("Qosd.start(): QosD Properties File Loaded");

    if (System.getSecurityManager() == null) System.setSecurityManager(new RMISecurityManager());

    /*The following if-statement checks if the naming provider property exists in
     * the properties file. If it does then it stores it in the jnp_host string. If
     * it doesn't then it uses a default naming provider string "jbossjmsserver1:1099" and
     * assigns it to jnp_host, stating this in the log file.
     */
    if (props.getProperty("org.openoss.opennms.spring.qosd.naming.provider") != null) {
      jnp_host = (String) props.getProperty("org.openoss.opennms.spring.qosd.naming.provider");
      LOG.info("Using JNP: {}", jnp_host);
    } else {
      LOG.warn(
          "Qosd.start(): Naming provider property not set, Using default: jnp://jbossjmsserver1:1099");
      jnp_host = "jnp://jbossjmsserver1:1099";
    }

    /* Fill a new properties object with the properties supplied in
     * the properties file.
     */
    env = new Properties();
    env.setProperty("java.naming.provider.url", jnp_host);
    env.setProperty(
        "java.naming.factory.initial",
        props.getProperty("org.openoss.opennms.spring.qosd.naming.contextfactory"));
    env.setProperty(
        "java.naming.factory.url.pkgs",
        props.getProperty("org.openoss.opennms.spring.qosd.naming.pkg"));

    // start a new connection manager thread
    try {
      alarmListConnectionManager.init(props, env);
      alarmListConnectionManager.start();
      // wait until the AlarmListConnectionManager has connected to bean
      LOG.info("Qosd.start(): Waiting Connection Manager Thread to get JMS connection");
      while (alarmListConnectionManager.getStatus() != AlarmListConnectionManager.CONNECTED) ;
      LOG.info("Qosd.start(): Connection Manager Thread JMS connection successfully registered");

      LOG.info("Qosd.start(): openNMS just restarted - sending alarm list rebuilt event");
      // send alarm list rebuilt event to EJB via the connection manager thread.
      alarmListConnectionManager.reset_list(
          "openNMS just restarted - alarm list rebuilt. Time:"
              + new Date()); // send an alarm list rebuilt event
    } catch (Throwable iae) {
      LOG.error("Qosd.start(): Exception caught starting alarmListConnectionManager", iae);
      throw new UndeclaredThrowableException(iae);
    }

    // setting up ossDao to access the OpenNMS database
    try {
      LOG.debug(
          "Qosd.start(): Using ossDao instance: {}",
          (ossDao == null ? "IS NULL" : ossDao.toString()));
      LOG.info("Qosd.start(): Initialising the Node and alarm Caches");
      ossDao.init();
      //	TODO REMOVE
      //			ossDao.updateNodeCaches();
      LOG.info(
          "Qosd.start(): Set up ossDao call back interface to QoSD for forwarding changes to alarm list");
      ossDao.setQoSD(this);
    } catch (Throwable ex) {
      LOG.error("Qosd.start(): Exception caught setting callback interface from ossDao", ex);
      throw new UndeclaredThrowableException(ex);
    }

    // set up thread to handle incoming OpenNMS events
    LOG.info("Qosd.start(): initialising OpenNMSEventHandlerThread");
    try {
      openNMSEventHandlerThread = new OpenNMSEventHandlerThread();
      openNMSEventHandlerThread.setOssDao(ossDao);
      openNMSEventHandlerThread.init();
      openNMSEventHandlerThread.start();
    } catch (Throwable ex) {
      LOG.error("Qosd.start(): Exception caught initialising OpenNMSEventHandlerThread", ex);
      throw new UndeclaredThrowableException(ex);
    }

    // send all the alarmList to EJB via the connection manager thread.
    LOG.info("Qosd.start(): openNMS just restarted - sending all alarms in rebuilt alarm list");
    try {
      // this.sendAlarms(); // interface has just started up. Send all alarms
      openNMSEventHandlerThread.sendAlarmList();
    } catch (Exception e) {
      LOG.error("Qosd.start(): problem sending initial alarm list Error:", e);
    }

    // register listener for OpenNMS events
    LOG.info("Qosd.start(): Starting OpenNMS event listener");
    try {
      registerListener();
    } catch (Exception e) {
      LOG.error("Qosd.start(): problem registering event listener Error:", e);
    }

    // TODO - replace ack handler code with QoSDrx receiver code

    LOG.info("QoSD Started");
  }