Upload
others
View
8
Download
0
Embed Size (px)
Citation preview
IT Training .Consultancy . Software Development. Staffing
Welcome to GKTCS
1
16 + Years of Experience ( MCA, PGDCS, BSc. [Electronics] , CCNA) Director , GKTCS Innovations Pvt. Ltd. Pune [ Nov 2009 – Till date ] IT Manager and Consultant at Rolta India Ltd, Mumbai [ April 2007 – Oct 2009 ] Associate Professor at Sinhgad Institute , Pune [Jan 2002 – April 2007] Instructor , ITM Bangalore [ May 2000 – Jan 2002 ] Project Trainee, DSYS Software Group, Bangalore [ Jan 1999 to April 2000]
Skills Python, Perl,Jython, Django, Ruby,Rails,Android , PHP, LAMP Data Communication & Networking, CCNA
UNIX /Linux Shell Scripting, System Programming
CA Siteminder, Autosys, SSO, Service Desk, Service Delivery
Author of 4 Books
National Paper Presentation Awards at BARC Mumbai
Director, GKTCS Innovations Pvt. Ltd, Pune.
Surendra Panpaliya
2
• Form a group of 2 or 3.
• Listen to your colleague.
• Appreciate everyone.
• Know everyone skills and appreciate the same.
• Learn in team.
• Cooperate to each other
• Please switch off / Silent your Mobile phone.
ICE Breaking
3
8 February 2015 4
Jython Programming
Surendra R. Panpaliya
M:9975072320 [email protected]
www.gktcs.com
• wsadmin Options
• Usage Information
• The Java Virtual Machine Initialization Phase
• The wsadmin Environment Initialization Phase
• The Connection Phase
• Defining the Scripting Language
• Trace-Related Options
• wsadmin Profile Script Files
• Commands and Script Files
• Interactive/Interpretive wsadmin Session
• Summary
5
Day 4: wsadmin
• The Administrative Scripting Objects
• Help for the Help Object
• Help for MBeans
• Help for MBean Attributes
• Help for MBean Operations
• Help for Additional MBean Information
• Help for Other Administrative Objects
• Help for WebSphere Messages
• Useful Information
• Summary
Introduction to Admin Objects
6
Day 5
• The AdminConfig Object
• AdminConfig Overview
• Configuration Identifier (config ID)
• Containment Path
• Configuration Types
• Using a config ID
• Show and Tell Methods
• Create and Modify Methods
• Configuration Verification/Validation
• Document Manipulation Methods
• Miscellaneous Methods
Introduction to Admin Objects
7
• The AdminControl Object
• Environment Information and Manipulation
• MBean Support Methods
• Objects, Names, and Instances
• Attribute-Related Methods
• Miscellaneous Methods
• *_jmx Methods
• Summary
Introduction to Admin Objects
8
Day 4
wsadmin
8 February 2015 9
• The wsadmin program can and should be considered a scripting engine for performing administrative tasks on an application server or its configuration. It can be used to execute individual commands or multiple commands in an interactive/interpretive fashion, or it can be used to execute script files.
• wsadmin commands and controls how WebSphere Application Server behaves and configures the way WebSphere Application Server starts.
wsadmin
10
• C:\IBM\WebSphere\AppServer\bin>wsadmin -?
• WASX7001I: wsadmin is the executable for WebSphere scripting.
• wsadmin
• [ -h(elp) ]
• [ -? ]
• [ -c <command> ]
• [ -p <properties_file_name>]
• [ -profile <profile_script_name>]
• [ -f <script_file_name>]
wsadmin
11
• [ -javaoption java_option]
• [ -lang language]
• [ -wsadmin_classpath classpath]
• [ -profileName profile]
• [ -conntype SOAP
• [-host host_name]
• [-port port_number]
• [-user userid]
• [-password password] |
wsadmin
12
• RMI
• [-host host_name]
• [-port port_number]
• [-user userid]
• [-password password] |
• NONE ]
• [ -jobid <jobid_string>]
• [ -tracefile <trace_file>]
• [ -appendtrace <true/false>]
• [ script parameters ]
wsadmin
13
• Command: A command to be passed to the script processor.
• properties_file_name : A java properties file to be used.
• profile_script_name :A script file to be executed before the main command or file.
• script_file_name : A command to be passed to the script processor.
• classpath : A classpath to be appended to built-in one.
• -conntype Specifies the type of connection to be used; the default argument is “SOAP” a conntype of “NONE” means that no server connection is made and certain operations will be performed in local mode.
wsadmin
14
• host_name Is the host used for the SOAP or RMI connection; the default is the localhost.
• password Is the password required when the server is running in secure mode.
• script parameters Anything else on the command line. These string values are passed to the script in the sys.argv variable.
• jobid_string A jobID string to be used to audit each invocation of wsadmin.
• trace_file Is the log file name and location where wsadmin trace output is directed.
wsadmin
15
• The Java Virtual Machine Initialization Phase
• -javaoption <java_option>
• For example, to define the maximum size to be used by the Java heap, one can use something like
• -javaoption -Xmx1024m.
• -wsadmin_classpath <classpath>
• This option should be used to add Java class files to the classpath.
• Multiple entries should be separated using a semicolon.
• Should a space exist in any of the directory names, surround the entire value in double quotes.
wsadmin
16
• If you have some Java code that uses the Java Management Extensions (JMX) to monitor and control the behavior of WebSphere, this is how you would load that code into wsadmin:
• -wsadmin_classpath “C:/Program Files/classes/myClasses.jar”
• The wsadmin Environment Initialization Phase
• The primary property file that is processed during the initialization of wsadmin is named
• wsadmin.properties
wsadmin
17
wsadmin
18
wsadmin
19
• “A profile defines the runtime environment. The profile includes all of the files that the server processes in the runtime environment and that you can change.”
• 1. Which wsadmin command script (for example, .bat or .sh) file was executed?
• “wsadmin” command script from a particular profile bin directory (that is, ”...\WebSphere\AppServer\profiles\AppSrv01\bin”) be executed, then this is exactly the same as having executed the
• “wsadmin” command script from the <WAS_HOME>\bin (for example,
20
• ”...\WebSphere\AppServer\bin”) directory and having specified ”-profileName AppSrv01” as a command-line option.
• 2. Which profileName has been identified as the “default?”
• This question is important should the “wsadmin” command script from the
• <WAS_HOME>\bin directory be executed without providing the profileName option,in which case this identifies the profileName to be used should one not be provided.
• 3. What wsadmin command-line options were specified?
21
• ...\bin>manageprofiles -getDefaultName
• AppSrv00
• Should you decide that a different profileName be used as the default for your environment,the manageprofiles command may be used to change the default, as shown in this example:
..\bin>manageprofiles -setDefaultName –profileName AppSrv00
• INSTCONFSUCCESS: Success:
• The default profile has been set.
22
• During its initialization, wsadmin looks for a file named wsadmin.properties in each of the following locations:
• 1. Below the installation root directory—For example, <WAS_HOME>\profiles
• \<profileName>\properties\wsadmin.properties.
• 2. The user default, or home directory—For example, <USERPROFILE> \wsadmin. properties.
• 3. The file specified by the WSADMIN_PROPERTIES environment variable (should one
• exist)—For example, %WSADMIN_PROPERTIES%.
23
Wsadmin.properties
24
Wsadmin.properties
25
• The wsadmin tool uses information from the property files to determine things such as: – The default communication protocol to be used, if any
– The hostname of the default application server
– The default port number to which the connection request should be sent
– The user and password to be used for authentication.
The Connection Phase
26
• This is when wsadmin uses the connection type value to determine whether a connection to an application server should be attempted.
• If not, that is, should -conntype none be specified on the command line or in the property file(s), wsadmin initialization does not attempt to connect to an application server and could be used to view and manipulate the application server configuration details.
• When wsadmin is not connected to an application server, it is called being in local mode.
The Connection Phase
27
• The properties and/or command-line options that are used during this connection phase are as follows:
– conntype
– host
– port
– user
– password
The Connection Phase
28
• WASX7209I Connection Message
• C:\IBM\WebSphere\AppServer\bin>wsadmin
• WASX7209I: Connected to process “server1” on node GktcsNode00 using SOAP connector; The type of process is: UnManagedProcess
• ...
• C:\IBM\WebSphere\AppServer\bin>wsadmin -profileName Dmgr01
• WASX7209I: Connected to process “dmgr” on node ragibsonCellManager01 using SOAP connector; The type of process is: DeploymentManager
Defining the Scripting Language
29
• The environment initialization phase determines the scripting language using the –lang option (from either a wsadmin.properties file or a command line option).
• The only valid entries are the case sensitive values jacl and jython. It is recommended that you locate the directive in your property file named com.ibm.ws.scripting.defaultLang and change the value from jacl to jython.
Trace-Related Options
30
• Three command-line options exist that relate to tracing of wsadmin:
– Tracefile
– Appendtrace
– jobid
• The first two of these have corresponding settings in wsadmin.properties (for example,traceFile and appendTrace).
• -jobid is only available as a command-line optionand is used to add a text string to the wsadmin trace file.
• This entry can be used to correlate the contents of the trace file with a specific invocation of wsadmin.
Trace-Related Options
31
• If the jobid text string contains spaces, then the string should be enclosed in quotation marks:
• wsadmin -jobid “Ports used” -f ListPorts.py
Another trace-related option is only available using wsadmin.properties file. Looking
• therein, you can see that, by default, this key=value is commented out, which means that a
• default level of tracing is selected:
• AbstractShell A JobID=Ports used
• After executing this command, the trace file (wsadmin.traceout) will contain a line like that
• shown in the code example that follows.
Trace-Related Options
32
• This can prove to be especially useful should the appendtrace option be specified, which could cause the trace messages from multiple invocations of the wsadmin tool to be contained in the trace file. This allows the section of the trace file associated with a specific wsadmin invocation to be quickly located by searching for the appropriate jobid text string:
• #com.ibm.ws.scripting.traceString=com.ibm.*=all=enabled
• ManagerAdmin I TRAS0017I: The startup trace state is *=info.
wsadmin Profile Script Files
33
• These script files must be of the appropriate language, which in this case is Jython. The default property file directive for this option is shown in the code example provided here:
• com.ibm.ws.scripting.profiles=.../securityProcs.jacl;
• .../LTPA_LDAPSecurityProcs.jacl
• Remember to change the file extension for these profile files from .jacl to .py, and verify that the specified files exist in the indicated locations. During the initialization of wsadmin, any files specified here will be used to configure the wsadmin scripting environment before any command or script is executed.
wsadmin Profile Script Files
34
• C:\IBM\WebSphere\AppServer\bin>wsadmin
• WASX7209I: Connected to process “server1” on node GktcsNode00 using SOAP connector; The type of process is: UnManagedProcess WASX7031I: For help, enter: “print Help.help()”
• wsadmin>dir()
• |[‘AdminApp’, ‘AdminConfig’, ‘AdminControl’, ‘AdminTask’, ‘Help’,|’LTPA_LDAPSecurityOff’, ‘LTPA_LDAPSecurityOn’, ‘TypedProxy’,|’__doc__’, ‘__name__’, ‘bsf’, ‘cellName’, ‘checkuserpw’, …..
wsadmin Profile Script Files
35
• You might not like to have the namespace cluttered with things that you’re not planning on using. So let’s remove the default profile script files that were used by commenting out the com.ibm.ws.scripting.profiles directive in the wsadmin.properties file.
• After doing this, you can see that the number of items made available in the default namespace is greatly reduced.
wsadmin Profile Script Files
36
• Minimum wsadmin Namespace
• 1|C:\IBM\WebSphere\AppServer\bin>wsadmin
• 2|WASX7209I: ...
• 3|WASX7031I: For help, enter: “print Help.help()”
• 4|wsadmin>dir()
• 5|[‘AdminApp’, ‘AdminConfig’, ‘AdminControl’, ‘AdminTask’, ‘Help’,
• 6|’TypedProxy’, ‘__doc__’, ‘__name__’, ‘bsf’, ‘sys’]
• 7|wsadmin>
wsadmin Profile Script Files
37
• C:\temp>set WAS_HOME=C:\IBM\WebSphere\AppServer
• C:\temp>%WAS_HOME%\bin\wsadmin -conntype none -f ListPorts.py
• wsadmin -f “C:\Program Files\scripts\ListPorts.py”
wsadmin Profile Script Files
38
• 1|C:\IBM\WebSphere\AppServer\bin>wsadmin spam and eggs
• 2|WASX7209I: Connected to process ...
• 3|WASX7411W: Ignoring the following provided option: [spam, and, eggs]
• 4|WASX7031I: For help, enter: “print Help.help()”
• 5|wsadmin>print sys.argv
• 6|[‘spam’, ‘and’, ‘eggs’]
• 7|wsadmin>
Interactive/Interpretive wsadmin Session
39
• Each of the following options causes wsadmin to exit after performing requested function:
• • help (or -?)
• • c <command>
• • f <script_file>
• If one of these options is not specified, the wsadmin scripting environment is initialized, and a “command prompt” (for example, wsadmin>) is displayed to indicate that wsadmin is awaiting user input to determine what needs to be done. You have seen examples of this previously.
Introduction to Admin Objects
40
Introduction to Admin Objects
41
• simpleModule Example6
• 1|...\bin>wsadmin
• 2|WASX7209I: Connected to process ...
• 3|WASX7031I: For help, enter: “print Help.help()”
• 4|wsadmin>print dir()
• 5|[‘AdminApp’, ‘AdminConfig’, ‘AdminControl’, ‘AdminTask’,
42
• 6|’Help’, ‘TypedProxy’, ‘__doc__’, ‘__name__’, ‘bsf’, ‘sys’]
• 7|wsadmin>import simpleModule
• 8|simpleModule namespace: [‘__doc__’, ‘__file__’, ‘__name__’]
• 9|wsadmin>quit
• 10|
43
• 11|...\bin>wsadmin -profile simpleModule.py
• 12|WASX7209I: Connected to process ...
• 13|simpleModule namespace: [‘AdminApp’, ‘AdminConfig’,
• 14|’AdminControl’, ‘AdminTask’, ‘Help’, ‘TypedProxy’, ‘__doc__’,
• 15|’__name__’, ‘bsf’, ‘sys’]
• 16|WASX7031I: For help, enter: “print Help.help()”
• 17|wsadmin>
• You can use a simple technique 44
• WSASobjects.py
• sys.modules[ ‘AdminApp’ ] = AdminApp
• sys.modules[ ‘AdminConfig’ ] = AdminConfig
• sys.modules[ ‘AdminControl’ ] = AdminControl
• sys.modules[ ‘AdminTask’ ] = AdminTask
• sys.modules[ ‘Help’ ] = Help
45
• moduleTest.py
• #———————————————————————
• # Name: moduleTest
• # Role: Show the difference between module & profile namespaces
• #———————————————————————
• print ‘moduleTest.py’
46
• wsadmin>print dir()
• 5|[‘AdminApp’, ‘AdminConfig’, ‘AdminControl’, ‘AdminTask’,
• 6|’Help’, ‘TypedProxy’, ‘__doc__’, ‘__name__’, ‘bsf’, ‘sys’]
• 7|wsadmin>import simpleModule
• 8|simpleModule namespace: [‘__doc__’, ‘__file__’, ‘__name__’]
• 9|wsadmin>quit
47
11|...\bin>wsadmin -profile simpleModule.py
• 12|WASX7209I: Connected to process ...
• 13|simpleModule namespace: [‘AdminApp’, ‘AdminConfig’,
• 14|’AdminControl’, ‘AdminTask’, ‘Help’, ‘TypedProxy’, ‘__doc__’,
• 15|’__name__’, ‘bsf’, ‘sys’]
• 16|WASX7031I: For help, enter: “print Help.help()”
• 17|wsadmin>
48
• simple technique that works well, has a minimum chance of making a mistake,
• and is also very easy to add to your environment.
• The technique involves using a property of the sys.modules dictionary.
• By adding entries for each of the administrative objects to sys.modules, imported modules can access these objects. The first attempt is a simple profile file (WSASobjects.py)
49
• WSASobjects.py
• sys.modules[ ‘AdminApp’ ] = AdminApp
• sys.modules[ ‘AdminConfig’ ] = AdminConfig
• sys.modules[ ‘AdminControl’ ] = AdminControl
• sys.modules[ ‘AdminTask’ ] = AdminTask
• sys.modules[ ‘Help’ ] = Help
50
• A simple module file (moduleTest.py) is shown in
• moduleTest.py
• #———————————————————————
• # Name: moduleTest
• # Role: Show the difference between module & profile namespaces
• #———————————————————————
• print ‘moduleTest.py’
51
• print ‘namespace before import: ‘ + str( dir() )
• import AdminApp, AdminConfig, AdminControl, AdminTask, Help
• print ‘namespace after import: ‘ + str( dir() )
• WSASobject Example
• 1|C:\IBM\WebSphere\AppServer\bin>wsadmin -profile WSASobjects.py
• 2|WASX7209I: Connected to process ...
• 3|WASX7031I: For help, enter: “print Help.help()”
• 4|wsadmin>import moduleTest 52
• 5|moduleTest.py
• 6|namespace before import: [‘__doc__’, ‘__file__’, ‘__name__’]
• 7|namespace after import: [‘AdminApp’, ‘AdminConfig’,
• 8|’AdminControl’, ‘AdminTask’, ‘Help’, ‘__doc__’, ‘__file__’,
• 9|’__name__’]
• 10|wsadmin>
53
• C:\IBM\WebSphere\AppServer\bin>wsadmin -conntype none
• wsadmin>import modifiedModuleTest
• modifiedModuleTest.py
• 14|namespace before import: [‘__doc__’, ‘__file__’, ‘__name__’]
• 15|Unable to import AdminTask
• 16|namespace after import: [‘AdminApp’, ‘AdminConfig’,
• 17| ‘AdminControl’, ‘Help’, ‘__doc__’, ‘__file__’, ‘__name__’]
54
• Checking for Administrative Object Availability
• 1|try :
• 2| import AdminTask
• 3|except :
• 4| print ‘Unable to import AdminTask’
• wsadmin>print Help.help()
55
wsadmin>print Help.help()
• Looking at this output shows two distinct types of methods:
• 1. Those that provide help for active MBeans (for example, attributes, operations, and so on).
• 2. Those that provide help for other administrative objects (such as help, AdminControl,and so on).
56
• Find all of the method names from this help text using the knowledge that each method name begins after a newline and is composed only of letters.
• It is conceivable that a method name might also include digits and possibly underscore characters, you can make use of a special RegExp meta-character to easily locate exactly this kind of character.
• After the method name, some whitespace occurs, followed by some text.
Assignment
57
• 1|wsadmin>print Help.help( ‘attributes’ )
• 2|WASX7268I: Method: attributes
• 4| Arguments: MBean
• 6| Description: Display information about the attributes of
• 7| the specified MBean.
• 9| Method: attributes
• 11| Arguments: MBean, attribute name
• 13| Description: Display information about the specified
• 14| attribute on the specified MBean.
• 15|wsadmin>
Help for MBeans
58
• Help for Help Methods—Attempt #1 (Helphelp1.py)
• 1|wsadmin>import re
• 2|wsadmin>mNames=re.compile(r’^(\w+)(?:\s+.*)$’,re.MULTILINE)
• 3|wsadmin>methods = mNames.findall( Help.help() )
• 4|wsadmin>for name in methods :
• 5|wsadmin> print ‘Help.help( “%s” )\n%s’ % ( name, ‘-’ * 70 )
• 6|wsadmin> print Help.help( name )
• 7|wsadmin> print ‘-’ * 70
• 8|wsadmin>
Help for MBeans
59
• Extracting Method Names with RegExp • 1|wsadmin>import re
• 2|wsadmin>mNames=re.compile(r’^(\w+)(?:\s+.*)$’,re.MULTILINE)
• 3|wsadmin>mNames.findall( Help.help() )
• 4|[‘attributes’, ‘operations’, ‘constructors’, ‘description’,
• 5|’notifications’, ‘classname’, ‘all’, ‘help’, ‘AdminControl’,
• 6|’AdminConfig’, ‘AdminApp’, ‘AdminTask’, ‘wsadmin’, ‘message’]
• 7|wsadmin>
• re.MULTILINE Multiline flag identifies that newline characters indicate the “end of line.”
Solution
60
• Helphelp2.py Sample Output
• # Help.help( “attributes” )
• WASX7268I: Method: attributes
• Arguments: MBean
• Description: Display information about the attributes of the specified MBean.
• Method: attributes
• Arguments: MBean, attribute name
• Description: Display information about the specified
• attribute on the specified MBean.
Helphelp2.py
61
• This method can be used to retrieve attributes for a given Mbean. For example, if you have an MBean for an active application server (svr), then the attributes for this application server can be obtained using Help.attributes( svr ).
• Subset of Active Application Server Attributes
• wsadmin>svr
‘WebSphere:name=server1,process=server1,platform=proxy,node=...
• wsadmin>print Help.attributes( svr )
• Attribute Type Access
• Name java.lang.String RO
• shortName java.lang.String RO
Help for MBean Attributes
62
• Example Use of MBattrAsDict Utility Method
1|wsadmin>import WAuJ_utilities as WAuJ
2|wsadmin>svr = AdminControl.queryNames(‘type=Server,*’ )
3|wsadmin>svrDict = WAuJ.MBattrAsDict( svr )
4|wsadmin>names = svrDict.keys()
5|wsadmin>names.sort()
6|wsadmin>print ‘\n’.join( names )
7|Modifiable
8|cellName
9|cellShortName
10|deployedObjects
Help for MBean Attributes
63
• 12|wsadmin>fields=’name,platformName,platformVersion,processType’
• 13|wsadmin>for name in fields.split( ‘,’ ) :
• 14|wsadmin> print ‘%-15s : %s’ % ( name, svrDict[ name ] )
• 15|wsadmin>
• 16|name : server1
• 17|platformName : IBM WebSphere Application Server
• 18|platformVersion : 6.1
• 19|processType : UnManagedProcess
• 20|wsadmin>
Help for MBean Attributes
64
• explains this example in more detail. Next, you’ll see how the technique used to understand the Help.attributes() method can be used with other methods of this and all of the WebSphere administrative objects.
• In fact, the next Help method used is Help.operations(). Passing this method the same MBean value (svr) results in the list of operations available for this same MBean.
Help for MBean Attributes
65
• explains this example in more detail. Next, you’ll see how the technique used to understand the Help.attributes() method can be used with other methods of this and all of the WebSphere administrative objects.
• In fact, the next Help method used is Help.operations(). Passing this method the same MBean value (svr) results in the list of operations available for this same MBean.
Help for MBean Attributes
66
The AdminConfig Object
67
• Looking at the AdminConfig.help() text, you see that this object can be used to perform several operations on WebSphere Application Server configuration objects. These operations include the following:
• List
• Create
• Remove
• Display
• Modify
AdminConfig Overview
68
• Looking at the AdminConfig.help() text, you see that this object can be used to perform several operations on WebSphere Application Server configuration objects. These operations include the following:
• List
• Create
• Remove
• Display
• Modify
AdminConfig Overview
69
The AdminApp Object
70
• The AdminApp object operates on applications. The following types of operations can be performed
• on an application:
• 1. Information
• 2. Install
• 3. Uninstall
• 4. Modify
• AdminApp.help() provides the complete list of method calls, and the details about each method can be displayed by calling AdminApp.help(‘methodName’ ).
The AdminApp object
71
• apps = AdminApp.list().splitlines()
• 1|wsadmin>import WAuJ_utilities as WAuJ
• 2|wsadmin>apps = AdminApp.list().splitlines()
• 3|wsadmin>ready = {}
• 4|wsadmin>for app in apps :
• 5|wsadmin>ready[ app ] = AdminApp.isAppReady( app )
• 6|wsadmin>
• 7|...
Application Informational Methods
72
• 8|wsadmin>WAuJ.displayDict( ready )
• 9|DefaultApplication : true
• 10| PlantsByWebSphere : true
• 11| SamplesGallery : true
• 12| ivtApp : true
• 13| query : true
• 14|wsadmin>
Application Informational Methods
73
• The following is an explanation of Listing:
• 1—Import utility library file (WAuJ_utilites) using an alias (WAuJ).
• 2—Build a list of deployed applications.
• 3—Initialize a dictionary variable to hold the ready state of each application.
• 4—Loop to iterate over each application name.
• 5—Assignment statement to save the current application status into the ready (dictionary)
variable.
Application Informational Methods
74
• 6—A blank line is required (by the interactive environment) to indicate the end of the for statement.
• 7—This line represents multiple output messages generated during the execution of the for loop.
• 8—Use the displayDict utility method to display the ready dictionary contents, which shows the ready status for each deployed application
Application Informational Methods
75
• Example Use of listModules()
• 1|wsadmin>app = AdminApp.list().splitlines()[ 0 ]
• 2|wsadmin>mods = AdminApp.listModules(app,’-server’).splitlines()
• 3|wsadmin>format = ‘AppName: %s\n Module: %s\n Server: %s\n’
• 4|wsadmin>for mod in mods :
• 5|wsadmin> ( name, module, server ) = mod.split( ‘#’ )
• 6|wsadmin> print format % ( name, module, server )
• 7|wsadmin>
Application Informational Methods
76
• 8|AppName: DefaultApplication
• 9| Module: DefaultWebApplication.war+WEB-INF/web.xml
• 10| Server: WebSphere:cell=GktcsCell01,node=GktcsNode01,...
• 11|
• 12|AppName: DefaultApplication
• 13| Module: Increment.jar+META-INF/ejb-jar.xml
• 14| Server: WebSphere:cell=rGktcsCell01,node=GktcsNode01,...
Application Informational Methods
77
• • 1—Get the name of a deployed application using the AdminApp.list() method.
• • 2—Get the list of modules for this application. By specifying the optional ”server”
• parameter, each result identifies the server with which this application module is associated.
• • 3—Define a format string so the formatted print statement won’t be too long.
• • 4—Process each module in the mods list using a for statement.
Application Informational Methods
78
• • 5—Extract the specified values from the result using ’#’ as a delimiter.2
• • 6—Display the values using a formatted print statement.
• • 7—Blank line to indicate the end of the for statement.
• • 8—Start of the formatted output for each module.
• AdminApp.view() method, can be used to display a great deal of information about an application or a module within an application. However, be aware that this method can easily generate lots of text.
Application Informational Methods
79
• • 5—Extract the specified values from the result using ’#’ as a delimiter.2
• • 6—Display the values using a formatted print statement.
• • 7—Blank line to indicate the end of the for statement.
• • 8—Start of the formatted output for each module.
• AdminApp.view() method, can be used to display a great deal of information about an application or a module within an application. However, be aware that this method can easily generate lots of text.
Application Informational Methods
80
• AdminApp.view() Example
• 1|( app, hr ) = AdminApp.list().splitlines()[ 0 ], ‘-’ * 70
• 2|print ‘Application: %s\n%s’ % ( app, hr )
• 3|print AdminApp.view( app ) + ‘\n’ + hr
• 4|for mod in AdminApp.listModules( app ).splitlines() :
• 5| print ‘Module: %s\n%s’ % ( mod, hr )
• 6| print AdminApp.view( mod ) + ‘\n’ + hr
Application Informational Methods
81
• To obtain the task names for a deployed application, specify ’-tasknames’ as the second,optional parameter to the view() method. For example:
• app = AdminApp.list().splitlines()[ 0 ]
• taskNames = AdminApp.view( app, ‘-tasknames’ ).splitlines()
• Lets view the information for a specific task by providing the task name as the second parameter to the view() method.
• For example:
• for name in taskNames[ :-1 ] :
print AdminApp.view( app, ‘-’ + name )
print ‘-’ * 70
Application Informational Methods
82
• To understand the installation of an enterprise application is the AdminApp.options() method. This method has a number of uses.
• The one just mentioned is obtained by providing a single parameter of an application name. For example:
• opts = AdminApp.options( app )
• The options() method returns a list of all the options available for editing the specified application.
• If no parameters are specified, the options() method returns the list of “general” options that are available for every installable application.
Application Informational Methods
83
• Application Name—If an application name is specified, the options() method returns information about all the modifiable options (that is, the ones available for editing) for the specified application.
• Module Name—If a module name is specified, the options() method returns information about the modifiable options for the specified module.
• Filename—If a filename is specified, the options() method returns information regarding the installation the specified file.
• Filename, operation—If a filename is specified with one of the following optional operations, the options() method returns information related to the installation of the specified file, and operation:
– installapp
– updateapp
– addmodule
– updatemodule
Application Informational Methods
84
• getDeployStatus() Example
• 1|wsadmin>app = AdminApp.list().splitlines()[ 0 ]
• 2|wsadmin>result = AdminApp.getDeployStatus( app )
• 3|ADMA5071I: Distribution status check started for applicatio...
• 4|WebSphere:cell=GktcsNode01Cell,node=GktcsNode00,distr...
• 5|ADMA5011I: The cleanup of the temp directory for applicatio...
• 6|ADMA5072I: Distribution status check completed for applicat...
• 7|wsadmin>result
• 8|’WebSphere:cell=ragibsonNode01Cell,node=GktcsNode00,dist...
• 9|wsadmin>
Application Informational Methods
85
• edit()
• editInteractive()
• install()
• installInteractive()
• uninstall()
• update()
• updateInteractive()
Application Installation Methods
86
• installInteractive() :-
• It has one “required” parameter, which is used to identify the fully qualified path of the file to be installed.
• The really neat thing about the “interactive” methods is that there is a built-in wizard to assist you with each phase, or task, associated with the process being performed (for example, edit, install, or update).
• As responses are provided to individual prompt, the wizard determines if some future tasks can be skipped based upon user input.
• Use the AdminConfig.save() method to copy the changes from the workspace to the application server configuration.
Application Installation Methods
87
• How would you start a newly installed application within wsadmin?
• For an unmanaged application server, this is as simple as the following:
1. Start the application server (if it is not already started) and start the wsadmin utility.
2. Get the MBean name of the application manager: AppMgr=AdminControl.queryNames(‘name=ApplicationManager,*’)
3. Invoke the startApplication method of the application manager:
AdminControl.invoke( AppMgr, ‘startApplication’, appName )
Application Installation Methods
88
• How can the script tell if an application is currently started or stopped?
• By looking for an Mbean associated with the specific application. If the MBean lookup returns an empty string, then no active MBean instance exists for the specified application, and the enterprise application is not started:
• bean=AdminControl.queryNames(‘name=%s,type=Application,*’ % appName)
• AdminApp.list(). It does not show each and every command or action performed to obtain all of the information currently displayed.
Application Installation Methods
89
• Which scripting commands are required to install an application?
• Well, using nothing but the default installation settings, it is as simple as the following:
• AdminApp.install( r’C:\temp\myApplication.ear’ )
• AdminConfig.save()
Application Installation Methods
90
• Passing Filenames to Scripts
1|C:\IBM\WebSphere\AppServer\bin>type bob.py
2|for arg in sys.argv :
3| print arg
4|...\WebSphere\AppServer\bin>wsadmin -f bob.py C:\temp\app.ear
5|WASX7209I: Connected to process “server1” on node GktcsN...
6|WASX7303I: The following options are passed to the scriptin...
7|that are stored in the argv variable: “[C:\temp\app.ear]”
8|C: emppp.ear
10|C:\IBM\WebSphere\AppServer\bin>
Application Installation Methods
91
• The only parameter that needs to be specified for the uninstall() method is the name of the application to be removed. For example:
• AdminApp.uninstall( ‘myApp’ )
• AdminConfig.save()
• “What’s the difference between the edit() and update() methods?”
• To change the options associated with an installed application,
• use either the AdminApp.edit() or the AdminApp.editInteractive() method.
• To change the contents of the application (that is, to add to, replace, or remove application sub-components), the AdminApp.update() or AdminApp.updateInteractive() method should be used.
Edit, Update, and Uninstall
92
• As with the installInteractive() method, you can use the editInteractive() method to make changes to the configuration settings associated with an installed application.
• Once all of the prompt answers have been provided, an edit() operation is performed, and a message is written to the trace file with the messageID of WASX7278I to show the options that were specified.
• The AdminApp.updateInteractive() method, unlike the installInteractive() and editInteractive() methods, requires more than the application name to be specified.
Edit, Update, and Uninstall
93
• The second parameter to this method is used to identify the content type to be updated. The available values for the content type parameter are as follows:
1. app—Indicates that the application is to be updated, with the “operation” option identifying the kind of operation to be performed on the application.
2. file—Indicates that a single file is to be added, removed, or updated at any scope within the deployed application.
3. modulefile—Indicates that a module is to be updated.
4. partialapp—Indicates that a partial application is to be updated.
Edit, Update, and Uninstall
94
• deleteUserAndGroupEntries()—This method is used to remove all of the user and group information for all of the roles, including RunAs roles, for a given application.
• AdminApp.deleteUserAndGroupEntries( ‘myApp’ )
• AdminConfig.save()
• export()—This method can be used to copy the contents of a deployed application to a user specified file. The two required parameters are the application name and the fully qualified output file name. The following code snippet demonstrates howthis method might be used:
• AdminApp.export( ‘myApp’, r’C:\temp\bob.zip’ )
Miscellaneous AdminApp Methods
95
• exportDDL()—This method can be used to copy the Data Definition Language (DDL) files from the EJB modules of an application to a user-specified directory.
AdminApp.exportDDL( ‘myApp’, r’C:\temp\myApp’ )
• publishWSDL()—The purpose of publishing the Web Services Description Language (WSDL) file for an application is to provide clients with the description of the Web service. This includes identifying the location information for it. So this method can be used to provide the WSDL information after modifying the endpoint values.
• AdminApp.publishWSDL( ‘myApp’, r’C:\temp\myWSDL.zip’ )
Miscellaneous AdminApp Methods
96
• If no WSDL exists in the specified application, an exception is raised. To cover that eventuality, it would probably be best to include a try/except statement, something like the following:
try :
AdminApp.publishWSDL( ‘myApp’, r’C:\temp\myWSDL.zip’ )
except :
print ‘No WSDL exists’
• updateAccessIDs()—This method is used to update the application binding file for a deployed application using access IDs for all of the users and groups that are defined to various roles in the application. There are two required parameters: the application file name and a Boolean value.
Miscellaneous AdminApp Methods
97
The AdminTask Object Server Management
98
• AdminReports
• ClusterConfigCommands
• ConfigArchiveOperations
• CoreGroupManagement
• GenerateSecurityConfigCommand
• NodeGroupCommands
• PortManagement
• ServerManagement
AdminTask command groups
99
• AdminTask methods to create and delete some servers, modify some configuration parameters, create and delete clusters and gather information about the servers in the cell.
• Simple One-Line Examples
• Open a command prompt, and change to the “bin” directory beneath the Deployment Manager’s profile directory. If the Deployment Manager is started, type the following command line:
• wsadmin -c “print AdminTask.reportConfiguredPorts()”
AdminTask command groups
100
wsadmin -c “print AdminTask.reportConfiguredPorts()”
• The information displayed shows the following for every server in your cell:
• The name of each server
• The name of the node containing the server
• The port number of each port used by the server
• The name associated with each port
AdminTask command groups
101
• If you would like to see the same information returned in a slightly different way and limited to only one server, say only the Deployment Manager, type the following command line:
wsadmin -c “print AdminTask.listServerPorts( ‘dmgr’ )”
• Here is yet another useful method, especially when you are troubleshooting your configuration:
• print AdminTask.reportConfigInconsistencies()
AdminTask command groups
102
• On a production cell, you want this report to say that there are no items. This method does not send its output to the screen. Instead, it sends its output to a file. The name and location of this file are specified in the wsadmin.properties file in each profile directory. The com.ibm.ws.scripting.validationOutput property controls this.
• If you would like a verbose checklist of security-related items, this command line can suffice:
• print AdminTask.generateSecConfigReport()
AdminTask command groups
103
• If youwould like a verbose checklist of security-related items, this command line can suffice:
• print AdminTask.generateSecConfigReport()
• The output is voluminous.
• However, this output does not take the place of having a genuine security audit performed by professionals. On the other hand, it does list many configuration items that affect the security of your cell and is a good place to start.
AdminTask command groups
104
• The output of this method shows the following information:
• The name that the Admin Console uses for this setting
• The attribute name the Admin Console uses for this setting
• The current value of this setting
• The breadcrumb path in the Admin Console for viewing this value
AdminTask command groups
105
• AdminTask methods that deal with Server Types are as follows:
– createServerType()
– getServerType()
– listServerTypes()
– showServerTypeInfo()
ServerType-Related Methods
106
• AdminTask.listServerTypes()
• wsadmin>print AdminTask.listServerTypes()
• PROXY_SERVER
• APPLICATION_SERVER
• WEB_SERVER
• GENERIC_SERVER
ServerType-Related Methods
107
• createServerType Arguments
*version - The Product Version
*serverType - The ServerType (e.g.: APPLICATION_SERVER)
*createTemplateCommand - The Command used to create a Server Template
*createCommand - The Command used to create a Server
defaultTemplateName - The name of the default Template (non-z/OS)
defaultzOSTemplateName - The name of the default z/OS Template (nonz/OS)
*configValidator - The name of the Config Validator class
ServerType-Related Methods
108
• Try ServerTypes.py • Output of ServerTypes.py
• createCommand : createApplicationServer
• createTemplateCommand : createApplicationServerTemplate
• defaultTemplateName : default
• defaultzOSTemplateName : defaultZOS
• name : APPLICATION_SERVER
• version : 6.0
• createCommand : createGenericServer
• createTemplateCommand : createGenericServerTemplate
• defaultTemplateName : default
• defaultzOSTemplateName : defaultZOS
• name : GENERIC_SERVER
• version : 6.0
ServerType-Related Methods
109
• The required and optional parameters for the getServerType() method are as follows:
• serverName—The Server Name
• nodeName—The Node Name
• From this, you can build an example getServerType() method call:
getServerType( ‘[ -serverName server1 -nodeName myNode01 ]’ ) • getServerType.py and Output
• ...\bin>type getServerType.py
• from WAuJ_utilities import ConfigIdAsDict
• for server in AdminConfig.list( ‘Server’
ServerType-Related Methods
110
• ...\bin>wsadmin -conntype none -f getServerType.py
• ...
• dmgr : GktcsCellManager01 : DEPLOYMENT_MANAGER
• nodeagent : GktcsNode01 : NODE_AGENT
• nodeagent : GktcsNode02 : NODE_AGENT
• server1 : GktcsNode01 : APPLICATION_
ServerType-Related Methods
111
Variables for the Examples
1| import AdminConfig
2| import AdminTask
3| NameOfSomeNode = “ExamplesNode01”
4| NameOfAnotherNode = “ExamplesNode02”
5| AppSrvName = “happy”
6| Cluster01Name = “group01”
7| Cluster01Member01 = “left”
8| Cluster01Member02 = “right”
9| CoreGroupName = “nassau”
10| NodeGroupName = “financial”
Creating Servers and Clusters
112
• Creating Servers
def createServers():
“““Create some servers and clusters”””
print AdminTask.createCoreGroup( ‘[-coreGroupName ‘ + \
CoreGroupName + ‘ ]’ )
print AdminTask.createNodeGroup( NodeGroupName, \
‘[-description “Servers used by accounting” ]’ )
print AdminTask.createApplicationServer( NameOfSomeNode, ‘[-name ‘ + AppSrvName + ‘ -templateName default]’ )
Creating Servers and Clusters
113
print AdminTask.addNodeGroupMember( NodeGroupName, ‘[ ‘ + \
‘-nodeName ‘ + NameOfSomeNode + ‘ ]’ )
print AdminTask.addNodeGroupMember( NodeGroupName, ‘[ ‘ + ‘-nodeName ‘ + NameOfAnotherNode + ‘ ]’ )
print AdminTask.createCluster( \
‘[-clusterConfig [-clusterName ‘ + Cluster01Name + ‘ ] ‘ + \
‘ -replicationDomain [-createDomain true ] ]’ )
print AdminTask.createClusterMember(‘[-clusterName ‘ + \
Cluster01Name + ‘ -memberConfig [-memberNode ‘ + \
NameOfAnotherNode + ‘ -memberName ‘ + Cluster01Member01 +
‘ -replicatorEntry true] -firstMember ‘ + ‘[-templateName default ‘ +
Creating Servers and Clusters
114
‘ -nodeGroup ‘ + NodeGroupName + \
‘ -coreGroup ‘ + CoreGroupName + ‘ ] ]’)
print AdminTask.createClusterMember(‘[-clusterName ‘ + \
Cluster01Name + ‘ -memberConfig [-memberNode ‘ + \
NameOfSomeNode + ‘ -memberName ‘ + \
Cluster01Member02 + ‘ -replicatorEntry true]]’)
Creating Servers and Clusters
115
8 February 2015 116
Summary
What did we learn today?
Recap and Memory Test.
Question and Answers
Contact Us on:
G K T C S Innovations Pvt. Ltd.
IT Training, Consultancy, Software Development, Staffing
#11,4th Floor,Sneh Deep, Near Warje Flyover Bridge,
Warje-Malwadi, Pune -411058, Maharashtra, India.
Mobile: +91- 9975072320, 8308761477
Email : [email protected]
Web: www.gktcs.com
117