Index Changes
ESB Console Home

How do I figure out all the details about a Target Runtime Environment

For the Trouble-Shooter/Analyst

The JmxExplorer.jar(info) is very useful in figuring out a target environment and can be used to diagnose problems at customer environments.

Run the jar file in an environment and retrieve All MBean information in an output file that is generated when the code is exercised.

There is a wealth of information that can be gleaned analyzing the generated output file, for it not only contains information about the MBeans registered in the target environment, but also the attribute values of all those MBeans.

Just place the jar file in a convenient place on the file system and run:

java -cp .;JmxExplorer.jar org.glassfish.openesb.management.test.Main

You will be prompted to enter host, port, userName, password and name of output file. Once you provide the values, it generates the output file that is an information treasure-trove!

If you use the JRMP port (default 8686) you would not need any other jar file other than the provided JmxExplorer.jar.

If you want to look at the source code, it is checked into the esb-console project at: https://esb-console.dev.java.net/source/browse/esb-console/trunk/JmxExplorer/

There's more you can do if you are a Developer

In-fact if you are a developer and have a penchant for doing more, the JmxExplorer.jar(info) file can be included as a class-library in your programs and can be used to retrieve interesting information about any runtime environmant.

Some operations of interest in the org.glassfish.openesb.management.Explorer class include:

// Retrieves all Object names of MBeans deployed on the target environment
public static final List<ObjectName> findAll(MBeanServerConnection connection);

// Get MBeanInfo of each ObjectName
public static final MBeanInfo getMBeanInfo(MBeanServerConnection connection, ObjectName anObjectName);

// Given a search criteria, search for all MBeans that match it.
// The match can be based on Class Name, Package Name, Attribute Names, Operation Names, Domain Names, etc.
public static final List<ObjectName> findMatchingMBeans(MBeanServerConnection connection, List<ObjectName> objectNames, Map<SearchCriteriaKey, String /*Semi-colon separated values*/> criteriaMap);

For example, the following code-fragment searches the target environment for all MBeans that are:

  1. Implemented by classes that have either "com.stc" or "org.glassfish.openesb" in their package name, or,
  2. Implemented by classes that have "ServerProxyMBean" in their names, or,
  3. Have attributes named either "restartRequired" or "threadPoolSize", or,
  4. Have operations named "getProxyOperation", or,
  5. Are registered with a domain name of either "com.sun.jbi" or "amx" or "org.glassfish"
                Map<SearchCriteriaKey, String /*Semi-colon separated values*/> criteriaMap = new HashMap<SearchCriteriaKey, String /*Semi-colon separated values*/>();

                criteriaMap.put(SearchCriteriaKey.PACKAGE_NAME, "com.stc; org.glassfish.openesb");
                criteriaMap.put(SearchCriteriaKey.CLASS_NAME, "ServerProxyMBean");
                criteriaMap.put(SearchCriteriaKey.ATTRIBUTE_NAME, "restartRequired; threadPoolSize");
                criteriaMap.put(SearchCriteriaKey.OPERATION_NAME, "getProxyOperation");
                criteriaMap.put(SearchCriteriaKey.DOMAIN_NAME, "com.sun.jbi; amx; org.glassfish");

                List<ObjectName> objectNameList = Explorer.findMatchingMBeans(connection, allObjectNamesList, criteriaMap);
                if(objectNameList != null) {
                    for(ObjectName objectName : objectNameList) {
                        System.out.println(objectName.getCanonicalName());
                        MBeanInfo info = Explorer.getMBeanInfo(connection, objectName);
                        System.out.println(Explorer.dump(info));
                    }
                }

The following is a typical code sample of exercising the library:

package org.glassfish.openesb.management.test;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.management.MBeanInfo;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;

import org.glassfish.openesb.management.CapsJmxObjectNames;
import org.glassfish.openesb.management.Explorer;
import org.glassfish.openesb.management.Utilities;
import org.glassfish.openesb.management.client.ConnectionFactory;
import org.glassfish.openesb.management.data.io.ExplorerWriter;

/**
 * Code sample to:
 *    1. List all MBeans and their information in a target environment
 *    2. For all the MBeans in the target system, find and display all information about  
 *       MBeans whose class implementations have "com.stc" as part of their package name
 * 
 * @author graj
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        String hostName = Utilities.getUserInput("Enter Instance host name <localhost> :", "localhost");
        String portString = Utilities.getUserInput("Enter Instance administration port <8686> :", "8686");
        String userName = Utilities.getUserInput("Enter user name :", null);
        String password = Utilities.getUserInput("Enter user password  :", null);
        int port = new Integer(portString);
        String outputFileName = Utilities.getUserInput("Enter output file name <output.txt>  :", "output.txt");

        File outputFile = null;
        outputFile = new File(outputFileName);
        try {
            outputFile.createNewFile();
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }

        MBeanServerConnection connection = null;
        ObjectName anObjectName = null;
        List<ObjectName> objectNameList = new ArrayList<ObjectName>();
        boolean result = false;
        MBeanInfo info = null;

        connection = ConnectionFactory.getInstance(hostName, port, userName, password);
        if (connection != null) {
            System.out.println("Connection Successful.");
            try {
                anObjectName = CapsJmxObjectNames.getServerProxyMBeanObjectName();
                result = connection.isRegistered(anObjectName);
                if (result == true) {
                    System.out.println(CapsJmxObjectNames.SERVER_PROXY_MBEAN_NAME + " is registered.");
                } else {
                    System.out.println(CapsJmxObjectNames.SERVER_PROXY_MBEAN_NAME + " is NOT registered.");
                }
                objectNameList = Explorer.findAll(connection);
                if (objectNameList != null) {
                    String contents = "";
                    // Write as XML file
                    try {
                        contents = ExplorerWriter.serialize(connection, objectNameList);
                        ExplorerWriter.setContents(new File(outputFileName + ".xml"), contents);
                    } catch (ParserConfigurationException ex) {
                        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (TransformerException ex) {
                        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
                System.out.println("***************************************************");
                Map<SearchCriteriaKey, String /*Semi-colon separated values*/> criteriaMap = new HashMap<SearchCriteriaKey, String /*Semi-colon separated values*/>();
                criteriaMap.put(SearchCriteriaKey.PACKAGE_NAME, "com.stc");
                objectNameList = Explorer.findMatchingMBeans(connection, objectNameList, criteriaMap);
                if(objectNameList != null) {
                    for(ObjectName objectName : objectNameList) {
                        System.out.println(objectName.getCanonicalName());
                        info = Explorer.getMBeanInfo(connection, objectName);
                        System.out.println(Explorer.dump(connection, objectName, info));
                    }
                }
            } catch (IOException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            } catch (MalformedObjectNameException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            System.out.println("Connection Failed.");
        }
    }
}

The XML output generated is of the form:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<EnvironmentExplorer xmlns="http://java.sun.com/xml/ns/esb/management/EnvironmentExplorer" version="1.0">
    <MBean className="javax.management.MBeanServerDelegate" description="Represents  the MBean server from the management point of view." objectName="JMImplementation:type=MBeanServerDelegate">
        <Descriptor valid="true"/>
        <Attribute description="The MBean server agent identification" isA="false" name="MBeanServerId" readable="true" type="java.lang.String" value="Precision-M6400_1271390413120" writable="false">
            <Descriptor valid="true"/>
        </Attribute>
        <Attribute description="The full name of the JMX specification implemented by this product." isA="false" name="SpecificationName" readable="true" type="java.lang.String" value="Java Management Extensions" writable="false">
            <Descriptor valid="true"/>
        </Attribute>
        <Attribute description="The version of the JMX specification implemented by this product." isA="false" name="SpecificationVersion" readable="true" type="java.lang.String" value="1.4" writable="false">
            <Descriptor valid="true"/>
        </Attribute>
        <Attribute description="The vendor of the JMX specification implemented by this product." isA="false" name="SpecificationVendor" readable="true" type="java.lang.String" value="Sun Microsystems" writable="false">
            <Descriptor valid="true"/>
        </Attribute>
        <Attribute description="The JMX implementation name (the name of this product)" isA="false" name="ImplementationName" readable="true" type="java.lang.String" value="JMX" writable="false">
            <Descriptor valid="true"/>
        </Attribute>
        <Attribute description="The JMX implementation version (the version of this product)." isA="false" name="ImplementationVersion" readable="true" type="java.lang.String" value="1.6.0_18-b07" writable="false">
            <Descriptor valid="true"/>
        </Attribute>
        <Attribute description="the JMX implementation vendor (the vendor of this product)." isA="false" name="ImplementationVendor" readable="true" type="java.lang.String" value="Sun Microsystems" writable="false">
            <Descriptor valid="true"/>
        </Attribute>
        <Notification description="Notifications sent by the MBeanServerDelegate MBean" name="javax.management.MBeanServerNotification" notificationTypes="JMX.mbean.unregistered;JMX.mbean.registered;">
            <Descriptor valid="true"/>
        </Notification>
    </MBean>
    <MBean className="com.sun.esb.eventmanagement.impl.EventForwarderMBean" description="Event Forwarder DynamicMBean" objectName="EventManagement:name=EventForwarderMBean">
        <Descriptor valid="true"/>
....
....
....
        <Operation description="" impact="3" name="getConfigBeanObjectName" returnType="javax.management.ObjectName">
            <Descriptor valid="true">
                <Field fieldName="bean" fieldValue="MBEAN"/>
                <Field fieldName="descriptorType" fieldValue="operation"/>
                <Field fieldName="displayname" fieldValue="getConfigBeanObjectName"/>
                <Field fieldName="name" fieldValue="getConfigBeanObjectName"/>
                <Field fieldName="role" fieldValue="operation"/>
            </Descriptor>
            <Parameter description="" name="param1" order="1" type="com.sun.enterprise.config.ConfigBean">
                <Descriptor valid="true"/>
            </Parameter>
        </Operation>
    </MBean>
</EnvironmentExplorer>

The generated XML can be parsed using:

        import org.glassfish.openesb.management.data.io.ExplorerReader;
        import org.glassfish.openesb.management.data.model.EnvironmentMeta;
        ....
        ....
        ....
        try {
            String uri = "E:/workspace/esb-console/JmxExplorer/output.txt.xml";
            EnvironmentMeta report = ExplorerReader.parseFromFile(uri);
            System.out.println(report.getDisplayString());
        } catch (MalformedURLException ex) {
            Logger.getLogger(ExplorerReader.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParserConfigurationException ex) {
            Logger.getLogger(ExplorerReader.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SAXException ex) {
            Logger.getLogger(ExplorerReader.class.getName()).log(Level.SEVERE, null, ex);
        } catch (URISyntaxException ex) {
            Logger.getLogger(ExplorerReader.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(ExplorerReader.class.getName()).log(Level.SEVERE, null, ex);
        }

Back to How-Tos


Number of visits: 42

JSPWiki v2.4.100
[RSS]
« Home Index Changes Prefs
This page (revision-20) was last changed on 17-Apr-10 09:27 AM, -0700 by Gopalan Suresh Raj