Oracle BI EE 11g – Systems Management API – JMX & MBeans – Dynamic User Generation
BI EE 11g introduces a new API for Systems Management called BI Systems Management API. This API has multitude of uses especially at places where complete automation/control of resources/system deployment is required. This API uses the Java JMX MBeans to expose the functionality externally. BI EE 11g Enterprise Manager uses this API internally to make updates/configuration changes. There are a total of 4 different ways of using the API. They are
1. Using Pre-Configured Enterprise Manager 2. Using System MBeans Browser 3. Using Java to connect through JMX 4. Using Weblogic Scripting
Enterprise Manager(EM) more or less exposes all the functionality to an Administrator. But the drawback with EM is that, it is a pure point & click application. When we have a lot of instances that require similar configuration updates/changes, we need an automated approach. This is where using the API directly through Java/Weblogic Scripting can be really helpful. The documentation of the API currently is limited only to certain administration aspects of BI EE. But actual methods available in the API is very exhaustive and can be used to build quite a lot of automated applications/utilities. In today's blog post, lets look at how we can use the API through Java and then perhaps use further non documented API methods to automate key configuration changes i.e create a new Weblogic user using JMX.
We start off with first looking at the documented Java Interfaces that we have as part of the systems management API.
For example, the PerformanceConfigurationMBean provides methods & attributes that can be queried and updated, similar to the operations that are available in the Performance tab of the Enterprise Manager.
oracle.biee.admin:oracleInstance=instance1, type=BIDomain.BIInstanceDeployment.BIComponent, biInstance=coreapplication, process=coreapplication_obis1,group=Service is the unique JMX name for the master BI Server.
biPerformanceMBeanName = new ObjectName("oracle.biee.admin:type=BIDomain.BIInstance.PerformanceConfiguration,biInstance=coreapplication,group=Service"); System.out.println("Found BI Cache MBean: " + biPerformanceMBeanName); mbs.invoke(biDomainMBeanName, "lock", args1, sig1); mbs.setAttribute(biPerformanceMBeanName,new Attribute("BIServerCacheEnabled",true);
The above is documented (the methods & attributes). But what is not documented are the other aspects of the JMX API. For example, a typical requirement is to add new users to the Default Authenticator through a script. To do that we need to first identify the MBean where the security aspects of Weblogic are exposed. The MBean is available under Runtime MBeans->Security->Domain: bifoundation_domain->myRealmDefaultAuthenticator
ObjectName securityMBeanName = new ObjectName("Security:Name=myrealmDefaultAuthenticator"); System.out.println("Found BI Instance Deployment MBean: " + securityMBeanName); Object[] objuser = {new String ("NewUser"), new String ("welcome1"), new String ("New User from JMX")}; String[] objstr = {new String ("java.lang.String"),new String ("java.lang.String"),new String ("java.lang.String")}; mbs.invoke(securityMBeanName,"createUser",objuser,objstr);
To execute custom JMX methods through Java, we need 2 jar files in our class path. They are wlclient.jar and wljmxclient.jar. Both of these files will be present under C:\oracle\Middleware\Oracle_BI1\opmn\lib folder. The full sample java code for updating the cache entry and create a new user is given below
package bieesysmgmt; import java.util.Hashtable; import javax.jws.WebMethod; import javax.jws.WebService; import javax.management.Attribute; import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; import javax.naming.Context; @WebService public class bieecacheentry { @WebMethod public static String bieecacheupdate(String cacheEntry) throws Exception { String Status = ""; try { MBeanServerConnection mbs = null; ObjectName biDomainMBeanName; ObjectName biInstanceMBeanName; ObjectName biPerformanceMBeanName; ObjectName biComponentMBeanName; String hostname = "venkatbiee"; String port = "7001"; String username = "weblogic"; String password = "welcome1"; String jmxUrl = "service:jmx:t3://" + hostname + ":" + port + "/jndi/weblogic.management.mbeanservers.domainruntime"; System.out.println("Connecting using URL: " + jmxUrl + " ..."); Hashtable h = new Hashtable(); h.put(Context.SECURITY_PRINCIPAL, username); h.put(Context.SECURITY_CREDENTIALS, password); h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote"); JMXConnector jmxConnector = JMXConnectorFactory.connect(new JMXServiceURL(jmxUrl), h); mbs = jmxConnector.getMBeanServerConnection(); Status = "Connected OK"; biDomainMBeanName = new ObjectName("oracle.biee.admin:type=BIDomain,group=Service"); biInstanceMBeanName = new ObjectName("oracle.biee.admin:type=BIDomain.BIInstance,biInstance=coreapplication,group=Service"); Status = Status + "-----" + "BIInstanceSuccess" + biInstanceMBeanName; biPerformanceMBeanName = new ObjectName("oracle.biee.admin:type=BIDomain.BIInstance.PerformanceConfiguration,biInstance=coreapplication,group=Service"); Status = Status + "-----" + "BICacheSuccess"+biPerformanceMBeanName; System.out.println("Cache MBean Yes/No: " + mbs.getAttribute(biPerformanceMBeanName, "BIServerCacheEnabled")); Status = Status + "-----"+ "Cache Original Value: "+ mbs.getAttribute(biPerformanceMBeanName, "BIServerCacheEnabled"); Object[] args1 = new Object[]{}; String[] sig1 = new String[]{}; mbs.invoke(biDomainMBeanName, "lock", args1, sig1); System.out.println("Cache MBean Yes/No: " + mbs.getAttribute(biDomainMBeanName,"Locked")); System.out.println("Locked domain OK"); mbs.setAttribute(biPerformanceMBeanName,new Attribute("BIServerCacheEnabled", Boolean.parseBoolean(cacheEntry))); // Commit Changes mbs.invoke(biDomainMBeanName, "commit", args1, sig1); System.out.println("Committed changes OK"); Status = Status + "-----"+ "Cache Updated Value: "+ mbs.getAttribute(biPerformanceMBeanName, "BIServerCacheEnabled"); biComponentMBeanName = new ObjectName("oracle.biee.admin:oracleInstance=instance1,type=BIDomain.BIInstanceDeployment.BIComponent,biInstance=coreapplication,process=coreapplication_obis1,group=Service"); mbs.invoke(biComponentMBeanName,"stop",args1,sig1); mbs.invoke(biComponentMBeanName,"start",args1,sig1); ObjectName securityMBeanName = new ObjectName("Security:Name=myrealmDefaultAuthenticator"); System.out.println("Found BI Instance Deployment MBean: " + securityMBeanName); Object[] objuser = {new String ("NewUser"), new String ("welcome1"), new String ("New User from JMX")}; String[] objstr = {new String ("java.lang.String"),new String ("java.lang.String"),new String ("java.lang.String")}; mbs.invoke(securityMBeanName,"createUser",objuser,objstr); return "Done"; } catch (Exception ex){ ex.getMessage(); } return "Yes"; } { } @WebMethod public String helperMethod (String helperInput) { return ("Success"); } public static void main(String[] args){ try{ System.out.println("Output"+ bieecacheupdate("false")); } catch (Exception ex) {System.out.println(ex.getMessage());} } }
Executing the above method should automatically update the ENABLE=NO; in NQSConfig.ini. Also, a new user in weblogic called NewUser will be created.