Showing posts with label Jython. Show all posts
Showing posts with label Jython. Show all posts

Saturday, October 17, 2015

Jython Deployment automation in WebSphere

We can have different JEE applications to install on IBM WebSphere Application Server such as:

  1. Enterprise applications .ear files
  2. Web Applications .war files
  3. Business Application
  4. Utility/shared libraries .jar files
You need to know what type of application you wish to deploy. Where to install it in the Cell. If it is an EJB application you need to provide the binding details as an initial parameter. All application-related functions are available with AdminApp object. For making the application changes permanent you need to save the AdminConfig.

Web application deployment with Jython wsadmin


Let's see the war file installation process


AdminApp.install(ear, '[-BindJndiForEJBBusiness [[ejb_1.jar ejb1   ejb_1.jar,META-INF/ejb-jar.xml test.ejb1 jndi1 ]]]')

# For Web application inside .ear files you need to provide virtual host name. These virtual host varies in the ND cell.
AdminApp.install('fullpath/yourApp.ear', ['-MapWebModToVH', [['.*', '.*', 'default_host']]])
AdminConfig.save()


A menu driven Jython script for wsadmin


#================================================================
#
#               Script Name :  Deployment.py
#               Created Date:   17 Oct 2015
#               Developed by:   Pavan Devarakonda
#
#================================================================

def cls(): print '\n'*45
def linedesign(): print '@'*50
def menu():
        linedesign()
        print """Deployment options
        1. Show deployed Apps
        2. Install App
        3. Uninstall App
        4. Exit
        """
        linedesign()
        ch=input("Please enter your choice: ")
        return ch

def main():
        """ Main program logic starts here """
        while 1:
                ch=menu()
                if ch == 1:
                        cls(); linedesign()
                        print "The list of application deployed on the Cell"
                        print AdminApp.list()
                        linedesign()
                elif ch == 2:
                        print "You selected to deploy application"
                        appPath=raw_input("Enter application path: ")
                        appName=raw_input("Enter application name: ")
                        AdminApp.install( appPath,  ['-appname',appName , '-MapWebModToVH', [['.*', '.*', 'default_host']]])
                        AdminConfig.save()
                elif ch == 3:
                        linedesign()
                        print "Uninstall which application?"; appName=raw_input("Application name: ")
                        AdminApp.uninstall(appName)
                        AdminConfig.save()
                        print "Uninstallation completed...."
                else:
                        print "Exiting from the script...."
                        #sys.exit(0)
                        break

main()


Its execution as follows:

Check the defalthost port number mapping on the admin console.

execfile('/home/vagrant/scripts/Deployment.py')

Deployment script execution output

Install Web application on WebSphere server

Application Status after installing

Uninstall web application using Jython 

Web application access successful this concludes Jython script working fine


WebSphere Admins please write your comments how to make more generic script which could deploy to cluster as well.

  • Deploy EJB, WebService applications
  • Target to selected cluster or app-server
  • Clearing cache for web application
  • App server restart if required


Friday, August 29, 2014

Getting Node id, Cell ID, Server ID of Mbean in wsadmin

Basic understanding of wsadmin objects
  • Node – an individual system, either physical or virtual
  • Node Manager – the process controlling the individual node and all servers in all cells, it executes the commands of the Deployment Manager
  • Profile – a WebSphere entity similar to a node concept wise
  • Application Server – a Java Virtual Machine (JVM) process
  • Application – a Java enterprise application it could be .ear file with some modules
  • Cluster – a group of Servers, all running the same applications
  • Cell – an administrative domain of one or more servers
  • Deployment Manager (DM) – the administration application for a cell
How do all these pieces work together? 
 “Multiple Nodes in a Cell run Servers that contain Applications. All pieces are controlled via the Deployment Manager”
 

How to retrieving  Node ID in wsadmin?

This task is very much required for most of the create method executions. When you create servers, when you construct Cluster Member servers your script need Node id. Ofcourse if you wish to Sync the differe!!nt members of a node also requird the Node id.

wsadmin>AdminConfig.getid('/Node:DmgrNode05')
'DmgrNode05(cells/DmgrCell05/nodes/DmgrNode05|node.xml#Node_1)'

How to retrieving Cell Name in wsadmin?

wsadmin>CellName=AdminControl.getCell()

What is the command to Retrieving Cell ID in wsadmin?

wsadmin>AdminConfig.getid('/Cell:'+CellName)
'DmgrCell05(cells/DmgrCell05|cell.xml#Cell_1)'

How can I retrieving the Servers list in wsadmin?

wsadmin>AdminTask.listServers('[-serverType APPLICATION_SERVER]')
'server1(cells/DmgrCell05/nodes/AppSrvNode/servers/server1|server.xml)'

How to fetch the Server ID on wsadmin?

wsadmin>AdminConfig.getid('/Server:server1')
'server1(cells/DmgrCell05/nodes/AppSrvNode/servers/server1|server.xml#Server_1407376951191)'
wsadmin>

Different automation scripts requires the wsadmin provided MBean values. so that we can store in the Jython variables like list and use them.

Hoping this post helped you in doing simple command exections on your wsadmin prompt. Keep writing your comments and thoughts on this blog 

Containerization with Docker

Containerization with Docker
Learn modern microservices containers grow