Thursday, 26 January 2017

WLST Script to change the BPEL properties , EDN status , Audit level and create partitions..

WLST Script to change the BPEL properties , EDN status , Audit level and create partitions..

Step 1) Create a property file with AdminServer details . Let us say the property filename is : dev.properties.

admin.url=t3://AdminServerName:7001
admin.soaurl=t3://SOAServerName:8001
admin.username=Weblogic
admin.password=Weblogic1

Step 2) Create a WLST script with below entries . let us say , script name is :  fmwBPELMbean.py

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.management.Attribute;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.Query;
import javax.management.QueryExp;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.OpenDataException;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

from java.io import FileInputStream
from java.util import Properties
from org.apache.log4j import *
import javax.management.openmbean.CompositeDataSupport;

if __name__ == '__main__':
    from wlstModule import *



def loginToAdmin(config):
        adminuser = config.get("admin.username")
   
   adminpwd = config.get("admin.password")
        adminurl = config.get("admin.soaurl")
        logger.info('Logging into SOA URL:"+adminurl')
        connect(adminuser,adminpwd,adminurl)

def partitionExists(part):
        foldermbean = sca_getFolderMBean();
        try:
                folders = mbs.getAttribute(foldermbean, "Folders")
                for folder in folders:
                        if folder.getName() == part:
                                return True
                return False
        except Exception, detail:
                print 'Exception:', detail

def createSOAPartition(config):
        loginToSOA(config)
        if not partitionExists('Partition1'):
                sca_createPartition ('Partition1')
        if not partitionExists('Partition2'):
                sca_createPartition ('Partition2')
        if not partitionExists('Partition3'):
                sca_createPartition ('Partition3')
        if not partitionExists('Partition4'):
                sca_createPartition ('Partition4')

        sca_listPartitions()

def changelog(config):
        #requires admin login
        loginToAdmin(config)
        domainRuntime()
        SOAInfraConfigobj = ObjectName('oracle.as.soainfra.config:Location=wls_soa1,name=soa-infra,type=SoaInfraConfig,Application=soa-infra')

        print 'Before: AuditLevel at SOAConfig (Global)~', mbs.getAttribute(SOAInfraConfigobj,'AuditLevel')

        mbs.setAttribute(SOAInfraConfigobj,Attribute("AuditLevel","Off"))
        print 'After : AuditLevel at SOAConfig (Global)~', mbs.getAttribute(SOAInfraConfigobj,'AuditLevel')


def changeEDN(config):
        custom()
        cd('oracle.as.soainfra.config/oracle.as.soainfra.config:name=edn,type=EDNConfig,Application=soa-infra')
        pausedval=get('Paused')
        logger.info('EDN Paused value = ' + str(pausedval))
        sca_disableEventsDelivery()
        logger.info('EDN Paused value = ' + str(pausedval))

def changeBPEL(config):
        logger.info('Processing BPEL')
        BPELConfigobj = ObjectName('oracle.as.soainfra.config:Location=wls_soa1,name=bpel,type=BPELConfig,Application=soa-infra')

        print 'Before: AuditLevel at BPELConfig (Global)~', mbs.getAttribute(BPELConfigobj,'AuditLevel')
        print 'Before: DisableSensors at BPELConfig (Global)~', mbs.getAttribute(BPELConfigobj,'DisableSensors')
        print 'Before: AuditStorePolicy at BPELConfig (Global)~', mbs.getAttribute(BPELConfigobj,'AuditStorePolicy')
        print 'Before: RecurringMaxMessageRaiseSize at BPELConfig (Global)~', mbs.getAttribute(BPELConfigobj,'RecurringMaxMessageRaiseSize')
        print 'Before: StartupMaxMessageRaiseSize at BPELConfig (Global)~', mbs.getAttribute(BPELConfigobj,'StartupMaxMessageRaiseSize')

        # instructions say None.  off appears to be valid, not None
        mbs.setAttribute(BPELConfigobj,Attribute('AuditLevel','off'))

        mbs.setAttribute(BPELConfigobj,Attribute('DisableSensors',1))
        mbs.setAttribute(BPELConfigobj,Attribute('AuditStorePolicy','async'))
        mbs.setAttribute(BPELConfigobj,Attribute('RecurringMaxMessageRaiseSize',0))
        mbs.setAttribute(BPELConfigobj,Attribute('StartupMaxMessageRaiseSize',0))

        print 'After : AuditLevel at BPELConfig (Global)~', mbs.getAttribute(BPELConfigobj,'AuditLevel')
        print 'After : DisableSensors at BPELConfig (Global)~', mbs.getAttribute(BPELConfigobj,'DisableSensors')
        print 'After : AuditStorePolicy at BPELConfig (Global)~', mbs.getAttribute(BPELConfigobj,'AuditStorePolicy')
        print 'After : RecurringMaxMessageRaiseSize at BPELConfig (Global)~', mbs.getAttribute(BPELConfigobj,'RecurringMaxMessageRaiseSize')
        print 'After : StartupmaxMessageRaiseSize at BPELConfig (Global)~', mbs.getAttribute(BPELConfigobj,'RecurringMaxMessageRaiseSize')

def changeBPELRecovery(config):
        logger.info('Processing BPEL')
        BPELConfigobj = ObjectName('oracle.as.soainfra.config:Location=wls_soa1,name=bpel,type=BPELConfig,Application=soa-infra')
        rec_config_obj  = mbs.getAttribute(BPELConfigobj, 'RecoveryConfig')
        rec_recurrr_obj = rec_config_obj.get('RecurringScheduleConfig')
        rec_startup_obj = rec_config_obj.get('StartupScheduleConfig')
        rec_cluster_obj = rec_config_obj.get('ClusterConfig')

        #Update configs
        new_startup_obj = setStartupConfig(rec_startup_obj,BPELConfigobj)
        new_recur_obj = setRecurringConfig(rec_recurrr_obj,BPELConfigobj)
        new_clust_obj = setClusterConfig(rec_cluster_obj,BPELConfigobj)

        #Create HashMap for Assignment
   
   pyMap = { "ClusterConfig":new_clust_obj, "RecurringScheduleConfig":new_recur_obj, "StartupScheduleConfig":new_startup_obj }
        javaMap = java.util.HashMap()
        for k in pyMap.keys():
                javaMap[k] = pyMap[k]

        new_rec_config_obj = CompositeDataSupport(rec_config_obj.getCompositeType(), javaMap)

        #javax.management.Attribute
        SOAattribute = Attribute('RecoveryConfig', new_rec_config_obj)

        mbs.setAttribute(BPELConfigobj, SOAattribute)

def setRecurringConfig(recur_obj,BPELMBeanobj):
        print ' in Recurring Config'
        cnt = 0
        keySet = recur_obj.getCompositeType().keySet()

        keys = keySet.toArray()
        keyitems = [ key for key in keys ]
        values = recur_obj.getAll(keyitems)
        for key in keys:
                print 'Processing key:',key

                if key == 'maxMessageRaiseSize':

                        print 'bpel current RecurringScheduleConfig:maxMessageRaiseSize ' + key + ' to value ' + str(values[cnt])
                        values [cnt] = Integer(0)
                        print 'bpel set RecurringScheduleConfig:maxMessageRaiseSize ' + key + ' to value ' + str(values[cnt])
                if key == 'stopWindowTime':
                        print 'bpel set RecurringScheduleConfig:stopWindowTime ' + key + ' to value ' + str(values[cnt])
                        values [cnt] = '00:00'
                        print 'bpel set RecurringScheduleConfig:stopWindowTime ' + key + ' to value ' + str(values[cnt])
                if key == 'startWindowTime':
                        print 'bpel set RecurringScheduleConfig:startWindowTime ' + key + ' to value ' + str(values[cnt])
                        values [cnt] = '00:00'
                        print 'bpel set RecurringScheduleConfig:startWindowTime ' + key + ' to value ' + str(values[cnt])
                if key == 'subsequentTriggerDelay':
                        print 'bpel set RecurringScheduleConfig:subsequentTriggerDelay ' + key + ' to value ' + str(values[cnt])
                        values [cnt] = Long(0)
                        print 'bpel set RecurringScheduleConfig:subsequentTriggerDelay ' + key + ' to value ' + str(values[cnt])
                if key == 'threshHoldTimeInMinutes':
                        print 'bpel set RecurringScheduleConfig:threshHoldTimeInMinutes ' + key + ' to value ' + str(values[cnt])
                        values [cnt] = Integer(0)
                        print 'bpel set RecurringScheduleConfig:threshHoldTimeInMinutes ' + key + ' to value ' + str(values[cnt])
                cnt = cnt + 1
        new_obj = CompositeDataSupport(recur_obj.getCompositeType(), keyitems, values)
        return new_obj


def setClusterConfig(cluster_obj,BPELMBeanobj):
        print ' in ClusterConfig '
        cnt = 0
        keySet = cluster_obj.getCompositeType().keySet()
        keys = keySet.toArray()
        keyitems = [ key for key in keys ]
        values = cluster_obj.getAll(keyitems)
        for key in keys:
                print 'Processing key:',key
                cnt = cnt + 1
        new_obj = CompositeDataSupport(cluster_obj.getCompositeType(), keyitems, values)

      return new_obj


def setStartupConfig(startup_obj,BPELMBeanobj):
        print ' in Startup Config'
        cnt = 0
        keySet = startup_obj.getCompositeType().keySet()

        print 'keySet:',keySet
        keys = keySet.toArray()
        print 'keys:',keys
        keyitems = [ key for key in keys ]
        print 'keyitems:',keyitems
        values = startup_obj.getAll(keyitems)
        print 'keySet',keySet
        for key in keys:
                print key
                if key == 'maxMessageRaiseSize':
                        print 'bpel current StartupScheduleConfig:maxMessageRaiseSize ' + key + ' to value ' + str(values[cnt])
                        values [cnt] = Integer(0)
                        print 'bpel set StartupScheduleConfig:maxMessageRaiseSize ' + key + ' to value ' + str(values[cnt])
                if key == 'startupRecoveryDuration':
                        print 'bpel set StartupScheduleConfig:startupRecoveryDuration ' + key + ' to value ' + str(values[cnt])
                        values [cnt] = Long(0)
                        print 'bpel set StartupScheduleConfig:startupRecoveryDuration ' + key + ' to value ' + str(values[cnt])
                if key == 'subsequentTriggerDelay':
                        print 'bpel set StartupScheduleConfig:subsequentTriggerDelay ' + key + ' to value ' + str(values[cnt])
                        values [cnt] = Long(0)
                        print 'bpel set StartupScheduleConfig:subsequentTriggerDelay ' + key + ' to value ' + str(values[cnt])
                cnt = cnt + 1
        new_obj = CompositeDataSupport(startup_obj.getCompositeType(), keyitems, values)
        return new_obj





##################### Main line ##########################

env=sys.argv[1]
print "Config file:" + env
configfile = FileInputStream(env)

print "Loaded file : " + env
configProps = Properties()
configProps.load(configfile)

PropertyConfigurator.configure("log4j.properties")
logger = Logger.getLogger("SOASetup")


logger.info('Starting')
try:
        createconn(end,configProps)
        changelog(configProps)
        changeBPEL(configProps)
        changeBPELRecovery(configProps)
        changeEDN(configProps)
        createSOAPartition(configProps)

except Exception, e:
        print 'Exception---------------------------'
        print e
        cancelEdit('y')

logger.info('Ending')

3) Invoke WLST to change BEPL configurations : wlst.sh fmwBPELMbean.py  dev.properties

2 comments:

  1. Great post, thanks. I implemented this today and noticed that sca_createPartition has now been superseded with sca_createFolder

    Thanks again.

    Dave

    ReplyDelete