What can be worse than to redeploy IBM Maximo manually? It is to redeploy it manually on a daily basis or, even worse, to do it several times a day. At the very beginning this process may seem a sacred activity but it quickly becomes a routine which distracts with it high amount of simple yet manual steps. It may be especially annoying in a development environment were you frequently need to try a new functionality. A number of simple and repetitive actions looks like a perfect candidate for automation. And that’s were WebSphere’s
wsadmin scripting tool comes in handy.
I’m going to demonstrate this recipe in Windows environment but you will hardly feel the difference on Linux – after changing passes and switching from .bat to .sh scripts everything else stays the same. What is important is to use WebSphere Network Deployment since
wsadmin scripting tool is embedded in WebSphere and is not available for WebLogic or other versions of WebSphere apart from Network Deployment. This approach was tested on WAS ND 8.5.5 but it should work without any changes for WAS ND 7.0.0 as well. Maximo version is 22.214.171.124 so the process should be the same for a whole 7.5 family. I also assume that Maximo is installed and running. Let’s start.
wsadmin works as a JMX client to access and control WebSphere MBeans objects. Plus it has an access to WebSphere control files i.e. configurations. Thus we are going to deal with two types of objects: MBeans and configuration files. Each MBean is represented with an MBean name and each configuration file is represented with its configuration ID. It’s important to mention that the same idea is used in WebSphere admin console underneath so any action from admin console can be reproduced in
wsadmin gains access to WebSphere objects through several helping objects: Help, AdminControl, AdminConfig, AdminTask and AdminApp. Help.help() can give you the main source of info, AdminControl provides access to MBeans, AdminConfig is used to control configuration, AdminTask and AdminApp acts as a utility objects for common tasks. We are going to use AdminControl, AdminConfig and AdminApp objects in this article.
As I’ve mentioned every action from WAS administration console can be reproduced in a
wsadmin. To simplify this process there is a special help portlet which I’m going to use. You may see it for example if you navigate to
Server > Server Types > WebSphere Application Servers
and look for a help portlet on the left side of the screen. If not, then you should activate it. To do it go to
System Administration > Console Preferences
and tick “Show the help portlet” option.
Building the script file
The idea behind the script is simple: to update Maximo we should stop the server, then update the application, save changes and finally start the server. It gives us three tasks: to start/stop server, to update application and to save changes.
Stopping/starting application server
At first we should check if the server is running. If it’s stopped and we try to stop it again then we will get an error message.
Every running Application server has corresponding MBean object. We’re not going to use it directly but check if corresponding object exists. If so then server is running. If not then server is stopped and there is no need to stop it again.
To get MBean name we will firstly obtain server configuration ID. The easiest way to do it is to use
AdminConfig.getid method which accepts path to the object in form
/key:value/*. In this case it would be
then with a method AdminConfig.getObjectName we can obtain MBean name if MBean exists. The final function will be
def server_is_started(): jmx_query = '/Node:' + SERVER_NODE + '/Server:' + SERVER + '/' server_config_id = AdminConfig.getid(jmx_query) return len(AdminConfig.getObjectName(server_config_id)) > 0
starting and stopping server is even simplier. We will use
AdminControl.stopServer. Both methods accept server and node name.
AdminControl.stopServer("MXServer", "ctgNode01") AdminControl.startServer("MXServer", "ctgNode01")
Note that there are also an overloaded versions of this methods where you can provide timeout instead of default one. It might be useful if default timeout is not sufficient.
Updating an application
The most convenient option to update an application is to use Admin Console help. To do that you should log in WAS Admin console and go through the usual process of updating application. At the very last step right before clicking “Finish” click on “View administrative scripting command for last action” instead. The resulting command may look somewhat scary but the only part you should be aware of is the path to Maximo .ear file. We are going to replace it with our own value.
After updating the application we should save our changed or they will be discarded. It is performed with a single command
Combine everything in a final script
Once we define all major components building the resulting script is straightforward. With constants moved to a separate variables it will look as following:
SERVER = 'MXServer' SERVER_NODE = 'ctgNode01' EAR_LOCATION = 'C:\IBM\SMP\maximo\deployment\default\maximo.ear' FULL_SERVER_NAME = SERVER_NODE + ": " + SERVER def get_server_config_id(): def server_is_started(): jmx_query = '/Node:' + SERVER_NODE + '/Server:' + SERVER + '/' server_config_id = AdminConfig.getid(jmx_query) return len(AdminConfig.getObjectName(server_config_id)) > 0 if server_is_started(): print "Stopping server " + FULL_SERVER_NAME AdminControl.stopServer(SERVER, SERVER_NODE) else: print "Server is already stopped. No need to stop" print "Updating application" AdminApp.update('MAXIMO', 'app', '[ -operation update -contents ' + EAR_LOCATION + ' -nopreCompileJSPs -installed.ear.destination ' + '$(APP_INSTALL_ROOT)/ctgCell01 -distributeApp ' + '-nouseMetaDataFromBinary -deployejb -createMBeansForResources ' + '-noreloadEnabled -nodeployws -validateinstall warn ' + '-noprocessEmbeddedConfig -filepermission ' + '.*\.dll=755#.*\.so=755#.*\.a=755#.*\.sl=755 ' + '-noallowDispatchRemoteInclude -noallowServiceRemoteInclude ' + '-asyncRequestDispatchType DISABLED -nouseAutoLink ' + '-noenableClientModule -clientMode isolated -novalidateSchema ' + '-MapModulesToServers ' + '[[ "MBO EJB Module" mboejb.jar,META-INF/ejb-jar.xml ' + 'WebSphere:cell=ctgCell01,node=ctgNode01,server=webserver1' + '+WebSphere:cell=ctgCell01,node=ctgNode01,server=MXServer ]' + '[ "MAXIMO Web Application" maximouiweb.war,WEB-INF/web.xml ' + 'WebSphere:cell=ctgCell01,node=ctgNode01,server=webserver1+' + 'WebSphere:cell=ctgCell01,node=ctgNode01,server=MXServer ]' + '[ "MBO Web Application" mboweb.war,WEB-INF/web.xml ' + 'WebSphere:cell=ctgCell01,node=ctgNode01,server=webserver1+' + 'WebSphere:cell=ctgCell01,node=ctgNode01,server=MXServer ]' + '[ "MEA Web Application" meaweb.war,WEB-INF/web.xml ' + 'WebSphere:cell=ctgCell01,node=ctgNode01,server=webserver1+' + 'WebSphere:cell=ctgCell01,node=ctgNode01,server=MXServer ]' + '[ "REST Web Application" maxrestweb.war,WEB-INF/web.xml ' + 'WebSphere:cell=ctgCell01,node=ctgNode01,server=webserver1+' + 'WebSphere:cell=ctgCell01,node=ctgNode01,server=MXServer ]]]' ) print "Saving changes" AdminConfig.save() print "Starting server " + FULL_SERVER_NAME AdminControl.startServer(SERVER, SERVER_NODE)
Running script file
Save the result in autoupdate.py file. You can now run it with a command:
'C:\Program Files (x86)\IBM\WebSphere\AppServer\profiles\ctgDmgr01\bin\wsadmin.bat' -lang jython -user wasadmin -f autoupdate.py
if security is enabled then you should supply password in interractive mode or at the script starting with
In this article you’ve learned how to make a simple
wsadmin script to run Maximo update in automatic way. Even tho the script was run manually it can be easily added to a simple .bat or .sh file for Maximo build/deploy or called from Ant/Maven build tool to deploy compiled code. Plus it can be used as an example of using
wsadmin tool for scripting day-to-day activity with WAS ND. I hope you find this information useful