Friday, November 9, 2012

Jython Script to create Server

JYTHON SCRIPT TO CREATE SERVER

Copy the Below Code and create a file create_server.py and place the file in Deployment Manager Bin Directory  :-
#-------------------------------------------#
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 server_create(node,server):
 node=AdminConfig.getid('/Node:'+node+'/')
 attr=[['name', server]]
 print "creating server .."
 AdminConfig.create('Server',node,attr)
 print "server created .."
 AdminConfig.save()
 print "saving config .."


arglen=len(sys.argv)
number_of_argument=2
if ( arglen != number_of_argument):
 print "pass 2 arguments .."
 sys.exit(-1)

server=sys.argv[0]
node=sys.argv[1]
server_create(node,server)


#----------------------------------------#









Execute the script using below wsasmin command
Windows:
Go to DMGR BIN directory

 wsadmin.bat -f create_server.py -lang jython -port -conntype SOAP -user -password  

Unix :-
Go to DMGR BIN directory


 ./wsadmin.sh -f create_server.py -lang jython -port -conntype SOAP -user -password  

Example :
 ./wsadmin.sh -f create_server.py -lang jython -port 8879 -conntype SOAP -user wasadmin -password wasadmin test_server test_node

Wednesday, December 14, 2011

WSADMIN - Part 1


The wsadmin program is a scripting engine for performing administrative tasks on an application server or its configuration. It can execute individual commands as well as in interactive fashion , or it can execute script file.

The way wsadmin program is executed is dependent on the Operating system being used. The examples below shows how wsadmin program is executed in Windows and Unix environment.The ./ before the name of the file to be executed on a Unix environment is an indication that the specified file is located in the current directory.

• AIX —wsadmin.sh
• Linux —wsadmin.sh

• z/OS —wsadmin.sh
• Windows —wsadmin


are options specified by user and are optional.


Where is wsadmin located :-
  
In case of standalone application server, wsadmin is located at WAS_HOME /bin directory.


In ND application server,  wsadmin.sh is located both at WAS_HOME/bin  and also at WAS_PROFILE_HOME/bin

WAS_HOME is location where base binaries are installed .
WAS_PROFILE_HOME is location where profile is created.

Launching of wsadmin :-

Here I will be explaining and showing launching of wsadmin in ND environment on Unix Operating System.Basically in ND environment, best practice is to launch wsadmin from Deployment profile.We can launch wsadmin from /bin or from Node profile also, but it is almost always launched from Deployment profile only.

 The way we launch wsadmin also depends upon whether Websphere have security turned on or not.
  1. If Global security is not turned on, it is launched just by executing ./wsadmin.sh command as shown below in screenshot.
 



 2. If Global security is turned on, then we will have to pass user name and password to connect to wsadmin program and options we need to pass is described below and shown below in screenshot.
               ./wsadmin.sh -user -password



3. If Global security is turned on and we don't want to pass user and password every time we execute wsadmin.So, for that , we need to update 3 properties in soap.client.props located at /properties, below are the properties which we need to update.

1. Update "com.ibm.SOAP.securityEnabled" to  value as true.
2. Update "com.ibm.SOAP.loginUserid" with websphere admin user.
3. Update "com.ibm.SOAP.loginPassword" with websphere admin password.

You don't have to bounce Deployment manager to have this take affect,you can do this on the fly , whether you want to enable this functionality or disable this functionality after enabling.

Below screenshot shows the location of soap.client.props


Below it shows the properties with updated values


Below screenshot shows, after updating this we don't have to pass user name and password with we are executing wsadmin , with global security on in websphere.


This concludes the first part of wsadmin,Second part to follow soon. Keep yours eyes open and check the blog with  other updates also. Please comment and let me know where do I need to improve when I am explaining as I want to explain everything in as easy way as it can be and if you like this port it then please share it on facebook or twitter.






Monday, December 12, 2011

Measuring Repsonse time of IBM HTTP Webserver

Response times can be found in the access log file identified by either the TransferLog or CustomLog directives defined in the IBM HTTP Server's httpd.conf file as long as the LogFormat directive is modified to include either the %D or %T format parameters. In addition to these two parameters, the LogFormat should be updated with a constant string (e.g. TIME:) that can be used to easily identify the response times in the access log. The %D parameter will report the time taken to serve the request, in microseconds, while the %T will report the time taken to serve the request in seconds.
The following example shows how to modify the default common LogFormat found in the httpd.conf file to report the time in microseconds.
Original definition:
LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog logs/access.log common

Which will produce output similar to the following:

127.0.0.1 - - [04/Nov/2011:21:06:05 -0400] "GET / HTTP/1.1" 200 3325


Change to:
LogFormat "%h %l %u %t \"%r\" %>s TIME: %D %b" common
CustomLog logs/access.log common

Example output found in the access.log will look like the following:

127.0.0.1 - - [04/Nov/2011:21:06:05 -0400] "GET / HTTP/1.1" 200 TIME: 78125 3325

The text in bold blue shows the response time in microseconds.

With this information, you can now parse the access log looking for requests that meet specific response time criteria. 

Sunday, November 13, 2011

Jython Script to check the status of listener ports of all servers of cluster

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

clusterName='CLUSTER_NAME'
cId = AdminConfig.getid("/ServerCluster:"+ clusterName +"/" )
cList = AdminConfig.list("ClusterMember", cId ).split(lineSeparator)
for sId in cList:
server = AdminConfig.showAttribute(sId, "memberName" )
node = AdminConfig.showAttribute(sId, "nodeName" )
cell = AdminControl.getCell()

s1 = AdminControl.completeObjectName('cell='+ cell +',node='+node +',name='+ server +',type=Server,*')
if len(s1) > 0:
print server + " state is started"
else:
print server + " is down"

print "Server " + server + " has the following Listener Ports"
lPorts = AdminControl.queryNames('type=ListenerPort,cell='+ cell+',node='+ node +',process='+ server +',*')
lPortsArray = lPorts.split(lineSeparator)
for lPort in lPortsArray:
lpcfgId = AdminControl.getConfigId(lPort)
lpName = AdminConfig.showAttribute(lpcfgId, "name")
lpstate = AdminControl.getAttribute(lPort, 'started')
if lpstate == 'true':
print lpName + " is started "
else :
print lpName + " is stopped "

print ""

Jython script to create Variable at Cluster Scope

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


def variable(cluster,varname1,varvalue1):

global AdminApp
global AdminConfig
global AdminControl

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

######################################## Getting config ID of cell ################################################

cell = AdminControl.getCell()

cellid = AdminConfig.getid('/Cell:'+ cell)

Clusterid = AdminConfig.getid('/ServerCluster:'+ cluster +'/')

varMapserver = AdminConfig.getid('/ServerCluster:'+ cluster +'/VariableMap:/')

if len(varMapserver) > 0:

print " Variable Map exists on Cluster ........... "

variables = AdminConfig.list("VariableSubstitutionEntry", varMapserver).split(lineSeparator)
for variable in variables[:]:
vname = AdminConfig.showAttribute(variable, "symbolicName")
if (vname == varname1) :
print "Removing old variable " + vname + " from variables.xml..."
AdminConfig.remove(variable)

nameattr1 = ['symbolicName', varname1]
valattr1 = ['value', varvalue1]
desc1 = ["description", varname1]
attr1 = [nameattr1, valattr1, desc1]
attrs1 = [attr1]

entries1 = ['entries', attrs1 ]

print "creating new variable " + varname1

AdminConfig.modify(varMapserver, [entries1] )

print " Cluster Level Variable Configured ................ "

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


else:

print " Variable Map doesn't exists on Cluster ........... "

varMapserver = AdminConfig.create('VariableMap', Clusterid, [])

print " Variable Map created on Cluster ........... "

nameattr1 = ['symbolicName', varname1]
valattr1 = ['value', varvalue1]
desc1 = ["description", varname1]
attr1 = [nameattr1, valattr1, desc1]
attrs1 = [attr1]

entries1 = ['entries', attrs1 ]

print "creating new variable " + varname1

AdminConfig.modify(varMapserver, [entries1] )

print " Cluster Level Variable Configured ................ "

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


AdminConfig.save()

######################################################### Full Resyncronization #########################################################

print " Fully Resyncronizing nodes ........... "

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

for nodename in nodelist :

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


########################################################## Main Program #############################################################

arglen=len(sys.argv)

num_exp_args=2

if (arglen != num_exp_args):

print "Two arguments are required."

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 = sys.argv[1]
varname1=str(properties.getProperty("VARIABLE_NAME"))
varvalue1=str(properties.getProperty("VARIABLE_VALUE"))

variable(cluster,varname1,varvalue1)

Jython Script to create variable at Node Scope

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


def variable(node,varname1,varvalue1):

global AdminApp
global AdminConfig
global AdminControl

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



cell = AdminControl.getCell()

cellid = AdminConfig.getid('/Cell:'+ cell)




nodeid= AdminConfig.getid('/Cell:'+ cell +'/Node:'+ node +'/')

varMapserver = AdminConfig.getid('/Cell:'+ cell +'/Node:'+ node +'/VariableMap:/')

if len(varMapserver) > 0:

print " Variable Map exists on node ........... "

variables = AdminConfig.list("VariableSubstitutionEntry", varMapserver).split(lineSeparator)
for variable in variables[:]:
vname = AdminConfig.showAttribute(variable, "symbolicName")
if (vname == varname1) :
print "Removing old variable " + vname + " from variables.xml..."
AdminConfig.remove(variable)

nameattr1 = ['symbolicName', varname1]
valattr1 = ['value', varvalue1]
desc1 = ["description", varname1]
attr1 = [nameattr1, valattr1, desc1]
attrs1 = [attr1]

entries1 = ['entries', attrs1 ]

print "creating new variable " + varname1

AdminConfig.modify(varMapserver, [entries1] )

AdminConfig.save()

print " Node Level Variable Configured ................ "

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

else:

print " Variable Map doesn't exists on node ........... "

varMapserver = AdminConfig.create('VariableMap', nodeid, [])

print " Variable Map created on node ........... "

nameattr1 = ['symbolicName', varname1]
valattr1 = ['value', varvalue1]
desc1 = ["description", varname1]
attr1 = [nameattr1, valattr1, desc1]
attrs1 = [attr1]

entries1 = ['entries', attrs1 ]

print "creating new variable " + varname1

AdminConfig.modify(varMapserver, [entries1] )

AdminConfig.save()

print " Node Level Variable Configured ................ "

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




######################################################### Full Resyncronization #########################################################

print " Fully Resyncronizing nodes ........... "

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

for nodename in nodelist :

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


########################################################## Main Program #############################################################

arglen=len(sys.argv)

num_exp_args=2

if (arglen != num_exp_args):

print "Two arguments are required."

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


node = sys.argv[1]
varname1=str(properties.getProperty("VARIABLE_NAME"))
varvalue1=str(properties.getProperty("VARIABLE_VALUE"))

variable(node,varname1,varvalue1)

Jython Script to creating queue destination at cluster scope.

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 QF(cluster,qmanager,jndiname,queue_name,target,name):

# Declare global variables

global AdminConfig
global AdminControl

# Gets the name of cell

cell = AdminControl.getCell()

cellid = AdminConfig.getid('/Cell:'+ cell +'/')

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


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


#------QueueConnectionFactory--------#

MS=AdminConfig.getid('/ServerCluster:'+ cluster +'/JMSProvider:WebSphere MQ JMS Provider/')

QD=AdminConfig.getid('/ServerCluster:'+ cluster +'/JMSProvider:WebSphere MQ JMS Provider/MQQueue:'+ name +'/')

if len(QD) == 0 :
print "Queue does not exists .... "
else :
print "Queue exists, so removing old Queue ... "
AdminConfig.remove(QD)
print "Queue removed .. "


print "Creating Queue Destination .. "

name1 = ["name" , name]

jndi = ["jndiName" , jndiname ]

qm = ["baseQueueManagerName", qmanager ]

queue = ["baseQueueName", queue_name ]

target = ["targetClient", target ]

qd_attr = [name1 , jndi , qm , queue , target ]

newqf = AdminConfig.create('MQQueue' , MS , qd_attr)

print "Queue Destination created .. "

AdminConfig.save()

print " Saving Configuraion "

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




#--------------------------------------------------------------#


## Full Syncronization ##

print " Syncronizing configuration with Master Repository "

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

for nodename in nodelist :

print " syncronizing nodes .......... "

####################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,*')

print AdminControl.invoke(sync , 'sync')

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

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

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

#main program starts here

cluster = sys.argv[0]
target = sys.argv[1]
jndiname = sys.argv[2]
queue_name = sys.argv[3]
name=sys.argv[4]
qmanager = sys.argv[5]

QF(cluster,qmanager,jndiname,queue_name,target,name)