org.opennms.netmgt.utils
Class NodeLabel

java.lang.Object
  extended by org.opennms.netmgt.utils.NodeLabel

public class NodeLabel
extends 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
static int MAX_NODE_LABEL_LENGTH
          Maximum length for node label
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
 
Constructor Summary
NodeLabel()
          Default constructor
NodeLabel(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, 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, Connection dbConnection)
          This method determines what label should be associated with a particular node.
 String getLabel()
          Returns the node label .
 char getSource()
          Returns the node label source flag .
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, Connection dbConnection)
          This method queries the 'node' table for the value of the 'nodelabel' and 'nodelabelsource' fields for the node with the provided nodeID.
 void setLabel(String nodeLabel)
          Sets the node label.
 void setSource(char nodeLabelSource)
          Sets the node label source flag
 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

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
Constructor Detail

NodeLabel

public NodeLabel()
Default constructor


NodeLabel

public NodeLabel(String nodeLabel,
                 char nodeLabelSource)
Constructor

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

getLabel

public 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(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 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:
SQLException

retrieveLabel

public static NodeLabel retrieveLabel(int nodeID,
                                      Connection dbConnection)
                               throws 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:
SQLException

assignLabel

public static void assignLabel(int nodeID,
                               NodeLabel nodeLabel)
                        throws 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:
SQLException

assignLabel

public static void assignLabel(int nodeID,
                               NodeLabel nodeLabel,
                               Connection dbConnection)
                        throws 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:
SQLException

computeLabel

public static NodeLabel computeLabel(int nodeID)
                              throws 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:
SQLException

computeLabel

public static NodeLabel computeLabel(int nodeID,
                                     Connection dbConnection)
                              throws 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:
SQLException

toString

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

Overrides:
toString in class Object
Returns:
String which represents the content of this NodeLabel


Copyright © 2009. All Rights Reserved.