Class NodeLabelDaoImpl

  • All Implemented Interfaces:
    NodeLabel

    public class NodeLabelDaoImpl
    extends Object
    implements NodeLabel

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

      • NodeLabelDaoImpl

        public NodeLabelDaoImpl()
        Default constructor
      • NodeLabelDaoImpl

        public NodeLabelDaoImpl​(String nodeLabel,
                                OnmsNode.NodeLabelSource nodeLabelSource)
        Constructor
        Parameters:
        nodeLabel - Node label
        nodeLabelSource - Flag indicating source of node label
    • Method Detail

      • getLabel

        public String getLabel()
        Returns the node label .
        Specified by:
        getLabel in interface NodeLabel
        Returns:
        node label
      • retrieveLabel

        public NodeLabel retrieveLabel​(int nodeID)
                                throws SQLException
        Deprecated.
        Use a NodeDao#load(Integer) method call instead
        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.
        Specified by:
        retrieveLabel in interface NodeLabel
        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 - if any.
      • assignLabel

        @Transactional
        public void assignLabel​(int nodeID,
                                NodeLabel nodeLabel)
                         throws SQLException
        Deprecated.
        Use a NodeDao#update(org.opennms.netmgt.model.OnmsNode) method call instead
        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.
        Specified by:
        assignLabel in interface NodeLabel
        Parameters:
        nodeID - Unique identifier of the node to be updated.
        nodeLabel - Object containing label and source values.
        dbConnection - SQL database connection
        Throws:
        SQLException - if any.
      • computeLabel

        public NodeLabel computeLabel​(int nodeID)
                               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.
        Specified by:
        computeLabel in interface 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 - if any.
      • 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.
        Specified by:
        toString in interface NodeLabel
        Overrides:
        toString in class Object
        Returns:
        String which represents the content of this NodeLabel