PolicyObserver - 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 : Registering PolicyObserver
Related files : PolicyObserverExample.java, ExecutePolicyObserverExample.java
Location : <Web NMS Home>/examples/policy

You may require a notification whenever a policy is added, updated, deleted, executed or stopped from execution. This is possible by registering an observer with the policy engine.

Procedure to register as an observer

Two possibilities arise while registering as an observer :

Server and Client on

Server and Client running in the same JVM

When the server and the client run on the same JVM, you use the static method getPolicyAPI() present under NmsClientUtil to get a NmsPolicyAPI handle.
 
com.adventnet.nms.db.NmsPolicyAPIapi=com.adventnet.nms.util.NmsClientUtil.getPolicyAPI();

Server and Client runing in different JVMs

When the server and the client run on different JVMs,  NmsPolicyAPI handle is obtained using RMI lookup
 
com.adventnet.nms.db.NmsPolicyAPIapi= (NmsPolicyAPI) Naming.lookup("//"+hostname+"//NmsPolicyAPI");

Once NmsPolicyAPI handle is got, you register an observer as follows.
 
api.register(Observer);

 
Note : You should take care of the number of TopoObservers as well as the amount of work done by the observers, which might cause performance issues.

For every change in Policy, each observer gets notified with a Properties Object comprising

Action type

intaction-integer.parseInt((String)prop.get("action"));

The following table lists the type of actions.
 
Action Type Description
NmsPolicyAPI_POLICY_ADDED This is for policy addition
NmsPolicyAPI.POLICY_UPDATED This is for policy update
NmsPolicyAPI.POLICY_DELETED This will be the action type when a policy gets deleted from the PolicyEngine
NmsPolicyAPI.POLICY_STOPPED This will be the action type when a policy gets stopped
NmsPolicyAPI.POLICY_EXECUTED This is for policy execution.

Policy Name

String Name= (String)prop.get("name");

Group Name

String GroupName = (String)prop.get("groupName");

Current Status

intcurrentStatus = Integer.parseInt((String)prop.get("currentStatus"));

The following table lists various status possibilities :
 
Status Description
NmsPolicyAPI.POLICY_DISABLED This will be the status, if the policy is in the diaabled state.
NmsPolicyAPI.POLICY_STOPPED If the policy is not under execution, this will be the status.
NmsPolicyAPI.POLICY_SCHEDULED This will be the status, when the policy is under Scheduled state
NmsPolicyAPI.POLICY_EXECUTED When policy is executed, update to observers will be with this policy status.

If you require more properties about the policy, you can do so using NmsPolicyAPI.

Working with the Example

The steps given below will help you in integrating this example with Web NMS. If any of the steps given below are not followed properly, then the example might not function in a desired manner.
Classpath Settings

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

Compiling and Bundling with Web NMS

Compile it over the destination directory using the following syntax in the command prompt.

javac -d <Web NMS Home>/classes PolicyObserverExample.java.

javac -d <Web NMS Home>/classes ExecutePolicyObserverExample.java.

rmic -d <Web NMS Home>/classes test.PolicyObserverExample


Invoking the Example

If Web NMS is running in other hosts execute the following command :

java test.ExecutePolicyObserverExample -h <hostname> -p <RMI Port>

If Web NMS is running in localhost and the RMI registry is running in the default port 1099, no need for passing the arguments. The command for this case will be,

java test.ExecutePolicyObserverExample

Connecting the client

Sample Output

On running the ExecutePolicyObserverExample.java successfully, the following line will be printed on the console : " Register PolicyObserver true".

Upon doing any further operation like adding/deleting/executing/updating a policy, the following lines will be printed :



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