Shalini's Weblog

« Cisco Disco | Main | Photos »

GlassFish : Self Management Rules

Thursday Jan 19, 2006

Self Management is an initiative taken in GlassFish to reduce the complexity of the management tasks. Mundane management tasks are automated by means of self-configuring. System Administrators who are responsible for monitoring the application server for unpredictable conditions no longer have to detect them manually. This is an easy-to-use feature that comes in handy at the unpredictable run-time conditions. This feature enables to recover from failures by detecting and preventing them, thus improving availability (self-healing). Even security threats are detected and self-protective actions are taken in response. The framework has been developed using standard technologies.

Self Management comprises of a set of management rules. You could create different rules based on the various event types. As mentioned at glassfish.dev.java.net, the different type of events are as follows.

  • Lifecycle events
  • Monitor events
  • Log events
  • Trace events
  • Timer events
  • Notification events
This blog is more about how to create management rules easily. I will show examples for some of the different type of rules. The action we take in response to the occurrence of an event, could be anything from sending an email notification to displaying an alert or killing some processes depending on what is appropriate for the particular event.

Let us take an example of displaying a pop-up window as an alert. Action mBeans implement the NotificationListener interface. The handleNotification() method for our action will look like the following.

    public synchronized void handleNotification(Notification notification,Object handback) {
        try {
            JFrame. setDefaultLookAndFeelDecorated(true);
            JFrame myFrame = new JFrame("MyAction");
            myFrame. setSize(250, 180);
            myFrame. setLocation(300,200);
            myFrame. getContentPane().add( new Label("Action has been invoked",Label.CENTER), BorderLayout.CENTER);
            myFrame. setVisible(true);
            myFrame. show();
        } catch (Exception ex) { // Log the exception }
    }

Let us name this class as CustomAction which is in the com.sun.myrule.action package. It has a corresponding CustomActionMBean. Follow these steps to deploy the action on the application server.

1. Compile the files and make a jar out of these two files.

2. After starting the application server, open the admin console by typing http://localhost:4848 on a browser.



Figure1: Admin Console


3. On the left pane, click on "Custom MBeans". On the right pane, all the deployed mbeans are listed. To deploy our action mbean, click on Deploy. Select the jar file that you just created against the "File to upload" column and click Next.



Figure2: Custom MBeans




Figure3: Creating Custom MBeans


4. Enter a name for the mbean. This will later be used while creating the rule. Enter name as "CustomAction".

5. Enter the class name along with the package name. In this case, it is com.sun.myrule.action.CustomAction.



Figure4: Creating Custom MBeans: Step 2


6. Click Finish.

The action mbean is successfully deployed on the application server.

We will use the same action mbean for all the rules. This action mbean will be called each time an event is triggered. For more information on actions, refer to actions section in glassfish.dev.java.net

Now let us proceed and create rules.

Simple rules for creating a rule:

1. Identify the event type you need. For example : lifecycle
2. Identify the mandatory and optional properties for that event type. For example : lifecycle event requires a property called "name".
3. Identify the action mbean you would like to use for your rule.
4. You could use the Application server Command line interface (CLI) or the Graphical user interface (GUI) to create rules.
5. Make sure the server is started before proceeding with rule creation.

Example 1 : Assuming the administrator wants to be notified everytime the application server shuts down or is terminated because of a failure. Continuous monitoring is necessary for this kind of a situation. Therefore, a rule could be created mentioning a notification to be sent to the administrator when this event is triggered. Management rule bundles together the event and the action.

Let us examine how this rule could be created.

After starting the application server with the command "asadmin start-domain", use either CLI or GUI to create the rule.

CLI mode :

/bin/asadmin create-management-rule
--host localhost --port 4848 --user admin
--action CustomAction
--eventtype lifecycle
--eventloglevel WARNING --eventproperties name=shutdown
my_lifecycle_rule

GUI mode :

  • Start admin console by typing http://hostname:port on a browser, after starting the application server.
  • Go to the Management Rules tab under the Configurations tab in the left pane. This displays the list of rules deployed on the server on the right pane.




  • Figure5 : Management Rules


  • Click on New
  • Type the name of the rule as "my_lifecycle_rule".
  • Check the Status checkbox to enable the rule.
  • Enter description
  • Choose event type as lifecycle.
  • Click on Next if you are done with this page.




  • Figure6 : New Management Rule


  • In the next page, select "shutdown" against Event and enter a description if desired.
  • Select "CustomAction" listed in the action list box and click Finish.




Figure7 : New Management Rule : Step 2


The rule is successfully created and is deployed on the application server. The action will be triggered everytime the application server shuts down. Similarly, rule could be configured to take some action on ready and termination.

Example 2 : The administrator wants to be beeped once in a while regarding some status. A rule could be created to do this as follows.

CLI mode :

/bin/asadmin create-management-rule
--host localhost --port 4848 --user admin
--action CustomAction
--eventtype timer
--eventloglevel INFO
--eventproperties pattern=MM\\/dd\\/yyyy\\/HH\\:mm\\:ss:
datestring=01\\/20\\/2006\\/12\\:00\\:00:
period=30000000:
message=Hello
my_timer_rule

Note here that "/" and ":" are escape sequences. Period, mentioned in milliseconds, is the period after which the notification is to be sent after the date mentioned in datestring.

GUI mode :
  • Start admin console by typing http://hostname:port on a browser, after starting the application server.
  • Go to the Management Rules tab under the Configurations tab in the left pane. This displays the list of rules deployed on the server on the right pane.
  • Type the name of the rule as "my_timer_rule".
  • Check the Status checkbox to enable the rule.
  • Enter description
  • Choose event type as timer.
  • Click on Next if you are done with this page.
  • Enter the values for datestring, pattern and other fields.
  • Select "CustomAction" listed in the action list box and click Finish.
Another example of a rule to monitor the runtime memory of the JVM can be found here .

Like this post? del.icio.us | furl | slashdot | technorati | digg
Comments:

How do you capture the log events broadcasted by Glassfish ....no documentation on that

Posted by akhilesh on March 04, 2008 at 11:51 PM IST #

Can you publish the code of the "corresponding MBean". This would help to find out how to capture the log events ...

Posted by batzee on March 06, 2008 at 03:43 PM IST #

The log events could be captured by setting the type to "log". The corresponding attributes are "loggerName" and "level".

Posted by Shalini on March 13, 2008 at 04:24 PM IST #

Post a Comment:
  • HTML Syntax: NOT allowed