Posts

Jython operators and sequences in wsadmin

Image
Welcome back to Jython learning blog again. today I have explored different categories of operators how they can be used in Jython for wsadmin. prerequisites for this is you must have a Jython for WebSphere installed on your VM and you are on wsadmin prompt. Types of operators (inherited from Python): Arithmetic operators Comparison operators Relational operators  These simple experiments would give you a base for building automation scripts in your projects. Jython Operators on wsadmin   How can Jython deals with Arithmetic operators Every language supports the Arthematic operators and in Jython same operators as in C or Python languages. wsadmin>x,y = 10, 20 wsadmin>print x, y 10 20 wsadmin>x+y 30 wsadmin>x+y+30 60 wsadmin>y-x 10 wsadmin>x-y -10 wsadmin>x*y 200 wsadmin>x**2 100 wsadmin>y/x 2 wsadmin>y%x 0 How to use Jython Comparison operators? The comparing operators mostly used in the 'if-else' or 'while' blocks which returns eith...

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...