Create a JMS Configuration on Oracle Weblogic 11g 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.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值