I remember some years back when Rittman Mead first received the OBIEE 11g beta and I tried installing it for the first time. It was a nightmare. If you think the 184.108.40.206 release was challenging, you should have tried working with any one of the betas. It was with these first few releases that Weblogic was injected into my world. Some time around the first month of starting the beta, I recall Mark Rittman saying something along the lines of: "all the Fusion Middleware stuff looks interesting, but I'm glad we won't have to know anything about that." You see... I just wanted a nice career in BI, but here I am writing a blog post on working with JMX MBeans.
JMX MBeans are complicated, meaning that careers probably exist for working with JMX MBeans and little else. I'm truly sorry to hear that. For the layperson (and by this, I mean people who work in BI), trying to understand MBeans probably ranks somewhere between getting decent service at a restaurant in the UK, and understanding why the Anomaly needs to join with the Source. It's complex enough that most vendors provide utilities to simplify the process... which means using anything other than Java to work with them. For Weblogic, we have Weblogic Scripting Tool (WLST).
WLST is really just a specific implementation of Jython designed into a command-line utility that in many ways feels like SQL-Plus or RMAN. It's designed to work interactively or in scripted fashion, and Rittman Mead has offered up some free WLST scripts to the community over the years via GitHub. If you take a look at our deploy_rpd.py script for example, you can make some sense of how WLST works. I've reworked that script slightly in this post to use hardcoded values instead of variables, to remove the exception handling, etc., to make the logic easier to follow. It's shown here in two parts... the first part which connects to the Weblogic Administration Server and locks the domain:
import sys import os connect('weblogic', 'welcome1', 't3://localhost:7001'); domainCustom() cd ('oracle.biee.admin') cd ('oracle.biee.admin:type=BIDomain,group=Service') print 'Locking the configuration...' objs = jarray.array(, java.lang.Object) strs = jarray.array(, java.lang.String) invoke('lock', objs, strs)
This lock method is equivalent to the "Lock and Edit" button inside Fusion Middleware Control. We use the cd command to navigate to the BIDomain MBean because the lock method (as well as commit and rollback ) is in that MBean. The invoke command is used to execute MBean methods in WLST and accept parameters for those methods. To do this we use generic Object and String arrays because the invoke command is generic and needs to support an ever-changing series of parameters. The rest of the pared script is below:
cd ('..') cd ('oracle.biee.admin:type=BIDomain.BIInstance.ServerConfiguration,biInstance=coreapplication,group=Service') # Set the parameters params = jarray.array(['/mnt/hgfs/stewart/scripts/sugarcrm.rpd','Admin123'],java.lang.Object) # Set the parameters Signs sign = jarray.array(['java.lang.String', 'java.lang.String'],java.lang.String) # Invoke the procedure invoke( 'uploadRepository', params, sign) cd ('..') cd ('oracle.biee.admin:type=BIDomain,group=Service') objs = jarray.array(, java.lang.Object) strs = jarray.array(, java.lang.String) invoke('commit', objs, strs)
In the second part of this script, we navigate to the ServerConfiguration MBean, which contains the uploadRepository method. We populate the params array with the RPD path and RPD password, we upload the repository, and then navigate back to the BIDomain MBean to perform the commit.
WLST strikes me as an attempt to take a programmatic interface, one that is usually accessed through Java, and make it accessible to non-developers. In this regard, I see it as a major failure. The MBean methods have been abstracted to the point of being almost useless. This seems like the exact opposite of simple to me. It seems overly complex to have to construct arrays and populate them just to pass parameters to methods. I would prefer to just pass parameters as, well... parameters. Additionally... notice how we had to cd to the BIDomain MBean, cd away to go use the ServerConfiguration MBean, and then cd back again. I would prefer to use the MBeans the way they were meant to be used... as objects, so we would be able to instantiate and hold multiple MBean objects at the same time.
If WLST is indeed easier to use than Java, then this is quite an indictment of Java. It works pretty well when we are writing processes that are JMX specific... when the commands that we need to issue are all calls to MBeans and nothing else. But what happens if we want to write a process that involves interacting with MBeans as well as some other processes or APIs, such as calls to any of the Oracle BI Server XML API, in a unified script? WLST is terrible at this. In my first attempt at writing something like this, I used Perl to execute both validaterpd commands as well as MBean commands. I ended up having to maintain a separate Jython script along with the Perl script, which didn't sit well with me as a developer. What we really need is a language that is groovy to write and maintain, compiles to pure Java (just like Jython), and has the ability to encapsulate MBeans natively in a similar fashion to WLST. What we need is Groovy.
Groovy is a dynamic language that can be used to write scripts, or write object-oriented packages and classes, and can also be used to compile to Java byte code. Because it's simple to write and has native MBean object handling, it's easier (in my opinion) than WLST. How easy? Well, let's go through our deploy_rpd.py example, and see if it's easier to write and understand. Here's our upload repository script in Groovy:
import javax.management.remote.JMXConnectorFactory import javax.management.remote.JMXServiceURL import javax.naming.Context def h = new Hashtable() h.put(Context.SECURITY_PRINCIPAL, 'weblogic') h.put(Context.SECURITY_CREDENTIALS, 'welcome1') h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote") jmxConnector = JMXConnectorFactory.connect(new JMXServiceURL("service:jmx:t3://localhost:7001/jndi/weblogic.management.mbeanservers.domainruntime"), h) server = jmxConnector.getMBeanServerConnection() def biDomain = new GroovyMBean(server,'oracle.biee.admin:type=BIDomain,group=Service') def servConfig = new GroovyMBean(server, 'oracle.biee.admin:type=BIDomain.BIInstance.ServerConfiguration,biInstance=coreapplication,group=Service') biDomain.lock() servConfig.uploadRepository('/mnt/hgfs/stewart/scripts/sugarcrm.rpd', 'Admin123') biDomain.commit()
That's the whole script. There's a few things to point out here. First... establishing connectivity to the Weblogic Admin Server is slightly harder in Groovy. WLST hides a good bit of the complexity with connectivity, but the JMXConnectorFactory class in Groovy is a close second. However, once the connectivity is done, Groovy wins the rest of the way. Notice how we are able to configure two different MBean objects: biDomain for BIDomain and servConfig for ServerConfiguration. We don't have to cd back and forth across the MBean hierarchy to work with the different MBeans; we can simply instantiate as many MBeans at once as we need to. Also, notice that we don't have the generic invoke command to call the different methods in MBeans. We just call the method directly: if we want to call lock(), or commit(), or uploadRepository(), we just call it, and pass the parameters that it accepts. No need to build the generic Object and String arrays for passing in to invoke.
Because Groovy is very easy to execute external command-line processes (such as biserverxmlexec or biserverxmlgen) it's a great choice for unified OBIEE processes that need to work with executables and JMX MBeans together in a single script. Also... Groovy accepts Java syntax, so if we can't find the Groovy code samples we need from the internet, we can just plug in Java samples instead.