You are on page 1of 10

Automating Oracle Service Bus Deployments

This article describes the process of automating project deployments in Oracle Service Bus (OSB). In any large enterprise environment, application releases and deployments are a fully automated process. This automation needs to be extended to SOA project integrations that utilize OSB. Hence, the need emerges to fully automate SOA project deployments to OSB across different environments that can be integrated with existing change control systems and processes. In this article we will walk through the manual deployment steps for the OSB mortgage samples project and then describe the sample OSB automation in depth. In a typical enterprise we have to automate deployments across multiple environments i.e. Development, Test, User Acceptance Testing (UAT), Staging and Production. First we will outline the manual migration steps that typically need to be executed across these environments. Subsequently we will discuss the automation of these manual steps using a custom Jython (WLST) script in Oracle Service Bus. Oracle Service Bus provides a mechanism to export the project artifacts and provides a facility to create an environment specific customization file using the Service Bus Console. The migration across different environments is done manually as follows:

Export Project Artifacts (sbconfig.jar) Export a service bus customization.xml file Create environment specific customization files Import the exported project artifacts (sbconfig.jar) and execute the customization.xml on each environment

Detailed steps to import and execute the customization file are shown below:

Import sbconfig.jar
Select your exported file archive. In this example it is called sbconfig.jar.

Verify your imported artifacts by expanding the project tree. Click on the import button to proceed.

Execute Customization File

Next we will execute the customization file for the specific environment. Note within a typical customization file you will have environment specific settings for your endpoint addresses for business services, operational settings for retry logic, alert destinations etc. This file will need to be modified for each environment. In most cases the endpoint addresses will have to be modified to match the specific environment.

Click on the Execute button to apply the customization file for your specific environment. These manual steps described above complete the deployment of our Oracle Service Bus Project for a specific environment. These steps can be completely automated and integrated with the overall build deployment process using Jython (WLST) and Ant scripts. Below we will discuss this automation process and integration with a source control system. For our automated deployment we can establish a flexible directory structure in source control such as:

The sample download file at the end of this article contains the following files to automate OSB deployments: The WLST script to automate the steps described above of importing a project and applying the customization file. build.xml: Ant build script that invokes the WLST script to perform the deployment. This Ant script can be integrated with your overall build and deployment process. ALSBCustomizationFile.xml: An example customization file for OSB samples project Property file for configuring location of WLST automation script and associated properties Property file for configuring admin server, project archive, customization file and external config and key file for connecting to the WebLogic server using WLST

To run the sample project it is recommended to generate an associated config and key file for your target WebLogic server. This can be done by executing the following WLST commands: CALL "%BEA_HOME%/wlserver_10.3/server/bin/setWLSEnv.cmd" java weblogic.WLST connect(url='t3://localhost:7021') Server will prompt your WebLogic administrator to enter your weblogic username and password. After entering that information the WebLogic Administrator can execute the following commands to generate encrypted and a storeUserConfig('','') The last storeUserConfig() WLST command will generate the files containing the encrypted username/password information and the associated key file that can be used to decrypt the information. The automation of the deployment is done by the Python WLST script. This script does the following:

Load the properties file Connect to server Read the project jar file (sbconfig.jar) Create and start and ALSB change session Obtain ALSBConfigurationMBean instance Perform update operation in the session Execute environment customization file

Below is the WLST script that accomplishes this automation:

import wlstModule from from from from from from from from import SessionManagementMBean import ALSBConfigurationMBean com.bea.wli.config import Ref com.bea.wli.config.customization import Customization import FileInputStream java.util import HashMap java.util import ArrayList java.util import HashSet

import sys #================================================================================== # Entry function to deploy project configuration and resources # into a ALSB domain #================================================================================== def importToALSBDomain(): try: # Declare Variables sessionMBean = None alsbConfigurationMBean = None # Connect to Server print 'Connecting to server: ', adminUrl connectToServer(connectMethod) print 'Starting import of:', importJar, "on ALSB Admin Server:", adminUrl # Read import jar file print 'Read import jar file' theBytes = readBinaryFile(importJar) print 'Import file read successfully', importJar # Create unique session name print 'Creating unique session name' sessionName = createSessionName() print 'Created session name :', sessionName # Create and start session print 'Creating SessionMBean' sessionMBean = getSessionMBean(sessionName) print 'SessionMBean started new session' # obtain the ALSBConfigurationMBean instance that operates # on the session that has just been created. Notice that # the name of the mbean contains the session name. print 'Create ALSBConfiguration' alsbConfigurationMBean = findService(String(ALSBConfigurationMBean.NAME + ".") .concat(sessionName),ALSBConfigurationMBean.TYPE) print "ALSBConfiguration MBean found", alsbConfigurationMBean # Perform updates or read operations in the session using alsbSession # Upload Jar File

print 'Uploading Jar file' alsbConfigurationMBean.uploadJarFile(theBytes) print 'Jar Uploaded' print 'ALSB Project will now get imported' alsbJarInfo = alsbConfigurationMBean.getImportJarInfo() alsbImportPlan = alsbJarInfo.getDefaultImportPlan() alsbImportPlan.setPassphrase(passphrase) operationMap=HashMap() operationMap = alsbImportPlan.getOperations() print 'Default importPlan' printOpMap(operationMap) alsbImportPlan.setPreserveExistingEnvValues(false) alsbImportPlan.setPreserveExistingOperationalValues(false) print 'Modified importPlan' printOpMap(operationMap) importResult = alsbConfigurationMBean.importUploaded(alsbImportPlan) printDiagMap(importResult.getImportDiagnostics()) if importResult.getFailed().isEmpty() == false: print 'One or more resources could not be imported properly' raise

#customize if a customization file is specified #affects only the created resources if customFile != None : print 'Loading customization File', customFile iStream = FileInputStream(customFile) customizationList = Customization.fromXML(iStream) alsbConfigurationMBean.customize(customizationList) sessionMBean.activateSession(sessionName, "ALSBImport Operation Completed Successfully") print "Deployment of : " + importJar + " successful" except: print "Unexpected error:", sys.exc_info()[0] if sessionMBean != None: sessionMBean.discardSession(sessionName) raise #================================================================================= # Utility function to print the list of operations #================================================================================= def printOpMap(map): set = map.entrySet() for entry in set: op = entry.getValue() print op.getOperation(), ref = entry.getKey() print ref print #================================================================================= # Utility function to print the diagnostics #================================================================================= def printDiagMap(map): set = map.entrySet() for entry in set: diag = entry.getValue().toString() print diag print #================================================================================= # Connect to the Admin Server

#================================================================================= def connectToServer(connnectMethod): if connectMethod == "boot": connect(url=adminUrl, adminServerName=adminServer) else: connect(userConfigFile=configFile, userKeyFile=keyFile, url=adminUrl) domainRuntime() #================================================================================= # Utility function to read a binary file #================================================================================= def readBinaryFile(fileName): file = open(fileName, 'rb') bytes = return bytes #================================================================================= # Utility function to create an arbitrary session name #================================================================================= def createSessionName(): sessionName = String("ALSBImportScript-"+ Long(System.currentTimeMillis()).toString()) return sessionName #================================================================================= # Utility function to load a session MBeans #================================================================================= def getSessionMBean(sessionName): # obtain session management mbean to create a session. # This mbean instance can be used more than once to # create/discard/commit many sessions sessionMBean = findService(SessionManagementMBean.NAME,SessionManagementMBean.TYPE) # create a session sessionMBean.createSession(sessionName) return sessionMBean

# IMPORT script init try: # import the service bus configuration importToALSBDomain() except: print "Unexpected error: ", sys.exc_info()[0] dumpStack() raise

To run this sample simply unzip the archive attached at the end of this article to your c: drive. Edit the import.cmd and, files under the build/dev folder to match your environment configuration. Run the import.cmd script under c:\osb\build\dev\import.cmd to start the automated deployment process of the example in OSB. Make sure you have copies your generated encrypted configfile and keyfile under the right build folder. Conclusion: As project integrations within a typically OSB environment grow with adoption of SOA, automation of OSB deployments becomes a crucial activity that can simplify the overall

deployment process across environments. Automation also helps minimize the risks associated with error prone manual configurations of projects across environments and allow for OSB deployments to be integrated within enterprise wide change control systems and processes. This allows an organization's SOA based integrations using OSB to expand and scale easily with complete automation of the OSB project deployments. Sample Download: