Showing posts with label Automation. Show all posts
Showing posts with label Automation. Show all posts

Friday, February 26, 2010

WebSphere automated deployment on Hudson

Hudson CI server provides plug-in for automated deployment to Tomcat or JBoss servers. But on my current job we use IBM WebSphere as application server in cluster environment. To implement nightly builds with automated testing we had to figure out way to automate deployment.

General idea and code is based on Luciano Resende's posting.



Usual deployment procedure for IBM WebSphere cluster is:



1.Stop cluster

2.Undeploy application

3.Deploy application and change application parameters like classloaders' order

4.Start cluster

5.As a part of automated testing procedure, we had to wait till start completes and then start test

All these steps could take 10-15 minutes depending on environment, was security enabled or not, etc.

To implement automated deployment for WebSphere we can use wsadmin thin client and Apache ant in conjunction with bash scripts.



In order to use wsadmin remotely, several files need to be copied from IBM Websphere node manager.

Wsadmin script, provided on IBM's site, didn't work for me, so I had to change it slightly.

My version of wsadmin



view sourceprint?

01 #!/bin/bash



02 #set -x



03 # example wsadmin launcher



04 binDir=`dirname "$0"`



05 # WAS_HOME should point to the directory for the thin client



06 WAS_HOME="$binDir"



07 USER_INSTALL_ROOT="$WAS_HOME"



08 # JAVA_HOME should point to where java is installed for the thin client



09 WAS_LOGGING="-Djava.util.logging.manager=com.ibm.ws.bootstrap.WsLogManager -Djava.util.logging.configureByServer=true"



10 if [ -f ${JAVA_HOME}/bin/java ]; then



11 JAVA_EXE="${JAVA_HOME}/bin/java"



12 else



13 JAVA_EXE="${JAVA_HOME}/jre/bin/java"



14 fi



15 CLIENTSOAP=-Dcom.ibm.SOAP.ConfigURL=file:"$USER_INSTALL_ROOT"/properties/soap.client.props



16 CLIENTSAS=-Dcom.ibm.CORBA.ConfigURL=file:"$USER_INSTALL_ROOT"/properties/sas.client.props



17 CLIENTSSL=-Dcom.ibm.SSL.ConfigURL=file:"$USER_INSTALL_ROOT"/properties/ssl.client.props



18 wsadminTraceString=-Dcom.ibm.ws.scripting.traceString=com.ibm.*=all=enabled



19 wsadminTraceFile=-Dcom.ibm.ws.scripting.traceFile="$USER_INSTALL_ROOT"/logs/wsadmin.traceout



20 wsadminValOut=-Dcom.ibm.ws.scripting.validationOutput="$USER_INSTALL_ROOT"/logs/wsadmin.valout



21 # For debugging the utility itself



22 WAS_DEBUG="-Djava.compiler=NONE -Xdebug -Xnoagent"



23 #-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=7777"



24 SHELL=com.ibm.ws.scripting.WasxShell



25 # Parse the input arguments



26 isJavaOption=false



27 nonJavaOptionCount=1



28 for option in "$@" ; do



29 if [ "$option" = "-javaoption" ] ; then



30 isJavaOption=true



31 else



32 if [ "$isJavaOption" = "true" ] ; then



33 javaOption="$javaOption $option"



34 isJavaOption=false



35 else



36 nonJavaOption[$nonJavaOptionCount]="$option"



37 nonJavaOptionCount=$((nonJavaOptionCount+1))



38 fi



39 fi



40 done



41 DELIM=" "



42 C_PATH="$WAS_HOME/com.ibm.ws.admin.client_6.1.0.jar:$WAS_HOME/com.ibm.ws.security.crypto_6.1.0.jar"



43 #Platform specific args...



44 PLATFORM='/bin/uname'



45 case $PLATFORM in



46 AIX
Linux
SunOS
HP-UX)



47 CONSOLE_ENCODING=-Dws.output.encoding=console ;;



48 OS/390)



49 EXTRA_D_ARGS="-Dfile.encoding=ISO8859-1 $DELIM-Djava.ext.dirs="$JAVA_EXT_DIRS""



50 EXTRA_X_ARGS="-Xnoargsconversion" ;;



51 esac



52 # Set java options for performance



53 PLATFORM=`/bin/uname`



54 case $PLATFORM in



55 AIX)



56 PERF_JVM_OPTIONS="-Xms256m -Xmx256m -Xquickstart" ;;



57 Linux)



58 PERF_JVM_OPTIONS="-Xms256m -Xmx256m -Xj9 -Xquickstart" ;;



59 SunOS)



60 PERF_JVM_OPTIONS="-Xms256m -Xmx256m -XX:PermSize=40m" ;;



61 HP-UX)



62 PERF_JVM_OPTIONS="-Xms256m -Xmx256m -XX:PermSize=40m" ;;



63 OS/390)



64 PERF_JVM_OPTIONS="-Xms256m -Xmx256m" ;;



65 esac



66 "$JAVA_EXE" \



67 $EXTRA_X_ARGS \



68 $CONSOLE_ENCODING \



69 $javaOption \



70 $WAS_DEBUG \



71 "$CLIENTSAS" \



72 "$CLIENTSSL" \



73 "$CLIENTSOAP" \



74 ${JAASSOAP:+"$JAASSOAP"} \



75 -Dconfig_consistency_check="$CONFIG_CONSISTENCY_CHECK" \



76 -Dwas.install.root="$WAS_HOME" \



77 -Duser.install.root="$USER_INSTALL_ROOT" \



78 $EXTRA_D_ARGS \



79 $PERF_JVM_OPTIONS \



80 $WAS_LOGGING \



81 $wsadminTraceFile \



82 $wsadminTraceString \



83 $wsadminValOut \



84 $wsadminHost \



85 $wsadminConnType \



86 $wsadminPort \



87 $wsadminLang \



88 -classpath "$C_PATH" \



89 $SHELL "${nonJavaOption[@]}"



90 exit $?





Since we want use in on Hudson, probably on other server and locally, we need Ant script.

It's kinda big and a lot of parameters repeats but it gives idea that's happening.



view sourceprint?

001 <?xml version="1.0"?>



002 <project name="was-integration" basedir=".">



003 <property environment="env"/>



004 <property name="was.python.script" value="./wsIntegration.py"/>



005 <property name="application.name" value="APPLICATION"/>



006 <property name="application.cell" value="CELL"/>



007 <property name="application.cluster" value="CLUSTER"/>



008 <property name="host" value="HOST"/>



009 <property name="port" value="PORT"/>



010 <property name="application.ear" value="PATH_TO_EAR"/>



011 <property name="wsadmin" value="${basedir}/wsadmin.sh"/>



012



013 <target name="clusterState" >



014 <exec dir="." executable="${wsadmin}" outputproperty="currentState">



015 <arg value="-conntype"/>



016 <arg value="SOAP"/>



017 <arg value="-lang"/>



018 <arg value="jython"/>



019 <arg value="-host"/>



020 <arg value="${host}"/>



021 <arg value="-port" />



022 <arg value="${port}"/>



023 <arg value="-f"/>



024 <arg value="${was.python.script}"/>



025 <arg value="clusterState"/>



026 <arg value="${application.cell}"/>



027 <arg value="${application.cluster}"/>



028 </exec>



029 </target>



030



031 <target name="clusterStart" >



032 <exec dir="." executable="${wsadmin}">



033 <arg value="-conntype"/>



034 <arg value="SOAP"/>



035 <arg value="-lang"/>



036 <arg value="jython"/>



037 <arg value="-host"/>



038 <arg value="${host}"/>



039 <arg value="-port" />



040 <arg value="${port}"/>



041 <arg value="-f"/>



042 <arg value="${was.python.script}"/>



043 <arg value="clusterStart"/>



044 <arg value="${application.cell}"/>



045 <arg value="${application.cluster}"/>



046 </exec>



047 </target>



048



049 <target name="clusterStopt" >



050 <exec dir="." executable="${wsadmin}">



051 <arg value="-conntype"/>



052 <arg value="SOAP"/>



053 <arg value="-lang"/>



054 <arg value="jython"/>



055 <arg value="-host"/>



056 <arg value="${host}"/>



057 <arg value="-port" />



058 <arg value="${port}"/>



059 <arg value="-f"/>



060 <arg value="${was.python.script}"/>



061 <arg value="clusterStop"/>



062 <arg value="${application.cell}"/>



063 <arg value="${application.cluster}"/>



064 </exec>



065 </target>



066 <target name="undeployApplication" >



067 <exec dir="." executable="${wsadmin}">



068 <arg value="-conntype"/>



069 <arg value="SOAP"/>



070 <arg value="-lang"/>



071 <arg value="jython"/>



072 <arg value="-host"/>



073 <arg value="${host}"/>



074 <arg value="-port" />



075 <arg value="${port}"/>



076 <arg value="-f"/>



077 <arg value="${was.python.script}"/>



078 <arg value="undeployApplication"/>



079 <arg value="${application.name}"/>



080 </exec>



081 </target>



082



083 <target name="redeployApplication" >



084 <exec dir="." executable="${wsadmin}">



085 <arg value="-conntype"/>



086 <arg value="SOAP"/>



087 <arg value="-lang"/>



088 <arg value="jython"/>



089 <arg value="-host"/>



090 <arg value="${host}"/>



091 <arg value="-port" />



092 <arg value="${port}"/>



093 <arg value="-javaoption" />



094 <arg value="-Dwdm.http.host=${host}" />



095 <arg value="-f"/>



096 <arg value="${was.python.script}"/>



097 <arg value="redeployApplication"/>



098 <arg value="${application.ear}"/>



099 <arg value="${application.cell}"/>



100 <arg value="${application.cluster}"/>



101 <arg value="${application.name}"/>



102 </exec>



103 </target>



104 <target name="fullRedeploy">



105 <antcall target="clusterStopt"/>



106 <exec dir="." executable="./waitForState.sh">



107 <arg value="Cluster State: websphere.cluster.stopped"/>



108 <arg value="${host}"/>



109 <arg value="${port}"/>



110 <arg value="${application.cell}"/>



111 <arg value="${application.cluster}"/>



112 </exec>



113 <antcall target="undeployApplication"/>



114 <antcall target="redeployApplication"/>



115 <antcall target="clusterStart"/>



116 <exec dir="." executable="./waitForState.sh">



117 <arg value="Cluster State: websphere.cluster.running"/>



118 <arg value="${host}"/>



119 <arg value="${port}"/>



120 <arg value="${application.cell}"/>



121 <arg value="${application.cluster}"/>



122 </exec>



123 </target>



124 </project>





Most interesting last part then we stop cluster, wait till it shut downs completely, undeploy application, redeploy application, start cluster and wait will it starts successfully.



We use jython as wsadmin programming language.

Source code for wsIntegration.py



view sourceprint?

01 import sys



02 def clusterStop(cell, cluster):



03 cluster = AdminControl.completeObjectName('cell='+cell+',type=Cluster,name='+cluster+',*')



04 print "Stop Cluster : %s" % ( repr(cluster) )



05 AdminControl.invoke(cluster, 'stop')



06 def clusterStart(cell, cluster):



07 cluster = AdminControl.completeObjectName('cell='+cell+',type=Cluster,name='+cluster+',*')



08 print "Start Cluster : %s" % ( repr(cluster) )



09 AdminControl.invoke(cluster, 'start')



10 def clusterState(cell, cluster):



11 cluster = AdminControl.completeObjectName('cell='+cell+',type=Cluster,name='+cluster+',*')



12 state = AdminControl.getAttribute(cluster, 'state')



13 print "Cluster State: %s" %(state)



14 def appState(app):



15 state = AdminControl.completeObjectName('type=Application,name='+app+',*')



16 print "App State: %s" %(state)



17 def undeployApplication(appName):



18 AdminApp.uninstall( appName )



19 AdminConfig.save()



20 def redeployApplication(pathToFile, cell, cluster, appName):



21 print "installApplicationOnServer: fileName=%s appName=%s Cell=%s Cluster=%s" % ( pathToFile, appName, cell, cluster )



22 AdminApp.install(pathToFile,'[-nopreCompileJSPs -distributeApp -nouseMetaDataFromBinary -nodeployejb -appname "'+appName+'" -createMBeansForResources -noreloadEnabled -nodeployws -MapModulesToServers [["WEB_APP_NAME" WEB_APP_NAME.war,WEB-INF/web.xml WebSphere:cell='+cell+',cluster='+cluster+' ]] -MapWebModToVH [["WEB_APP_NAME" WEB_APP_NAME.war,WEB-INF/web.xml shared_host ]] -verbose]')



23 AdminConfig.save()



24 """modify classloader model for application"""



25 deploymentID = AdminConfig.getid('/Deployment:'+appName+'/')



26 deploymentObject = AdminConfig.showAttribute(deploymentID, 'deployedObject')



27 classldr = AdminConfig.showAttribute(deploymentObject, 'classloader')



28 AdminConfig.modify(classldr, [['mode', 'PARENT_LAST']])



29 """Modify WAR class loader model"""



30 AdminConfig.show(deploymentObject, 'warClassLoaderPolicy')



31 AdminConfig.modify(deploymentObject, [['warClassLoaderPolicy', 'SINGLE']])



32 AdminConfig.save()



33 """-----------------------------------------------------------



34 Phyton script to interface with WAS Admin/Management Tools



35 -----------------------------------------------------------"""



36 if len(sys.argv) < 1:



37 print "wasAdminIntegration.py : need parameters : functionName <ARGS>"



38 sys.exit(0)



39 if(sys.argv[0] == 'clusterStop'):



40 clusterStop(sys.argv[1], sys.argv[2])



41 if(sys.argv[0] == 'clusterStart'):



42 clusterStart(sys.argv[1], sys.argv[2])



43 if(sys.argv[0] == 'clusterState'):



44 clusterState(sys.argv[1], sys.argv[2])



45 if(sys.argv[0] == 'undeployApplication'):



46 undeployApplication(sys.argv[1])



47 if(sys.argv[0] == 'appState'):



48 appState(sys.argv[1])



49 if(sys.argv[0] == 'redeployApplication'):



50 redeployApplication(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])





In this code, replace "WEB_APP_NAME" with real application name or change the script so it can be passed with the rest of parameters.



For waiting part of the scripts, we will user same jython script in conjuction with bash.

Source for waitForState.sh:



view sourceprint?

01 #!/bin/bash



02 binDir=`dirname "$0"`



03 REQURED_STATE=$1



04 WAS_HOST=$2



05 WAS_PORT=$3



06 WAS_CELL=$4



07 WAS_CLUSTER=$5



08 if [ ! -n "$REQURED_STATE" ]

[ ! -n "$WAS_HOST" ]

[ ! -n "$WAS_PORT" ]

[ ! -n "$WAS_CELL" ]

[ ! -n "$WAS_CLUSTER" ];



09 then



10 echo "Usage: waitForState.sh <STATE> <HOST> <PORT> <CELL> <CLUSTER>"



11 exit 1



12 fi



13 CURR_STATE=""



14 echo "CURR_STATE: $CURR_STATE"



15 while [[ "$CURR_STATE" != "$REQURED_STATE" ]]



16 do



17 sleep 20



18 CURR_STATE="$($binDir/wsadmin.sh -conntype SOAP -lang jython -host $WAS_HOST -port $WAS_PORT -f ./wsAdminIntegration.py clusterState $WAS_CELL $WAS_CLUSTER
grep State:)"



19 echo "Current State: $CURR_STATE"



20 done


So, now we can use all these code in conjunction just by calling

view sourceprint?

1 ant fullRedeploy

Output log should be monitored for Websphere errors. If it return "Result: 99" for every operation, then everything is fine, otherwise, something went wrong.

Tuesday, February 16, 2010

Websphere Automation Tool ( WASIC)

WASIC is Websphere Application Server Installation and Configuraton Automation Tool.

Overview:-

WASIC is a tool to install, configure and administrate Websphere application server Version 6.1/7.0.

Features of WASIC:

1. Deployment Manager Installation.
2. Node Installation
3. Federate node to Deployment Manager.
4. Creating Profiles.
5. Install Update installers
6. Apply Fix Packs on Base Installation.
7. Changes port of deployment Manager
8. Checks whether ports are already in use.
9. Changes and checks node agent ports.
10.Webserver Installation and configure them with Application Server.
11.Cluster and server creation and configuring servers.
12.Create Cluster.
13.Create server and add the server to cluster.
14.Create Virtual hosts.
15.Max and minimum heap size.
16.Debug argument.
17.Http Transports
18.Boot classpath.
19.Classpath.
20.Create server level variable.
21.JVM arguments.
22.Changes ports of server.
23.JDBC and Data source creation.
24.Create JDBC provider at cluster level scope..
25.Create Data Source at cluster level scope.
26.Create J2c Authentication.
27.Create Connection Pool Setting.
28.Testing Database connection.
29.Cluster Stop and start.
30.Application installation.

Pre-requisites:-


These are the pre-requisites which we need to do before installing this tool.

1. Create one user which will be used as administrator.
2. ssh for this user should work in all UNIX boxes.
3. Directory under which deployment manager, node and webserver are to be installed should be under this user.
4. The Directory under which we will place this tool should be mounted on all UNIX boxes where we will be installing Websphere Application server.
5. Download the Websphere application server and HTTP server binaries.

Description:-

This tools does Base installation of Websphere Application server version 6.1, first it checks whether the WAS base installation is already done on UNIX m/c and if the base installation is not there it will install WAS base binaries. The location under which it will check whether WAS is already installed depends on the value specified in configure.properties file and response file and then it install Update installer and apply fix packs and after installing base binaries, it install deployment manager using manageprofile utility and values specified in property files and using ports defined in ports properties file. It also checks whether the ports are already in use or not if they are in use I will send the list the ports which are already in use and it also changed the SOAP TIME OUT value to 6000 as it is 180 by default which is very less.

It will then install number of Nodes specified in property file and install them on host specified in properties file and install the Base binaries if they are not installed on unix box and it they are installed then it install nodes and federate nodes to deployment manager, changes node agents ports and start node. It also changes Soap time out for nodes.
*It also install node and federate with Deployment Manager for existing environment.

After node installation is completed, then it installs webservers on the host where we want to install it as specified in property files and configure webserver to deployment manager and generate plug-in and propagate the plug-in back to webserver and start the admin and http server. Http server will be listening on the port in property file.



It then create cluster and create server and add server to cluster and configure all these things on server:-
o Create Virtual hosts.
o Max and minimum heap size.
o Web Container Thread Pool Setting
o Debug argument.
o Http Transports
o Boot class path.
o Class path.
o Create server level variable.
o JVM arguments.
o Changes ports of server.

All these values are picked from property files.
• Other things can also be configured depending upon requirement and script can be modified to accommodate those changes.

After configuring cluster and server creation now it create JDBC provider, Data source , J2c Authentication and connection pool setting on cluster level scope.

It then installs the application on cluster which is created and starts the cluster and sends an email out with Deployment manager console login.

So with one script execution it will do a full fledged environment creation taking all possible intervention of manual stuff to be done and script which we will have to execute will be WASIC.sh.

All these steps in environment creation can run as on single step and they can be executed separately as single steps depending upon needs and new feature can be added as per requirement.


NOTE ***** ALL VALUE ARE PULLED FROM PROPERTY FILES, SO EVERYTHING CAN BE VERSION CONTROLLED IN CLEARCASE.


This tool also works under these scenarios also:

1. If we have to just create Deployment manager.
2. If we have create standalones Application server.
3. If we have to add new node to existing environment.
4. If we have to add new cluster in existing environment.
5. If we have to add new server to existing cluster and configure it.
6. If we have to modify existing JDBC, Data source connection settings.
7. For daily to daily application deployments, cluster stop and cluster start.
8. Create new webserver.
9. Create new webserver and add this webserver to existing environment.
10. It will generate plug-in after application installation or any configuration change and propagate the plug-in to webserver.

For all this environment creation to work, all we have to do is copy the existing environment in WASIC configuration and rename it to the new environment what we want to create change the values in properties file and change the name of scripts and run the WASIC.sh with functional area name and environment name.

These all steps can also be integrated as part of Build Forge.

FUTURE ENHANCEMENT:

1. Create a Graphical user interface for WASIC tool.
2. Adding New features for V 7.0 which are installation of admin agent, Job Manager and registering node to admin Agent and job manager
3. Configuring Global Security, LDAP, LTPA, SSO.
4. Configuring SSL configuration, creating self signed certificate, replace an existing self signed certificate, creating certificate authority requests, receiving a certificate issued by a certificate authority, retrieving a signer certificate from a remote ssl port and adding a signer certificate to a keystore.
5. Installations of Websphere Portal Sever and Websphere Process server.
6. This tool can be modified as per requirement and more features can be added.
7. These scripts can be broken into small scripts, so that if we have to change one configuration file of server it will work.
8. The scripts can also be integrated with build Forge

Script to get the cell name

This Script get the name of the Cell:

import sys,java
from java.util import Properties
from org.python.modules import time
from java.io import FileInputStream

lineSep = java.lang.System.getProperty('line.separator')

global AdminApp
global AdminConfig
global AdminControl


# Getting config ID of cell

cell = AdminControl.getCell()

print " cell="+cell

Cluster Start and Stop Scripts

This Script will start the Cluster on Websphere Application Server:
Script to start Cluster and check for existence of application
Written By Suvash

import sys,java
from java.util import Properties
from java.io import FileInputStream
from org.python.modules import time
lineSep = java.lang.System.getProperty('line.separator')


def startcluster(cluster,appfile):

global AdminApp
global AdminConfig
global AdminControl

cell = AdminControl.getCell()

print " Cell name is --> "+ cell

Cluster = AdminControl.completeObjectName('cell='+ cell +',type=Cluster,name='+ cluster +',*')

state = AdminControl.getAttribute(Cluster, 'state')

if (state == 'websphere.cluster.running'):

print "Cluster --> " + cluster + " is running .......... "

print "Ripple starting cluster ............."

clusterMgr = AdminControl.completeObjectName('cell='+ cell +',type=ClusterMgr,*')

print AdminControl.invoke(clusterMgr, 'retrieveClusters')

Cluster = AdminControl.completeObjectName('cell='+ cell +',type=Cluster,name='+ cluster +',*')

print AdminControl.invoke(Cluster ,'rippleStart')

else:

print "Cluster --> " + cluster + " is stopped "

print "Starting cluster ............... "

clusterMgr = AdminControl.completeObjectName('cell='+ cell +',type=ClusterMgr,*')

AdminControl.invoke(clusterMgr, 'retrieveClusters')

Cluster = AdminControl.completeObjectName('cell='+ cell +',type=Cluster,name='+ cluster +',*')

print AdminControl.invoke(Cluster ,'start')

print " ---------------------------------------------------------------------------------------------- "

application = AdminConfig.getid("/Deployment:"+appfile+"/")

if len(application) > 0:

print " Deployment completed succesfully ........... "


arglen=len(sys.argv)

num_exp_args=1

if (arglen != num_exp_args):

print "One argument is required. This argument should be a properties file."

print " ----------------------------------------------------------------------------------------- "

sys.exit(-1)

propFile=sys.argv[0]

properties=Properties();

try:

properties.load(FileInputStream(propFile))

print " ----------------------------------------------------------------------------------------- "

print "Succesfully read property file "+propFile

print " ----------------------------------------------------------------------------------------- "

except:

print "Cannot read property file "+propFile
sys.exit(-1)

print " ----------------------------------------------------------------------------------------- "


appfile = str(properties.getProperty("APPLICATION_NAME"))

cluster = str(properties.getProperty("CLUSTER_NAME"))

startcluster(cluster,appfile)

This Script will stop Cluster :

Script to stop Cluster
Written By Charanjeet Singh

import sys,java
from java.util import Properties
from java.io import FileInputStream
from org.python.modules import time
lineSep = java.lang.System.getProperty('line.separator')


def stopcluster(cluster):

global AdminApp
global AdminConfig
global AdminControl

cell = AdminControl.getCell()

print " Cell name is --> "+ cell

Serverid = AdminConfig.getid('/Cell:'+ cell +'/ServerCluster:'+ cluster +'/')

memberlist = AdminConfig.showAttribute(Serverid, "members" )

print "test is:"+ memberlist

members = memberlist[1:len(memberlist)-1]

for member in members.split():

node = AdminConfig.showAttribute(member, "nodeName" )

server = AdminConfig.showAttribute(member, "memberName" )

serverId = AdminConfig.getid("/Cell:"+cell+"/Node:"+node+"/Server:"+server+"/")

s1 = AdminControl.completeObjectName('cell='+ cell +',node='+ node +',name='+ server +',type=Server,*')

print " Checking for the running Mbean of server :"+ server

if len(s1) > 0:

print " Server : "+ server +" is running"

print " Stopping Server :"+ server

AdminControl.stopServer(server, node, 'immediate' )

print " Server : "+ server +" stopped"

else :

print "Server : "+ server +" is stopped "

arglen=len(sys.argv)

num_exp_args=1

if (arglen != num_exp_args):

print "One argument is required. This argument should be a properties file."

print " ----------------------------------------------------------------------------------------- "

sys.exit(-1)

propFile=sys.argv[0]

properties=Properties();

try:

properties.load(FileInputStream(propFile))

print " ----------------------------------------------------------------------------------------- "

print "Succesfully read property file "+propFile

print " ----------------------------------------------------------------------------------------- "

except:

print "Cannot read property file "+propFile
sys.exit(-1)

print " ----------------------------------------------------------------------------------------- "



cluster = str(properties.getProperty("CLUSTER_NAME"))

stopcluster(cluster)

Changing Node Agent Port

This Script will change the ports of Node Agent:

WRITTEN BY Suvash
This Script changes node agent ports and picks port value from portsFile.properties

import sys,java
from java.util import Properties
from java.io import FileInputStream
from org.python.modules import time
lineSep = java.lang.System.getProperty('line.separator')

def change_port(bootstrap,orb,csiv2_multi,csiv2_server,dcs,drs,nda,nma1,nma2,sas,soap,host,node):

global AdminApp
global AdminConfig
global AdminControl
global AdminTask

cell = AdminControl.getCell()


portsDict = {}
portsDict["nodeName"] = node
portsDict["endPointName"] = "BOOTSTRAP_ADDRESS"
portsDict["host"] = host
portsDict["port"] = bootstrap
portsDict["modifyShared"] = "true"
AdminTask.modifyServerPort('nodeagent',
["-%s %s" % (key, value) for key, value in portsDict.items()])

portsDict = {}
portsDict["nodeName"] = node
portsDict["endPointName"] = "ORB_LISTENER_ADDRESS"
portsDict["host"] = host
portsDict["modifyShared"] = "true"
portsDict["port"] = orb
AdminTask.modifyServerPort('nodeagent',
["-%s %s" % (key, value) for key, value in portsDict.items()])


portsDict = {}
portsDict["nodeName"] = node
portsDict["endPointName"] = "CSIV2_SSL_SERVERAUTH_LISTENER_ADDRESS"
portsDict["host"] = host
portsDict["modifyShared"] = "true"
portsDict["port"] = csiv2_multi
AdminTask.modifyServerPort('nodeagent',
["-%s %s" % (key, value) for key, value in portsDict.items()])

portsDict = {}
portsDict["nodeName"] = node
portsDict["endPointName"] = "CSIV2_SSL_MUTUALAUTH_LISTENER_ADDRESS"
portsDict["host"] = host
portsDict["modifyShared"] = "true"
portsDict["port"] = csiv2_server
AdminTask.modifyServerPort('nodeagent',
["-%s %s" % (key, value) for key, value in portsDict.items()])


portsDict = {}
portsDict["nodeName"] = node
portsDict["endPointName"] = "DCS_UNICAST_ADDRESS"
portsDict["host"] = host
portsDict["modifyShared"] = "true"
portsDict["port"] = dcs
AdminTask.modifyServerPort('nodeagent',
["-%s %s" % (key, value) for key, value in portsDict.items()])

portsDict = {}
portsDict["nodeName"] = node
portsDict["endPointName"] = "DRS_CLIENT_ADDRESS"
portsDict["host"] = host
portsDict["modifyShared"] = "true"
portsDict["port"] = drs
AdminTask.modifyServerPort('nodeagent',
["-%s %s" % (key, value) for key, value in portsDict.items()])

portsDict = {}
portsDict["nodeName"] = node
portsDict["endPointName"] = "NODE_DISCOVERY_ADDRESS"
portsDict["host"] = host
portsDict["modifyShared"] = "true"
portsDict["port"] = nda
AdminTask.modifyServerPort('nodeagent',
["-%s %s" % (key, value) for key, value in portsDict.items()])


portsDict = {}
portsDict["nodeName"] = node
portsDict["endPointName"] = "NODE_IPV6_MULTICAST_DISCOVERY_ADDRESS"
portsDict["host"] = host
portsDict["port"] = nma1
portsDict["modifyShared"] = "true"
AdminTask.modifyServerPort('nodeagent',
["-%s %s" % (key, value) for key, value in portsDict.items()])


portsDict = {}
portsDict["nodeName"] = node
portsDict["endPointName"] = "NODE_MULTICAST_DISCOVERY_ADDRESS"
portsDict["host"] = host
portsDict["port"] = nma2
portsDict["modifyShared"] = "true"
AdminTask.modifyServerPort('nodeagent',
["-%s %s" % (key, value) for key, value in portsDict.items()])

portsDict = {}
portsDict["nodeName"] = node
portsDict["endPointName"] = "SAS_SSL_SERVERAUTH_LISTENER_ADDRESS"
portsDict["host"] = host
portsDict["port"] = sas
portsDict["modifyShared"] = "true"
AdminTask.modifyServerPort('nodeagent',
["-%s %s" % (key, value) for key, value in portsDict.items()])

portsDict = {}
portsDict["nodeName"] = node
portsDict["endPointName"] = "SOAP_CONNECTOR_ADDRESS"
portsDict["host"] = host
portsDict["modifyShared"] = "true"
portsDict["port"] = soap
AdminTask.modifyServerPort('nodeagent',
["-%s %s" % (key, value) for key, value in portsDict.items()])

#--Saving Configuration--#

AdminConfig.save()

## Syncronizing node

nodelist = AdminTask.listManagedNodes().split(lineSep)

for nodename in nodelist :

print " Syncronizing node.......... "

####################Identifying the ConfigRepository MBean and assign it to variable######################

repo = AdminControl.completeObjectName('type=ConfigRepository,process=nodeagent,node='+ nodename +',*')

print AdminControl.invoke(repo, 'refreshRepositoryEpoch')

sync = AdminControl.completeObjectName('cell='+ cell +',node='+ nodename +',type=NodeSync,*')

print AdminControl.invoke(sync , 'sync')

print " ----------------------------------------------------------------------------------------- "

print " Full Resyncronization completed "

print " ----------------------------------------------------------------------------------------- "

if (len(sys.argv)!= 13):

print "you didnt supplied correct number of argument"

else:

bootstrap=sys.argv[0]
orb=sys.argv[1]
csiv2_multi=sys.argv[2]
csiv2_server=sys.argv[3]
dcs=sys.argv[4]
drs=sys.argv[5]
nda=sys.argv[6]
nma1=sys.argv[7]
nma2=sys.argv[8]
sas=sys.argv[9]
soap=sys.argv[10]
host=sys.argv[11]
node=sys.argv[12]


change_port(bootstrap,orb,csiv2_multi,csiv2_server,dcs,drs,nda,nma1,nma2,sas,soap,host,node)

Websphere Application Deployment Script

This jython Script will Install and Update Application on cluster of Websphere Application Server:

WRITTEN BY Suvash

This Script install Application on cluster and map modules to Virtual Hosts

import sys,java
from java.util import Properties
from java.io import FileInputStream
from org.python.modules import time
lineSep = java.lang.System.getProperty('line.separator')


def appinstall(appfile,apppath,cluster,map_modules_cluster,map_modules_vh):

global AdminApp
global AdminConfig
global AdminControl

print " Getting Cell Name .."

cell = AdminControl.getCell()

print " Cell name is --> "+ cell

print " ----------------------------------------------------------------------------------------- "

###############################################################################################

## checking for the existence of application , is application exists then updating it and if it does not exists then installing it

application = AdminConfig.getid("/Deployment:"+appfile+"/")

if len(application) > 0:

print " ----------------------------------------------------------------------------------------- "

print " Application ---> " +appfile+ " is installed on cluster --> " + cluster

print " ----------------------------------------------------------------------------------------- "

print " Updating application --> " + appfile

pathToEAR = apppath

option1 = appfile

option2 = "\'app\'"

option3 = "-operation update -contents " + apppath + " -MapModulesToServers " + map_modules_cluster + " -MapWebModToVH " + map_modules_vh

print AdminApp.update(option1,'app',option3)

AdminConfig.save()

else :

print " Installing App on cluster --> " + cluster

print AdminApp.install(apppath , '[-appname '+appfile+' -cell '+cell+' -cluster '+cluster+' -MapModulesToServers '+map_modules_cluster+' -MapWebModToVH '+map_modules_vh+']')

print " ----------------------------------------------------------------------------- "

print " Application --> " +appfile+ " installed on cluster--> " +cluster

print " ----------------------------------------------------------------------------- "

print " Saving Configuration "

print " ----------------------------------------------------------------------------- "

AdminConfig.save()

print " ----------------------------------------------------------------------------- "

#####################Waiting for the application to expand and then starting the server################

print " Sleeping for 300 seconds after deploying application "

time.sleep(300)

app = AdminApp.isAppReady(appfile)

while (app == 'false'):

app = AdminApp.isAppReady(appfile)

if (app == 'true'):

print " Expansion of ear completed "

###########################Syncronizing Node######################

nodelist = AdminTask.listManagedNodes().split(lineSep)

for nodename in nodelist :

print " Syncronizing node.......... "

####################Identifying the ConfigRepository MBean and assign it to variable######################

repo = AdminControl.completeObjectName('type=ConfigRepository,process=nodeagent,node='+ nodename +',*')

print AdminControl.invoke(repo, 'refreshRepositoryEpoch')

sync = AdminControl.completeObjectName('cell='+ cell +',node='+ nodename +',type=NodeSync,*')

print AdminControl.invoke(sync , 'sync')

print " ----------------------------------------------------------------------------------------- "

print " Full Resyncronization completed "

print " ----------------------------------------------------------------------------------------- "


########################################################################################################

arglen=len(sys.argv)

num_exp_args=3

if (arglen != num_exp_args):

print "Three arguments are required. Two arguments should be a properties file."

print " ----------------------------------------------------------------------------------------- "

sys.exit(-1)

propFile=sys.argv[0]
propFile1=sys.argv[1]

properties=Properties();


try:

properties.load(FileInputStream(propFile))
properties.load(FileInputStream(propFile1))

print " ----------------------------------------------------------------------------------------- "

print "Succesfully read property file "+propFile
print "Succesfully read property file "+propFile1

print " ----------------------------------------------------------------------------------------- "

except:

print "Cannot read property file "+propFile
print "Cannot read property file "+propFile1
sys.exit(-1)

print " ----------------------------------------------------------------------------------------- "


appfile = str(properties.getProperty("APPLICATION_NAME"))

apppath = sys.argv[2]

cluster = str(properties.getProperty("CLUSTER_NAME"))

map_modules_cluster = str(properties.getProperty("MAP_MODULES_TO_SERVER"))

map_modules_vh = str(properties.getProperty("MAP_MODULES_TO_VH"))

print " app file " + appfile
print " apppath " + apppath
print " cluster " + cluster
print " map_modules_cluster " + map_modules_cluster
print " map_modules_vh " + map_modules_vh

appinstall(appfile,apppath,cluster,map_modules_cluster,map_modules_vh)