Customizing the PolicyObjectUI - 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 :
-
Periodic Policies - Policies
are triggered periodically by the server at the specified time interval.
By default, the periodic policies are configured to be executed in the
interval of 10 seconds.
-
Non-periodic Policies
- Policies are executed at the specified time. In this case, there is no
fixed time interval. You need to specify the time at which the policy has
to be executed. No default value is assigned for non-periodic policies.
For more details, refer to the
following section of our documentation :
Developer Guide --> Policy
Framework
Example Overview
Example name : Customizing
the PolicyObject UI
Related files : ExamplePolicyCustomizer.java
and ExamplePolicy.java
Location :
<Web
NMS Home>/examples/policy
By default a UI has been
provided for viewing the PolicyObject properties. If you want to have your
own UI, you can plugin your own UI forms. This example explains how this
can be done using the PolicyObjectCustomizer.
How to plugin your own property form
?
Follow the steps detailed
below to define your own property form :
-
Write a class extending com.adventnet.nms.ui.PolicyObjectCustomizer.
You need to override the following three methods :
-
public abstract void init(Properties
p);
-
public abstract Window getCustomizer();
-
public abstract Properties getProperties()
The method init(Properties p)
will be called first, before instantiating the customizer to pass the required
PolicyObject properties.
-
Construct a GUI and return
it as "Window" Object so that Web NMS takes care of making it visible.
-
Instantiate your customizer
class. Upon doing this, a Property change listener will be added to your
class.
-
After finishing all your modifications
make your component invisible and fire the property changed event by calling
the method firePropertyChange(). This is to initimate that all the modifications
have been completed.
-
After listening to the Property
changed event, Web NMS will get back the modified properties by calling
the method getProperties(). At this point, you need to return the modified
properties through the getProperties() method.
-
Web NMS finally updates the
Policy with modified properties.
You need to write two java files,
one to define your own customizer class and the other to invoke the customizer
class. Here, in this example, the ExamplePolicyCustomizer.java file
is used to construct a GUI and pass it as a Window Object to the Policy
Client. The ExamplePolicy.java is for invoking the customizer class.
Code Snippet
The following code snippets
would help you in defining your own property forms :
The init (Properties p
) method will be called first, before instantiating the customizer
to pass the required PolicyObject properties.
| public void init(Properties
p)
{
this.prop = p;
} |
The getCustomizer()
method actually returns a window to be displayed for the PolicyObject.
You can construct a GUI as per your requirement and can pass your GUI as
a Window Object to the PolicyClient. Then PolicyClient will take
care of displaying the Window for the corresponding PolicyObject.
public Window getCustomizer()
{
return getGUI();
} |
Once you complete all the
modifications in the property form, it is required to fire the PropertyChanged
Event in addition to disposing the customizer Window, to intimate the PolicyClient
that all modification has been done. If you do not want to save the
changes, simply dispose the window.
public void actionPerformed(ActionEvent
ae)
{
if(ae.getActionCommand().equals("Sumbit"))
{
prop.put("message",textarea.getText());
dialog.dispose();
this.firePropertyChange();
} |
Once the PolicyClient listens
to the PropertyChanged Event, it get backs the modified properties by the
method getProperties()
public Properties getProperties()
{
return this.prop;
} |
User written customizer class
can be mentioned in the method getPolicyObjectCustomizer() of the corresponding
PolicyObject. This method is defined in the ExamplePolicy.java
file, which is used to invoke the ExamplePolicyCustomizer class.
public String getPolicyObjectCustomizer()
{
return test.policy.policyui.ExamplePolicyCustomizer;
} |
Using
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.
The user defined file is
compiled and the class files are placed under the directories <Web NMS
Home>/ classes/test/policy/policies and <Web NMS Home>/classes/test/policy/policyui.
Then the customizer class file is bundled into the NmsClientClasses.jar
file. The ExamplePolicy class name should be entered into the Policy.conf
file, to invoke the user defined policy.
The following steps are to
be followed to use the user defined Policy from the policies of Web
NMS Client.
Classpath Settings
Set the class path as set
classpath= <Web NMS Home >/classes,
<Web NMS Home>/classes/NmsClientClasses.jar for compiling the ExamplePolicyCustomizer.java
file and ExamplePolicy.java file.
Compiling and Bundling with Web NMS
Compile the java files from
<Web NMS Home>/examples/policy directory using the following command
javac -d ../../classes
ExamplePolicyCustomizer.java and
javac -d ../../classes
ExamplePolicy.java
-
The ExamplePolicyCustomizer
class file will be created under <Web NMS Home >/ classes/test/policy/policyui
directory and the ExamplePolicy class file will be created under <Web
NMS Home >/ classes/test/policy/policies directory.
-
You have to bundle the ExamplePolicyCustomizer.class
file into the NmsClientClasses.jar file using the following command from
<Web NMS Home>/classes directory
jar -uvf NmsClientClasses.jar/test/policy/policyui/ExamplePolicyCustomizer.class
The above command will include
the class required to invoke the ExamplePolicyCustomizer.java file.
Invoking the Example
-
The following entry should be
made in Policy.conf file under <Web NMS Home>/conf directory.
<POLICY_CONF>
<POLICY_LIST>
----------------------------
<POLICY
classname="test.policy.policies.ExamplePolicy"
display_name="ExamplePolicy"
/>
</POLICY_LIST>
</POLICY_CONF>
-
Make an entry for this policy
in relationalclasses.conffile as shown below.
test.policy.policies.ExamplePolicy
policydb RelationalPolicyObject PolicyObject
-
Start the Web NMS Server
-
Start the client.
-
To view the change on the Web
NMS Client, select the policies and right click it.
-
From the pop-up menu select
the "AddPolicy" menu item.
-
The AdventNet Add Policy details
form gets displayed. In that form, the ExamplePolicy gets included
in the policy list (along with other policies), as specified in the policy.conf
file.
-
Choose the ExamplePolicy and
click on add.
-
The ExamplePolicyCustomizer
form gets displayed instead of the default screen.
-
After entering the values for
the GroupName and Message in the customizer click on submit thereby adding
the new policy.
Sample Output
The image shown below, is the
user-defined event details form invoked from the events panel of Web NMS
Client.

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