OpenNMS API 1.2.3

org.opennms.netmgt.rtc
Class DataManager

java.lang.Object
  extended byorg.opennms.netmgt.rtc.DataManager

public class DataManager
extends java.lang.Object

Contains and maintains all the data for the RTC. The basic datablock is a 'RTCNode' that gets added to relevant 'RTCCategory's. it also gets added to a map with different keys for easy lookup The map('RTCHashMap') is keyed with 'RTCNodeKey's(a nodeid/ip/svc combination), nodeid/ip combinations and nodeid and these keys either lookup a single RTCNode or lists of 'RTCNode's Incoming events have a method in the DataManager to alter data - for e.g., a 'nodeGainedService' event would result in the 'nodeGainedService()' method being called by the DataUpdater(s).

Author:
Sowmya Nataraj , OpenNMS.org

Field Summary
private  java.util.Map m_categories
          The RTC categories
private  RTCHashMap m_map
          map keyed using the RTCNodeKey or nodeid or nodeid/ip
private  java.util.HashMap m_serviceTableMap
          The service table map - this is built at startup and updated if a servicename that is not found in the map is found so as to avoid a database lookup for each servicename to serviceid mapping
 
Constructor Summary
DataManager()
          Constructor.
 
Method Summary
private  void addIpToCategory(java.util.List ipRTCs, RTCCategory cat)
          Add the RTCNodes known for an IP to the category.
private  void addNodeIpSvcToCategory(long nodeid, java.lang.String ip, java.lang.String svcname, RTCCategory cat, java.util.HashMap knownIPs, java.sql.PreparedStatement outagesGetStmt)
          Add a node/ip/service to the specified category.
 void addServiceMapping(java.lang.String svcname, long serviceid)
          Add the svcname/svcid mapping to the servicetable map
private  void createCategoriesMap()
          Creates the categories map.
private  void delNodeIpSvcToCategory(long nodeid, java.lang.String ip, java.lang.String svcname, RTCCategory cat)
          Delete a node/ip/service to the specified category.
 RTCNode get(long nodeid, java.lang.String ip, java.lang.String svcName)
          Get the rtcnode with this nodeid/ip/svcname.
 RTCNode get(RTCNodeKey key)
          Get the node from it's key.
 java.util.Map getCategories()
           
 int getServiceCount(long nodeid, java.lang.String catLabel)
          Get the service count for the nodeid in the context of the passed category
 int getServiceDownCount(long nodeid, java.lang.String catLabel)
          Get the service down count for the nodeid in the context of the passed category
 long getServiceID(java.lang.String svcname)
          Return the service id for the name passed
private  char getServiceStatus(long nodeid, java.lang.String ip, java.lang.String svc)
          Get the 'ismanaged' status for the nodeid, ipaddr combination
 double getValue(long nodeid, java.lang.String catLabel, long curTime, long rollingWindow)
          Get the value(uptime) for the nodeid in the last 'rollingWindow' starting at current time in the context of the passed category
 double getValue(java.lang.String catLabel, long curTime, long rollingWindow)
          Get the value(uptime) for the category in the last 'rollingWindow' starting at current time
 void interfaceDown(long nodeid, java.lang.String ip, long t)
          Add a lost service entry to the right nodes.
 void interfaceReparented(java.lang.String ip, long oldNodeId, long newNodeId)
          Reparent an interface.
 void interfaceUp(long nodeid, java.lang.String ip, long t)
          Add a regained service entry to the right nodes.
 void nodeDown(long nodeid, long t)
          Add a lost service entry to the right nodes.
 void nodeGainedService(long nodeid, java.lang.String ip, java.lang.String svcName)
          Handles a node gained service event.
 void nodeLostService(long nodeid, java.lang.String ip, java.lang.String svcName, long t)
          Handles a node lost service event.
 void nodeRegainedService(long nodeid, java.lang.String ip, java.lang.String svcName, long t)
          Add a regained service entry to the right node.
 void nodeUp(long nodeid, long t)
          Add a regained service entry to the right nodes.
private  void populateNodesFromDB(java.sql.Connection dbConn)
          Poplulates nodes from the database.
 void rtcNodeIpRescan(long nodeid, java.lang.String ip)
          Update the categories for a node.
 void rtcNodeRescan(long nodeid)
          Update the categories for a node.
 void serviceDeleted(long nodeid, java.lang.String ip, java.lang.String svcName)
          Remove node from the map and the categories on a 'serviceDeleted' event.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_categories

private java.util.Map m_categories
The RTC categories


m_map

private RTCHashMap m_map
map keyed using the RTCNodeKey or nodeid or nodeid/ip


m_serviceTableMap

private java.util.HashMap m_serviceTableMap
The service table map - this is built at startup and updated if a servicename that is not found in the map is found so as to avoid a database lookup for each servicename to serviceid mapping

Constructor Detail

DataManager

public DataManager()
            throws org.xml.sax.SAXException,
                   java.io.IOException,
                   java.sql.SQLException,
                   FilterParseException,
                   RTCException
Constructor. Parses categories from the categories.xml and populates them with 'RTCNode' objects created from data read from the database (services and outage tables)

Throws:
java.sql.SQLException - if there is an error reading initial data from the database
FilterParseException - if a rule in the categories.xml was incorrect
RTCException - if the initialization/data reading does not go through
org.xml.sax.SAXException
java.io.IOException
Method Detail

getServiceStatus

private char getServiceStatus(long nodeid,
                              java.lang.String ip,
                              java.lang.String svc)
Get the 'ismanaged' status for the nodeid, ipaddr combination

Parameters:
nodeid - the nodeid of the interface
ip - the interface for which the status is required
svc - the service for which status is required
Returns:
the 'status' from the ifservices table

addNodeIpSvcToCategory

private void addNodeIpSvcToCategory(long nodeid,
                                    java.lang.String ip,
                                    java.lang.String svcname,
                                    RTCCategory cat,
                                    java.util.HashMap knownIPs,
                                    java.sql.PreparedStatement outagesGetStmt)
Add a node/ip/service to the specified category.

Parameters:
nodeid - the nodeid to be added
ip - the interface to be added
svcname - the service to be added
cat - the category to which this node is to be added to
knownIPs - the hashtable of IP->list of RTCNodes (used only at startup)
outagesGetStmt - the prepared statement to read outages

delNodeIpSvcToCategory

private void delNodeIpSvcToCategory(long nodeid,
                                    java.lang.String ip,
                                    java.lang.String svcname,
                                    RTCCategory cat)
Delete a node/ip/service to the specified category. Note: This will not delete the service, it will just remove the node from the category.

Parameters:
nodeid - the nodeid to be added
ip - the interface to be added
svcname - the service to be added
cat - the category to which this node is to be added to

addIpToCategory

private void addIpToCategory(java.util.List ipRTCs,
                             RTCCategory cat)
Add the RTCNodes known for an IP to the category.

Parameters:
ipRTCs - the list of RTCNodes related to a particular IP
cat - the category to which the list is to be added

createCategoriesMap

private void createCategoriesMap()
Creates the categories map. Reads the categories from the categories.xml and creates the 'RTCCategory's map


populateNodesFromDB

private void populateNodesFromDB(java.sql.Connection dbConn)
                          throws java.sql.SQLException,
                                 FilterParseException,
                                 RTCException
Poplulates nodes from the database. For each category in the categories list, this reads the services and outage tables to get the initial data, creates 'RTCNode' objects that are added to the map and and to the appropriate category.

Parameters:
dbConn - the database connection.
Throws:
java.sql.SQLException - if the database read fails due to an SQL error
FilterParseException - if filtering the data against the category rule fails due to the rule being incorrect
RTCException - if the database read or filtering the data against the category rule fails for some reason

nodeGainedService

public void nodeGainedService(long nodeid,
                              java.lang.String ip,
                              java.lang.String svcName)
Handles a node gained service event. Add a new entry to the map and the categories on a 'serviceGained' event

Parameters:
nodeid - the node id
ip - the IP address
svcName - the service name

nodeLostService

public void nodeLostService(long nodeid,
                            java.lang.String ip,
                            java.lang.String svcName,
                            long t)
Handles a node lost service event. Add a lost service entry to the right node

Parameters:
nodeid - the node id
ip - the IP address
svcName - the service name
t - the time at which service was lost

interfaceDown

public void interfaceDown(long nodeid,
                          java.lang.String ip,
                          long t)
Add a lost service entry to the right nodes.

Parameters:
nodeid - the node id
ip - the IP address
t - the time at which service was lost

nodeDown

public void nodeDown(long nodeid,
                     long t)
Add a lost service entry to the right nodes.

Parameters:
nodeid - the node id
t - the time at which service was lost

nodeUp

public void nodeUp(long nodeid,
                   long t)
Add a regained service entry to the right nodes.

Parameters:
nodeid - the node id
t - the time at which service was regained

interfaceUp

public void interfaceUp(long nodeid,
                        java.lang.String ip,
                        long t)
Add a regained service entry to the right nodes.

Parameters:
nodeid - the node id
ip - the IP address
t - the time at which service was regained

nodeRegainedService

public void nodeRegainedService(long nodeid,
                                java.lang.String ip,
                                java.lang.String svcName,
                                long t)
Add a regained service entry to the right node.

Parameters:
nodeid - the node id
ip - the IP address
svcName - the service name
t - the time at which service was regained

serviceDeleted

public void serviceDeleted(long nodeid,
                           java.lang.String ip,
                           java.lang.String svcName)
Remove node from the map and the categories on a 'serviceDeleted' event.

Parameters:
nodeid - the nodeid on which service was deleted
ip - the ip on which service was deleted
svcName - the service that was deleted

rtcNodeRescan

public void rtcNodeRescan(long nodeid)
                   throws java.sql.SQLException,
                          FilterParseException,
                          RTCException
Update the categories for a node. This method will update the categories for all interfaces on a node.

Parameters:
nodeid - the nodeid on which SNMP service was added
Throws:
java.sql.SQLException - if the database read fails due to an SQL error
FilterParseException - if filtering the data against the category rule fails due to the rule being incorrect
RTCException - if the database read or filtering the data against the category rule fails for some reason

rtcNodeIpRescan

public void rtcNodeIpRescan(long nodeid,
                            java.lang.String ip)
                     throws java.sql.SQLException,
                            FilterParseException,
                            RTCException
Update the categories for a node. When SNMP is discovered on a node, we need to recalculate the categories for that node in case the filter is based on SNMP information. This method can be used for any node that requires the categories to be updated.

Parameters:
nodeid - the nodeid on which SNMP service was added
ip - the ip on which SNMP service was added
Throws:
java.sql.SQLException - if the database read fails due to an SQL error
FilterParseException - if filtering the data against the category rule fails due to the rule being incorrect
RTCException - if the database read or filtering the data against the category rule fails for some reason

interfaceReparented

public void interfaceReparented(java.lang.String ip,
                                long oldNodeId,
                                long newNodeId)
Reparent an interface. This effectively means updating the nodelist of the categories and the map Use the ip/oldnodeid combination to get all nodes that will be affected - for each of these nodes, remove the old entry and add a new one with new keys to the map Note: Each of these nodes could belong to more than one category. However, category rule evaluation is done based ONLY on the IP - therefore changing the nodeID on the node should update the categories appropriately

Parameters:
ip - the interface to reparent
oldNodeId - the node that the ip belonged to earlier
newNodeId - the node that the ip now belongs to

get

public RTCNode get(long nodeid,
                   java.lang.String ip,
                   java.lang.String svcName)
Get the rtcnode with this nodeid/ip/svcname.

Parameters:
nodeid - the node id
ip - the interface
svcName - the service

get

public RTCNode get(RTCNodeKey key)
Get the node from it's key.

Parameters:
key - the RTCNodeKey
Returns:
the node for this key.

getValue

public double getValue(java.lang.String catLabel,
                       long curTime,
                       long rollingWindow)
Get the value(uptime) for the category in the last 'rollingWindow' starting at current time

Parameters:
catLabel - the category to which the node should belong to
curTime - the current time
rollingWindow - the window for which value is to be calculated
Returns:
the value(uptime) for the category in the last 'rollingWindow' starting at current time

getValue

public double getValue(long nodeid,
                       java.lang.String catLabel,
                       long curTime,
                       long rollingWindow)
Get the value(uptime) for the nodeid in the last 'rollingWindow' starting at current time in the context of the passed category

Parameters:
nodeid - the node for which value is to be calculated
catLabel - the category to which the node should belong to
curTime - the current time
rollingWindow - the window for which value is to be calculated
Returns:
the value(uptime) for the node in the last 'rollingWindow' starting at current time in the context of the passed category

getServiceCount

public int getServiceCount(long nodeid,
                           java.lang.String catLabel)
Get the service count for the nodeid in the context of the passed category

Parameters:
nodeid - the node for which service count is to be calculated
catLabel - the category to which the node should belong to
Returns:
the service count for the nodeid in the context of the passed category

getServiceDownCount

public int getServiceDownCount(long nodeid,
                               java.lang.String catLabel)
Get the service down count for the nodeid in the context of the passed category

Parameters:
nodeid - the node for which service down count is to be calculated
catLabel - the category to which the node should belong to
Returns:
the service down count for the nodeid in the context of the passed category

getCategories

public java.util.Map getCategories()
Returns:
the categories

getServiceID

public long getServiceID(java.lang.String svcname)
                  throws java.sql.SQLException
Return the service id for the name passed

Parameters:
svcname - the service name whose service id is required
Returns:
the service id for the name passed, -1 if not found
Throws:
java.sql.SQLException

addServiceMapping

public void addServiceMapping(java.lang.String svcname,
                              long serviceid)
Add the svcname/svcid mapping to the servicetable map


OpenNMS API 1.2.3

Generated by eevans on May 29 2005 2015.