Click here to Skip to main content
Click here to Skip to main content

Tagged as

Create a JMS Configuration on Oracle Weblogic 11g using WSLT

, 25 Mar 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Python Script using WSLT

Introduction

Deploying an artifact or a package is commonly a delicate work on any environment that you are willing to install your application, at the expense to optimize your installation a well note to your work could the use of a Script File.

Background

On my brief experience in terms of application deployment is "I do not trust on me or anyone else to deploy my application", it is because depending on how large is your team and the time to be scheduled I always be susceptible to make a mistake in some part of documentation and I could be some kind of a tragedy to me that my package could be rejected even in a production installation, furthermore an application assembler, application server administrator, database administrator could also make a mistake too.

On the other hand Application Server have included a administration tool for quick manage and configuration that run on a script file, there is one for Websphere Application Server, Oracle Weblogic, Microsoft IIS and of course our friendly JBOSS Application Server.

This short tutorial describe how to run a Script File make it on Python/IronPython (linux/windows) in a console using Oracle Weblogic WLST.

Using the code

There is another method to create a Server Configuration on Oracle Weblogic if you can not use the console you could execute a script with your full configuration using WSLT.

This model solves problems like deployment on others environments like Quality Assurance and Production were you should don't have any permission to access from console, only a deployer will run the script and install any package on the server. You should follow the next steps:

1. First go to you Oracle Weblogic Home, for example the location of my Oracle Weblogic installation is:

[root@USER25 bin]# cd /root/Oracle/Middleware/11.1.2.4.0/   

2. Go to the next folder...

[root@USER25 bin]# cd /root/Oracle/Middleware/11.1.2.4.0/wlserver_10.3/server/bin   

3. Open a console and keep in mind you have to run Oracle Weblogic and the execute:

[root@USER25 bin]# ./setWLSEnv.sh  

Even there is another using the following sh or bat file located into:

../common/bin/wlst.sh 

4. Running above command you will have the opportunity to run the script on Python/IronPython on your weblogic on running state, I will show you an script example that runs several tasks to create a JMS Server, JMS Module, Queue, Dead Letter Queue and DESTINATION QUEUE that is the object we need for this tutorial, so this the code..

# OCTAVIO SANCHEZ HUERTA, http://zeosaho.blogspot.mx/
# SOFTWARE ENGINEER, ohuerta604@outlook.com
 
from java.io import FileInputStream
from java.util import Properties
 
 
def loadProperties(fileName):
    properties = Properties()
    input = FileInputStream(fileName)
    properties.load(input)
    input.close()
 
    result= {}
    for entry in properties.entrySet(): result[entry.key] = entry.value
 
    return result
 
 
properties = loadProperties("local.properties")
 
username = properties['username']
password = properties['password']
url = properties['providerURL']
 
 
connect(username, password, url)
adminServerName = cmo.adminServerName
 
try:
    print "Inicializando ..."
    domainName = cmo.name
    cd("Servers/%s" % adminServerName)
    adminServer = cmo
 
 
    def deleteIgnoringExceptions(mbean):
        try: delete(mbean)
        except: 
            print "delete mbean"
            pass
    
    def startTransaction():
        edit()
        startEdit()
 
    def endTransaction():
        save()
        activate(block="true")
 
    
    def createDLQ(qname, qjndiname,dkName):
        print "createDLQ() START"
        cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName)
        errorQueue = create(qname, "Queue")
        errorQueue.JNDIName = qjndiname
 
        errorQueue.subDeploymentName = subDeploymentName
                print dkName
 
        cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName)                        
        cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName+'/Queues/'+qname)
        set('DestinationKeys',jarray.array([String(dkName)],String))
 
        cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName+'/Queues/'+qname+'/DeliveryFailureParams/'+qname)
        cmo.setRedeliveryLimit(1)
        cmo.setExpirationPolicy('Log')
        
 
        cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName+'/Queues/'+qname+'/DeliveryParamsOverrides/'+qname)
        cmo.setRedeliveryDelay(5000)
 
        cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName+'/Queues/'+qname+'/DeliveryFailureParams/'+qname)
        cmo.unSet('ErrorDestination')
 
 
        cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName+'/Queues/'+qname+'/DeliveryParamsOverrides/'+qname)
        cmo.setPriority(-1)
        cmo.setDeliveryMode('Persistent')
        cmo.setTimeToDeliver('-1')
        cmo.setTimeToLive(-1)
        print "createDLQ() END"
    
    def createDestinationKey(dkname):
            print "createDestinationKey() START"     
        cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName)
        dk1 = create(dkname, "DestinationKey")
 
                dk1.setProperty("JMSPriority")
        dk1.setKeyType("String")
        dk1.setSortOrder("Descending")
            print "createDestinationKey() END"
 
    def createQueue(qname, qjndiname, dlqName,dkName):
        print "createQueue() START"
        cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName)
        q1 = create(qname, "Queue")
        q1.JNDIName = qjndiname
 
 
        q1.subDeploymentName = subDeploymentName
 
        cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName)                        
        cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName+'/Queues/'+qname)
        set('DestinationKeys',jarray.array([String(dkName)],String))
 
 
        cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName+'/Queues/'+qname+'/DeliveryParamsOverrides/'+qname)
        cmo.setRedeliveryDelay(2000)
 
        print "Assign failed destination to queue"
 
        cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName+'/Queues/'+qname+'/DeliveryFailureParams/'+qname)
        cmo.setRedeliveryLimit(3)
 
        cmo.setExpirationPolicy('Redirect')
        erQueue = getMBean('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName+'/Queues/'+dlqName)
        cmo.setErrorDestination(erQueue)
 
 
        cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName+'/Queues/'+qname+'/MessageLoggingParams/'+qname)
        cmo.setMessageLoggingEnabled(true)
        cmo.setMessageLoggingFormat('JMSDestination,JMSMessageID')
 
 
        cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName+'/Queues/'+qname+'/DeliveryParamsOverrides/'+qname)
        cmo.setPriority(-1)
        cmo.setDeliveryMode('Persistent')
        cmo.setTimeToDeliver('-1')
        cmo.setTimeToLive(-1)
        print "createQueue() END"
 
 
    def createCF(cfname, cfjndiname, xaEnabled):
        print "createCF() START"
        cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName)
        cf = create(cfname, "ConnectionFactory")
        cf.JNDIName = cfjndiname
        cf.subDeploymentName = subDeploymentName
 
        if (xaEnabled == "true"):
            cf.transactionParams.setXAConnectionFactoryEnabled(1)
        print "createCF() END"
 
 
    def createJMSModule():
        print "createJMSModule() START"
        cd('/JMSSystemResources')
        jmsModule = create(moduleName, "JMSSystemResource")
        jmsModule.targets = (adminServer,)    
    
        cd(jmsModule.name)
 
        sd = create(subDeploymentName, "SubDeployment")    
        myJMSServer = getMBean('/JMSServers/' + jmsServerName)
        sd.targets = (myJMSServer,)
        print "createJMSModule() END"
        
    
    def createJMSServer():
        print "createJMSServer() START"
        startTransaction()
 
        cd("/JMSServers")
        deleteIgnoringExceptions(jmsServerName)
        cd("/FileStores")
        deleteIgnoringExceptions(fileStoreName)
 
 
        cd('/')
        filestore = cmo.createFileStore(fileStoreName)
        filestore.setDirectory(properties['fileStoreDirecory'])
        filestore.targets = (adminServer,)
        endTransaction()
        
        startTransaction()
        cd("/JMSServers")
 
        jmsServer = create(jmsServerName, "JMSServer")
        jmsServer.setPersistentStore(filestore)
        jmsServer.targets = (adminServer,)
        endTransaction()
        print "createJMSServer() END"
    
    
    
    moduleName = 'TestJMSSModule'
    subDeploymentName = 'TestJMSSubDeployment'
    fileStoreName = 'TestFileStore'
    jmsServerName = 'TestJMSServer'
 
 
    startTransaction()
 
    cd("/JMSSystemResources")
    deleteIgnoringExceptions(moduleName)
    endTransaction()
 
    print "Create JMS Server"
    createJMSServer()
    
    startTransaction()
    print "Create JMS Module"
    createJMSModule()
 
    dkName1='DefaultDestinationKey'
    print "Create Destinantion Key DefaultDestinationKey"
    createDestinationKey(dkName1)
 
 
    queueEDQName1 = 'ApplicationBatchErrorQueue'
    queueEDQJNDIName1 = 'jms/ApplicationBatchErrorQueue'
    print "Create Error Destinantion ApplicationBatchErrorQueue"
    createDLQ(queueEDQName1, queueEDQJNDIName1,dkName1)
    
    queueName1 = 'ApplicationBatchReplyQueue'
    queueJNDIName1 = 'jms/ApplicationBatchReplyQueue'
    print "Create Queue ApplicationBatchReplyQueue"
    createQueue(queueName1, queueJNDIName1, queueEDQName1,dkName1)
 
    queueName2 = 'ApplicationBatchRequestQueue'
    queueJNDIName2 = 'jms/ApplicationBatchRequestQueue'
    print "Create Queue ApplicationBatchRequestQueue"
    createQueue(queueName2, queueJNDIName2, queueEDQName1,dkName1)
    
 
    queueEDQName3 = 'XMLMarshallerErrorQueue'
    queueEDQJNDIName3 = 'jms/XMLMarshallerErrorQueue'
    print "Create Error Destinantion XMLMarshallerErrorQueue"
    createDLQ(queueEDQName3, queueEDQJNDIName3,dkName1)
    
    queueName5 = 'XMLMarshallerReplyQueue'
    queueJNDIName5 = 'jms/XMLMarshallerReplyQueue'
    print "Create Queue XMLMarshallerReplyQueue"
    createQueue(queueName5, queueJNDIName5, queueEDQName3,dkName1)
 
    queueName6 = 'XMLMarshallerRequestQueue'
    queueJNDIName6 = 'jms/XMLMarshallerRequestQueue'
    print "Create Queue XMLMarshallerRequestQueue"
    createQueue(queueName6, queueJNDIName6, queueEDQName3,dkName1)
 
    myCFName = 'TestConnectionFactory'
    myCFJNDIName = 'jms/TestConnectionFactory'
    print "Create JMS XA Connection Factory TestConnectionFactory"
    createCF(myCFName, myCFJNDIName, "true")
    
    
    endTransaction()
except:
    print "ocurrio un error"
    dumpStack()
    cancelEdit("y")
 
 
print "disconnect"
disconnect()
 
print "exit"

exit()

Properties File:

username=weblogic
password=weblogic1
providerURL=t3://localhost:7101
fileStoreDirecory=/config/jms/TestFileStore 

If you follow the script you will get a declaration of an array on XML, that because if you check Weblogic documentation a Destination Key is an Array of String, so in Python you will have to declare your DeclarationKeys as String[] please keep in mind that note.

The segment of code we carry on the next ...

def createDestinationKey(dkname):  
    print "createDestinationKey() START"    
    cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName)  
    dk1 = create(dkname, "DestinationKey")  
    dk1.setProperty("JMSPriority")  
    dk1.setKeyType("String")  
    dk1.setSortOrder("Descending")  
    print "createDestinationKey() END"   

Here we define a part of the XML that is deployed on the server, we pass the property, keytype and sort order that should be published on Oracle Weblogic, this procedure can be executed as a transaction as python script.

   ...   
 cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName)                    
   cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName+'/Queues/'+qname)  
   set('DestinationKeys',jarray.array([String(dkName)],String))  
 ...   

5. The comand we need to execute on a terminal is:

[root@USER25 bin]# java weblogic.WLST createJmsServer.py   

Or you could also use wlst.sh

./wlst.sh  createJmsServer.py 

6. Finally we will see the trace of execution, and verifying with Weblogic Console all configuration created that has been a declaration into python file, this is so much powerful of course you can create a JNDI or any task that we do over console.

Best Regards,

Points of Interest

This kind of Installation could be doing on different Application Server and course it does not matter what king of operating system your are using for example HP-UX, Linux (any distros that could handle application server installation), and Microsoft Windows (using .NET for example IronPython).

Using Script file instead of Application Console is more useful on Production State beacuse it run twice or even more faster.

History

You can use a Script for a lot of things.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Octavio Sánchez Huerta
Software Developer (Senior) TATA Consultancy Services
Mexico Mexico
Proactive and continuing professional development in projects capable of high performance, high pressure, committed and responsible with my work, high willingness to research and innovation, responsible for working with large teams. My goal is to acquire an education as IT Solutions Architect in the field of SOA solutions, my interest is focused on design and development over Enterprise Architecture.
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.1411019.1 | Last Updated 25 Mar 2014
Article Copyright 2014 by Octavio Sánchez Huerta
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid