org.opennms.bb.dp.capsd.components
Class CapsWriter

java.lang.Object
  |
  +--org.opennms.bb.dp.capsd.components.CapsWriter
All Implemented Interfaces:
DBRunnable

public final class CapsWriter
extends Object
implements DBRunnable

The CapsWriter class is designed to use the information collected by the CapsReadere and write the information to persistant storage. The data is store into the distributed poller database using SQL statements defined in the properties for the system.

The class is designed to be created using an instance of the CapsReader class and then run later as a database runnable. The run of the instance will be passed an SQL connection where the persistant information will be stored.

Version:
$Revision: 1.22 $
Author:
Sowmya, OpenNMS

Inner Class Summary
private static class CapsWriter.AddressToSoapDocument
          This static class is used to build an compliant SOAP document that is sent to the discover daemon.
 
Field Summary
private static String IF_ADMIN_STATUS
          The lookup string for looking up the value of ifAdminStatus
private static String IF_DESCR
          The lookup string for looking up the value of ifDescr
private static String IF_INDEX
          The lookup string for looking up the value of ifIndex
private static String IF_OPER_STATUS
          The lookup string for looking up the value of ifOperStatus
private static String IF_PHYS_ADDR
          The lookup string for looking up the value of ifPhysAddr
private static String IF_SPEED
          The lookup string for looking up the value of ifSpeed
private static String IF_TYPE
          The lookup string for looking up the value of ifType
private static String IP_ADDR_ENT_ADDR
          The lookup string for looking up the value of ipAdEntAddr
private static String IP_ADDR_ENT_NETMASK
          The lookup string for looking up the value of ipAdEntNetMask
private static String IP_ADDR_IF_INDEX
          The lookup string for looking up the value of ipAdEntIfIndex
private  com.sun.media.jsdt.Channel m_channel
          The JSDT Communication channel.
private  com.sun.media.jsdt.Client m_client
          The JSDT Client.
private  String m_createDate
          Creation date of the node.
private  Set m_dupNodes
          Set of nodes (ip addresses) already known to Capsd.
private static char[] m_hexDigit
           
private  List m_ifEntries
          The list of IfEntry objects from the MIB on the remote host.
private  List m_ipAddrEntries
          The list of IP Address entries corresponding to the interfaces on the remote host.
private  IPv4Address m_nodeAddress
          The original address that was sent by the discovery process to capsd.
private  Dictionary m_services
          The dictionary of services that are index via the interface address.
private  SystemGroup m_sysGroup
          The SNMP System Group information collected from the node.
private static String SYS_CONTACT
          The lookup string for looking up the value of sysContact
private static String SYS_DESCR
          The lookup string for looking up the value of sysDescr
private static String SYS_LOCATION
          The lookup string for looking up the value of sysLocation
private static String SYS_NAME
          The lookup string for looking up the value of sysName
private static String SYS_OBJECTID
          The lookup string for looking up the value of sysObjectID
 
Constructor Summary
private CapsWriter()
          The class' default constructor.
  CapsWriter(CapsReader capsReader, com.sun.media.jsdt.Channel channel, com.sun.media.jsdt.Client client)
          The class' constructor that is used to create an instance of a writer object.
 
Method Summary
private  void dbInsertInterface(PreparedStatement stmt, IfTableEntry ifEntry, IPv4Address ifAddress, int nodeKey)
          This method is used to add a specific interface into the database.
private  void dbInsertInterfaces(Connection dbcomm, int nodeKey)
          This method is used to insert the information about the interface into the database.
private  int dbInsertNode(Connection dbcomm)
          This method is designed to insert the currently known information about the queried node(interface) into the distributed poller database.
private  void dbInsertServices(PreparedStatement stmt, IPv4Address ifAddress, int ifIndex, int nodeKey)
          This method is used to insert the supported services for the interface into the datastore.
private  void dbInsertSnmp(PreparedStatement stmt, IfTableEntry ifEntry, IPv4Address ifAddress, int nodeKey)
          This method is used to insert the SNMP information gathered about an interface into the database.
 void dbRun(Connection connection)
          This method of the CapsWriter class does the bulk of the work for the instance.
private  String getIpAddress(int ifIndex)
          This method is used to find the corresponding IP Address for the indexed interface.
private  String getNetmask(int ifIndex)
          This method is used to find the corresponding netmask for the indexed interface.
private  String toHexString(byte[] physAddr)
          This method converts the physical address, normally six bytes, into a hexidecimal string.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

m_hexDigit

private static final char[] m_hexDigit

m_nodeAddress

private IPv4Address m_nodeAddress

The original address that was sent by the discovery process to capsd.


m_sysGroup

private SystemGroup m_sysGroup

The SNMP System Group information collected from the node.


m_ifEntries

private List m_ifEntries

The list of IfEntry objects from the MIB on the remote host. This is a list of IfTableEntry objects.


m_ipAddrEntries

private List m_ipAddrEntries

The list of IP Address entries corresponding to the interfaces on the remote host. This information is also collected via SNMP.


m_dupNodes

private Set m_dupNodes

Set of nodes (ip addresses) already known to Capsd.


m_services

private Dictionary m_services

The dictionary of services that are index via the interface address.


m_createDate

private String m_createDate

Creation date of the node.


m_channel

private com.sun.media.jsdt.Channel m_channel

The JSDT Communication channel.


m_client

private com.sun.media.jsdt.Client m_client

The JSDT Client.


SYS_OBJECTID

private static final String SYS_OBJECTID
The lookup string for looking up the value of sysObjectID

SYS_NAME

private static final String SYS_NAME
The lookup string for looking up the value of sysName

SYS_DESCR

private static final String SYS_DESCR
The lookup string for looking up the value of sysDescr

SYS_LOCATION

private static final String SYS_LOCATION
The lookup string for looking up the value of sysLocation

SYS_CONTACT

private static final String SYS_CONTACT
The lookup string for looking up the value of sysContact

IF_INDEX

private static final String IF_INDEX
The lookup string for looking up the value of ifIndex

IF_DESCR

private static final String IF_DESCR
The lookup string for looking up the value of ifDescr

IF_TYPE

private static final String IF_TYPE
The lookup string for looking up the value of ifType

IF_SPEED

private static final String IF_SPEED
The lookup string for looking up the value of ifSpeed

IF_PHYS_ADDR

private static final String IF_PHYS_ADDR
The lookup string for looking up the value of ifPhysAddr

IF_ADMIN_STATUS

private static final String IF_ADMIN_STATUS
The lookup string for looking up the value of ifAdminStatus

IF_OPER_STATUS

private static final String IF_OPER_STATUS
The lookup string for looking up the value of ifOperStatus

IP_ADDR_IF_INDEX

private static final String IP_ADDR_IF_INDEX
The lookup string for looking up the value of ipAdEntIfIndex

IP_ADDR_ENT_ADDR

private static final String IP_ADDR_ENT_ADDR
The lookup string for looking up the value of ipAdEntAddr

IP_ADDR_ENT_NETMASK

private static final String IP_ADDR_ENT_NETMASK
The lookup string for looking up the value of ipAdEntNetMask
Constructor Detail

CapsWriter

private CapsWriter()
            throws UnsupportedOperationException

The class' default constructor. The constructor will always throw an exception and not designed to be instantianted without a CapsReader object to interogate information from.

Throws:
UnsupportedOperationException - Always thrown by the constructor.

CapsWriter

public CapsWriter(CapsReader capsReader,
                  com.sun.media.jsdt.Channel channel,
                  com.sun.media.jsdt.Client client)

The class' constructor that is used to create an instance of a writer object. The object is always paired with a reader object that has all the information gleaned about then node.

Once an instance of the object is initialized the dbRun method must be called to actually store the information to the database.

Parameters:
capsReader - the CapsReader object that has all the data
channel - the JSDT channel to which nodes are added after being added to the DB - discovery then reads off this channel to update the 'knownNodes'
client - the JSDT client identification for this object
Method Detail

dbInsertNode

private int dbInsertNode(Connection dbcomm)
                  throws SQLException

This method is designed to insert the currently known information about the queried node(interface) into the distributed poller database.

See the create.sql script from the sql module in CVS on OpenNMS for more information about the layout of the database.

Parameters:
dbcomm - The JDBC database connection.
Returns:
The node identifier key from the database.
Throws:
SQLException - Thrown if an error occurs inserting the node into the database.
java.lang.NullPointerException - Thrown if the sql statement could not be loaded from the system properties.

dbInsertInterfaces

private void dbInsertInterfaces(Connection dbcomm,
                                int nodeKey)
                         throws SQLException

This method is used to insert the information about the interface into the database. The information includes all the known information queried by the CapsReader object.

Parameters:
dbcomm - The connection to the databse.
nodeKey - The node id for the interfaces
Throws:
SQLException - Thrown if an error occurs committing the information to the database.
java.lang.NullPointerException - Thrown if the method is unable to load the SQL statements from the properties.

dbInsertInterface

private void dbInsertInterface(PreparedStatement stmt,
                               IfTableEntry ifEntry,
                               IPv4Address ifAddress,
                               int nodeKey)
                        throws SQLException

This method is used to add a specific interface into the database. The interface addition includes information discovered by the SNMP agent such as it's operational status. If the insert fails then an exception is thrown by the method. The method also attempts to lookup the hostname for the specified IP Address. If the lookup fails then a null record is written to the hostname field.

Parameters:
stmt - The SQL prepared statment used to insert the information
ifEntry - The SNMP Information collected about the interface
ifAddress - The Interface IP Address.
nodeKey - The node identification key
Throws:
SQLException - Thrown if the insertion into the database fails.

dbInsertSnmp

private void dbInsertSnmp(PreparedStatement stmt,
                          IfTableEntry ifEntry,
                          IPv4Address ifAddress,
                          int nodeKey)
                   throws SQLException

This method is used to insert the SNMP information gathered about an interface into the database. The information includes the network maks, interface index, physical address, and interace status along with other fields.

Parameters:
stmt - The prepared SQL statement.
ifEntry - The SNMP interface information.
ifAddress - The IP Address of the interface
nodeKey - The foreign key node identifier
Throws:
SQLException - Thrown if an error occurs adding the information to the datastore.

dbInsertServices

private void dbInsertServices(PreparedStatement stmt,
                              IPv4Address ifAddress,
                              int ifIndex,
                              int nodeKey)
                       throws SQLException

This method is used to insert the supported services for the interface into the datastore. Each service that was supported on the interface is written as a row in the ifServices table.

Parameters:
stmt - The SQL statement for inserting rows.
ifAddress - The IP Address of the interface.
ifIndex - The index of the lan card.
nodeKey - The node's foreign key constraint
Throws:
SQLException - Thrown if an error occurs setting up the bindings or executing the statement.

getIpAddress

private String getIpAddress(int ifIndex)

This method is used to find the corresponding IP Address for the indexed interface. The list of IP Address entries are searched until the first IP Address is found for the interface. The IP Address is then returned as a string. If there is no interface corresponding to the index then a null is returned to the caller.

Parameters:
ifIndex - The interface index for.
Returns:
IP Address for the indexed interface.

getNetmask

private String getNetmask(int ifIndex)

This method is used to find the corresponding netmask for the indexed interface. The list of IP Address table entries are searched until the first netmask address is found for the interface. The netmask is then returned as a string. If there is no interface corresponding to the index then a null is returned.

Parameters:
ifIndex - The interface index to search for.
Returns:
The netmask for the interface.

toHexString

private String toHexString(byte[] physAddr)

This method converts the physical address, normally six bytes, into a hexidecimal string. The string is not prefixed with the traditional "0x", but is the raw hexidecimal string in upper case.

NOTICE: The string is converted based on the starndard US-ASCII table. Each NIBBLE is converted to an integer and added to the character '0' (Zero).

Parameters:
physAddr - The physical address to convert to a string.
Returns:
The converted physical address as a hexidecimal string.

dbRun

public void dbRun(Connection connection)

This method of the CapsWriter class does the bulk of the work for the instance. The information that was grabbed by the constructor is written to the persistant store by the run method. The run method can be called multiple times with different connections if necessary.

Specified by:
dbRun in interface DBRunnable
Parameters:
connection - the database connection to be used by this object to add data to the DB