Search This Blog

Showing posts with label WebLogic12c. Show all posts
Showing posts with label WebLogic12c. Show all posts

Wednesday, August 31, 2022

JMS Module with ConnectionFactory and Queue configuration using WLST

After almost three and half years again revisited to the JMS module script. This time the project needs are quite different. Where the Oracle WebLogic domains classified environments  but they are standalone server domains. That is only AdminServer will be there in the domain and that would be target for the JMS module, JMS Destinations.



Lets begin the experimenting now, the prerequisites for this are:

  1. A WebLogic Domain configured with single AdminServer
  2. AdminServer should be up and RUNNING
  3. To execute the WLST script required PATH, alias should be defined in the profile as shown below:
  4. export MW_HOME=/u01/app/oracle/fmw
    export WL_HOME=$MW_HOME/wls/wlserver
    export USER_MEM_ARGS="-Djava.security.egd=file:/dev/./urandom"
    alias wlst="$MW_HOME/oracle_common/common/bin/wlst.sh -skipWLSModuleScanning"
    

    You can use this freshly created alias wlst at any directory to invoke WLST shell.  The option -skipWLSModuleScanning is easy, faster learnt while working on docker containers and simple way to use.

  5. Execute the configure JMS Servers
  6. The WLST Script for JMS configurations and all frequently changing values are moved into the properties file.


#========================================
# WLST Script purpose: Configuring JMS Module
# Author: Pavan Devarakonda
# Update date: 3rd Aug 2017
#========================================
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)

##########################################
# Create JMS Moudle will take the 
# arguments as name, subdeployment name
# target can be on admin or managed server or cluster
##########################################
def createJMSModule(jms_module_name, adm_name, subdeployment_name):
        cd('/JMSServers')
        jmssrvlist=ls(returnMap='true')
        print jmssrvlist
        cd('/')
        module = create(jms_module_name, "JMSSystemResource")
        #cluster = getMBean("Clusters/"+cluster_target_name)
        #module.addTarget(cluster)
        #adm_name=get('AdminServerName')
        adm=getMBean("Servers/"+adm_name)
        module.addTarget(adm)
        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)

##########################################
# JMS Queu configuration function 
# arguments are : JMS module name, Queue jndiname
# Queue name, jndi name hu
##########################################
def createJMSQ(jms_module_name,jndi,jms_queue_name):
        jms_module_path = getJMSModulePath(jms_module_name)
        cd(jms_module_path)
        cmo.createQueue(jms_queue_name)
        cd(jms_module_path+'/Queues/'+jms_queue_name)
        cmo.setJNDIName(jndi)
        cmo.setSubDeploymentName(subdeployment_name)

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

connect(adminUser,adminPassword,adminURL)
#adm_name=get('AdminServerName')
adm_name=ls('Servers',returnMap='true')[0]
print adm_name
edit()
startEdit()

##########################################
#   JMS CONFIGURATION## 
##########################################
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)):
        i=int(a)
        jms_mod_name=configProps.get("jms_mod_name"+ str(i))
        #cluster=configProps.get("jms_mod_target"+ str(i))
        subdeployment_name=configProps.get("subdeployment_name"+ str(i))
        createJMSModule(jms_mod_name,adm_name,subdeployment_name)
        total_q=configProps.get("total_queue"+str(i))
        j=1
        while(j <= int(total_q)):
                queue_name=configProps.get("queue_name"+ str(i)+str(j))
                queue_jndi=configProps.get("queue_jndi"+ str(i)+str(j))
                createJMSQ(jms_mod_name,queue_jndi,queue_name)
                j = j + 1
        i=i+1
        a = a+1
save()
activate(block="true")
disconnect() 


Now see this is a sample of properties file that could help you to build the JMS Module, be read by the WLST script at the run time:
###################################################
# JMS SUBDEPLOY CONFIGURATION
###################################################
total_subdply=2
total_default_jms_module=2
total_conf=0
subdeployment_name1=DemoJMSFAServer1
subdeployment_name2=DemoJMSFAServer2

###################################################
# JMS MODULE CONFIGURATION
###################################################
jms_mod_name1=Demo-SystemModule1
jms_mod_name2=Demo-SystemModule2

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

###################################################
#   JMS QUEUE CONFIGURATION
###################################################

total_queue1=2
queue_name11=Q1
queue_jndi11=Q1

queue_name12= BQ1
queue_jndi12= BQ1


total_queue2=2
queue_name21=Q2
queue_jndi21=Q2

queue_name22= BQ2
queue_jndi22= BQ2

#========== ADMIN DETAILS =========================
adminUser=weblogic
adminPassword=welcome1
adminURL=t3://192.168.33.100:8100
output
$ wlst jms_module.py jms_module.properties

let's see what happen when you apply this logic on your project? Did you notice any errors? Please write back 🔙 with your error screen shot. 

How do you know everything went well? Open the WebLogic Administration console to check the JMS Module Configuration has successfully created a new JMS resource or not.

You may be intrested to learn more WLST scripting for JMS you can also visit the Uniform Distributed Queue configuration post. Thanks for being with us in this post, Please write to us your errors and exceptions when you run this script.

Saturday, February 3, 2018

Remotely domain extension using WLST

WebLogic latest version 12.2.x come up with different WebLogic domain templates and their usage methods in WLST. Usually WebLogic domain can be created with base domain template using wls.jar. Then after that domain need to be customized as the projects where we need the extended domain.

  1. When the domain spread across multiple machines/nodes
  2. One successful configuration domain reuse to create new domains
Here is small experiment with the domain template, here we have two nodes associated with  192.168.33.100 - Machine100 and 192.168.33101 - Machine101 IP addresses and machine. The admin server configured in the Machine100 and also two web servers in webcluster, two app servers in appcluster. The whole configuration we need in Machine101.

Earlier to WebLogic 12.2 version we have pack and unpack option only for the domain expansion in the remote machine otherwise copy the domain folder need to copy. 

In the latest versions of WebLogic 12.2.x above are having different WLST methods that relates to template usage.
Remotely extension of WebLogic Domain using WLST and pack-unpack
Lets explore options available in WLST

selectTemplate() in WLST

There are multiple domain templates, extension templates for domains are available in Oracle WebLogic installation media pack it self. Some of the application specific templates also available with the media pack.

selectCustomTemplate() in WLST

We can create our own WebLogic domain template using writeTemplate() that will be containing the project specific configurations such as - servers, cluster, JDBC, JMS are pre-configured and reusable. The select custom template method followed by loadTemplate command.

loadTemplates() in WLST

The loadTemplates(0 is the command always used after selectTemplate or selectCustomTemplate commands.

Automation solution: Create domain template and configure domain


Like here we need to create extension domain in the Machine101, you may need to to do for multiple machines in production environments.

The process is simplified into few steps
  1. connect to the existing domain
  2. Read the domain and generate the custom domain template
  3. Create the extended domain enter the same domain name and path or fresh domain can be configured with the new domain name, listen address modification as required

#======================================
# 
# File: remoteDomain.py
# Applicable WebLogic version: 12.2.x
# This will solve pack and unpack strange issues
#
#===============================================
def printline(s):
    print "-"*10 + s
 
def createDomainTemplate(templateLocation):
    
    ''' Generate the custom domain template  '''
    connect(admuser,admpass,admurl)
    
    print ("Writing Custom Template...")
    writeTemplate(templateLocation)
    print ("Writing Template...: Completed")
    disconnect()
    
def create_Domain(templateLocation, domainPath):
 ''' Creating extended domain remotely 
 selectCustomTemplate, loadTemplates will get the inputs
 then writeDomain will create the domain '''
 
 selectCustomTemplate(templateLocation)
 loadTemplates()
 print ("Creating extended domain...")
 writeDomain (domainPath)
 closeTemplate()
 print ("Creating domain...: Completed")
       
       
def main():
 '''
 Change the following values according to your domain
 user security better to use storeuserconfig
 and domain template 
 you can move these variables into properties file
 '''
 templateLocation ='/u01/app/oracle/prod_domain_template.jar'
 domainPath='/u01/app/oracle/prod_domain'
 admuser='weblogic'
 admpass='welcome1'
 admurl='192.168.33.100:8001'
 
 createDomainTemplate(templateLocation)
 create_Domain(templateLocation, domainPath)
    
if __name__ == "__main__":
    printline()
    print("SCRIPT BEING RUN DIRECTLY")
    printline()
    main()
 printline()

Remotely execution of script

WLST SCRIPT

Saturday, April 8, 2017

WebLogic 12c Cluster Domain configuration using WLST offline

Objective of this script is to Leverage the time takes to configure the WebLogic Domain and after starting the admin server then following list need to be configured for HA/reliability.
Everytime I work on new project there is a need of creation of the clustered domain. From my past experiences collected all basic requirements together list them over here.

  • AdminServer configuration includes Name, Listen Address, ListenPort
  • User credentials username, password
  • After writing basic domain going for create machine which include Name, type of machine
  • Nodemaager includes NMTypes such as plain, ssl, hosted node, nodemanager port
  • Managed servers have Name, ListenAddress, ListenPort, set machine
  • Cluster includes name, ClusterAddress, Servers part of the cluster interesting part here
Assumptions for this task:

WebLogic 12.2.1 cluster domain creation with WLST
WLST Configuring WebLogic Cluster Domain


In the script as per my convenience some of them are hardcoded, My hardcoded values:
  1. Managed Server list
  2. Cluster list
In this script lots of Python sequence functions are used.

  • List index, 
  • Dictionary keys
  • String startwith

Lets begin the fun of WLST HERE...
# purpose:  Create the domian with the one Admin Server along with the
# two managed servers in each cluster. app_cluster, web_cluster
# Assumption here all managed servers runs on the same machine
# Modified date: 07-April-2017
# File name     :       create_clusterdomain.py
# Dependencies  :       cluster_domain.properties
# Note this names of managed servers, cluster, hostname all hard coded
#
def printline(s):
    print "-"*10 + s

loadProperties('/u01/app/software/scripts/pybin/cluster_domain.properties')

# Created a Cluster and assaign the servers to that cluster
# Create a domain from the weblogic domain template

WLHOME=os.environ["WL_HOME"]
readTemplate(WLHOME+'/common/templates/wls/wls.jar')
printline("reading template completed")

# Configure the Administration Servers with out using SSL Port

cd('Servers/AdminServer')
set('ListenAddress',WLSAdminIP)
set('ListenPort', int(AdminPort))

printline("AdminServer ListenAddress, port set")

cd('/')
cd('Security/base_domain/User/weblogic')
cmo.setPassword(AdminPasswd)
printline("User credentials set")

setOption('OverwriteDomain', 'true')
writeDomain(DomainPath+'/'+DomainName)
printline("Domain creation done.")

closeTemplate()
readDomain(DomainPath+'/'+DomainName)
machines={'myM100':'192.168.33.100', 'myM110':'192.168.33.110'}

for m in machines.keys():
        cd('/')
        create(m, 'UnixMachine')
        cd('Machine/' + m)
        create(m, 'NodeManager')
        cd('NodeManager/' + m)
        set('ListenAddress', machines[m])
        set('NMType','ssl')

# Create the Managed Servers and  configuration them
ManagedServerList=['app01','app02','web01','web02']

app_ca=""
web_ca=""
for s in ManagedServerList:
        cd('/')
        create(s,'Server')
        cd('Server/'+s)
        i=ManagedServerList.index(s)
        lp=8101+i
        set('ListenPort', int(lp))
        j=int(s[-1])
        m=machines.keys()[j-1]
        set('ListenAddress', machines[m])
        set('Machine', m)

        if s.startswith('app') :
                if j%2==0:
                        app_ca+=','
                app_ca+=machines[m]+':'+str(lp)

        elif s.startswith('web'):
                if j%2==0:
                        web_ca+=','
                web_ca+=machines[m]+':'+str(lp)

        printline("Managed server :"+s+" created")

printline("configured managed servers done.")
printline("app cluster address:"+app_ca)
printline("Web cluster address:"+web_ca)

# Create and Configure a Cluster and assian the Managed Servers to that cluster
clusters={'app_clustr1':'app01,app02', 'web_clustr1':'web01,web02'}
clstrs=clusters.keys()
for c in clstrs:
        cd('/')
        create(c,'Cluster')
        assign('Server', clusters[c],'Cluster', c)
        cd('Clusters/'+c)
        set('ClusterMessagingMode','multicast')
        if c.startswith('app'):
                set('ClusterAddress',app_ca)
        elif c.startswith('web'):
                set('ClusterAddress',web_ca)
        set('MulticastAddress','237.0.0.101')
        set('MulticastPort',7200+clstrs.index(c))
        printline("cluster "+c+" created")

printline("Configured clusters and assigned managed servers done.")
#Write the domain and Close the domain template

updateDomain()
closeDomain()

printline("Task completed successfully, exiting!!!")
exit()

Now the properties file which you can enhance with your limitations
WLSAdminIP=192.168.33.100
AdminPort=8001
AdminPasswd=welcome1
DomainPath=/u01/app/oracle/domains
DomainName=uat_domain


Lets have the execution screen for you:





Please write your valuable feedback on this post, so that we can keep improve further to have more interesting fun stuff soon for you.

Popular Posts