Script Libraries in WebSphere Application Server V7

37
IBM Software Group ® WebSphere ® Support Technical Exchange Script Libraries in WebSphere Application Server V7 Ganesan Karuppaiah ([email protected]) & Vikram Thommandru ([email protected]) WebSphere Application Server L2 Support 17 February 2011

Transcript of Script Libraries in WebSphere Application Server V7

Page 1: Script Libraries in WebSphere Application Server V7

IBM Software Group

®

WebSphere® Support Technical Exchange

Script Libraries in WebSphere Application Server V7

Ganesan Karuppaiah ([email protected]) & Vikram Thommandru ([email protected])WebSphere Application Server L2 Support17 February 2011

Page 2: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 2 of 37

Agenda

Overview – WebSphere AdministrationOverview of wsadminScripting LibraryRAD and Scripting LibraryTroubleshootingQuestions and Answers

Page 3: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 3 of 37

Overview – WebSphere Administration

Page 4: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 4 of 37

WebSphere Administration General tool sets that are available with most editions of

the productCommand-line toolsAdministrative ConsoleScripting toolJava™ programming APIs

Command-Line ToolsSimple programs that you run from a command

prompt to perform specific tasks. Ex:startServer, addNode

Page 5: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 5 of 37

WebSphere Administration Administrative Console

The Administrative Console is a graphical interface that provides many administration features.

Scripting toolwsadmin, is a powerful, non-graphical tool that lets

you execute administrative operations interactively or from a script file (jython & jacl)

Java programming APIsUsing the administrative programming API, you can write your

own custom administration client to perform specific administration functions

WebSphere Application Server public APIs and limitationshttp://www-01.ibm.com/support/docview.wss?uid=swg21257822

Page 6: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 6 of 37

Overview – wsadmin

Page 7: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 7 of 37

wsadmin The wsadmin tool operates on configurations and

running objects through set of management objects. AdminConfig, AdminControl, AdminApp, AdminTask

and Help. These low level JMX objects can be complicated. To help the administrator WebSphere provides multiple

options. Information Center SamplesAdministrative console command assistance Interactive ModeAdminTaskJython Scripting library

Page 8: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 8 of 37

wsadmin challenges

Page 9: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 9 of 37

wsadmin challenges Create a JDBC Provider 1. Identify the parent ID and assign it to the node variable.

node = AdminConfig.getid('/Cell:mycell/Node:mynode/')print nodeExample output:

mynode(cells/mycell/nodes/mynode|node.xml#Node_1)

2. Identify the required attributes: print AdminConfig.required('JDBCProvider')

Example output:

Attribute Type

name String

implementationClassName String

3. Set up the required attributes and assign it to the jdbcAttrs variable.

n1 = ['name', 'JDBC1']

implCN = ['implementationClassName', 'myclass']

jdbcAttrs = [n1, implCN]

print jdbcAttrs

Example output:

[['name', 'JDBC1'], ['implementationClassName', 'myclass']]

4. Create a new JDBC provider using node as the parent:

AdminConfig.create('JDBCProvider', node, jdbcAttrs)

Example output: JDBC1(cells/mycell/nodes/mynode|resources.xml#JDBCProvider_1) es

5.Save the changesAdminConfig.save()

Page 10: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 10 of 37

wsadmin challenges AdminTask is another easy way to complete the particular

wsadmin task without going thru multiple steps. Using interactive command makes scripting experience very easy.

The administrative (AdminTask) commands do not replace any existing configuration commands or running object management commands but provide a way to access these commands and organize the inputs.

Ex: AdminTask.createDatasource('-interactive')

Page 11: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 11 of 37

wsadmin challenges Random search using .Ex: wsadmin JDBC create

Page 12: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 12 of 37

wsadmin challenges Direct menu view

Network Deployment• Scripting the application serving environment (wsadmin)

− Scripting for Data access resources

Problem: You may not find the exact

samples in the information center.

Page 13: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 13 of 37

wsadmin challenges Enabling console command Assistance

Page 15: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 15 of 37

Jython Scripting library

Page 16: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 16 of 37

Jython Scripting libraryScripting using low level JMX objects like

AdminConfig and AdminTask can be complicated.

WebSphere also provides a high level set of Jython objects (not JMX MBeans) that wrap the low level objects and simplify the scripting.

Internally these Jython objects use the same JMX objects like AdminApp, AdminConfig and AdminControl.

Page 17: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 17 of 37

Jython Scripting library The Jython script library provides a set of procedures to

automate the most common WebSphere® Application Server V7.0 administration functions.

For example, you can use the script library to easily configure servers, applications, mail settings, resources, nodes, business-level applications, clusters, authorization groups, and more.

You can run each script procedure individually, or combine several procedures to quickly develop new scripts.

Page 18: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 18 of 37

RAD and Scripting Library

Page 19: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 19 of 37

Scripting in RADRational Application Developer (RAD) adds some

functions related to scripting. There is a special type of project in RAD for Jython code.

You can create and maintain resources for Jython scripts in Jython projects.

Scripts can be run against a specified WebSphere installation and profile in the workbench.

Page 20: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 20 of 37

RAD- Creating Jython Projects1. In the menu bar, select File > New > Project .

The New Project wizard opens.

2. Expand the Jython folder and select Jython Project. Click Next. The New Jython Project wizard opens.

3. In the Project name, type a name for the new Jython project.

4. Click Finish.

Page 21: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 21 of 37

RAD- Creating Jython Projects

Related taskshttp://publib.boulder.ibm.com/infocenter/radhelp/v7r5/topic/com.ibm.ws.ast.jythontools.doc/topics/tcreatejythonproject.html

Page 22: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 22 of 37

RAD- Creating Jython script files1. In the menu bar, select File > New > Other. The New

wizard opens.

2. Expand the Jython folder and select Jython Script File. Click Next.

3. In the Parent folder field, specify the path of an existing project folder in the current workspace where you want to store the new Jython script file. You must specify a project folder that already exists in the workspace.

4. In the File name field, type a name for your new Jython script file. The file extension must be .py or .jy.

5. Click Finish to create the Jython script file.

Page 23: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 23 of 37

RAD- Creating Jython Projects

Related taskshttp://publib.boulder.ibm.com/infocenter/radhelp/v7r5/topic/com.ibm.ws.ast.jythontools.doc/topics/tcreatejythonfiles.html

Page 24: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 24 of 37

RAD- Enabling Jython script library You can enable 'Jython script library' in RAD. This makes

existing Jython Objects from script library available for RAD Jython project.

If you are writing scripts that will run against a WebSphere Application Server v7.0, you can take advantage of the Jython script library newly added for Version 7.0 release of WebSphere Application Server.

Restrictions If you are writing scripts against a WebSphere Application Server v6.1 or

earlier, you cannot use the Jython script library. The scripts in the Jython script library are only supported for WebSphere Application Server v7.0.

Page 25: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 25 of 37

RAD- Enabling Jython script library

To display the Jython script library as content assists or tips in the Jython editor:1. Select from the toolbar Windows > Preferences > Jython. The Jython preference page opens.2. Select and enable the Enable content assist for WebSphere Application V7 script libraries check box.

Page 26: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 26 of 37

RAD- Jython script library

1. In Navigator view, expand the Jython project that contains the Jython script file you want to use content assists or tips.

2. Right-click the Jython script file. In the pop-up menu, select Open With > Jython Editor.

Page 27: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 27 of 37

RAD- Jython script library

Place your cursor in a partially entered string of code in the Jython editor: Start content assists, by pressing Ctrl+Space Start content tips, by pressing Ctrl+Shift+Space

If the Jython editor finds valid candidates for this position, a list of possible completions is shown in a floating window.

Page 28: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 28 of 37

Examples using Scripting Libraries.createJDBCProvider

This script creates a JDBC provider in your environment. The script returns the configuration ID of the new JDBC provider.

To run the script, specify the node name, server name, JDBC provider, and implementation class arguments. You can optionally specify attributes.

Page 29: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 29 of 37

AdminJDBC.createJDBCProvider(nodeName, serverName, jdbcProvider, implementationClass, attributes)

The following example command contains required attributes only:

C:\WAS7\AppServer\profiles\dmgr01\bin>wsadmin -lang jythonWASX7209I: Connected to process "dmgr" on node vikramnode using SOAP connector; The

type of process is: DeploymentManager WASX7031I: For help, enter: "print Help.help()“

wsadmin>wsadmin>AdminJDBC.createJDBCProvider(“MyNode01", "server1",

"myJDBCProvider", "com.ibm.db2.jcc.DB2ConnectionPoolDataSource")

Scripting Libraries Command usage

Page 30: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 30 of 37

Output of the command :--------------------------------------------------------------- AdminJDBC: createJDBCProvider Scope: node MyNode01 server server1 JDBC provider:name myJDBCProviderimplClassName com.ibm.db2.jcc.DB2ConnectionPoolDataSource

Optional attributes:otherAttributesList Usage: AdminJDBC.createJDBCProvider("CNameNode06", "server1", "myJDBCProvider", "com.ibm.db2.jcc.DB2ConnectionPoolDataSource")---------------------------------------------------------------

'myJDBCProvider(cells/vikramcell/nodes/CNameNode06/servers/server1|resources.xml#JDBCProvider_1296502671390)‘

wsadmin>

Examples using Scripting Libraries.

Page 31: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 31 of 37

Modifying class loader modes for applicationsUsing wsadmin scripting libraries :

Syntax: AdminApplication.configureClassLoaderLoadingModeForAnApplication (appName, classloaderMode)

Example usageAdminApplication.configureClassLoaderLoadingModeForAnApplication (“ivtApp",

"PARENT_LAST")Lets compare this with regular (direct) AdminConfig object :

Step 1:Retrieve the configuration ID of the object that you want to modify and set it to the dep variable. For example: dep = AdminConfig.getid('/Deployment:ivtApp/') Step 2:Identify the deployed object and set it to the depObject variable. For example: depObject = AdminConfig.showAttribute(dep, 'deployedObject')

Step 3:Identify the class loader and set it to the classldr variable. For example: classldr = AdminConfig.showAttribute(depObject, 'classloader')

Examples using Scripting Libraries.

Page 32: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 32 of 37

Step 4:Show the current attribute values of the configuration object with the showall command, for

example: print AdminConfig.showall(classldr) Example output: [libraries []] [mode PARENT_FIRST]

Step 5:Modify the attributes of the configuration object with the modify command, for example: AdminConfig.modify(classldr, [['mode', 'PARENT_LAST']])

Step 6:Save the configuration changes. Use the following command example to save your

configuration changes:AdminConfig.save()

Step 7:Verify the changes that you made to the attribute value with the showall command, for

example: AdminConfig.showall(classldr)Example output: [libraries []] [mode PARENT_LAST]

Examples using Scripting Libraries.

Page 33: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 33 of 37

Troubleshooting & References

Page 34: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 34 of 37

Problem Troubleshooting & References

MustGather: wsadmin problems in WebSphere Application Serverhttp://www.ibm.com/support/docview.wss?uid=swg21140940

InfoCenter -Jython script libraryhttp://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?

topic=/com.ibm.websphere.nd.doc/info/ae/ae/welc_ref_adm_jython.html

RedBook:WebSphere Application Server V7:Administration with Scriptinghttp://www.redbooks.ibm.com/redpapers/pdfs/redp4576.pdf

Page 35: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 35 of 37

Additional WebSphere Product Resources Learn about upcoming WebSphere Support Technical Exchange webcasts, and access

previously recorded presentations at:http://www.ibm.com/software/websphere/support/supp_tech.html

Discover the latest trends in WebSphere Technology and implementation, participate in technically-focused briefings, webcasts and podcasts at:http://www.ibm.com/developerworks/websphere/community/

Join the Global WebSphere Community: http://www.websphereusergroup.org

Access key product show-me demos and tutorials by visiting IBM® Education Assistant:http://www.ibm.com/software/info/education/assistant

View a webcast replay with step-by-step instructions for using the Service Request (SR) tool for submitting problems electronically:http://www.ibm.com/software/websphere/support/d2w.html

Sign up to receive weekly technical My Notifications emails:http://www.ibm.com/software/support/einfo.html

Page 36: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 36 of 37

We Want to Hear From You!

Tell us about what you want to learn

Suggestions for future topicsImprovements and comments about our webcasts

We want to hear everything you have to say!

Please send your suggestions and comments to: [email protected]

Page 37: Script Libraries in WebSphere Application Server V7

IBM Software Group

WebSphere® Support Technical Exchange 37 of 37

Questions and Answers