OpenNMS API 1.2.3

org.opennms.netmgt.utils
Class NodeLabel

java.lang.Object
  extended byorg.opennms.netmgt.utils.NodeLabel

public class NodeLabel
extends java.lang.Object

This class contains convenience functions for retrieving and modifying the label associated with a managed node. The 'node' table contains a 'nodelabel' and 'nodelabelsource' field. The 'nodelabel' is a user-friendly name associated with the node. This name can be user-defined (via the WEB UI) or can be auto-generated based on what OpenNMS knows about the node and its interfaces. The 'nodelabelsource' field is a single character flag which indicates what the source for the node label was.

 
 Valid values for node label source are: 'U' User defined 'H' Primary
 interface's IP host name 'S' Node's MIB-II sysName 'A' Primary interface's IP
 address
 
 

Author:
Mike , OpenNMS

Field Summary
private static java.lang.String DEFAULT_SELECT_METHOD
          Default primary interface select method.
private  java.lang.String m_nodeLabel
          Node label
private  char m_nodeLabelSource
          Flag describing source of node label
static int MAX_NODE_LABEL_LENGTH
          Maximum length for node label
private static java.lang.String SELECT_METHOD_MAX
          Primary interface selection method MAX.
private static java.lang.String SELECT_METHOD_MIN
          Primary interface selection method MIN.
static char SOURCE_ADDRESS
           
static char SOURCE_HOSTNAME
           
static char SOURCE_NETBIOS
           
static char SOURCE_SYSNAME
           
static char SOURCE_UNKNOWN
          Initalization value for node label source flag
static char SOURCE_USERDEFINED
          Valid values for node label source flag
(package private) static java.lang.String SQL_DB_RETRIEVE_MANAGED_INTERFACES
          The SQL statement to retrieve all managed IP address & hostName values associated with a particular nodeID
(package private) static java.lang.String SQL_DB_RETRIEVE_NETBIOS_NAME
          The SQL statement to retrieve the NetBIOS name associated with a particular nodeID
(package private) static java.lang.String SQL_DB_RETRIEVE_NODELABEL
          The SQL statement to retrieve the current node label and node label source values associated with a node.
(package private) static java.lang.String SQL_DB_RETRIEVE_NON_MANAGED_INTERFACES
          The SQL statement to retrieve all non-managed IP address & hostName values associated with a particular nodeID
(package private) static java.lang.String SQL_DB_RETRIEVE_SYSNAME
          The SQL statement to retrieve the MIB-II sysname field from the node table
(package private) static java.lang.String SQL_DB_UPDATE_NODE_LABEL
          The SQL statement to update the 'nodelabel' and 'nodelabelsource' fields of 'node' table
 
Constructor Summary
NodeLabel()
          Default constructor
NodeLabel(java.lang.String nodeLabel, char nodeLabelSource)
          Constructor
 
Method Summary
static void assignLabel(int nodeID, NodeLabel nodeLabel)
          This method updates the 'nodelabel' and 'nodelabelsource' fields of the 'node' table for the specified nodeID.
static void assignLabel(int nodeID, NodeLabel nodeLabel, java.sql.Connection dbConnection)
          This method updates the 'nodelabel' and 'nodelabelsource' fields of the 'node' table for the specified nodeID.
static NodeLabel computeLabel(int nodeID)
          This method determines what label should be associated with a particular node.
static NodeLabel computeLabel(int nodeID, java.sql.Connection dbConnection)
          This method determines what label should be associated with a particular node.
 java.lang.String getLabel()
          Returns the node label .
 char getSource()
          Returns the node label source flag .
private static void loadAddressList(java.sql.ResultSet rs, java.util.List ipv4AddrList, java.util.List ipHostNameList)
          Utility method for loading the address and host name lists from a result set retrieved from the 'ipInterface' table of the database.
static NodeLabel retrieveLabel(int nodeID)
          This method queries the 'node' table for the value of the 'nodelabel' and 'nodelabelsource' fields for the node with the provided nodeID.
static NodeLabel retrieveLabel(int nodeID, java.sql.Connection dbConnection)
          This method queries the 'node' table for the value of the 'nodelabel' and 'nodelabelsource' fields for the node with the provided nodeID.
private static IPv4Address selectPrimaryAddress(java.util.List ipv4AddrList, java.lang.String method)
          Returns the primary interface from a list of addresses based on the specified selection method.
 void setLabel(java.lang.String nodeLabel)
          Sets the node label.
 void setSource(char nodeLabelSource)
          Sets the node label source flag
 java.lang.String toString()
          This method is responsible for returning a String object which represents the content of this NodeLabel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SQL_DB_UPDATE_NODE_LABEL

static final java.lang.String SQL_DB_UPDATE_NODE_LABEL
The SQL statement to update the 'nodelabel' and 'nodelabelsource' fields of 'node' table

See Also:
Constant Field Values

SQL_DB_RETRIEVE_NETBIOS_NAME

static final java.lang.String SQL_DB_RETRIEVE_NETBIOS_NAME
The SQL statement to retrieve the NetBIOS name associated with a particular nodeID

See Also:
Constant Field Values

SQL_DB_RETRIEVE_MANAGED_INTERFACES

static final java.lang.String SQL_DB_RETRIEVE_MANAGED_INTERFACES
The SQL statement to retrieve all managed IP address & hostName values associated with a particular nodeID

See Also:
Constant Field Values

SQL_DB_RETRIEVE_NON_MANAGED_INTERFACES

static final java.lang.String SQL_DB_RETRIEVE_NON_MANAGED_INTERFACES
The SQL statement to retrieve all non-managed IP address & hostName values associated with a particular nodeID

See Also:
Constant Field Values

SQL_DB_RETRIEVE_SYSNAME

static final java.lang.String SQL_DB_RETRIEVE_SYSNAME
The SQL statement to retrieve the MIB-II sysname field from the node table

See Also:
Constant Field Values

SQL_DB_RETRIEVE_NODELABEL

static final java.lang.String SQL_DB_RETRIEVE_NODELABEL
The SQL statement to retrieve the current node label and node label source values associated with a node.

See Also:
Constant Field Values

SOURCE_USERDEFINED

public static final char SOURCE_USERDEFINED
Valid values for node label source flag

See Also:
Constant Field Values

SOURCE_NETBIOS

public static final char SOURCE_NETBIOS
See Also:
Constant Field Values

SOURCE_HOSTNAME

public static final char SOURCE_HOSTNAME
See Also:
Constant Field Values

SOURCE_SYSNAME

public static final char SOURCE_SYSNAME
See Also:
Constant Field Values

SOURCE_ADDRESS

public static final char SOURCE_ADDRESS
See Also:
Constant Field Values

SOURCE_UNKNOWN

public static final char SOURCE_UNKNOWN
Initalization value for node label source flag

See Also:
Constant Field Values

MAX_NODE_LABEL_LENGTH

public static final int MAX_NODE_LABEL_LENGTH
Maximum length for node label

See Also:
Constant Field Values

SELECT_METHOD_MIN

private static final java.lang.String SELECT_METHOD_MIN
Primary interface selection method MIN. Using this selection method the interface with the smallest numeric IP address is considered the primary interface.

See Also:
Constant Field Values

SELECT_METHOD_MAX

private static final java.lang.String SELECT_METHOD_MAX
Primary interface selection method MAX. Using this selection method the interface with the greatest numeric IP address is considered the primary interface.

See Also:
Constant Field Values

DEFAULT_SELECT_METHOD

private static final java.lang.String DEFAULT_SELECT_METHOD
Default primary interface select method.

See Also:
Constant Field Values

m_nodeLabel

private java.lang.String m_nodeLabel
Node label


m_nodeLabelSource

private char m_nodeLabelSource
Flag describing source of node label

Constructor Detail

NodeLabel

public NodeLabel()
Default constructor


NodeLabel

public NodeLabel(java.lang.String nodeLabel,
                 char nodeLabelSource)
Constructor

Parameters:
nodeLabel - Node label
nodeLabelSource - Flag indicating source of node label
Method Detail

getLabel

public java.lang.String getLabel()
Returns the node label .

Returns:
node label

getSource

public char getSource()
Returns the node label source flag .

Returns:
node label source flag

setLabel

public void setLabel(java.lang.String nodeLabel)
Sets the node label.

Parameters:
nodeLabel - Node label

setSource

public void setSource(char nodeLabelSource)
Sets the node label source flag

Parameters:
nodeLabelSource - Flag indicating source of node label

retrieveLabel

public static NodeLabel retrieveLabel(int nodeID)
                               throws java.sql.SQLException
This method queries the 'node' table for the value of the 'nodelabel' and 'nodelabelsource' fields for the node with the provided nodeID. A NodeLabel object is returned initialized with the retrieved values. WARNING: A properly instantiated and initlaized Vault class object is required prior to calling this method. This method will initially only be called from the WEB UI.

Parameters:
nodeID - Unique identifier of the node to be updated.
Returns:
Object containing label and source values.
Throws:
java.sql.SQLException

retrieveLabel

public static NodeLabel retrieveLabel(int nodeID,
                                      java.sql.Connection dbConnection)
                               throws java.sql.SQLException
This method queries the 'node' table for the value of the 'nodelabel' and 'nodelabelsource' fields for the node with the provided nodeID. A NodeLabel object is returned initialized with the retrieved values.

Parameters:
nodeID - Unique ID of node whose label info is to be retrieved
dbConnection - SQL database connection
Returns:
object initialized with node label & source flag
Throws:
java.sql.SQLException

assignLabel

public static void assignLabel(int nodeID,
                               NodeLabel nodeLabel)
                        throws java.sql.SQLException
This method updates the 'nodelabel' and 'nodelabelsource' fields of the 'node' table for the specified nodeID. A database connection is retrieved from the Vault. WARNING: A properly instantiated and initlaized Vault class object is required prior to calling this method. This method will initially only be called from the WEB UI.

Parameters:
nodeID - Unique identifier of the node to be updated.
nodeLabel - Object containing label and source values.
Throws:
java.sql.SQLException

assignLabel

public static void assignLabel(int nodeID,
                               NodeLabel nodeLabel,
                               java.sql.Connection dbConnection)
                        throws java.sql.SQLException
This method updates the 'nodelabel' and 'nodelabelsource' fields of the 'node' table for the specified nodeID. If nodeLabel parameter is NULL the method will first call computeLabel() and use the resulting NodeLabel object to update the database.

Parameters:
nodeID - Unique identifier of the node to be updated.
nodeLabel - Object containing label and source values.
dbConnection - SQL database connection
Throws:
java.sql.SQLException

computeLabel

public static NodeLabel computeLabel(int nodeID)
                              throws java.sql.SQLException
This method determines what label should be associated with a particular node. A database connection is retrieved from the Vault. WARNING: A properly instantiated and initlaized Vault class object is required prior to calling this method. This method will initially only be called from the WEB UI.

Parameters:
nodeID - Unique identifier of the node to be updated.
Returns:
NodeLabel Object containing label and source values
Throws:
java.sql.SQLException

computeLabel

public static NodeLabel computeLabel(int nodeID,
                                     java.sql.Connection dbConnection)
                              throws java.sql.SQLException
This method determines what label should be associated with a particular node. Algorithm for determining a node's label is as follows: 1) If node has a NetBIOS name associated with it, the NetBIOS name is used as the node's label. 2) If no NetBIOS name available, retrieve all the 'ipinterface' table entries associated with the node with an 'isManaged' field value of 'M' 3) Find the primary interface where "primary" is defined as the managed interface with the smallest IP address (each IP address is converted to an integer value -- the IP address with the smallest integer value wins). 4) IF the primary interface's IP host name is known it becomes the node's label. ELSE IF the node's MIB-II sysName value is known it becomes the node's label ELSE the primary interface's IP address becomes the node's label. NOTE: If for some reason a node has no "managed" interfaces null is returned for the NodeLabel.

Parameters:
nodeID - Unique identifier of the node to be updated.
dbConnection - SQL database connection
Returns:
NodeLabel Object containing label and source values or null if node does not have a primary interface.
Throws:
java.sql.SQLException

loadAddressList

private static void loadAddressList(java.sql.ResultSet rs,
                                    java.util.List ipv4AddrList,
                                    java.util.List ipHostNameList)
                             throws java.sql.SQLException
Utility method for loading the address and host name lists from a result set retrieved from the 'ipInterface' table of the database.

Parameters:
rs - Database result set
ipv4AddrList - List of IPv4Address objects representing the node's interfaces
ipHostNameList - List of IP host names associated with the node's interfaces.
Throws:
java.sql.SQLException - if there is any problem processing the information in the result set.

selectPrimaryAddress

private static IPv4Address selectPrimaryAddress(java.util.List ipv4AddrList,
                                                java.lang.String method)
Returns the primary interface from a list of addresses based on the specified selection method.

Parameters:
ipv4AddrList - List of addresses from which to select the primary interface.
method - String (either "min" or "max") which indicates how the primary interface is to be selected.
Returns:
The IPv4Address object from the address list which has been selected as the primary interface.

toString

public java.lang.String toString()
This method is responsible for returning a String object which represents the content of this NodeLabel. Primarily used for debugging purposes.

Returns:
String which represents the content of this NodeLabel

OpenNMS API 1.2.3

Generated by eevans on May 29 2005 2015.