Index Changes
This is version 3. It is not the current version, and thus it cannot be edited.
[Back to current version]   [Restore this version]
ESB Console Home

How do I enable Alerting For a standalone Fuji instance

To enable Alerting For a standalone Fuji instance, you need the following:

  1. Make sure to prepare the backend as described in How to enable Common Management and Monitoring support for a standalone Fuji instance

You would then need to use the Common Management and Monitoring API and write client code to access the functionality.

  • You will need jbi-admin-common.jar in your client side classpath
  • Include the extended.management.api.core archive that enables the extended core management client side API in your client side classpath - can be built from esb-console/extended/api/extended.management.api.core - and include it in your client classpath.
  • To receive alerts, you need to include the extended.management.api.alerts archive in your client side classpath - this enables alert reception, and alert management client side API - it can be built from esb-console/extended/api/extended.management.api.alerts - in you client side classpath.

Download

It is always better to Checkout and Build from scratch. However, if you want to try out the Management and Monitoring capabilities without having to build it from scratch, I will infrequently upload a jar file at my convenience that you can download from here alert-client.jar(info) that you can test according to instructions mentioned below:

Installation

Step 1: - Download and extract the pre-built jars

Extract the jar into a directory of your choice:
jar -xvf alert-client.jar
The contents are expanded to a core folder which has an backend folder that contains the fuji-management archive, and the FujiEventManagementWebApp archive. There is also a client folder that contains the archives that have to be included in your client classpath for you to exercise the management capabilities remotely, viz., jbi-admin-common.jar, and the extended.management.api.core archive.
 Directory of E:\client

09/17/2009  11:16 AM    <DIR>          .
09/17/2009  11:16 AM    <DIR>          ..
08/30/2009  05:04 AM           163,296 extended.management.api.alerts.jar
08/30/2009  07:23 PM           482,316 extended.management.api.core.jar
09/03/2009  03:10 PM            76,900 extended.management.api.samples.jar
05/14/2009  01:20 AM           360,075 jbi-admin-common.jar
09/17/2009  11:16 AM               787 run.bat
               5 File(s)      1,083,374 bytes

Start the Standalone Fuji instance making sure you provide an environment variable called com.sun.jbi.fuji.admin.jmx.connectorPort which points to a port that you'd like to use as your RMI Administration connector as shown. For e.g., as follows:

java -jar -Dcom.sun.jbi.fuji.admin.jmx.connectorPort=8585 ./bin/felix.jar

You can then exercise the management and monitoring capabilities of the runtime using the management and monitoring API. Make sure you client side code includes the mandatory client jars available in the client folder in addition to any other jar file you use in your client classpath.


Alerting Client Java Source Sample: TestAlertNotificationListener.java


This is the client sample to subscribe for alerts.
package org.glassfish.extended.management.sample.impl.alerts;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.glassfish.openesb.extended.management.api.alerts.Alert;
import org.glassfish.openesb.extended.management.api.alerts.AlertNotificationService;
import org.glassfish.openesb.extended.management.api.alerts.AlertsManagementService;
import org.glassfish.openesb.extended.management.client.ExtendedManagementClient;
import org.glassfish.openesb.extended.management.client.ExtendedManagementClientFactory;
import org.glassfish.openesb.extended.management.common.ExtendedManagementRemoteException;


/**
 *
 * @author gopalan
 */
public class TestAlertNotificationListener {
    String                   dasPort;

    String                   dashostname;

    String                   dasUser;

    String                   dasPassword;

    AlertsManagementService  managementService;

    AlertNotificationService notifService;

    ExtendedManagementClient     client;

    String                   subscriptionID;

    List                     idList    = new ArrayList();

    Map                      filterMap = new HashMap();


    /**
     * @throws ExtendedManagementRemoteException
     *
     */
    public TestAlertNotificationListener() throws ExtendedManagementRemoteException {
        init();
    }

    public boolean init() throws ExtendedManagementRemoteException {
        boolean valid = false;
        dashostname = getUserInput(" enter DAS host name <localhost> :",
                "localhost");
        dasPort = getUserInput(" enter DAS http port <4848> :", "4848");
        dasUser = getUserInput("  enter user name <admin> :", "admin");
        dasPassword = getUserInput(" enter user password <adminadmin>  :",
                "adminadmin");
        int port = new Integer(dasPort);
        client = ExtendedManagementClientFactory.getInstance(dashostname, port,
                dasUser, dasPassword);
        if (client != null) {
            System.out.println("Management Client is valid.");
            valid = true;
            managementService = client.getService(org.glassfish.openesb.extended.management.api.alerts.AlertsManagementService.class);
            notifService = managementService.getAlertNotificationService();
            if (notifService == null) {
                valid = false;
                System.out
                        .println("Could not obtain Alert Management Notification service");
            }
        } else {
            System.out.println("Could not obtain the Management Client.");
            valid = false;
        }
        return valid;
    }

    public String getUserInput(String message, String defaultValue) {
        String returnvalue = "";
        System.out.println(message);
        try {
            returnvalue = new BufferedReader(new InputStreamReader(System.in))
                    .readLine();
            if (returnvalue.length() == 0) {
                returnvalue = defaultValue;
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return returnvalue;

    }

    public void subscribe(String[] targets) throws Exception {
        subscriptionID = notifService.subscribe(new HashMap<String, String>(),
                targets, this, "eventProcessCallBack", new Boolean(true), this,
                "exceptionProcessCallBack");
        System.err.println(" subcription id is " + subscriptionID);
    }

    public void eventProcessCallBack(Alert alert) {
        System.out.println(" ---> alert received <-----");
        System.out.println("alert date :" + alert.getAlertDateString());
        System.out.println("alert severity :" + alert.getAlertSeverity());
        System.out.println("alert message code :" + alert.getAlertMessageCode());
        System.out.println("alert server name :" + alert.getAlertServer());
        System.out.println("alert message details :"
                + alert.getAlertMessageDetails());
        System.out.println("alert component name :" + alert.getAlertComponentName());
        System.out.println("alert component project path :" + alert.getAlertComponentProjectPath());
        System.out.println("alert component type :" + alert.getAlertComponentType());
        System.out.println("alert deployment :" + alert.getAlertDeployment());
        System.out.println("alert environment :" + alert.getAlertEnvironment());
        System.out.println("alert logical host :" + alert.getAlertLogicalHost());
        System.out.println("alert physical host :" + alert.getAlertPhysicalHost());
        System.out.println("alert server type :" + alert.getAlertServerType());
        System.out.println("alert state :" + alert.getAlertState());
        System.out.println("alert status :" + alert.getAlertStatus());
        System.out.println("alert type :" + alert.getAlertType());


    }

    public void exceptionProcessCallBack(Exception e) {
        System.out.println("exception  details :\n");
        e.printStackTrace();

    }

    public void unsubscribe() {
        if (subscriptionID == null) {
            return;
        }
        String[] SubscriptionIDs = { subscriptionID };
        try {
            notifService.unsubscribe((String[]) SubscriptionIDs);
            subscriptionID = null;
        } catch (ExtendedManagementRemoteException exception) {
            int index = 0;
            String[] causes = exception.getCauseMessageTrace();
            for (String cause : causes) {
                System.out.println("Cause #" + (++index) + ": " + cause);
            }
        }

    }

    private void execCommand(String cmd) throws Exception {
        try {
            if (cmd.toLowerCase().equals("reg")) {
                subscribe(null);
            } else if (cmd.toLowerCase().equals("unreg")) {
                unsubscribe();
            }
        } catch (ExtendedManagementRemoteException exception) {
            int index = 0;
            String[] causes = exception.getCauseMessageTrace();
            if(causes != null) {
                for (String cause : causes) {
                    System.out.println("Cause #" + (++index) + ": " + cause);
                }
            }
        }

    }

    public String displayOptions() throws Exception {
        String cmd = "";
        init();

        while (true) {
            System.out
                    .println("valid opeartions:\n"
                            + " REG - subscribe client for notification no filter and targets optional (comma delimited string) (can be called multiple time -return ID for each) \n"
                            + " UNREG - unsubscribe client from receiving notification\n"
                            + " EX - to exit the program ");
            System.out.println("Please Select opertion:");

            cmd = new BufferedReader(new InputStreamReader(System.in))
                    .readLine();
            String[] validOption = { "reg", "unreg", "ex" };
            boolean valid = false;
            for (String option : validOption) {
                String testCmd = cmd.toLowerCase();
                if (testCmd.startsWith(option)) {
                    valid = true;
                    break;
                }
            }

            if (valid == false) {
                System.out.println();
                System.out.println();
                System.out.println();
                displayOptions();
            } else {
                System.out.println();
                System.out.println();
                System.out.println("the command is = " + cmd);
                System.out.println();
                System.out.println();
                if (cmd.equalsIgnoreCase("ex")) {
                    unsubscribe();
                    System.exit(0);
                } else {
                    execCommand(cmd);
                }
            }

        }
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        try {
            TestAlertNotificationListener test = new TestAlertNotificationListener();
            test.displayOptions();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}




Back to to How Tos


Number of visits: 14

JSPWiki v2.4.100
[RSS]
« Home Index Changes Prefs
This particular version was published on 17-Sep-09 11:23 AM, -0700 by Gopalan Suresh Raj