NodeDeletePolicy - Example



 

Feature Overview

The word 'policy', in general, refers to a plan of action. Here, in Web NMS context, it refers to executing a task or set of tasks at a specified time based on a set of specified conditions. Policies are tasks that are executed by Web NMS at a system level, at a specified point of time. In Network Management, policies are used to control a variety of network activities like automated backups, routing & prioritization of network traffic, bandwidth allocation, cleaning up database tables, deleting failed nodes, etc.

This policy framework enables scalable administration of the Web NMS server and the network elements managed by it. The primary goal of the policy engine is to enable administration of complex functions easily. In Web NMS, policies can be used to customize the behaviour of the NMS and to provide a framework for adding policies for different network elements.

Web NMS policies can be broadly classified into two categories :

For more details, refer to the following section of our documentation : Developer Guide --> Policy Framework

Example Overview

Example name : NodeDeletePolicy
Related files : NodeDeletePolicy.java
Location : <Web NMS Home>/default_impl/policies

Failed Node Deletion Policy allows you to delete  nodes of status major and critical  in the database,that exists for  more than 7 days without any change in status .

Description

The NodeDeletePolicy class extends PeriodicPolicyObject of com.adventnet.management.policy db package. Policies which need to be called at fixed time interval extend this class.

The methods in NodeDeletePolicy are

This method sets theUser  and Base properties for the policy object.The User Properties which are declared in nodedelete() are  first removed and then set .This is done to avoid duplication of Property names..The User Properties that are set are "delete after days" i.e.,the property name and (ii)"7" the property value. All failed nodes existing in the database for more than 7 days gets deleted. You can set your own property value.
The super.setBaseProperties() " method is invoked to set  the Base Properties. The Base Properties that are  set are GroupName,Status,Help URL and Period of  the policy object.
public Properties getProperties()

The getProperties() method returns the Base and UserProperties.

public String getHelpURL()

The getHelpURL() method returns the  Help URL  of the NodeDeletePolicy object. The URL must be relative to the Help Directory

public String getPolicyObjectCustomizer()

The getPolicyObjectCustomizer() method helps you to invoke your own customizer class if any.

public  void executeAction(PolicyEvent policyEvt)

The executeAction() method is the main method from where the execution of the Policy begins.


Code Snippets

The execution of the Policy starts from this method
 
TopoAPI api = (TopoAPI)NmsUtil.getAPI("Topo");

     if (api == null)

  {

   return;

  }

     Vector nodes = api.getNodes();

     for (Enumeration en = nodes.elements();en.hasMoreElements();)

  {

  Node node = api.getNode((String) en.nextElement());

TopoAPI gives the list of nodes in the database
 
int status = node.getStatus();

............................................................

if ((status != sev1) && (status != sev2))

      continue;

The status of the node is checked. If the status of the node Critical or Major -  the loop continues
 
if ( node.getStatusChangeTime() >

       ((new Date()).getTime() - (24*60*60*1000* deleteAfter)) )

For nodes  with status critical or major, the date and time is fetched .If such nodes exists for more than 7 days (on calculation)  the nodes get deleted provided the node has only one interface. Nodes with multiple interfaces remains in the database and do not get deleted

Working with the Example

Implementation for NodeDeletePolicy has been provided, by default, in Web NMS. So, there is no need for setting classpaths. However, if you want to customize the NodeDeletePolicy.java file you will have to integrate it separately in the following way.

Classpath Settings

Set the classpath as <Web NMS Home>\classes; <Web NMS Home>\ classes\AdventNetFramework.jar;

Compiling and Bundling with Web NMS

Invoking the Example

From Java UI

Sample Output

On successful execution of this policy, if any node with status critical or major remain in the same criticality for more than 7 days, that node will be deleted from the database.


Copyright © 1996-2002, AdventNet Inc. All Rights Reserved.