Build and deployment of Oracle Service Bus (OSB) projects using Ant/Weblogic scripts(WLS)
Index:
•Introduction
•Explanation
•Steps
-Setting Ant_Home:
-Creating the build.properties,build.xml file
-Creating import.py file
-Creating export.py file
-Running Ant commands
•Issues can be faced
•Mavenising the AntBuild Script
•Changes to be done in build.xml
•References
Introduction:
In OSB Projects, we generally use either eclipse IDE or work directly in sbconsole. If we need to build and deploy some of the projects
from the current server to a different server, it involves a manual process of creating the jar and exporting it.
The whole process can be automated with the use of ANT / WLST scripts from Oracle. These scripts provide us with the facility to import
a project jar to sbconsole and again export a group of projects present in the server in jar form that can be used in other servers.
This document will provide an easy way to build and deploy the OSB projects.
And also deployment of configuration JAR is performed by WLST. Basically there is three individual operations(creating jar, importing jar,
exporting jar) are executing in the script. To make three individual operations work in sequence automatically mavenisation can be
done.
Steps for setting Ant_Home:
•Download the ant file with .zip extension from “http://ant.apache.org/” and rename the folder to “ant”.
•Set environmental variables JAVA_HOME to your Java environment, ANT_HOME to the directory you uncompressed Ant to, and add %ANT_HOME%/bin
to your PATH.
•Once it is set, run the “ant” command in command promt. It will give
Buildfile: build.xml does not exist!
Build failed
Steps for creating the build.properties, build.xml file:
1.
Create a folder in sworkspace. Now first create file with the name build.properties and place the
code
fmw.home=
# /Oracle/Middleware
eclipse.home=${fmw.home}/oepe_11gR1PS3
weblogic.home=${fmw.home}/wlserver_10.3
osb.home=${fmw.home}/Oracle_OSB1
wls.username = weblogic uersname
wls.password = weblogic password
wls.server = localhost:port
Internal Use 3
Oracle Service Bus Configuration
# properties for workspace export
config.project="Configuration Name"
# location for creating the jar with a file name
config.jar= /sbconfig.jar
config.subprojects="Sub Projects to be added"
config.includeDependencies=true
#Directory location
workspace.dir=
# export properties
export.project = None
# location for exporting the jar with file name
export.jar = /sbconfigExport.jar
export.customFile = None
# import properties
import.project = None
import.jar = /sbconfig.jar
#location for imorting the jar with file name,same as create
#file name.
import.customFile = /cust.xnl
# customisation file location(optional)
2. Now create a file with the name build.xml and place the following code.
classpathref="library.osb"
arguments="${wls.username} ${wls.password} ${wls.server} ${export.project}
${export.jar} ${export.customFile}">
arguments="${wls.username} ${wls.password} ${wls.server} ${import.project} ${import.jar} ${import.customFile}">
location(mentioned in
the build.properties file)
-->
jar="${eclipse.home}/plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar"
fork="true" failonerror="true" maxmemory="768m">
3. Now create a file with the name import.py and place the following code .
from java.util import HashMap
from java.util import HashSet
from java.util import ArrayList
from java.io import FileInputStream
from com.bea.wli.sb.util import Refs
from com.bea.wli.config.customization import Customization
from com.bea.wli.sb.management.importexport import ALSBImportOperation
import sys
# Entry function to deploy project configuration and resources
# into a ALSB domain
def importToALSBDomain():
try:
SessionMBean = None
print 'Attempting to import :', importJar, "on ALSB Admin Server listening on :", adminUrl
theBytes = readBinaryFile(importJar)
print 'Read file', importJar
sessionName = createSessionName()
print 'Created session', sessionName
SessionMBean = getSessionManagementMBean(sessionName)
print 'SessionMBean started session'
ALSBConfigurationMBean = findService(String("ALSBConfiguration.").concat(sessionName),
"com.bea.wli.sb.management.configuration.ALSBConfigurationMBean")
print "ALSBConfiguration MBean found", ALSBConfigurationMBean
ALSBConfigurationMBean.uploadJarFile(theBytes)
print 'Jar Uploaded'
if project == "None":
Internal Use 6
Oracle Service Bus Configuration
print 'No project specified, additive deployment performed'
alsbJarInfo = ALSBConfigurationMBean.getImportJarInfo()
alsbImportPlan = alsbJarInfo.getDefaultImportPlan()
alsbImportPlan.setPassphrase(passphrase)
alsbImportPlan.setPreserveExistingEnvValues(true)
importResult = ALSBConfigurationMBean.importUploaded(alsbImportPlan)
SessionMBean.activateSession(sessionName, "Complete test import with customization using wlst")
else:
print 'ALSB project', project, 'will get overlaid'
alsbJarInfo = ALSBConfigurationMBean.getImportJarInfo()
alsbImportPlan = alsbJarInfo.getDefaultImportPlan()
alsbImportPlan.setPassphrase(passphrase)
operationMap=HashMap()
operationMap = alsbImportPlan.getOperations()
print
print 'Default importPlan'
printOpMap(operationMap)
set = operationMap.entrySet()
alsbImportPlan.setPreserveExistingEnvValues(true)
#boolean
abort = false
#list of created ref
createdRef = ArrayList()
for entry in set:
ref = entry.getKey()
op = entry.getValue()
#set different logic based on the resource type
type = ref.getTypeId
if type == Refs.SERVICE_ACCOUNT_TYPE or type == Refs.SERVICE_PROVIDER_TYPE:
if op.getOperation() == ALSBImportOperation.Operation.Create:
print 'Unable to import a service account or a service provider on a target system', ref
abort = true
elif op.getOperation() == ALSBImportOperation.Operation.Create:
#keep the list of created resources
createdRef.add(ref)
if abort == true :
print 'This jar must be imported manually to resolve the service account and service provider dependencies'
SessionMBean.discardSession(sessionName)
raise
print
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
print 'Customization applied to the created resources only', createdRef
iStream = FileInputStream(customFile)
customizationList = Customization.fromXML(iStream)
filteredCustomizationList = ArrayList()
setRef = HashSet(createdRef)
# apply a filter to all the customizations to narrow the target to the created resources
for customization in customizationList:
print customization
newcustomization = customization.clone(setRef)
filteredCustomizationList.add(newcustomization)
ALSBConfigurationMBean.customize(filteredCustomizationList)
SessionMBean.activateSession(sessionName, "Complete test import with customization using wlst")
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
# Utility function to read a binary file
def readBinaryFile(fileName):
file = open(fileName, 'rb')
bytes = file.read()
return bytes
# Utility function to create an arbitrary session name
def createSessionName():
sessionName = String("SessionScript"+Long(System.currentTimeMillis()).toString())
return sessionName
# Utility function to load a session MBeans
def getSessionManagementMBean(sessionName):
SessionMBean = findService("SessionManagement", "com.bea.wli.sb.management.configuration.SessionManagementMBean")
SessionMBean.createSession(sessionName)
return SessionMBean
# IMPORT script init
try:
# import the service bus configuration
# argv[1] is the export config properties file
importToALSBDomain()
except:
print "Unexpected error: ", sys.exc_info()[0]
dumpStack()
raise
4. Now create a file with the name export.py and place the following code .
from java.io import FileInputStream
from java.io import FileOutputStream
from java.util import ArrayList
from java.util import Collections
from com.bea.wli.sb.util import EnvValueTypes
from com.bea.wli.config.env import EnvValueQuery;
from com.bea.wli.config import Ref
from com.bea.wli.config.customization import Customization
from com.bea.wli.config.customization import FindAndReplaceCustomization
import sys
#=======================================================================================
# Utility function to load properties from a config file
#=======================================================================================
def exportAll():
try:
ALSBConfigurationMBean = findService("ALSBConfiguration", "com.bea.wli.sb.management.configuration.ALSBConfigurationMBean")
print "ALSBConfiguration MBean found"
print project
if project == "None" :
ref = Ref.DOMAIN
collection = Collections.singleton(ref)
if passphrase == None :
print "Export the config"
theBytes = ALSBConfigurationMBean.export(collection, true, None)
else :
print "Export and encrypt the config"
theBytes = ALSBConfigurationMBean.export(collection, true, passphrase)
else :
ref = Ref.makeProjectRef(project);
print "Export the project", project
collection = Collections.singleton(ref)
theBytes = ALSBConfigurationMBean.exportProjects(collection, passphrase)
aFile = File(exportJar)
out = FileOutputStream(aFile)
out.write(theBytes)
out.close()
print "ALSB Configuration file: "+ exportJar + " has been exported"
if customFile != "None":
print collection
query = EnvValueQuery(None, Collections.singleton(EnvValueTypes.WORK_MANAGER), collection, false, None, false)
customEnv = FindAndReplaceCustomization('Set the right Work Manager', query, 'Production System Work Manager')
print 'EnvValueCustomization created'
customList = ArrayList()
customList.add(customEnv)
print customList
aFile = File(customFile)
out = FileOutputStream(aFile)
Customization.toXML(customList, out)
out.close()
print "ALSB Dummy Customization file: "+ customFile + " has been created"
except:
raise
# EXPORT script init
try:
exportAll()
except:
print "Unexpected error: ", sys.exc_info()[0]
dumpStack()
raise
Running command through Ant Script:
•Open command promt, and copy the location where the Build.xml file is present.
•First run the command “ant export”,to export the jar in specified location.
•Then run the command “ant importToWLServer”,to deploy the jar into weblogic server.
•Next run the command “ant exportFromWLServer”,(optional ) to again create a jar depending on whatever your sbconsole is having. And this jar can be used to deploy it into different server.
Issues can be faced:
•In the time of running the ant command, errors may arise like java:13
Solution:
Maximum probabality is the jar problem, The launcher jar org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar is not
present in {eclipse.home}/plugins/ location.
You can search the jar from your middleware home.place the jar with source code
• At the time of importing the jar you may get error like - Import Error,No Module name config.(import.py line 7)
Solution:
check the below jars are present with proper version, Basically there is a jar dependency in the time of middleware
installation.
com.bea.common.configfwk_1.5.0.0.jar {osb.home}/modules
com.bea.core.xml.xmlbeans_2.1.0.0_2-5-1.jar {osb.home}/modules
sb-kernel-api.jar {osb.home}/lib
Mavenising the AntBuild Script:
We can mavenise the build script using pom.xml. So using this we can atomize the whole script .For that it needs to add a pom.xml file, and also modify build.xml file a bit. For that first create a pom.xml file and place this code
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
Choose your grop ID
Choose your Artifact Id
Choose your project name
http://maven.apache.org
1.0.0-SNAPSHOT
maven-antrun-plugin
export
validate
run
itws
compile
run
efws
compile
run
org.apache.ant
ant-nodeps
1.8.1
Changes to be done in build.xml
Add this properties in your build.xml file
/cust.xml" />
After Mavenising this, delete the build.properties file from the folder. In build.xml file just place the build.
properties file contents.
And Now Run the command “mvn compile” then every ant step will be automatized.
References:
• The Definitive Guide to SOA: Oracle Service Bus
• http://docs.oracle.com/cd/E13159_01/osb/docs10gr3/eclipsehelp/tasks.html
• http://docs.oracle.com/cd/E17904_01/doc.1111/e15032/upgrade.htm