Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

IBM Washington Systems Center

WebSphere Scripting: WSADMIN, jacl, jython

LeeWinTai tai@us.ibm.com

Advanced Technical Support

2005-09-23

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

OurAgenda

WSADMIN basics Scripting with WSADMIN

JACL Jython

Script examples

IBM Washington Systems Center

2005-09-23

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

WSADMINConcepts
WSADMINisnotakeyboardrecordingmechanism!

WSADMINisascriptinginterfaceusedatthecommandline. Windows,Linux,USS WSADMINcan: Install/uninstallapplications Stop/startservers Createnewservers

IBM Washington Systems Center

2005-09-23

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

InteractivevsInlineCommands
Interactivecommands
Telnet or OMVS

Entercommand Usefulforquickadministrativetasks Entercommand


4 IBM Washington Systems Center

Receiveoutput

stopserver install/uninstallapplications
2005-09-23 2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

InteractivevsInlineCommands
Inlinecommands
Telnet or OMVS

Usectoindicate inlinecommand Command

BBOWIAPPjobusesinlinecommandtoinstalltheadministrativeconsole

IBM Washington Systems Center

2005-09-23

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

UsingwsadminFromYourWorkstation
wsadmin.batWindows wsadmin.shUnixandLinux
SOAP port

Deployment Manager

wsadmin.shhost<host>port<port>

Isglobalsecurityturnedon? No
Noworries

SOAP port

Yes
CAcertificate mustbeon clientskeyring Provideuserid andpassword

Application Server

IBM Washington Systems Center

2005-09-23

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

CanWeUseWSADMINIftheServerisDown?
Itdepends!

wsadmininlocalmode Manipulates configurationdata

wsadmin.shconntypenone

HFS

Theserverdoesnothavetobeup

Obviously,thisdoesnotworkfromyourworkstation...
7 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

CanWeUseWSADMINiftheServerisDown?
Itdepends!

wsadmininremotemode
wsadmin.shconntypesoap wsadmin.shconntypermi

Connectsto server

Manipulates Itisnotrecommendedtouseremotemode andtheadminconsolesimultaneously configurationdata

HFS

IBM Washington Systems Center

2005-09-23

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

UsingWSADMINWithGlobalSecurityOn
wsadmin.shconntypesoapuser<user>password<pw>

soap.client.props securityEnabled=true

sas.client.props securityEnabled=true

ImportserversCAcertificateontoclientkeyringusingikeyman.(sh|bat) ShouldnotbenecessaryifexecutingwsadminfromUSS
9 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

IsThisaSecurityExposure?
wsadmin.shconntypesoapuser<user>password<pw>

Hmm..Icoulduse pstodisplay runningprocesses Grr...


Disgruntledemployee

Specifyuseridand password

soap.client.props

sas.client.props

10

IBM Washington Systems Center

2005-09-23

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

AreThereMultipleWSADMINs?

OnlyifinanND $dmgr/profiles/default/bin/wsadmin.sh $appserver/profiles/default/bin/wsadmin.sh environment Oneforeach applicationserver Each of these are a managed process to which WSADMIN can connect.

11

IBM Washington Systems Center

2005-09-23

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

UsingWSADMINObjects
WSADMINusesfourobjects:
AdminApp manipulate applications AdminControl manipulate objects (e.g., servers)

AdminConfig manipulate configuration data

Help self-explanatory

12

IBM Washington Systems Center

2005-09-23

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

WhatCanIDoWiththeAdminAppObject?
install uninstall edit list

AdminApphelplisting:

13

IBM Washington Systems Center

2005-09-23

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

AdminAppInstallinganApplication
Q:Whatoptions?
$AdminApp install <filename> <options>

A:$AdminAppoptions

Notalloptionsarerequired forinstallation

Remember to save and synchronize after installation: Details to come...


14 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

AdminAppInstallationOptions
$AdminApp options <earfile> Use this to find options specific to the ear file

Whatisthe syntaxforthese options? Works


$AdminApp taskInfo <earfile> <option> This works for only for some options. $AdminApp taskInfo <earfile> MapModulesToServers

Doesntwork
$AdminApp taskInfo <earfile> preCompileJSPs
15 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

AdminAppInstallationOptions
$AdminApp taskInfo <earfile> MapModulesToServers
wsadmin>$AdminApptaskInfo/u/tai/SuperSnoop.earMapModulesToServers MapModulesToServers:Selectingservers Specifytargetssuchasapplicationserversorclustersofapplicationserverswhereyouwanttoinstall themodulescontainedinyourapplication.Modulescanbeinstalledonthesameapplicationserverordispersed amongseveralapplicationservers.Also,specifytheWebserversastargetsthatwillserveasroutersforrequests tothisapplication.Thepluginconfigurationfile(plugincfg.xml)foreachWebserverisgeneratedbasedonthe applicationswhichareroutedthroughit. WASX7348I:EachelementoftheMapModulesToServerstaskconsistsofthefollowing3fields:"Module","URI","Server". Ofthesefields,thefollowingmaybeassignedvalues:"Server" andthefollowingarerequired:"Server" Thecurrentcontentsofthetaskafterrunningdefaultbindingsare: Module:SuperSnoopWeb URI:SuperSnoopWeb.war,WEBINF/web.xml Server:WebSphere:cell=wsc1.washington.ibm.com,node=wsc1.washington.ibm.com,server=server1
16 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

AdminAppUninstallinganApplication
Wow,thatwaseasy!

$AdminAppuninstallmyapp

Youmustusetheapplicationname, nottheearfilename
Saving is not necessary after uninstallation

ADMA5106I: Application myapp uninstalled successfully.


17 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

AdminConfig
Usedtocreate,remove,ormodifyconfigobjectsvirtualhosts,servers,etc. LetstakealookattheWebContainerobject
$AdminConfig attributes WebContainer Use this to find a list of all types $AdminConfig types Use this to find a list of all types
. . WSGWInstance WSGWProxyService WSGWTargetService WebContainer WebContainerInboundChannel WebModuleConfig WebModuleDeployment WebModuleRef . .
18 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation

. . "defaultVirtualHostNameString" "enableServletCachingboolean" . .

WebSphere Scripting: WSADMIN, JACL, Jython

AdminConfigWhichWebContainer?
$AdminConfig show <object> Show attributes of a given config object
wsadmin>$AdminConfig show WebContainer WASX7015E: Exception running command: "$AdminConfig show WebContainer"; exception information: com.ibm.ws.scripting.ScriptingException: WASX7077E: Incomplete config id: need closing parenthesis in "WebContainer"

$AdminConfig list <object> Lists all config objects of a given type


wsadmin>$AdminConfig list WebContainer (cells/h6cell/nodes/h6dmgrnd/servers/dmgr|server.xml#WebContainer_1) (cells/h6cell/nodes/h6nodea/servers/h6sr01a|server.xml#WebContainer_1112019030113) (cells/h6cell/nodes/h6nodea/servers/h6sr01b|server.xml#WebContainer_1118253253830) (cells/h6cell/nodes/h6nodea/servers/h6sr02a|server.xml#WebContainer_1112020441556) (cells/h6cell/nodes/h6nodea/servers/h6sr03a|server.xml#WebContainer_1112139804785)

$AdminConfig modify <object> <attributes> Change specified attributes of a given config object
wsadmin>$AdminConfig modify (cells/h6cell/nodes/h6nodea/servers/h6sr03a|server.xml#WebContainer_1112139804785) {{ enableServletCaching true }}

19

IBM Washington Systems Center

2005-09-23

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

AdminControl
Save changes Start / stop servers Initiate synchronization

$AdminControlsave

$AdminControlstartServerh6sr03a

WASX7015E: Exception running command: "$AdminControl startServer h6sr03a"; exception information: com.ibm.ws.scripting.ScriptingException: WASX7344E: Node name is required when the client is connected to process type "DeploymentManager".

$AdminControlstartServerh6sr03ah6nodea $AdminControlstopServerh6sr03a
WASX7015E: Exception running command: "$AdminControl startServer h6sr03a h6nodea"; exception information: com.ibm.websphere.management.exception.ConnectorException org.apache.soap.SOAPException: [SOAPException: faultCode=SOAP-ENV:Client; msg=Read timed out; targetException=java.net.SocketTimeoutException: Read timed out]

20

IBM Washington Systems Center

2005-09-23

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

AdminControlNodeSynchronization
set var [$AdminControl completeObjectName type=NodeSync,node=h6nodea,*] $AdminControl invoke $var sync

WebSphere:platform=common,cell=h6cell,version=6.0.2.1,name=nodeSync, mbeanIdentifier=nodeSync,type=NodeSync,node=h6nodea,process=nodeagent

Thismustbedoneforeachnodethatyouwantsynchronized.

21

IBM Washington Systems Center

2005-09-23

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

ExternalScriptsJaclandJython
Benefitsofusinganexternalscript

WASexpectsscriptstobeinASCII Usescript.encodingpropertyfor WSADMIN UseASCIIfileeditoronz/OS EditonyourPCandFTPtoHFS

passinginparameters controlflow errorcheckingandhandling

UsefoptiontotellWSADMINtouseanexternalscript:
$ ./wsadmin.sh -f install.jacl

Jacl
ImplementationoftheTclinterpreterwritteninJava DefaultscriptinglanguageexpectedbyWAS

Jython
ImplementationofPythonwritteninJava
22 IBM Washington Systems Center 2005-09-23 2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

CommandLineParametersJacl
Takingparametersfromthecommandline Usethisscriptformultipleservers,nodes,applications,etc.
puts writes to stdout (by default) if wrong number, go here argc the number of arguments check for correct number of arguments lindex retrieve list element argv list of arguments

if right number, go here

if { !($argc == 5) } { puts You don't have the correct puts Usage: ... } else { set serverName [lindex $argv set nodeName [lindex $argv set cellName [lindex $argv set application [lindex $argv set appName [lindex $argv }
set read / write variables
2005-09-23

nu
set serverName to first argument set nodeName to second argument etc.

0] 1] 2] 3] 4]

23

IBM Washington Systems Center

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

CommandLineParametersJython
len number of items in a list sys.argv list of arguments

print writes to stdout

check for correct number of arguments

if wrong number, go here

if right number, go here

if (len(sys.argv) != 5): print You don't have the correct nu print Usage: ... } else { serverName = sys.argv[0] nodeName = sys.argv[1] cellName = sys.argv[2] application = sys.argv[3] appName = sys.argv[4] }
getopt not available

set serverName to first argument set nodeName to second argument etc.

24

IBM Washington Systems Center

2005-09-23

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

VerifyingtheNodeExists
llength returns number of items in a list

Jac

l
print error message if node is not found

set node [$AdminConfig getid /Node:$nodeName/] if {[llength $node] == 0} { puts "Error -- node not found for name $nodeName" return } getid returns configid of an object nodeName passed in as an argument

check length of result

Jy

node = AdminConfig.getid("/Node:" + nodeName + "/") print "ex1: checking for existence of node " + nodeName if len(node) == 0: print "Error -- node not found for name " + nodeName return

th on
print error message if node is not found

25

IBM Washington Systems Center

2005-09-23

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

VerifyingtheServerExists
Determineifthegivenserverisavailable
set runningServer [$AdminControl completeObjectName type=server,node=$nodeName,process=$serverName,* if {[llength $runningServer] == 0 } { puts Error: Server not running... return }

Jac l

completeObjectName returns object name

serverName passed in as an argument

runningServer = AdminControl.completeObjectName("type=Server,node="+nodeName+",process="+serverName+",*") if len(runningServer) == 0: puts Error: Server not running... return

Jy

th on

26

IBM Washington Systems Center

2005-09-23

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

CheckExistingApplications
Checktoseeiftheapplicationisalreadyontheserver...
foreach loops over each item in list AdminApp list returns list of all install applications foundApp set to true if app exists; false otherwise AdminApp list returns list of all install applications split splits string into list of strings

set foundApp false foreach app [$AdminApp list] { if { $app == $appName } { set foundApp true } Jac } l compare app to appName

app set to each item in the list

for..in loops over each item in list

foundApp = false for app in AdminApp.list().split(): if (app == appName): Jy foundApp = true

th on

27

IBM Washington Systems Center

2005-09-23

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

InstallingandRemovinganApplication
$AdminApp uninstall $appName

Jac l

set options [list -server $serverName] lappend options -node $nodeName -appname $appName $AdminApp install $app $options $AdminConfig save lappend append list elements install self-explanatory app ear file we are deploying

uninstall self-explanatory

appName passed in as an argument

save commit unsaved changes

AdminApp.uninstall(appName)

options = [-server + serverName options = options + -node + nodeName options = options + -appname + appName + ] AdminApp.install(app,options) Jy AdminConfig.save()

th on

28

IBM Washington Systems Center

2005-09-23

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

CreatingaNewServerJacl

nodeName passed in as an argument set name [list name $serverName] set server [$AdminConfig create Server $nodeName name $name] create Server self-explanatory

NestedOptions

someoptionshavetheirownoptions e.g.,addressoptionincludehostandportoptions usenestedlistsorconcatenation


set http and https transports set hostlist [list host {}] set portlist [list port 9080] set addresslist [list $hostlist $portlist]

set http [list [list sslEnabled false] [list address [list [list host {}] [list port 9080]]]] set https [list [list sslEnabled true] [list address [list [list host {}] [list port 9081]]] [list sslConfig DefaultSSLSettings]] set transports [list transports:HTTPTransport [list $http $https]] set webcontainer [$AdminConfig list WebContainer $server] $AdminConfig modify $webcontainer [list $transports]

modify change specified attributes


29 IBM Washington Systems Center 2005-09-23

set http and https ports


2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

CreatingaNewServerJython
name = [["name", serverName]] server = AdminConfig.create(Server, node, name)

NestedOptions someoptionshavetheirownoptions e.g.,addressoptionincludehostandportoptions usenestedlistsorconcatenation


hostlist = [host,] portlist = [port,9080] addresslist = [hostlist,portlist]

http = [["sslEnabled", "false"], ["address", [["host", ""], ["port", 9080]]]] https = [["sslEnabled", "true"], ["address", [["host", ""], ["port", 9081]]], ["sslConfig", "DefaultSSLSettings"]] transports = [["transports:HTTPTransport", [http, https]]] webcontainer = AdminConfig.list("WebContainer", server) AdminConfig.modify(webcontainer,transports)

30

IBM Washington Systems Center

2005-09-23

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

SynchronizationOfAllNodes
list get a list of all nodes

set node_ids [$AdminConfig list Node] foreach node $node_ids { set nodename [$AdminConfig showAttribute $node name] set nodesync [$AdminControl completeObjectName type=NodeSync,node=$nodename,*] if { !($nodesync=="") } then { $AdminControl invoke $nodesync sync } }

Jac l

Check for empty string because we dont to sync the dmgrs node list get a list of all nodes

Use for loop to cycle through all nodes split split list into elements

node_ids = AdminConfig.list("Node").split() for node in node_ids: nodename = AdminConfig.showAttribute(node,"name") nodesync = AdminControl.completeObjectName("type=NodeSync,node=" + nodename + ",*") if nodesync != "": AdminControl.invoke(nodesync,"sync")

Jy

th on

31

IBM Washington Systems Center

2005-09-23

2005 IBM Corporation

WebSphere Scripting: WSADMIN, JACL, Jython

Questions?

32

IBM Washington Systems Center

2005-09-23

2005 IBM Corporation

You might also like