Search This Blog

Showing posts with label Cluster. Show all posts
Showing posts with label Cluster. Show all posts

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.

Thursday, April 11, 2013

Home

Do you know this fun thing about Python scripting sing a poem of quotations just by by importing 'this' module.
wls:/offline> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
wls:/offline>

Content

You are invited for the contribution of WLST scripts and articles.

Technorati Claim token code JDU3DCFE66EH

Friday, February 12, 2010

Restarting 24 x 7 Domain with WLST

Here I have little bit struggle to reach a conclusion that, what all servers need to stop? when to stop? the preparing script I did with my analysis that stated that few sites requires 24x7 HA. Few of them don't need the HA, that is site can have sometime outage where it doesn't have request for the application.

Me and Prasanna Yalam discussed about a strategy where every time you run few servers can be stopped from different physical locations. when starting them up then only next round of managed servers can be stopped. This strategy implementation firstly thought with 2 scripts then I made it 2 phases one by one can be done with user input. This module named as 'regularStop()', which supports 24x7 HA domain.

One more thing we need to consider here is most of the Production deployments are in nostage mode, when new version release of application code requires complete domain down option requirement. This is another module take cares where it will stop all clusters in the domain should be passed. The module named as 'releaseStop()'. This you can use for any WebLogic domain.


After composing whole script ran it then found that there is need of server state or cluster state when it is given shutdown command. So every shutdown command is followed by state command given that gives more confidence on script how it is executing.

Finally by performing releaseStop() or RegularStop() we can go for stopping the Admin Server.


Note: Don't forget proper indentations, while editing my script it might be disturbed here.
#====================================
# Script File: StopWLDomain.py
# This module is for 24x7  Domain****
# First phase stops few managed servers of few sites
# Second phase will be used for stop remaining servers
# Note that Second phase allowed only when you press 'y'
# before that you need to Start all the Phase 1 stopped servers.
#====================================
def conn():
 try:
  connect(user, passwd, adminurl)
 except ConnectionException,e:
  print '\033[1;31m Unable to find admin server...\033[0m'
  exit()

#====================================
# Stop all instances of a Cluster 
#====================================
def stopClstr(clstrName):
 try:
  shutdown(clstrName,"Cluster")
  state(clstrName,"Cluster")
 except Exception, e:
  print 'Error while shutting down cluster ',e
  dumpStack()
  return

#====================================
# All the instances of all Clusters will be down for release
#====================================
def releaseStop():
 clstrList=["webclstr1", "webclstr2'..."ejbclstr"]
 for clstr in clstrList:
  stopClstr(clstr) 

#====================================
# Stop a instances given as parameter 
#====================================
def stopInst(iservr):
 try:
  state(str(iservr))
  shutdown(str(iservr), 'Server',force="true")
  state(str(iservr))
 except Exception, e:
  print iservr, 'is having error in shutting down'
  pass

#====================================
# Regular Rstart is 24x7 supported for :SITE1, SITE2, SITE3
#====================================
def regularStop():
 clstrList=["non247clstr1", "non247clstr2"]
 for clstr in clstrList:
  stopClstr(clstr) 
 servrList=servrList=["app1","app2","app3"... "web1","web2"] #sitewise list of servers need to stop
 for inst in servrList:
  stopInst(inst)
 print 'Now, please start the instances exclude the phase 2 instances ...'
 phase2=raw_input("Want to proceed for Phase 2...(y/n)")
 if phase2 == 'y':
  serverList=["app4","web3"...] # remaining Managed Servers to stop after phase servers UP n Running
  for inst in serverList:
   stopInst(inst)

#====================================
# Exiting the script
#====================================
def quit():
 disconnect()
 exit()

#====================================
# The main script starts here...
#====================================
if __name__ == "main":
 conn()
 print ' 1. Regular Stop (24x7)\n 2. Release Stop\n 0. Quit\n'
 sAns=raw_input('Enter your choice: ')
 if int(sAns) == 1:
 regularStop()
 elif int(sAns) == 2:
 releaseStop()
 elif int(sAns)== 0:
 quit()
 else:
 print 'Warning: Invalid option...'
 exit()
 print 'Finally stopping admin now...'
 shutdown()

#========WLST=BY=EXAMPLES==============

You can run this script with java in your PATH and weblogic.jar in the CLASSPATH.
java weblogic.WLST StopWLDomain.py

Popular Posts