rss
SOATUBE
Oracle
Custom Search SOABYTE here

Thursday, December 11, 2014

Oracle BPEL using JMX and MBeans

Oracle BPEL using JMX n MBeans

About JMX:

JMX (Java Management Extension) is part of J2SE 5.0 and meant to programmatically  manage and monitor application resources, Service Oriented Networks and Systems objects.   Refer the Wiki : http://en.wikipedia.org/wiki/Java_Management_Extensions

About MBeans:

MBeans, short  form of MangedBeans are used to represent the resources in jvm, java applications and application servers  through java objects. So, with the combination of JMX (Java programming APIs) and MBeans (java objects that are representing the resources such as Transaction monitors, JDBC Drivers and Printers and many more) we can collect/extract statistics related to performance, resource usages, and many more for the resources running in JVM.  Refer the Wiki: http://en.wikipedia.org/wiki/Java_Management_Extensions#Managed_Bean

This blog is meant to give some pointers/apis to fetch the details of resources (such as BPEL Domains, BPEL Servers, BPEL Composites, BPEL Composite configurations etc) hosted in Weblogic application server.  Have fun …

Topic

1)- Get BPEL Domains and Managed servers (weblogic) using JAVA 
2)- Get BPEL Composites hosted on Weblogic server
3)- Get BPEL Composite revisions
4)- Get all callable services (references) of a given BPEL Composite

1)- How to get BPEL Domains, managed servers, their restart dates and status :

public class PPKBPELExtraction {
    //Make sure to define below properties based on your BPEL Domain/Manged server setups.
    String host;
    String port;
    String userName;
    String pwd;
    String webserverHost;
    String defaultDomain;
    String bpel_listner_port;
    String bpel_listner_host;

            JMXServiceURL jmxServiceURL = null;
       Hashtable<String,String> jmxJNDIProperties = new Hashtable<String, String>();     
       JMXConnector jmxConnector = null;
       MBeanServerConnection mBeanServerConnection = null;    
       Hashtable<String, String> mBeanQueryStrings = new Hashtable<String, String>();
       String uriForDomainConfig = "/jndi/weblogic.management.mbeanservers.domainruntime";
       JMXConnector jmxConnectorForDomainConfig = null;
       MBeanServerConnection mBeanServerConnectionForDomainConfig = null;
       Hashtable<String,String> jmxJNDIPropertiesForDomainConfig = new Hashtable<String, String>();       
       JMXServiceURL jmxServiceURLForDomainConfig = null;
       SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");

public void getDomainDetails() {
       writeToLog(" getDomainDetails() => ");
              try {                                    
                     jmxServiceURLForDomainConfig = new JMXServiceURL("t3",this.host,Integer.parseInt(this.port),uriForDomainConfig);
                     jmxJNDIPropertiesForDomainConfig.put(Context.SECURITY_PRINCIPALthis.userName);
                     jmxJNDIPropertiesForDomainConfig.put(Context.SECURITY_CREDENTIALSthis.pwd);
                     jmxJNDIPropertiesForDomainConfig.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES"weblogic.management.remote");                  
                     jmxConnectorForDomainConfig = JMXConnectorFactory.connect(jmxServiceURLForDomainConfigjmxJNDIPropertiesForDomainConfig);
                     mBeanServerConnectionForDomainConfig = jmxConnectorForDomainConfig.getMBeanServerConnection();
              } catch (Exception expGetDomainDetails) {
                     writeToLog("expGetDomainDetails : " + expGetDomainDetails.toString());
              }
              String queryString = "com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean";
       ObjectName domainObject = null;
       ObjectName domainObjectName = null;
       String domainName = null;
       Date activationDate = null;
              ObjectName[] serverObjects;
              int length = 0;
              String serverName;
              String serverState;
        
       try {
              ObjectName objectName = new ObjectName(queryString);
              Set<ObjectName> objectNameSet =mBeanServerConnectionForDomainConfig.queryNames(objectName, null);
              Iterator<ObjectName> objectNameSetIterator = objectNameSet.iterator();
              while (objectNameSetIterator.hasNext()){
                     domainObject = objectNameSetIterator.next();
                     domainObjectName = (ObjectName) mBeanServerConnectionForDomainConfig.getAttribute(domainObject,"DomainRuntime");
                     domainName = (String) mBeanServerConnectionForDomainConfig.getAttribute(domainObjectName,"Name");
                     activationDate = (Date) mBeanServerConnectionForDomainConfig.getAttribute(domainObjectName, "ActivationTime");
                     serverObjects = (ObjectName[]) mBeanServerConnectionForDomainConfig.getAttribute(domainObject,"ServerRuntimes");
                     length = serverObjects.length;
                     Vector<Server> tmpServer = new Vector<Server>();
                     for (int i = 0; i < length; i++) {
                         serverName = (String) mBeanServerConnectionForDomainConfig.getAttribute(serverObjects[i], "Name");
                         serverState = (String) mBeanServerConnectionForDomainConfig.getAttribute(serverObjects[i],"State");
                         tmpServer.add(new Server(domainName,serverName,null,serverState));
                     }
                     this.domains.add(new Domain(domainName, activationDate,this.type,tmpServer));
                     this.defaultDomain = domainName;
                     tmpServer = null;
                     domainObject = null;
              } 
              objectNameSetIterator = null;
              objectNameSet = null;
       } catch (Exception expDomain) {
              this.domains.add(new Domain(this.defaultDomain, (new Date()) ,"",null)); // Incase admin server is down.
              writeToLog("expDomain : " + expDomain.toString());
              writeToLog("Looks like Adminserver is having issues,  so defaulting Admin server activation date with sysdate");
       }
            try {
                     if (jmxConnectorForDomainConfig != null)
                           jmxConnectorForDomainConfig.close();
                           jmxJNDIPropertiesForDomainConfig = null;
                           jmxConnectorForDomainConfig = null;
                           mBeanServerConnectionForDomainConfig = null;
              } catch (Exception expClose) {
                     writeToLog("expClose : " + expClose.toString());
              }
              writeToLog(" <= getDomainDetails()");
    } 

2)- How to get bpel composites hosted in Weblogic managed server?

    public void fetchBPELComposite() {
        ObjectName compositeObjectName = null;
        String dn = null;
        Iterator<ObjectName> iterator = null;
        Set<ObjectName> queryObjectName = null;
        EndPoint endPoint = null;
        String compositeName = null
        String revision = null;
        String compositeName1 = null;
       try {
            ObjectName queryObject = new ObjectName("oracle.soa.config:j2eeType=SCAComposite,Application=soa-infra,*");
            queryObjectName = mBeanServerConnection.queryNames(queryObject, null);
            iterator = queryObjectName.iterator();

            while (iterator.hasNext()) {
              compositeObjectName = iterator.next();
              dn = (String) mBeanServerConnection.getAttribute(compositeObjectName, "DN");
              compositeName = (String) mBeanServerConnection.getAttribute(compositeObjectName, "Name");
            }
       } catch (Exception expGetBPELComposite) {
              writeToLog("getBPELComposite() " + expGetBPELComposite.toString());
       } finally {
            compositeObjectName = null;
            dn = null;
            iterator = null
            queryObjectName = null;
       }      
     }

3)- How to get the default revision of a BPEL Composite

=> In the below api DN is the Compsoite DN name (which you can obtain from Enterprise manager).
       public boolean defaultRevision(String dn) {
              boolean returnValue= false;
              ObjectName queryObject = null;
              ObjectName soaInfra = null;
              Object[] vInputs = {dn};
              String[] vTypes = {String.class.getName()};
              
              try {
                     queryObject = new ObjectName("oracle.soa.config:name=soa-infra,j2eeType=CompositeLifecycleConfig,Application=soa-infra,*");
                     Set<ObjectName> objectNameSet = mBeanServerConnection.queryNames(queryObject, null);
                     Iterator<ObjectName> iterator = objectNameSet.iterator();
                     while (iterator.hasNext()) {
                           soaInfra = iterator.next();
                           returnValue = (Boolean) mBeanServerConnection.invoke(soaInfra, "isDefaultCompositeRevision", vInputs, vTypes);
                     }
              }catch (Exception expIsDefaultRevision ) {
                     returnValue = false;
                     writeToLog("expIsDefaultRevision : "+ expIsDefaultRevision.toString());
              }
              return returnValue;
       }

4)- How to get the services (references) called from given BPEL Composite :

       public void bPELEndSCAReferences(EndPoint pEndPoint, String pCompositeName, String pRevision) {         
       StringBuffer querySB = newStringBuffer("oracle.soa.config:j2eeType=SCAComposite.SCAReference.SCABinding,wsconfigtype=ServiceRefMappingPortInfoConfig,revision=").append(pRevision).append(",Application=soa-infra,SCAComposite=\"");
       querySB.append(pCompositeName+"\",*");
       String query = querySB.toString().trim();
       ObjectName on = null;
       String referenceName = null;
       String referenceWSDL = null;
       Vector<EndPoint> ref = new Vector<EndPoint>();
       EndPoint reference = null;
       try {
              ObjectName qn = new ObjectName (query);
              Set<ObjectName> objectSet = mBeanServerConnection.queryNames(qn, null);
              Iterator<ObjectName> iterator = null;
              iterator = objectSet.iterator();
            while ((iterator != null) && (iterator.hasNext())) {
                 on = iterator.next();
                 referenceName = (String) mBeanServerConnection.getAttribute(on, "PolicySubjectName");
                 referenceWSDL = (String) mBeanServerConnection.getAttribute(on, "Location");
                 reference = new EndPoint(this.defaultDomain, referenceName,null,true,"http","REFERENCE",referenceName,this.rand.nextLong());
                 reference.monitorURL = referenceWSDL;
                 //writeToLog("Domain " + this.defaultDomain +" Composite " + " Reference:" + referenceName +"; wsdl:"+ referenceWSDL);
                 ref.add(reference);
              }             
       } catch (Exception exp) {
              writeToLog("PPK Exception in displayBPELEndSCAReferences()" + exp.toString());
              writeToLog("query string : " + query);
              writeToLog("composite : " + pCompositeName + pRevision);
       }
       if ((pEndPoint.references != null) && (pEndPoint.references.size() > 0))
              pEndPoint.references.addAll(ref);
       else
           pEndPoint.references = ref;
    }


2 comments:

dhilBlog said...

Hi Amiya,

Can you share the import statements in this java file.
I'd like to know which jar file has the 'EndPoint' class file.

Regards,
Adhil

Amiya Kumar said...

Here you go :--

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.management.Attribute;
import javax.management.MBeanServerConnection;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.Query;
import javax.management.QueryExp;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.OpenDataException;

Post a Comment

 
Blogger Profile