Pages

Thursday, February 4, 2010

Invoking FMW Application MBeans in Weblogic

In the Fusion Middleware 11g Oracle added a lot of ADF, MDS and Soa Suite Application MBeans. These MBeans have attributes and operations which you can set , get or invoke. So with these MBeans you can control ADF, MDS or a Soa composite. Off course you do the same in the FMW Enterprise Manager(EM) application but sometimes it can be better to script actions so you can garantee that your Acceptance or Production Weblogic are the same. So lets take a look add these FMW MBeans and play with these FMW Mbeans. First we need to go the EM application to get an overview. The EM has a nice MBeans Browser.
Here you get a list of the Application Defined MBeans. These MBeans can't be invoked with a specific WLST command.
For example we can select a Soa composite application.
Here we can see or change the attributes of this Composite Mbean, We can retrieve these attributes and some of them we can change when the Access of the attribute = RW

In the operation tab we can see the operation methods of this MBean. You also can invoke the operation in this EM application just by selecting the operation.
Now lets invoke these operations from WLST or rettrieve an attribute
We need to start WLST
cd FMW_HOME\wlserver_10.3\common\bin
wlst.cmd
connect('weblogic','weblogic1','t3://localhost:7001')

To stop WLST we can use
disconnect()
exit()

In the WLST windows after we are connected we can go the domainRuntime where the application MBeans are located. domainRuntime()
Then we can lookup the MBean, the MBean can be seen in the MBean Browser ( above the atrributes & operations) For example mdsBean = ObjectName('oracle.mds.lcm:name=MDSDomainRuntime,type=MDSDomainRuntime')
We can invoke for example the operation listRepositories, this operation has no parameters.
Type repositories = mbs.invoke(mdsBean, 'listRepositories',None,None)
When the operation has parameters then we need to provide the parameters and the type of these parameters like this.
params = [Name]
sign = ['java.lang.String']
partitions = mbs.invoke(mdsBean, "listPartitions", params, sign)
To get an MBean attribute value we can use getAttribute
mdsObject = ObjectName(repository)
Name = mbs.getAttribute(mdsObject, 'Name')
Here is an example where I retrieve all the MDS repositories with the parttions.
domainRuntime()

mdsBean = ObjectName('oracle.mds.lcm:name=MDSDomainRuntime,type=MDSDomainRuntime')

print 'invoke listRepositories without parameters on mds bean'
repositories = mbs.invoke(mdsBean, 'listRepositories',None,None)
for repository in repositories:
mdsObject = ObjectName(repository)
Name = mbs.getAttribute(mdsObject, 'Name')
print 'mds repository object: ', Name
params = [Name]
sign = ['java.lang.String']
partitions = mbs.invoke(mdsBean, "listPartitions", params, sign)
for partition in partitions:
print 'partition: ', partition

or a Soa Suite example to get a list with all the deployed composites
domainRuntime()

soaBean = ObjectName('oracle.soa.config:Location=soa_server1,name=soa-infra,j2eeType=CompositeLifecycleConfig,Application=soa-infra')
print soaBean
composites = mbs.getAttribute(soaBean, 'DeployedComposites')
for composite in composites:
print 'composite: ',composite


Here an example to set a SOA Composite auditlevel to Development mode
# function to help locate a mbean(s)
# that match a specific name
def findMBean(prefix, name):
    # get a listing of everything in the current directory
    mydirs = ls(returnMap='true');
        
    # we're going to use a regular expression for our test
    pattern = java.util.regex.Pattern.compile(str(prefix) + str('.*name=') + str(name) + str('.*$'));
        
    # loop through the listing
    for mydir in mydirs:
        x = java.lang.String(mydir);
        matcher = pattern.matcher(x);
        # if we find a match, add it to the found list
        while matcher.find():
            return x;

print 'starting the script ....'
username = 'weblogic'
password = 'weblogic1'
url='t3://localhost:7001'

connect(username,password,url)

custom();
cd('oracle.soa.config');

composite = findMBean('oracle.soa.config:partition=default,j2eeType=SCAComposite',
                      '"CallingComposite"');
print 'bean ' + str(composite);
cd( composite );
print 'path: ' + pwd();

params = jarray.array(['auditLevel','Development'],
                       java.lang.Object)
sign   = jarray.array(['java.lang.String','java.lang.String'], 
                      java.lang.String)
invoke('setProperty', 
       params, 
       sign); 

disconnect();

The same but then in an other way
print 'starting the script ....'
username = 'weblogic'
password = 'weblogic1'
url='t3://localhost:7001'

connect(username,password,url)

domainRuntime()

helloworldComposite = ObjectName('oracle.soa.config:Location=AdminServer,partition=default,j2eeType=SCAComposite,revision=1.0,label=soa_d84546d1-22b0-496a-8b33-a5705caf19e6,Application=soa-infra,wsconfigtype=WebServicesConfig,name="Helloworld"')
print helloworldComposite
params = ['auditLevel','Development'] 
sign = ['java.lang.String','java.lang.String'] 
mbs.invoke(helloworldComposite, 'setProperty', params, sign) 
print mbs.getAttribute(helloworldComposite, 'Properties')

18 comments:

  1. Thanks for the post. I found the information useful for scripting some required changes for the BAM Server MBeans...

    For example

    bamBean = ObjectName('oracle.bam.common:name=BAMCommonConfig,type=Config,Application=oracle-bam,ApplicationVersion=11.1.1')
    appURL = Attribute('ApplicationURL','http://localhost:5102')
    mbs.setAttribute(bamBean,appURL)
    mbs.getAttribute(bamBean,'ApplicationURL')

    ReplyDelete
  2. Edwin,

    I've few doubts of invoking the MBean operations through WLST.

    1. Suppose, a MBean has an operation with an user defined class (or an Enum) in its parameter. How can that be invoked through WLST script ? I specify ['a.b.MyClass.MyEnum'] and ['a.b.MyClass'] as the values to last 2 parameters of mbs.invoke call. But I get "UnsupportedOperationException: Could not find MBean operation" when I attempt to do it.

    2. Can this set of wlst commands be stored in a file(with specific extensions ) and executed whenever needed?

    Can you please clarify?

    Thanks
    Raj

    ReplyDelete
  3. Hi,

    both is possible, WLST is based on jhyton http://www.jython.org/ . the java version of phyton. Search for jhyton

    and you can store it in a file and run it in wlst by using runFile('xxx')

    thanks

    ReplyDelete
  4. Hi,

    We have set Audit to off at server level for performance,
    but we need to set audit level for certain composites to be at development.

    When we deploy a composite the setting are overridden so I am trying to set the Audit Level for the composite using MBean programatically
    after deploying the composite. I have automated the deployment using Python(calling soaDeployComposite.py).

    The audit levels are stored as a property for the composite and can you let me know how to set it using WLST/Python

    Its set using the setProperty operation found in the System MBean browser
    Attribute: Properties

    Thanks,
    Jp

    ReplyDelete
  5. Hi,

    this should work, lookup the mbean reference of your composite. in the system mbean browser of the Enterprise Manager

    here is the wlst code


    print 'starting the script ....'
    username = 'weblogic'
    password = 'weblogic1'
    url='t3://localhost:7001'

    connect(username,password,url)

    domainRuntime()

    helloworldComposite = ObjectName('oracle.soa.config:Location=AdminServer,partition=default,j2eeType=SCAComposite,revision=1.0,label=soa_d84546d1-22b0-496a-8b33-a5705caf19e6,Application=soa-infra,wsconfigtype=WebServicesConfig,name="Helloworld"')
    print helloworldComposite
    params = ['auditLevel','Development']
    sign = ['java.lang.String','java.lang.String']
    mbs.invoke(helloworldComposite, 'setProperty', params, sign)
    print mbs.getAttribute(helloworldComposite, 'Properties')

    ReplyDelete
  6. Hi,

    That worked using WLST. Thanks.

    But i have one more issue to get through, constructing the MBean name after i deploy the composite using Python scripts.

    Is there any way we can get it only with composite name, version and partition which only information i have at the time of deployment.

    Thanks,
    Jp

    ReplyDelete
  7. Hi,

    Here you got a example


    # function to help locate a mbean(s)
    # that match a specific name
    def findMBean(prefix, name):
    # get a listing of everything in the current directory
    mydirs = ls(returnMap='true');

    # we're going to use a regular expression for our test
    pattern = java.util.regex.Pattern.compile(str(prefix) + str('.*name=') + str(name) + str('.*$'));

    # loop through the listing
    for mydir in mydirs:
    x = java.lang.String(mydir);
    matcher = pattern.matcher(x);
    # if we find a match, add it to the found list
    while matcher.find():
    return x;

    print 'starting the script ....'
    username = 'weblogic'
    password = 'weblogic1'
    url='t3://localhost:7001'

    connect(username,password,url)

    custom();
    cd('oracle.soa.config');

    composite = findMBean('oracle.soa.config:partition=default,j2eeType=SCAComposite',
    '"CallingComposite"');
    print 'bean ' + str(composite);
    cd( composite );
    print 'path: ' + pwd();

    params = jarray.array(['auditLevel','Development'],
    java.lang.Object)
    sign = jarray.array(['java.lang.String','java.lang.String'],
    java.lang.String)
    invoke('setProperty',
    params,
    sign);

    disconnect();

    ReplyDelete
  8. Hi Edwin,

    Since navigating through MBean was taking a long time as we are having more than 200 composites.

    We went for having the property in the composite.xml to have auditLevel as Development always,
    So now the deployment will not change it to inherit

    Development

    Thanks,
    Jp

    ReplyDelete
  9. Can we get the list of partitions using WLST in a script using sca_listPartitions or any other way, Thanks in advance.

    ReplyDelete
  10. Hi,

    you can also use this ANT script

    40.7.5.2.17 Listing All Available Partitions in the SOA Infrastructure

    ant -f ant-sca-mgmt.xml listPartitions -Dhost=host -Dport=port -Duser=user

    very simple.

    thanks

    ReplyDelete
  11. Hi Edwin,

    very useful hints fro scripting.
    By the way, which editor you are using?
    Is it Notepad++?

    Brgds,

    Loukas

    ReplyDelete
  12. Hi,

    Thanks. It's all enterprise manager and some web syntax highlighting framework.

    thanks edwin

    ReplyDelete
  13. Hi,

    great post on WLST. But let me ask a question: I'm trying to do this kind of manipulations through Java. Can you direct me to any kind of documentation or examples on how to query SOA Suite MBeans?

    Thanks in advance

    ReplyDelete
  14. Hi Edwin,

    I am very new to Custom WSLT and I have a requirement to create new Custom Log Handler in WLST.

    I followed some Oracle Documentation and came up with this basic code for a Single Instance SOA Suite Server (AdminServer, soa-infra).

    #Load the Properties and get the values
    properties = loadProperties('ApplicationDeployments.properties')
    username = properties['username']
    password = properties['password']
    connectionURL = properties['providerURL']
    connect(username,password,connectionURL)
    adminServerName = cmo.adminServerName
    print ('Connected to the Weblogic Environment' + adminServerName)
    domainRuntime()
    listLogs(target='AdminServer')

    but I get the error

    Traceback (innermost last):
    File "", line 1, in ?
    File "configureLogs.py", line 26, in ?
    NameError: listLogs

    Can you tell me where would I be going wrong and can you point me in the right direction please.

    ReplyDelete
  15. HI All,
    I am trying to change AUDIT LEVEL for a particular Composite called HelloWorldSOA2. But i am getting error whilte running the script as per this blog.

    I am calling this object.
    helloworldComposite = ObjectName('oracle.soa.config:Location=gpossoa_wdvra00a281_11582,partition=default,j2eeType=SCAComposite,revision=1.0,label=HelloWorldSOA2,Application=soa-infra,wsconfigtype=WebServicesConfig,name="HelloWorldSOA2"')

    In that object, what is label?
    Where do i define my composite name?


    javax.management.InstanceNotFoundException: javax.management.InstanceNotFoundException: Unable to contact MBeanServer for oracle.soa.config:Location=gpossoa_wdvra00a281_11582,partition=default,j2eeType=SCAComposite,revision=1.0,Application=soa-infra,wsconfigtype=WebServicesConfig,name="HelloWorldSOA2"

    ReplyDelete
  16. connect(XXX)
    domainRuntime()

    helloworldComposite = ObjectName('oracle.soa.config:Location=gpossoa_wdvra00a281_11582,partition=default,j2eeType=SCAComposite,revision=1.0,Application=soa-infra,name="HelloWorldSOA2"')
    print helloworldComposite
    params = ['auditLevel','Development']
    sign = ['java.lang.String','java.lang.String']
    mbs.invoke(helloworldComposite, 'setProperty', params, sign)
    print mbs.getAttribute(helloworldComposite, 'Properties')

    ReplyDelete
  17. Hi Edwin,

    I'm trying to do 2 things using wlst/jython

    - list jms resource policy using wls:/xxx_domain/domainConfig/SecurityConfiguration/xxx_domain/Realms/myrealm/Authorizers/XACMLAuthorizer> cmo.getPolicy('type=,application=xxxJmsSystemResource')

    but I don't get any results. I have a policy configured on this resource with 2 users.

    - list the SAML Issuer names. In com.oracle.jps:Location=AdminServer,type=JpsConfig, I can only see the default www.oracle.com Issuer name but not the other one we have defined. The other one defined is stored in domain/config/fmwconfig/policy-accessor-config.xml. Whereas the MBean seems to list the SAML Issuer names from jps-config.xml only.

    How do I extract this info?

    ReplyDelete
  18. Hi Edwin,

    How can we get only Names of the deployed composites into a variable?

    ReplyDelete