Posts

Control the WebSphere Cluster using Jython

Image
Hello automation with Jython enthuiastic Guys!! Welcome to this post. In this post we are going to explore more WebSphere cluster specific operations. Which are most important for doing automations with wsadmin scripting. Cluster State using Jython You can get the state of the cluster using AdminControl object method getAttribute will give that. The cluster state might be one of the three common important states websphere.cluster.running websphere.cluster.partial.start websphere.cluster.partial.stopped websphere.cluster.stopped Cluster object required to get the state of the cluster, AdminControl will gives us the state of the cluster getAttribute method will takes two argument cluster object and 'state' command. Cluster = AdminControl.completeObjectName('cell='+ cell +',type=Cluster,name='+ cluster +',*') state = AdminControl.getAttribute(Cluster, 'state') Start Cluster with Jython To start the member servers of a clust...

Jython Deployment automation in WebSphere

Image
We can have different JEE applications to install on IBM WebSphere Application Server such as: Enterprise applications .ear files Web Applications .war files Business Application Utility/shared libraries .jar files You need to know what type of application you wish to deploy. Where to install it in the Cell. If it is an EJB application you need to provide the binding details as an initial parameter. All application-related functions are available with AdminApp object. For making the application changes permanent you need to save the AdminConfig. Web application deployment with Jython wsadmin Let's see the war file installation process AdminApp.install(ear, '[-BindJndiForEJBBusiness [[ejb_1.jar ejb1 ejb_1.jar,META-INF/ejb-jar.xml test.ejb1 jndi1 ]]]') # For Web application inside .ear files you need to provide virtual host name. These virtual host varies in the ND cell. AdminApp.install('fullpath/yourApp.ear', ['-MapWebModToVH', [[...

File operations in Jython

Image
File operations are very important for Jython scripting. File Operations in wsadmin scripting Creating a file with list of archives which are present in the installableApp folder. vagrant@ubuntu-was8:~/IBM/WebSphere/AppServer/installableApps$ ls > ~/scripts/applist.txt vagrant@ubuntu-was8:~/IBM/WebSphere/AppServer/installableApps$ cat ~/scripts/applist.txt AjaxProxy.war CacheMonitor.ear DefaultApplication.ear ... WSNServicePoint.ear These kind of need would be in every automation script; It may be list of deployables or Server to be restarted. ############################### # # Script File: fileoper.py # usage : wsadmin -f [path 2="" script=""]/fileoper.py # The file read operation # ############################### import os,sys f=open("/home/vagrant/scripts/applist.txt") for appName in f.readlines(): print appName.split('.')[0] print "End of the file..." wsadmin>execfile('/home/vagrant/scripts/fileoper...

Programming Control in Jython

Image
The if-else construct in Jython Syntax: if condition1 : true statements elif condition2 : true condition2 statements else: false statements Example: In your monitoring scripts you might need for the variable must be cross check across multiple servers. Assuming that you got the JVM Valules using if condition statements find which server is having more Java objects occupied. # This script illustrates the if-else-elif usage print "Enter 3 server JVM Size in MB: " s1, s2, s3= input('3 integer values') print "Given JVM Values:", s1, s2, s3 print '#'*50 if s1 > s2 and s1 >s3: print s1, " s1 JVM server overloaded" elif s2 > s1 and s2 > s3: print s2, " s2 jvm overloaded" elif s3 > s1 and s3 > s2: print s3, " s3 JVM Overloaded" else: print "Error in input plz check" print '#'*50 Output: wsadmin>execfile('/home/vagrant/scripts/ifel...

String sequence in Jython wsadmin

 String sequence in Jython Strings are set of characters enclosed with single quotes or double or triple quotes. String objects are similar to tuple sequence objects. String objects are immutable. You cannot change the current string content. We need to use the new string object for modify the contents. Strings can be two variants: raw string normal string All the help method out comes are raw strings they are parsed when it is given to print command. wsadmin>rawstr=AdminTask.help() wsadmin>rawstr 'WASX8001I: The AdminTask object enables the execution of available admin\n\tcommands. AdminTask commands operate in two modes:\n\tthe default mode is one which AdminTask communicates with the WebSphere\n\tserver to accomplish its task. A local mode is also available, in which\n\tno server communication takes place. The local mode of operation is\n\tinvoked by bringing up the scripting client using the command line\n\t"-. ... ... Use help command\n\t\t\t\t\tto ge...

Jython List in wsadmin

A list can hold following type of data variables numbers strings  List varieties on wsadmin shell Let us have different data into the list and then try to access the elements using index values. wsadmin>varlist=[100,'Raghav', 99.9,'M'] wsadmin>print varlist [100, 'Raghav', 99.9, 'M'] wsadmin>print varlist[2] 99.9 wsadmin>print varlist[1] Raghav Number List in Jython Lets experiment with different numbers on Jython shell. When I entered big number then Jython shell throwing Overflow error. To fix this we need to append 'L' this is only for assigning the values of List elements. wsadmin>numlist=[9000,9999999999, 8988,0] Traceback (innermost last): (no code object) at line 0 OverflowError: integer literal too large wsadmin>numlist=[9000,9999999999L, 8980, 0] wsadmin>print numlist[1] 9999999999 wsadmin>print numlist[3] 0 String Lists String variable also works in similar to other data types. He...

Tuples in Jython

Image
Tuple Hi everyone in this post I would like to workout how does the Jython tuple can be constructed and how to display their content and their operations. WebSphere Admin must know about tuple because it is heavily used internal MBeans for storing data in them. What I have understood about Tuple data type is: A tuple is a sequence of immutable Python Objects in the Jython The  tuple content cannot be changed - only assignment that is why we don't see any other functions on them Use parenthesis () to define Here elements can be stored into a tuple with comma-separated values Tuples can contain numbers, strings, nested sub-tuples, or nothing or combination that is heterogeneous types Tuple in Jython Let me experiment and prove that all. # This script list how to use the tuple. t1=(1,2,3,4) print "integer tuple", t1 t2=(1.2,10.5,13.4) print "float tuple", t2 t3=('app1','app2','app3') print "string tuple", ...