Followers

Wednesday, August 7, 2013

Setting up the JMS resources through WLST script



The below WLST script help us to set up the JMS resources.
JMSConpiguration.py
connect('weblogic','weblogic', 't3://localhost:8000')

edit()
startEdit()

print 'Creating File Store'
cd('/')
cmo.createFileStore('BAMMonitoringJMSFileStore')
cd('/FileStores/BAMMonitoringJMSFileStore')
cmo.setDirectory('BAMMonitoringJMSFileStore')
set('Targets',jarray.array([ObjectName('com.bea:Name=AdminServer,Type=Server')], ObjectName))


print 'Creating JMS Server'
cd('/')
print 'Creating JMS Server.'
cmo.createJMSServer('BAMMonitoringServer')
cd('/JMSServers/BAMMonitoringServer')
cmo.setPersistentStore(getMBean('/FileStores/BAMMonitoringJMSFileStore'))
cmo.setTemporaryTemplateResource(None)
cmo.setTemporaryTemplateName(None)
cmo.addTarget(getMBean('/Servers/AdminServer'))

print 'Creating JMS Module'
cd('/')
cmo.createJMSSystemResource('BAMJMSSystemResource')
cd('/JMSSystemResources/BAMJMSSystemResource')
cmo.addTarget(getMBean('/Servers/AdminServer'))
cmo.createSubDeployment('BAMSubdeDloyment')

print 'Creating Connection Factory'
cd('/')
cd('/JMSSystemResources/BAMJMSSystemResource/JMSResource/BAMJMSSystemResource')
cmo.createConnectionFactory('BAMMonitoringConnectionfactory')
cd('/JMSSystemResources/BAMJMSSystemResource/JMSResource/BAMJMSSystemResource/ConnectionFactories/BAMMonitoringConnectionfactory')
cmo.setJNDIName('jms/BAMMonitoringConnectionfactory')
#set('SubDeploymentName','BAMSubdeDloyment')
cd('/JMSSystemResources/BAMJMSSystemResource/JMSResource/BAMJMSSystemResource/ConnectionFactories/BAMMonitoringConnectionfactory/SecurityParams/BAMMonitoringConnectionfactory')
cmo.setAttachJMSXUserId(false)
cd('/JMSSystemResources/BAMJMSSystemResource/JMSResource/BAMJMSSystemResource/ConnectionFactories/BAMMonitoringConnectionfactory/ClientParams/BAMMonitoringConnectionfactory')
cmo.setClientIdPolicy('Restricted')
cmo.setSubscriptionSharingPolicy('Exclusive')
cmo.setMessagesMaximum(10)
#cd('/JMSSystemResources/BAMJMSSystemResource/JMSResource/BAMJMSSystemResource/ConnectionFactories/BAMMonitoringConnectionfactory/TransactionParams/BAMMonitoringConnectionfactory')
#cmo.setXAConnectionFactoryEnabled(true)
cd('/JMSSystemResources/BAMJMSSystemResource/JMSResource/BAMJMSSystemResource/ConnectionFactories/BAMMonitoringConnectionfactory')
cmo.setDefaultTargetingEnabled(true)

print 'Creating Queue'
cd('/')
cd('/JMSSystemResources/BAMJMSSystemResource/JMSResource/BAMJMSSystemResource')
cmo.createQueue('BAMMonitoringQueue')
cd('/JMSSystemResources/BAMJMSSystemResource/JMSResource/BAMJMSSystemResource/Queues/BAMMonitoringQueue')
set('JNDIName','jms/BAMMonitoringQueue')
set('SubDeploymentName','BAMSubdeDloyment')
cd('/JMSSystemResources/BAMJMSSystemResource/SubDeployments/BAMSubdeDloyment')
cmo.addTarget(getMBean('/JMSServers/BAMMonitoringServer'))

print 'JMS Resources are Successfully Created'
activate()
Executing the script:
Set the environment by executing the below script
$WL_Home/wlserver_10.3/server/bin/setWLSEnv.sh
Execute JMSConpiguration.py
Wlst.sh JMSConpiguration.py

Creating JMS Adapter connection factory through WLST script

The below WLST script will help us to create the JMS adapter connection factories. Before Executing the script change the details accordingly.

configureJMSAdapterConnection.py

TargetServerName='AdminServer'

soaHome='oracle/Middleware/Oracle_SOA1'

appPathJms=soaHome+'/soa/connectors/JmsAdapter.rar'
appNameJms='JmsAdapter'
moduleOverrideNameJms=appNameJms+'.rar'
JMSJNDIName = 'eis/wls/BAMQueueConnection'
JMSConnectionfactory='jms/BAMMonitoringConnectionfactory'
#Sever Details

moduleDescriptorName='META-INF/weblogic-ra.xml'
planPathJms=soaHome+'/soa/connectors/Plan_JMS.xml'

def createJMSConnectionFactory():

        edit()
        startEdit()
        startApplication(appNameJms)
        myPlanJms=loadApplication(appPathJms, planPathJms)
        makeDeploymentPlanVariable(myPlanJms,'ConnectionInstance_eis/Jms_JNDIName_13102979357209', JMSJNDIName , '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="oracle.tip.adapter.jms.IJmsConnectionFactory"]/connection-instance/[jndi-name="'+JMSJNDIName+'"]/jndi-name',moduleOverrideNameJms)
        makeDeploymentPlanVariable(myPlanJms, 'ConfigProperty_eis/JMS_JNDIName_ConnectionFactory_Name_13102979357210', JMSConnectionfactory,'/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="oracle.tip.adapter.jms.IJmsConnectionFactory"]/connection-instance/[jndi-name="'+JMSJNDIName+'"]/connection-properties/properties/property/[name="ConnectionFactoryLocation"]/value',moduleOverrideNameJms)

        myPlanJms.save();
        save();
        cd('/AppDeployments/JmsAdapter/Targets');
        updateApplication(appNameJms, planPathJms);
        activate(block='true');
     
  
def makeDeploymentPlanVariable(wlstPlan, name, value, xpath,overrideName, origin='planbased'):
    wlstPlan.destroyVariable(name)
    wlstPlan.destroyVariableAssignment(name, overrideName, moduleDescriptorName)
    variableAssignment = wlstPlan.createVariableAssignment(name, overrideName, moduleDescriptorName)
    variableAssignment.setXpath(xpath)
    variableAssignment.setOrigin(origin)
    wlstPlan.createVariable(name, value)
    print 'moduleDescriptorName=',moduleDescriptorName


def main():
       adminURL='t3://localhost:9001'
       adminUserName='weblogic'
       adminPassword='welcome1'
       connect(adminUserName, adminPassword, adminURL)
       createJMSConnectionFactory()
       disconnect()
main()

Login to the server, cd to the folder where the script is available and execute the script as shown below.

%MIDDLEWARE_HOME%\wlserver_10.3\common\bin\wlst.cmd configureJMSAdapterConnection.py

JMS foreign server creation with WLST

The below WLST script help us to create a Foreign JNDI server in a local server for a JMS resources running in a remote server(in different domain).

The JMS clients can use the local JNDI configured in the local server to send the messages to the remote JMS server.

ConfigureForeignJMSServer.py

connect('weblogic','welcome1', 't3://localhost:9001')
edit()
startEdit()

cd('/')
cmo.createJMSSystemResource('
BAMForeginJMSResource')

cd('/SystemResources/BAMForeginJMSResource')
set('Targets',jarray.array([ObjectName('com.bea:Name=AdminServer,Type=Server')], ObjectName))

cd('/JMSSystemResources/BAMForeginJMSResource/JMSResource/BAMForeginJMSResource')
cmo.createForeignServer('BAMForeignJMSServer')

cd('/JMSSystemResources/BAMForeginJMSResource/JMSResource/BAMForeginJMSResource/ForeignServers/BAMForeignJMSServer')
cmo.setDefaultTargetingEnabled(true)

cmo.setJNDIPropertiesCredential('welcome1')

cmo.setConnectionURL('t3://localhost:8000')
cmo.createJNDIProperty('java.naming.security.principal')

cd('/JMSSystemResources/BAMForeginJMSResource/JMSResource/BAMForeginJMSResource/ForeignServers/BAMForeignJMSServer/JNDIProperties/java.naming.security.principal')
cmo.setValue('weblogic')

cd('/JMSSystemResources/BAMForeginJMSResource/JMSResource/BAMForeginJMSResource/ForeignServers/BAMForeignJMSServer')

cmo.createForeignConnectionFactory('ForeignJMSConnectionFactory')

cd('/JMSSystemResources/BAMForeginJMSResource/JMSResource/BAMForeginJMSResource/ForeignServers/BAMForeignJMSServer/ForeignConnectionFactories/ForeignJMSConnectionFactory')
cmo.setLocalJNDIName('jms/BAMMonitoringConnectionfactory')
cmo.setRemoteJNDIName('jms/BAMMonitoringConnectionfactory')

cd('/JMSSystemResources/BAMForeginJMSResource/JMSResource/BAMForeginJMSResource/ForeignServers/BAMForeignJMSServer')
cmo.createForeignDestination('ForeignJMSDestination')

cd('/JMSSystemResources/BAMForeginJMSResource/JMSResource/BAMForeginJMSResource/ForeignServers/BAMForeignJMSServer/ForeignDestinations/ForeignJMSDestination')
cmo.setLocalJNDIName('jms/BAMMonitoringQueue')
cmo.setRemoteJNDIName('jms/BAMMonitoringQueue')

activate()


The same script can be modified to create a Foreign JNDI Server for other JMS providers.

Login to the server, cd to the folder where the script is available and execute the script as shown below.

%MIDDLEWARE_HOME%\wlserver_10.3\common\bin\wlst.cmd ConfigureForeignJMSServer.py

Tuesday, August 6, 2013

WLST Script for force Garbage collection


  1. # WLST script which calls GC.
  2. from java.util import *
  3. from javax.management import *
  4. import javax.management.Attribute
  5. print 'starting the script .... '
  6. connect('userid','password',url='t3://192.168.17:9001')
  7. state('AdminServer')
  8. # For Force GC ....
  9. domainRuntime()
  10. cd('/ServerRuntimes/AdminServer/JVMRuntime/AdminServer')
  11. print ' Performing Force GC...'
  12. cmo.runGC()
  13. disconnect()
  14. print 'End of script ...'
  15. exit()

WLST script to delete the JMS messages in the Queue

wls:/offline> connect('weblogic','welcome1','t3://localhost:7001')
wls:/WLST_domain/serverConfig> serverRuntime()
wls:/WLST_domain/serverRuntime>cd('JMSRuntime/AdminServer.jms/JMSServers/JMSServer-0/Destinations/SystemModule-0!Queue-0')
wls:/WLST_domain/serverRuntime/JMSRuntime/AdminServer.jms/JMSServers/JMSServer-0/Destinations/SystemModule-0!Queue-0> ls()
wls:/WLST_domain/serverRuntime/JMSRuntime/AdminServer.jms/JMSServers/JMSServer-0/Destinations/SystemModule-0!Queue-0> cmo.deleteMessages('')

Garbage Collection Notes



    The heap size influences the following:

– The GC frequency and the pause during collections
– The number of short and long term objects
– Fragmentation and locality problems

    An undersized heap with the concurrent collector leads to full GCs with an increase in load and also fragmentation problems.

    An oversized heap leads to increased collection times and locality problems (smear problem).

    The permanent generation may be a factor on applications that dynamically generate and load many classes (JSP and CFM application servers).

    Size the heap to handle peak and burst loads.

    Be sure to increase the memory as you increase the number of processors, since allocation can be parallelized.

    Configure as much memory as possible to the virtual machine unless you have problems with pauses.

    Do not choose a maximum value for the heap unless you know that the heap is greater than the default maximum heap size.

 – Explicit garbage collection calls (System.gc())  force a major collection.

    Measure the effectiveness of explicit GC calls by disabling them using the following option:

 -XX:+DisableExplicitGC

    Increase the MaxPermSize to accommodate the dynamically generated classes.

-XX:MaxPermSize=nnn

    Use -XX:+AggressiveHeap for throughput applications.

    Applications that rely on finalization (finalize method) will cause lag in garbage collection. Try reducing the dependency on finalization.

    The more CPUs, the more the advantages of the concurrent collector increase.

    The increase in the lifetime of objects increases the frequency of collection as live objects take heap space. So keep live objects to the needed minimum.

– Set a limit for pooled objects and do not set this value too high.

    Avoid setting old generation size too small as this may result in undersized heaps.

– An undersized heap may reduce collection time and lead to fragmentation and frequent full GCs.

    Increase young generation to decrease the frequency of collection, but this will increase pause. So choose a size for the young generation where the pause is tolerable.

    An increase in load will fill up the heap faster and this will increase the collection frequency. To reduce the collection frequency, increase the heap size.

    Use the default serial collector for smaller applications.

    For larger applications hosted on WebLogic Server, use the throughput collector.

-XX:+UseParallelGC

Read more: http://www.wikiconsole.com/wiki/?p=4662#ixzz2bF1JyO2c