Search This Blog

Oracle Fusion Middleware Administration Course

Oracle Fusion Middleware Administration Course
OFMW Admin Course

Friday, August 4, 2017

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 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 module, JMS Destinations.

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

  1. A WebLogic Domain configured with single AdminServer
  2. Server should be up and running
  3. To execute the WLST script required PATH, alias should be defined in the profile
  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 alias wlst at any directory to invoke WLST shell.  The option -skipWLSModuleScanning is easy, faster learnt while working on docker and simple way to use.

  5. Execute the configure JMS Servers
  6. WLST Script and all frequently changing values in 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, 
# Queue name, jndi name
##########################################
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 the sample properties file:
###################################################
# 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?

How do you know everything went well? Open the WebLogic 12 administration console to check the JMS Module Configuration has successful or not.

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.

Wednesday, July 26, 2017

Logging configuration for domain and WebLogic server

Why we need Logging?
To understand in a basic level, when we run the WebLogic Servers we don't know what is happening inside the process.  It is kind of black box to us. To know what is happening inside the domain or server side to get more details we have logging mechanism enabled in WebLogic domains.

WebLogic Logging works for multiple hierarchical Subsystem. At the top level it is already enabled and we can use the existing setup. But for some reasons each project will have separate logging needs.

When we can use this?
If there are multiple Testing logging configuration at different levels:
  1. domain logs - global status 
  2. Server logs - admin or managed server status
  3. Resource level logs - JDBC, JMS, application status
We can set the common attributes of JMX MBean reset with new values which will work for your project needs.

While creating this snippet we have tried to execute it on WebLogic 11g [10.3.6] and WebLogic 12c.

########################################################################
# Python Script file: logrotate.py
# Author: Pavan Devarakonda
# Date : 25-Jul-2017
########################################################################
loadProperties('demodomain.properties')
# Functions
def editMode():
   edit()
   startEdit()

def saveActivate():
   save()
   activate()
   print '###### Completed configuration of domain logs ##############'

def exitDisconnect():
        disconnect()
        exit()

def connectToAdmin():
    connect(username,password,url)

def domainlog_rotation(domainname,FC,MinSize):
        """
        It will take the three parameters domainpath ,domainname is string values
        and FileCount -  FC and File MinSize - MinSize are integer values these values loaded from properties
        so they need to type cast to integers
        """
        cd('/Log/'+domainname)
        cmo.setRotationType('bySize')
        cmo.setRotateLogOnStartup(true)
        cmo.setFileCount(int(FC))
        cmo.setNumberOfFilesLimited(true)
        cmo.setFileMinSize(int(MinSize))
        cmo.setLogFileRotationDir(domainpath+domainname+'/RotationDir')
        save()

def ServerLogRotation(S,SFC,SMinsize):
        """
        This module will rotate the AdminServer or Managed Server loggger settings
        It takes three params - S as name of the server, SFC - Server FileCount, SMinsize - Server FileMinSize
        """
        print S+ ' server log  setting...'
        cd('/Servers/'+S+'/Log/'+S)
        cmo.setRotationType('bySize')
        cmo.setRotateLogOnStartup(true)
        cmo.setFileCount(int(SFC))
        cmo.setNumberOfFilesLimited(true)
        cmo.setFileMinSize(int(SMinsize))
        cmo.setLogFileRotationDir(domainpath+domainname+'/RotationDir +S')

def printline(): print '#'*50

def main():
        printline(); print 'Starting domain logs Configurations '; printline()
        connectToAdmin()
        editMode()
        domainlog_rotation(domainname,FC,MinSize)
        printline(); print 'Starting Server logs configurations' ; printline()
        cd('/')
        for server_name in ls('Servers',returnMap='true'):
                if server_name == 'AdminServer':
                        ServerLogRotation(server_name,ASFC,ASMinsize)
                else:
                        ServerLogRotation(server_name,MSFC,MSMinsize)
        saveActivate()
        exitDisconnect()

main()

Please double check all indentation blocks.
The properties file used for sample tests is as follows:

#WebLogic console connection parameters
username=weblogic
password=welcome1
url=t3://192.168.33.102:8001
domainname=demo_domain

# Domain logger configurations
FC=4
MinSize=5
domainpath=/u01/oracle/domains/

# ManagedServer logger configurations
MSFC=3
MSMinsize=2

# AdminServer logger configurations
ASFC=5


Sample execution output as follows:
WebLogic Logger configuration using WLST 

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.

Wednesday, February 22, 2017

Restricted JRF WebLogic infrastructure domain configuration using WLST

While working on Fusion Middleware products we need to prepare the WebLogic restricted JRF domain, most of the time configuration Wizard leads to confusion and stuck with what to do for RCU configurations. Even when you need to create a domain for Collocated OHS Environment.

Pr-requisites:
  1. Oracle JDK Installed
  2. Oracle Fusion Middleware Infrastructure 12.2.1 installed
  3. Environment setup with bash profile
Templates used for configuring the Restricted JRF domain

  1. JRF Restricted template - oracle.jrf_restricted_template.jar
  2. Enterprise Manager - oracle.em_wls_restricted_template.jar
  3. Coherence - wls_coherence_template.jar [default selected with above anyone of the template]


 Lets first create the properties file:

TEMPLATE=/u01/app/oracle/fmw1221/wlserver/common/templates/wls/wls.jar 
MW_HOME=/u01/app/oracle/fmw1221
ADMIN_LISTEN_ADDRESS=192.168.33.100
ADMIN_PORT=8001
ADMIN_USER=weblogic
ADMIN_PWD=Welcome1
DOMAIN_NAME=RestrictedJRF_Domain
DOMAIN_DIR=/u01/app/oracle/domains

Note: You could modifiy the MW_HOME  path

The WLST Script is  as follows:

def create_prod_domain():
 print "Reading base domain tempalte"
 readTemplate(TEMPLATE)
 cd('/')

 print "AdminServer settings"
 cmo.setName(DOMAIN_NAME)
 cd('Servers/AdminServer')
 cmo.setListenAddress(ADMIN_LISTEN_ADDRESS)
 cmo.setListenPort(int(ADMIN_PORT))
 cd( '/' )
 cd( 'Security/'+DOMAIN_NAME+'/User/' +ADMIN_USER)
 cmo.setPassword(ADMIN_PWD)
 cd('/')

 print "Production domain setup.."
 setOption("ServerStartMode", "prod")
 setOption("OverwriteDomain", "true")
 writeDomain( DOMAIN_DIR+'/'+DOMAIN_NAME )
 print "=============================================="
 print "Production domain created successfully..."
 print "=============================================="

 closeTemplate()


def apply_jrf2domain():
 # Apply the JRF Template.
 print "reading domain:"+DOMAIN_NAME
 readDomain(DOMAIN_DIR+'/'+DOMAIN_NAME )
 addTemplate(MW_HOME + '/oracle_common/common/templates/wls/oracle.jrf_restricted_template.jar')
 print "Adding Template :oracle.jrf_restricted_template.jar"

 # I'm including the EM template too.
 addTemplate(MW_HOME + '/em/common/templates/wls/oracle.em_wls_restricted_template.jar')
 print "Added Template :oracle.em_wls_restricted_template.jar"

 updateDomain()
 print "Updated the domain with Restricted JRF and Enterprise Manager templates"
 closeDomain()
 print "Close the domain"
 exit()

def main():
 print "=============================================="
 print "Welcome to Restricted JRF domain configuration"
 print "=============================================="

 create_prod_domain()
 print "Domain created successfully..."
 apply_jrf2domain()

main()

The script execution will be as follows:
wlst -loadProperties RestrictedJRF_domain.properties create_RestrictedJRF_domain.py

Note: wlst must be aliased to the Infrastructure installation wlserver path
Restricted JRF WebLogic infrastructure domain with EM template
 Advantage of this domain:
  • Enterprise Manager Fusion Middleware Control
  • Easy to work on FW products such as SOA, OSB, and Collocated OHS etc
Note that it will be consuming more memory foot print than regular base domain.

Start your Restricted JRF Domain and when you look into WebLogic Admin console deployments see the following:

WebLogic Restricted Domain deployment

Popular Posts

Oracle WebLogic Administration Course

Oracle WebLogic Administration Course
WebLogic Training

Followers