Monday, January 17, 2011

Useful One Liner scripts for WAS Administrator

Useful One Liner scripts for WAS Administrator:-

1. AdminTask.reportConfiguredPorts() : Lists every server in your cell. Shows all the ports each server uses
2. AdminTask.reportConfigInconsistencies() : Checks the configuation repository and reports any structural inconsistencies
3. AdminApp.list() : Lists every application installed in your cell
4, AdminApp.view( 'appName' ) : Replace appName with one of the names returned by AdminApp.list(). The name must be surrounded by quotes
6. AdminTask.generateSecConfigReport() : Shows every setting related to security in your entire cell. Shows the current value of the setting. Shows the menu path through the Admin Console to that setting. The printout is a little confusing at first, but it is very useful once you get used to reading it.
7. AdminTask.createApplicationServer('Node1', '[-name serverNode1 ]') : Creates a new application server called "serverNode1" in a node called "Node1"

BuildForge/RAFW

To all those people who are using information from my blog.I want to update you all that from now I will be adding BuildForge and RAFW information in this blog.

Build Forge and RAFW comes under IBM Rational Tools.Build Forge is used to integrate Build and Deployment , and can be used as integration tools which integrate all the components in SDLC.

RAFW is Rational Automation framework for Websphere and is part of Build Forge.It is a automate tools which automate WAS/WP/WESB/WVE Installation,configuration and Administration tasks and you don't have to maintain any scripts it comes with all the scripts.

Please keep on checking new update as I will be explaining more on these tools in future.

Jython Script to Start Cluster

This Jython script starts cluster if it is stopped and ripple starts cluster if cluster is already running.

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):

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

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)
cluster = sys.argv[0]
startcluster(cluster)

This Jython script stop cluster.

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" )

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 the cluster name."

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

sys.exit(-1)

cluster=sys.argv[0]

stopcluster(cluster)

jython script to uninstall , install Application and sync nodes

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,mapresref):

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 " uninstalling application --> " + appfile
AdminApp.uninstall(appfile)
print " ----------------------------------------------------------------------------------------- "
print "application uninstalled .. "
AdminConfig.save()
print " ----------------------------------------------------------------------------------------- "
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 " ----------------------------------------------------------------------------- "
application = AdminConfig.getid("/Deployment:"+appfile+"/")
if len(application) > 0:
print " ----------------------------------------------------------------------------------------- "
print " Application ---> " +appfile+ " is successfully installed on cluster --> " + cluster
print " ----------------------------------------------------------------------------------------- "

#####################Waiting for the application to expand and then starting the server################
print " Sleeping for 60 seconds after deploying application "
time.sleep(60)
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 +',*')
AdminControl.invoke(repo, 'refreshRepositoryEpoch')
sync = AdminControl.completeObjectName('cell='+ cell +',node='+ nodename +',type=NodeSync,*')
AdminControl.invoke(sync , 'sync')
print " ----------------------------------------------------------------------------------------- "
print " Full Resyncronization completed "
print "



arglen=len(sys.argv)
num_exp_args=2
if (arglen != num_exp_args):
print "Three arguments are required. Two arguments should be a properties file."
print " ----------------------------------------------------------------------------------------- "
sys.exit(-1)
propFile=sys.argv[1]
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 " ----------------------------------------------------------------------------------------- "
apppath = sys.argv[0]
cluster = str(properties.getProperty("ENV_CLUSTER_NAME"))
map_modules_cluster = str(properties.getProperty("ENV_PCS_MAP_MODULES_TO_SERVER"))
map_modules_vh = str(properties.getProperty("PCS_MAP_MODULES_TO_VIRTUAL_HOST"))
appfile = str(properties.getProperty("ENV_PCS_APP_NAME"))
mapresref = str(properties.getProperty("MAP_RESOURCE_REF"))

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

Sunday, January 16, 2011

Websphere Scripting

Please contact me if you need any help in websphere automation scripting , websphere scripting , jython , ant and shell scripting . I will be more than happy to resolve your issue. I have developed all the scripts required to automated Websphere Administration tasks.Please email me as I don't check comments on regular basis.


Interested Please email me at websphereautomation@yahoo.com