Creating Deployment Script for OSB Projects

Creating Deployment Script for OSB Projects

NOTE: In this script we do not have any JNDIs, DataSources or any adapters. This is simply to demonstrate how to create scripts which can export the project from sbconsole and also import the same on another environment.. say SIT, Prod etc.

The script will hold below steps:-
1. Creation of configfile.secure and keyfile.secure
2. Export
3. Import
4. Appendix-A: files used for exporting osb artifacts
5. Appendix-B: files used for importing osb artifacts

Now, Let's start..

Creation of configfile.secure and keyfile.secure (One time task)

files to be created:-
1. configfile.secure 2. keyfile.secure

Open the weblogic scripting tool and run the following command to create .secure files

cd /u01/Oracle/Middleware/wlserver_10.3/common/bin
./wlst.sh

Now, it will show you like below:-
















Now, execute below command to connect with weblogic:-

connect('WeblogicUser','WeblogicPassword','hostName:Port')

E.g. connect('weblogic','Oracle123','localhost:7001')
 
Now, you should see below screen:-










Now, execute below command to generate configfile.secure and keyfile.secure files

Syntax:-
storeUserConfig(PathForFileToCreate/configfile.secure','PathForFileToCreate/keyfile.secure')

E.g. storeUserConfig('/u01/app/cluster/DeploymentScripts/build/dev/configfile.secure','/u01/app/cluster/DeploymentScripts/build/dev/keyfile.secure')

Once you execute the above command, it will ask for ‘Y’ or ‘N’






Type y and press enter






Files are created in few seconds. Just wait for command to show the below result








Check the location for the newly created files:-






NOTE:- These files will be used for running the complete deployment script as it will help the script to make a secured connection with weblogic server







EXPORT
 
Exporting OSB Project/Artifacts along with Customization File using scripts:-
Let’s take a look on all the files which we create for exporting the artifacts:-

1.

configfile.secure

These act as weblogic credentials store and help script make a connection with weblogic server. Filepath to these files are set in export.properties file

2.

keyfile.secure

3.

export.sh

All classpaths are set in this shell script and it runs Exportbuild.xml

4.

Exportbuild.xml

Here we set the property which tells which environment (dev, stg, prd etc.) are we going to export the osb artifacts from.

Also, It runs ant.properties file to set properties of Filepath for export.config.file and alsb.export.script

5.

exportAnt.properties

Sets Filepath for export.config.file (i.e. export.properties) and alsb.export.script (i.e. export.py)

6.

export.properties

Sets properties related to weblogic credentials for making connection to weblogic server.

It reads configfile.secure and keyfile.secure file data.

It also sets Filepath for SBConfigJarFile and also for CustomizationFile

7.

export.py

The main script which is responsible for importing the  SBConfigJarFile into sbconsole and also executing CustomizationFile in order to make changes in the osb projects as per the new environment.

Other prerequisites for exporting OSB artifacts from the given environment:-
a) sbconfig.jar (the desired file name to be exported along with the filepath where you want to export)
b) ALSBCustomizationFile.xml(the desired file name to be exported along with the filepath where you want to export)
Once ALSBCustomizationFile.xml is exported, you will have to make needful changes as per the new environment (such as stg, prd etc.) where you want to migrate the osb artifacts to.
These file names and their desired filepaths are to be set in export.properties file as mentioned in the above table.
 
Once you are done with all the above artifacts just change the configuration settings such as your folder locations, sbconfig jar file name and/or location, customization file name and/or location etc.
 
 
IMPORT
 
Now, Let’s take a look on all the files which we create for complete deployment task:-

1.

configfile.secure

These act as weblogic credentials store and help script make a connection with weblogic server

2.

keyfile.secure

3.

import.sh

All classpaths are set in this shell script and it runs build.xml

4.

build.xml

Here we set the property which tells for which environment (dev, stg, prd etc.) are we going to do the deployment.

Also, It runs ant.properties file to set properties of Filepath for import.config.file and alsb.import.script

5.

ant.properties

Sets Filepath for import.config.file and alsb.import.script

6.

import.properties

Sets properties related to weblogic credentials for making connection to weblogic server. It reads configfile.secure and keyfile.secure file data.

It also sets Filepath for SBConfigJarFile and also for CustomizationFile

7.

import.py

The main script which is responsible for importing the  SBConfigJarFile into sbconsole and also executing CustomizationFile in order to make changes in the osb projects as per the new environment.
Other prerequisites for deploying OSB artifacts from one environment to other:-
a) sbconfig.jar (the jar file which is to be imported/deployed/migrated to the given environment)
b) ALSBCustomizationFile.xml (duly customized file as per the given environment where you are importing/deploying/migrating the above jar file)
 
Once you are done with all the above artifacts just change the configuration settings such as your folder locations, sbconfig jar file name and/or location, customization file name and/or location etc.
For further clarification please open and the above files in the sequence and take a look once.
 
 

Appendix-A: files used for exporting osb artifacts
configfile.secure (This file is generated by the commands mentioned above)
#WebLogic User Configuration File; 2
#Wed Jun 08 10:14:40 IST 2016
weblogic.management.username={AES}4Ui/ZJOGAeKQifpazZdJwmZHT/YLXzjJFudWT8fFB0o\=
weblogic.management.password={AES}9FglslCZu9PN4VN0pyvSvoKpqNE3Kg1B+GdtYj8ja5c\=
 
keyfile.secure (This Encrypted file is generated by the commands mentioned above)
##ó¬Q# >B„¬‰÷¼èÀŠì<SýôI÷áìx#Gµ5›žÿd]’Û®#´#­#àéúZŠ#ò,½Ý×Qøs#~"ÿ
 
export.sh
#This path will/may change as per your linux environment. Give path of your OSB Home
export OSB_HOME=/u01/Oracle/Middleware
#Check this path as per your environment as well..
echo "Setting Weblogic server Environment..."
. ${OSB_HOME}/wlserver_10.3/server/bin/setWLSEnv.sh
#These classpaths are set in the beginning only..
export CLASSPATH=${CLASSPATH}:${OSB_HOME}/Oracle_Osb1/lib/sb-kernel-api.jar
export CLASSPATH=${CLASSPATH}:${OSB_HOME}/modules/com.bea.common.configfwk.ja_1.4.0.0.jar
export CLASSPATH=${CLASSPATH}:${OSB_HOME}/Oracle_Osb1/lib/sb-kernel-impl.jar
export CLASSPATH=${CLASSPATH}:${OSB_HOME}/wlserver_10.3/server/lib/weblogic.jar
export CLASSPATH=${CLASSPATH}:${OSB_HOME}/Oracle_OSB1/lib/alsb.jar
export CLASSPATH=${CLASSPATH}:${OSB_HOME}/Oracle_OSB1/modules/com.bea.common.configfwk_1.6.0.0.jar
export BUILD_ENVIRONMENT=dev
#below command will remain as it is. It runs exportbuild.xml using in-built ant script
ant -buildfile Exportbuild.xml import -verbose
 
Exportbuild.xml
<project default="prompt">
<!-- ALSB domain creation project -->
<property environment="env"/>
<property file="exportAnt.properties" />
<taskdef name="wlst" classname="weblogic.ant.taskdefs.management.WLSTTask"/>
<!-- below is the path  -->
<target name="export">
<echo message="exportscript: ${alsb.export.script}"/>
<echo message="exportconfig: ${export.config.file}"/>
<wlst properties="${export.config.file}" fileName="${alsb.export.script}" debug="true">
</wlst>
</target>
</project>
 
exportAnt.properties
export.config.file=export.properties
alsb.export.script=export.py
export.properties
##################################################################
# OSB Admin Security Configuration                                                                       #
##################################################################
# adminUser=weblogic
# adminPassword=Oracle123
# connectMethod=userconfig
# adminServer=AdminServer
adminUrl=t3://localhost:7001
configFile=/u01/app/cluster/DeploymentScripts/build/dev/configfile.secure
keyFile=/u01/app/cluster/DeploymentScripts/build/dev/keyfile.secure
##################################################################
# OSB Jar to be exported                                                                                            #
##################################################################
exportJar=exportedByMahi.jar
##################################################################
# Optional passphrase and project name.                                                                   #
# If you specify a project, the script exports all the                                                   #
# resources contained in the project. If you do not specify a                                    #
# project, the script exports the entire configuration.                                                #
##################################################################
passphrase=
project=MBProject
##################################################################
# Optional, create a dummy customization file                                                         #
##################################################################
customizationFile=myCustomizationFile.xml

 
export.py (This py file should be properly indented else you will end up with error)
import wlstModule
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.sb.management.configuration import ALSBConfigurationMBean
from java.util import HashMap
from java.util import HashSet
from com.bea.wli.sb.management.importexport import ALSBImportPlan
from com.bea.wli.sb.management.importexport import ALSBImportOperation
from com.bea.wli.config.mbeans import ConfigMBean
import sys
#====================================================================
# Utility function to load properties from a config file
#=========================================================================
def exportAll():
            try:
            # Declare Variables
                        sessionMBean = None
                        alsbConfigurationMBean = None
                        print 'Connecting to server: '
                        connect(userConfigFile=configFile, userKeyFile=keyFile, url=adminUrl)
                        domainRuntime()

                        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 :
                                    ALSBConfigurationMBean = findService('ALSBConfiguration', 'com.bea.wli.sb.management.configuration.ALSBConfigurationMBean')
                                    print "ALSBConfiguration MBean found"

                                    print project

                                    configMBean = JMX.newMBeanProxy(mbs, ObjectName.getInstance("com.bea:Name=Config.XBus Kernel,Type=com.bea.wli.config.mbeans.ConfigMBean"), ConfigMBean)
                                    print "ConfigMBean found"

                                    # Get reference to OSB project
                                    ref = Ref.makeProjectRef(project)
                                    print "Exporting JAR for OSB project:", project
                                    collection = Collections.singleton(ref)
                                    print "NOTE: This single JAR can hold multiple projects or resources"

                                    theBytes = ALSBConfigurationMBean.exportProjects(collection, passphrase)
                        aFile = File(exportJar)
                        out = FileOutputStream(aFile)
                        out.write(theBytes)
                        out.close()
                        print "OSB Project SBConfig jar: "+ exportJar + " has been exported"
                                                ## Export OSB customization file
                        print "Exporting customization file for... :", project
                        theBytes = configMBean.createCustomizationFile(collection, EnvValueTypes.ENV_VALUE_TYPES);
                        out = FileOutputStream(customizationFile);
                        out.write(theBytes);
                        out.close();
                        print "Customization file for " + project + " has been exported successfully exported"

            except:
                        raise

# EXPORT script init
try:
            exportAll()
except:
            print "Unexpected error: ", sys.exc_info()[0]
            dumpStack()
            raise
 
 
Appendix-B: files used for importing osb artifacts
configfile.secure
As Above
 
keyfile.secure
As Above

 
import.sh
export OSB_HOME=/u01/Oracle/Middleware
echo "Setting Weblogic server Environment..."
. ${OSB_HOME}/wlserver_10.3/server/bin/setWLSEnv.sh
export CLASSPATH=${CLASSPATH}:${OSB_HOME}/Oracle_Osb1/lib/sb-kernel-api.jar
export CLASSPATH=${CLASSPATH}:${OSB_HOME}/modules/com.bea.common.configfwk.ja_1.4.0.0.jar
export CLASSPATH=${CLASSPATH}:${OSB_HOME}/Oracle_Osb1/lib/sb-kernel-impl.jar
export CLASSPATH=${CLASSPATH}:${OSB_HOME}/wlserver_10.3/server/lib/weblogic.jar
export CLASSPATH=${CLASSPATH}:${OSB_HOME}/Oracle_OSB1/lib/alsb.jar
export CLASSPATH=${CLASSPATH}:${OSB_HOME}/Oracle_OSB1/modules/com.bea.common.configfwk_1.6.0.0.jar
export BUILD_ENVIRONMENT=dev
ant -buildfile ../scripts/build.xml import -verbose
 
 
build.xml
<project default="prompt">
<!-- ALSB domain creation project -->
<property environment="env"/>
<property file="../${env.BUILD_ENVIRONMENT}/ant.properties" />
<taskdef name="wlst" classname="weblogic.ant.taskdefs.management.WLSTTask"/>
<target name="import">
<echo message="importscript: ${alsb.import.script}"/>
<echo message="importconfig: ${import.config.file}"/>
<wlst properties="${import.config.file}" fileName="${alsb.import.script}" debug="true">
</wlst>
</target>
</project>
 
ant.properties
import.config.file=/u01/app/cluster/DeploymentScripts/build/dev/import.properties
alsb.import.script=/u01/app/cluster/DeploymentScripts/build/scripts/import.py
 
import.properties
##################################################################
# ALSB Admin Security Configuration                              #
##################################################################
connectMethod=userconfig
adminUrl=t3://localhost:7001
adminServer=AdminServer

configFile=/u01/app/cluster/DeploymentScripts/build/dev/configfile.secure

# E.g. keyFile=c:/osb/build/dev/keyfile.secure
keyFile=/u01/app/cluster/DeploymentScripts/build/dev/keyfile.secure

##################################################################
# ALSB Jar to be exported, optional customization file                                           #
##################################################################
importJar=/u01/app/cluster/DeploymentScripts/configuration/sbconfig.jar

##################################################################
# E.g. customFile=/u01/app/cluster/DeploymentScripts/build/dev/ALSBCustomizationFile.xml            #
##################################################################
customFile=/u01/app/cluster/DeploymentScripts/build/dev/ALSBCustomizationFile.xml

##################################################################
# Optional passphrase                                                                                                 #
##################################################################
passphrase=
 
import.py
import wlstModule
from com.bea.wli.sb.management.configuration import SessionManagementMBean
from com.bea.wli.sb.management.configuration import ALSBConfigurationMBean
from com.bea.wli.config import Ref
from com.bea.wli.config.customization import Customization
from java.io import FileInputStream
from java.util import HashMap
from java.util import ArrayList
from 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 + " is successfully done"
            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 = file.read()
    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
~~~~~Thank You~~~~~

Featured Post

How to create an AQ (Advanced Queue) on Oracle DB

Keywords: Advanced Queue, AQ, AQ Creation, Queue, Queue Creation, How to create a queue, Queue in SOA, SOA, OSB, BPEL -------------------...