Search This Blog

Showing posts with label 12c. Show all posts
Showing posts with label 12c. Show all posts

Thursday, January 31, 2013

JMS Module Uniform Distributed Queue using WLST


This post is continous series of JMS configurations experimenting with Python. Here the JMS module configuration changes for the JMS will be stored to config.xml repository and its sub-deployment module descriptor in a separate file. JMS system module can be defined with name, target to servers or cluster, its related sub-deployments such as Queue or publisher/Subscriber topics.

The WebLogic JMS related Mbeans are constructed as follows :
  • JMSBean
  • JMSSystemReourceMBean
  • QueueBean
  • JMSConnectionFactoryBean
  • DistributedQueueBean
  • UniformDistributedQueueBean
  • SubdeploymentMBean

While configuring you need to understand that JMS system module, that consists of ConnectionFactory that give access to the JMS services, and there could be a different scenario on demand. The machines are high-powered, low powered are in the same cluster then JMS destinations must be distributed destinations with ‘Allocate members Uniformly’ option set to false and manually select more physical destination from the high powered machines.The configuring JMS module is going to have various sub-deployment components in it. First we need to configure the JMS Module name, target to the advanced deployment as sub-deployment. 


Now you need brainstrom, and provide your customized domain with JMS module details in the properties file, let me give you sample :
############################################################################### 
# JMS MODULE CONFIGURATION
############################################################################### 
total_default_jms_module=1
jms_mod_name1=jmsSystemModule
jms_mod_target1=my_cluster

Subdeployment in JMS Module

Most of the Admins not really aware of the use of subdeployment. We need to configure a subdeployment per JMS Module. While configuring the subdeployment we have to provide the target as JMS servers which are configured in the first section. Why we need a subdeployment is interesting topic  • To avoid network traffic between JMS components communication • It will group Connection factories, queues, topics

 • Easy to migrate
WebLogic - JMS Module configuration using WLST

###############################################################################
# JMS SUBDEPLOY CONFIGURATION
###############################################################################
total_subdply=1
subdeployment_name=aJmssub

JMS Connection Factory

We have configured the ConnectionFactory properties as follows
###############################################################################
# JMS CONNECTION FACTORY CONFIGURATION
##########
conf_jndi1=myConnectionFactory
conf_name1=MyConnectionFactory
Configuring Uniform distributed queue using WLST We have configured the Queue with Distributed option because we have multiple JMS providers. The Uniform Distributed Queue is the one of the best practice when you have Clustered WebLogic Domain. While configuring this you need a name for the Uniform Distributed Queue and a JNDI name for it.
###############################################################################
#   UNIFORM DISTRIBUTED QUEUE CONFIGURATION
###############################################################################
total_udq=3
udq_name1=jmsIncomingChannel
udq_jndi1=jms/incoming/response
The JMS Module configuration with Subdeployment target to JMS Servers configured earlier. ConnectionFactory, Uniform Distributed Queue target to subdeployment.
from java.util import Properties
from java.io import FileInputStream
from java.io import File
from java.io import FileOutputStream
from java import io
from java.lang import Exception
from java.lang import Throwable
import os.path
import sys

envproperty=""
if (len(sys.argv) > 1):
        envproperty=sys.argv[1]
else:
        print "Environment Property file not specified"
        sys.exit(2)
propInputStream=FileInputStream(envproperty)
configProps=Properties()
configProps.load(propInputStream)

def createJMSModule(jms_module_name,cluster_target_name):
        cd('/JMSServers')
        jmssrvlist=ls(returnMap='true')
       # jmssrvlist=['AjmsServer1','AjmsServer2']
        cd('/')
        module = create(jms_module_name, "JMSSystemResource")
        cluster = getMBean("Clusters/"+cluster_target_name)
        module.addTarget(cluster)
        cd('/SystemResources/'+jms_module_name)

        module.createSubDeployment(subdeployment_name)
        cd('/SystemResources/'+jms_module_name+'/SubDeployments/'+subdeployment_name)
        list=[]
        for j in jmssrvlist:
                s='com.bea:Name='+j+',Type=JMSServer'
                list.append(ObjectName(str(s)))
        set('Targets',jarray.array(list, ObjectName))


def getJMSModulePath(jms_module_name):
        jms_module_path = "/JMSSystemResources/"+jms_module_name+"/JMSResource/"+jms_module_name
        return jms_module_path

def createJMSTEMP(jms_module_name,jms_temp_name):
        jms_module_path= getJMSModulePath(jms_module_name)
        cd(jms_module_path)
        cmo.createTemplate(jms_temp_name)
        cd(jms_module_path+'/Templates/'+jms_temp_name)
        cmo.setMaximumMessageSize(20)

def createJMSUDQ(jms_module_name,jndi,jms_udq_name):
        jms_module_path = getJMSModulePath(jms_module_name)
        cd(jms_module_path)
        cmo.createUniformDistributedQueue(jms_udq_name)
        cd(jms_module_path+'/UniformDistributedQueues/'+jms_udq_name)
        cmo.setJNDIName(jndi)
    #    cmo.setDefaultTargetingEnabled(bool("true"))
        cmo.setSubDeploymentName(subdeployment_name)

def createJMSConnectionFactory(jms_module_name,cfjndi,jms_cf_name):
        jms_module_path = getJMSModulePath(jms_module_name)
        cd(jms_module_path)
        cf = create(jms_cf_name,'ConnectionFactory')
        jms_cf_path = jms_module_path+'/ConnectionFactories/'+jms_cf_name
        cd(jms_cf_path)
        cf.setJNDIName(cfjndi)
        cd (jms_cf_path+'/SecurityParams/'+jms_cf_name)
        #cf.setAttachJMXUserId(bool("false"))
        cd(jms_cf_path+'/ClientParams/'+jms_cf_name)
        cmo.setClientIdPolicy('Restricted')
        cmo.setSubscriptionSharingPolicy('Exclusive')
        cmo.setMessagesMaximum(10)
        cd(jms_cf_path+'/TransactionParams/'+jms_cf_name)
        #cmo.setXAConnectionFactory(bool("true"))
        cd(jms_cf_path)
        cmo.setDefaultTargetingEnabled(bool("true"))

adminUser=configProps.get("adminUser")
adminPassword=configProps.get("adminPassword")
adminURL=configProps.get("adminURL")

connect(adminUser,adminPassword,adminURL)

edit()
startEdit()

 # ====# JMS CONFIGURATION## ##########################################
total_temp=configProps.get("total_temp")
total_udq=configProps.get("total_udq")
total_conf=configProps.get("total_conf")
tot_djmsm=configProps.get("total_default_jms_module")
subdeployment_name=configProps.get("subdeployment_name")

a=1
while(a <= int(tot_djmsm)):
        var1=int(a)
        jms_mod_name=configProps.get("jms_mod_name"+ str(var1))
        cluster=configProps.get("jms_mod_target"+ str(var1))
        createJMSModule(jms_mod_name,cluster)
        i=1

        while(i <= int(total_temp)):
                t_name=configProps.get("temp_name"+ str(i))
                createJMSTEMP(jms_mod_name,t_name)
                i = i + 1

        j=1
        while(j <= int(total_udq)):
                udq_name=configProps.get("udq_name"+ str(j))
                udq_jndi=configProps.get("udq_jndi"+ str(j))
                createJMSUDQ(jms_mod_name,udq_jndi,udq_name)
                j = j + 1
        k = 1
        while(k <= int(total_conf)):
                conf_name=configProps.get("conf_name"+ str(k))
                conf_jndi=configProps.get("conf_jndi"+ str(k))
                createJMSConnectionFactory(jms_mod_name,conf_jndi,conf_name)
                k = k + 1
        a = a+1

save()
activate(block="true")
disconnect()
############################################################

The sample properties listed for helping out how to create here for your projects.
###############################################################################
# JMS SUBDEPLOY CONFIGURATION
###############################################################################
total_subdply=1
total_default_jms_module=1
total_conf=1
subdeployment_name=demoSub

###############################################################################
# JMS CONNECTION FACTORY CONFIGURATION
######################################################
conf_jndi1=demoCF
conf_name1=jms/demoCF

###############################################################################
#   UNIFORM DISTRIBUTED QUEUE CONFIGURATION
###############################################################################
 

total_temp=0
total_udq=2
udq_name1=jmsIncomingChannel
udq_jndi1=jms/incoming/response
temp_name1=jmsIncomingChannel1

udq_name2=jmsOutgoingChannel
udq_jndi2=jms/outgoing/response
temp_name2=jmsOutgoingChannel1

adminUser=weblogic
adminPassword=welcome1
adminURL=t3://192.168.1.106:8100
###############################################################################
# JMS MODULE CONFIGURATION
###############################################################################
total_default_jms_module=1
jms_mod_name1=demo_jmsmod
jms_mod_target1=democlstr

To execute this JMS Module with subdeployments you need to pass the properties file as argument
java weblogic.WLST jms_module.py jms_module.properties
pavanbsd@ubuntu:~/pybin$ wlst jmsmodnq.py jmsmodnq.properties

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Connecting to t3://192.168.1.106:8100 with userid weblogic ...
Successfully connected to Admin Server "demoadmin" that belongs to domain "demodomain".

Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.

Location changed to edit tree. This is a writable tree with
DomainMBean as the root. To make changes you will need to start
an edit session via startEdit().

For more help, use help('edit')
You already have an edit session in progress and hence WLST will
continue with your edit session.

Starting an edit session ...
Started edit session, please be sure to save and activate your
changes once you are done.
drw-   jms_ms1
drw-   jms_ms2

MBean type JMSSystemResource with name demo_jmsmod has been created successfully.
MBean type ConnectionFactory with name jms/demoCF has been created successfully.
Saving all your changes ...
Saved all your changes successfully.
Activating all your changes, this may take a while ...
The edit lock associated with this edit session is released
once the activation is completed.
Activation completed
Disconnected from weblogic server: demoadmin

Keep writing back 🔙 your error screen shot comments and suggestions on this post. Keep smiling cheers!! 

Wednesday, October 28, 2009

Dynamic Domain creation with WLST

Introducing Dynamism

Hey all wise WLA welcome to this exclusive WLST blog again!

My dear buddies, this week I was invited  for a discussion on generic and dynamic domain creation in WebLogic for a development environment. The need of a script that is generic in the sense not specific to any operating environments such as Solaris, Linux, Windows or Mac. And, It should prompt for all the desired inputs to build a basic WebLogic domain in a development environment.

It looks like some what interactive and can be dynamic.

After looking into many search engines we did not get any generic or dynamic one. We took this from some part of the script from WebLogic forums and some from python forums. Finally got into conclusion that you need few lines of python required for Operating environment details to fetch from the system.


Why Dynamic Domain Script?


  • The richness of this script is that,  you can use this for your environment directly.
  • This is reusable script.
  • It is for time saving compare to the regular config.sh execution
  • ease of use script
  • You can execute on Windows same script can run on Solaris without any changes
We also experimented this same script executed in WebLogic 9.x version and again in WebLogic 11g also successfully. So this dynamic and generic domain configuration script publishing for the all who want to explore the WLST with their experiments.


Prerequisites and preparation



To execute this script you must define the following:

1. JAVA_HOME define this from WebLogic installation paths
2. WL_HOME define this as WebLogic installation
3. CLASSPATH must have weblogic.jar for running weblogic.WLST
4. PATH must contain JAVA_HOME/bin to run java commands
After setting these you can verify above with echo each environment variable. In Nix platform you can try as:
echo $PATH 
echo $CLASSPATH
echo $WL_HOME
echo $JAVA_HOME
In Windows you can verify it by replace $ with % symbol.

###########################################################
# This script will dynamically create the domain as per your inputs
# Run on : Oracle WebLogic 8.1, 9.2 10.3 (11g)
# Author : Pavan Devarakonda
###########################################################

import os

WLHOME=os.environ['WL_HOME']

#==========================================
# Create a domain from the weblogic domain template.
#==========================================
readTemplate(WLHOME+'/common/templates/domains/wls.jar')
cd('Servers/AdminServer')
AdminName=raw_input('Please Enter Admin ServerName: ')
set('Name',AdminName)
#==========================================
# Configure the Administration Server
#==========================================
AdminListenAdr=raw_input('Please Enter Admin Listen Address: ')
AdminListenPort=int(input('Please enter Admin listen Port: '))

set('ListenAddress',AdminListenAdr)
set('ListenPort', AdminListenPort)

#====================================================
# Define the password for user weblogic. You must define the password before you
# can write the domain.
#====================================================
cd('/')
cd('Security/base_domain/User/weblogic')
usr=raw_input('Please Enter AdminUser Name: ')
set('Name',usr)
AdminPassword=raw_input('Please enter Admin password:')
cmo.setPassword(AdminPassword)

# - OverwriteDomain: Overwrites domain, when saving, if one exists.
setOption('OverwriteDomain', 'true')

#==============================================
# Write the domain, close template and finally exit from the WLST
#==============================================
domainPath=raw_input('Enter the domain path: ')
domainName=raw_input('Enter domain name: ')
print 'Given domain path, name : ', domainPath, domainName
writeDomain(domainPath+"/"+domainName)
closeTemplate()
exit()


Sample Execution
Assume that you saved the above script with the name as "createDomain.py". Of course you can choose your own name for the script!
At your command prompt you can invoke this script as follows:

[WLA@server~/.AdminScripts]$ java weblogic.WLST createDomain.py 
 
Initializing WebLogic Scripting Tool (WLST) ...
 
Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands
 
Please Enter Admin ServerName: testAdmin
Please Enter Admin Listen Address: 127.0.0.1
Please enter Admin listen Port: 8007
Please Enter AdminUser Name: system
Please enter Admin password:weblogic103
Enter the domain path: /home/wluser/domains/    
Enter domain name: testdomain
Given domain path, name :  /home/wluser/domains/testdomain
 
Exiting WebLogic Scripting Tool.
 
[WLA@server~/.AdminScripts]$ cd ../domains
[WLA@server~/domains]$ ls 
nmdomain103    testdomain

If you want the same thing without interactive mode, you just want to change the values you don't want to change the Python script for customizing your WebLogic domain then you can use properties file as shown below:

# File: myWLSTdom.properties
domainTemplate=c:/wls12c/wlserver/common/templates/domains/wls.jar

#Following property is the default property and should not be changed.
weblogicdomainpasspath=Security/base_domain/User/weblogic

adminUser=weblogic
adminPassword=weblogic123$


adminServerName=admin_myWLSTdom
adminServerListenaddr=localhost
admlistenport=7100

OverwriteDomain=true
domainName=myWLSTdom
domainHome=/wldomains/myWLSTdom

Creating WLST base domain


Now let use the properties file and have simple adminserver configurations can be customized with set function.

loadProperties('myWLSTdom.properties')
readTemplate(domainTemplate)

def printInStyle(txt):
 print'-'*10 +txt
 
cd('Servers/AdminServer')
printInStyle('Give your custom AdminServer name')
set('Name',adminServerName)

printInStyle('Set the ListenAddress and ListenPort')
set('ListenAddress',adminServerListenaddr)
set('ListenPort', int(admlistenport))

# Security
printInStyle('Creating Password')
cd('/')
cd(weblogicdomainpasspath)
cmo.setPassword(adminPassword)

printInStyle('Setting StartUp Options')
setOption('OverwriteDomain', OverwriteDomain)

# Create Domain to File System
printInStyle('Writing Domain To File System')
# Change the path to your domain accordingly
writeDomain(domainHome)
closeTemplate()
# Exiting
print('Exiting now...')
exit()

Little cosmotizing with function 'printInStyle', here we can give any symbol then we can have multiple times the number you postfix to the '*'. In the above we had 10 times '-' symbol is printed then the text message.

C:\pbin>java weblogic.WLST -skipWLSModuleScanning create_basedomain.py

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

----------Give your custom AdminServer name
----------Set the ListenAddress and ListenPort
----------Creating Password
----------Setting StartUp Options
----------Writing Domain To File System
Exiting now...


Exiting WebLogic Scripting Tool.


Create Production Domain with WLST


A base WebLogic domain in production mode with generic option using properties file. If you compare with the above script this is having properties and more generic. We have experimented this script with Windows and Linux platforms.

readTemplate(TMPLATE)
cd('/')
cmo.setName(DOMAIN_NAME)
cd('Servers/AdminServer')
cmo.setListenAddress(ADMIN_LISTENADDRESS)
cmo.setListenPort(int(ADMIN_PORT))
cd( '/' )
cd( 'Security/'+DOMAIN_NAME+'/User/' +ADMIN_USER)
cmo.setPassword(ADMIN_PWD)
cd('/')
setOption("ServerStartMode", "prod")
setOption("OverwriteDomain", "true")

writeDomain( DOMAIN_DIR+’/'+DOMAIN_NAME )
closeTemplate()



Let me try with the WebLogic 11g version, if you have latest 12c then the domain template path changes as C:/Oracle/Middleware/wlserver/common/templates/wls/wls.jar
If you are using vagrant box use /home/vagrant/fmw/oraclehome/wlserver/common/teplates/wls/wls.jar
The sample properties file looks like this:

TMPLATE = 'C:/Oracle/Middleware/wlserver_10.3/common/templates/domains/wls.jar'
ADMIN_PORT = 8001 
ADMIN_PWD =  weblogic123
ADMIN_USER = weblogic
DOMAIN_DIR = C:/wlsdomains
DOMAIN_NAME = NC_DOMAIN
ADMIN_LISTENADDRESS = 192.168.1.18


java weblogic.WLST -loadProperties ncdomain.properties createproddomain.py

Confirmation of the Domain creation as following screen shot:

WebLogic production domain created with WLST




Suggestions and improvements

1. You can improve this script for Clustered environment.
2. You can add more functions for each resource configurations such as JDBC DataSource, JMS, and application deployment
3. Verifying the given domain path is also recommended
4. The python script must have exception handling I mean there should try: except: blocks to make more robust.

Buddy you can extend your domain template using pack and unpack commands.

Popular Posts