Thursday, 9 October 2014

Build,Deploy,Undeploy OSB Projects Using Wlst + Maven in Weblogic 11g

In this article we will be looking how to build,deploy OSB projects created using OEPE IDE Editor and how to look for the released version information in OSB console.

Key Points

With the 12.1.3 release of Oracle Service Bus and Oracle SOA Suite we can actually build all our soa projects with Maven without calling a utility like configjar or ANT from Maven .But since we are using Oracle SOA 11.1.7 Release we need to depend on configjar utility.

Step 1:

Create a hello world OSB project in eclipse OEPE but don't deploy the application in server.

Step 2:

After creating the project your folder structure should look something like below.



Step 3:

Start the weblogic server if not started and make sure current application is not deployed.

Step 4:

Add Maven capability to the project OSB project.

Copy below files in the project folder

import.properties
import.py
pom.xml
settings.xml
undeploy.py


Step 5:

Open a DOS prompt and set the classpath as below. In future we can probably have this classpath in parent pom files.

set classpath=C:/Oracle/Middleware/Oracle_OSB/lib/sb-kernel-api.jar;C:/Oracle/Middleware/Oracle_OSB/lib/sb-kernel-impl.jar;C:/Oracle/Middleware/Oracle_OSB/modules/com.bea.common.configfwk_1.7.0.0.jar;C:/Oracle/Middleware/wlserver_10.3/server/lib/weblogic.jar;%classpath%

Step 6:

Run the pom file using below script and it should build and deploy the generated jar file in local osb domain.

mvn clean install -Dweblogic.home=C:\Oracle\Middleware\wlserver_10.3 -Dosb.home=C:\OracleMiddleware\Oracle_OSB

Step 7:

Make sure you test the deployed OSB project using SOAPUI or by UI Admin Console and the release version is available in the OSB project console.

UNDEPLOY OSB PROJECTS

Step 1:

To undeploy existing OSB project follow below steps.

=> Make sure the project you want to delete is already deployed in server and the project name is mentioned in import.properties.

=> Run below command

C:\oracle_fusion\Middleware\oracle_common\common\bin\wlst undeploy.py import.properties

References
http://biemond.blogspot.co.uk/2013/04/offline-oracle-service-bus.html
http://docs.oracle.com/cd/E28280_01/dev.1111/e15866/app_export.htm
http://www.ateam-oracle.com/getting-started-with-continuous-integration-for-osb/
http://www.ateam-oracle.com/building-osb-projects-with-maven-and-removing-the-eclipse-dependency/
http://www.youtube.com/watch?v=NxD9mETS9Zo
http://biemond.blogspot.co.uk/2014/06/maven-support-for-1213-service-bus-soa.html
http://biemond.blogspot.co.uk/2012/10/build-and-deploy-osb-projects-with-maven.html
https://code.google.com/p/maven-replacer-plugin/issues/detail?id=81
http://www.capgemini.com/blog/capgemini-oracle-blog/2011/08/version-information-in-the-osb-servicebus-console
http://stackoverflow.com/questions/6307191/maven-replace-a-file-in-a-jar
http://stackoverflow.com/questions/3264064/unpack-zip-in-zip-with-maven
https://community.oracle.com/thread/2240514?tstart=0
http://blog.darwin-it.nl/2014/03/osb-remove-artefacts-with-wlst.html
Import.properties
##################################################################
# OSB Admin Security Configuration                              #
##################################################################
adminUrl=t3://localhost:7001
importUser=weblogic
importPassword=weblogic123
 
##################################################################
# OSB Jar to be exported, optional customization file           #
##################################################################
#importJar=sbconfig.jar
importJar=target/$ARTIFACTID$-$VERSION$.jar
#importJar=$TARGETDIR$/$ARTIFACTID$-$VERSION$.jar
#customizationFile=OSBCustomizationFile.xml
 
##################################################################
# Optional passphrase and project name                           #
##################################################################
#passphrase=osb
project=dummy
Import.PY
# Copyright 2012 Oracle Corporation. 
# All Rights Reserved. 
# 
# Provided on an 'as is' basis, without warranties or conditions of any kind, 
# either express or implied, including, without limitation, any warranties or 
# conditions of title, non-infringement, merchantability, or fitness for a 
# particular purpose. You are solely responsible for determining the 
# appropriateness of using and assume any risks. You may not redistribute. 
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(importConfigFile):
    try:
        SessionMBean = None
        print 'Loading Deployment config from :', importConfigFile
        exportConfigProp = loadProps(importConfigFile)
        adminUrl = exportConfigProp.get("adminUrl")
        importUser = exportConfigProp.get("importUser")
        importPassword = exportConfigProp.get("importPassword")
 
        importJar = exportConfigProp.get("importJar")
        customFile = exportConfigProp.get("customizationFile")
 
        passphrase = exportConfigProp.get("passphrase")
        project = exportConfigProp.get("project")
 
        connectToServer(importUser, importPassword, adminUrl)
 
        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:
            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 load properties from a config file
#=======================================================================================
 
def loadProps(configPropFile):
    propInputStream = FileInputStream(configPropFile)
    configProps = Properties()
    configProps.load(propInputStream)
    return configProps
 
#=======================================================================================
# Connect to the Admin Server
#=======================================================================================
 
def connectToServer(username, password, url):
    connect(username, password, url)
    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("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(sys.argv[1])
 
except:
    print "Unexpected error: ", sys.exc_info()[0]
    dumpStack()
    raise
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.temp.osb</groupId>
  <artifactId>temp</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <dependencies/>
  
   <properties>
    <osbHome>C:/oracle_fusion/Middleware/Oracle_OSB</osbHome>
 <targetHome>${basedir}\target</targetHome>
 <buildDirectory>${basedir}</buildDirectory>
 <dir.tmp>${basedir}\tmp</dir.tmp>
 <configurationJAR>${basedir}\target\${artifactId}-${version}.jar</configurationJAR>
  </properties>
 
   <build>
    <plugins>
    
   <plugin>
        <groupId>com.google.code.maven-replacer-plugin</groupId>
        <artifactId>replacer</artifactId>
        <version>1.5.2</version>
        <executions>
           <execution>
      <id>execution1</id>
              <phase>prepare-package</phase>
                <goals>
                   <goal>replace</goal>
                </goals>                    
         <configuration>
            <ignoreMissingFile>true</ignoreMissingFile>
            <file>${basedir}/settings.xml</file>
            <outputFile>${targetHome}/settings.xml</outputFile>
            <regex>false</regex>
            <replacements>
               <replacement>
                  <token>$WORKSPACE_HOME$</token>
                  <value>${osbProjectBase}</value>
               </replacement>
               <replacement>
                  <token>$OSBINCLUDESYSTEM$</token>
                  <value>${osbIncludeSystem}</value>
               </replacement>
               <replacement>
                  <token>$BUILDDIR$</token>
                  <value>${buildDirectory}</value>
               </replacement>
               <replacement>
                  <token>$ARTIFACTID$</token>
                  <value>${artifactId}</value>
               </replacement>
               <replacement>
                  <token>$VERSION$</token>
                  <value>${version}</value>
               </replacement>               
                <replacement>
                 <token>$TARGETDIR$</token>
                  <value>${targetHome}</value>
               </replacement>

            </replacements>    
         </configuration>
    </execution>
       
    <execution>
      <id>execution2</id>
              <phase>prepare-package</phase>
                <goals>
                   <goal>replace</goal>
                </goals>                    
         <configuration>
            <ignoreMissingFile>true</ignoreMissingFile>
            <file>${basedir}/import.properties</file>
            <outputFile>${targetHome}/import.properties</outputFile>
            <regex>false</regex>
            <replacements>
               <replacement>
                  <token>$WORKSPACE_HOME$</token>
                  <value>${osbProjectBase}</value>
               </replacement>
               <replacement>
                  <token>$OSBINCLUDESYSTEM$</token>
                  <value>${osbIncludeSystem}</value>
               </replacement>
               <replacement>
                  <token>$BUILDDIR$</token>
                  <value>${buildDirectory}</value>
               </replacement>
               <replacement>
                  <token>$ARTIFACTID$</token>
                  <value>${artifactId}</value>
               </replacement>
               <replacement>
                  <token>$VERSION$</token>
                  <value>${version}</value>
               </replacement>               
                <replacement>
                 <token>$TARGETDIR$</token>
                  <value>${targetHome}</value>
              </replacement>
            </replacements>    
         </configuration>
    </execution>
   

   <!--
       <execution>
      <id>execution3</id>
              <phase>prepare-package</phase>
                <goals>
                   <goal>replace</goal>
                </goals>                    
         <configuration>
            <ignoreMissingFile>true</ignoreMissingFile>
            <file>${basedir}/config/pom.properties</file>
            <outputFile>${targetHome}/config/pom.properties</outputFile>
            <regex>false</regex>
            <replacements>
               <replacement>
                  <token>$WORKSPACE_HOME$</token>
                  <value>${osbProjectBase}</value>
               </replacement>
               <replacement>
                  <token>$OSBINCLUDESYSTEM$</token>
                  <value>${osbIncludeSystem}</value>
               </replacement>
               <replacement>
                  <token>$BUILDDIR$</token>
                  <value>${buildDirectory}</value>
               </replacement>
               <replacement>
                  <token>$ARTIFACTID$</token>
                  <value>${artifactId}</value>
               </replacement>
               <replacement>
                  <token>$VERSION$</token>
                  <value>${version}</value>
               </replacement>               
                <replacement>
                 <token>$TARGETDIR$</token>
                  <value>${targetHome}</value>
              </replacement>
      <replacement>
                 <token>$GROUPID$</token>
                  <value>${groupId}</value>
              </replacement>
            </replacements>    
         </configuration>
    </execution>
   -->
     </executions>
      </plugin>
   
   <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <executions>
          <execution>
            <id>deafult-cli</id>
            <phase>package</phase>
            <configuration>
              <target>
                <echo>
WARNING
-------
You must set the weblogic.home and osb.home environment variables
when you invoke Maven, e.g.:
mvn compile -Dweblogic.home=/osb11.1.1.7/wlserver_10.3
-Dosb.home=/osb11.1.1.7/Oracle_OSB1
                </echo>
                <taskdef name="configjar"
                  classname="com.bea.alsb.tools.configjar.ant.ConfigJarTask"
                  classpathref="maven.plugin.classpath"/>
                <configjar settingsFile="${targetHome}/settings.xml"
                  debug="true">
                </configjar>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
    
    
     <execution>
        <id>repack</id>
        <phase>package</phase>
        <goals>
          <goal>run</goal>
        </goals>
        <configuration>
         <target name="insertPOMVersion">
    <echo message=">>> updating ${configurationJAR}   ${dir.tmp}" />
    <delete dir="${dir.tmp}" />
    <mkdir dir="${dir.tmp}" />
    <unzip src="${configurationJAR}" dest="${dir.tmp}" />
    <replace file="${dir.tmp}/${artifactId}/_projectdata.LocationData">
        <replacefilter token="proj:description/"
            value="proj:description>${version}&lt;/proj:description" />
    </replace>
    <delete file="${configurationJAR}" />
    <zip destfile="${configurationJAR}">
        <fileset dir="${dir.tmp}">
            <include name="**" />
        </fileset>
  </zip>
 <delete dir="${dir.tmp}" /> 
 </target>
        </configuration>
      </execution>
    
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant</artifactId>
            <version>1.7.1</version>
          </dependency>
          <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant-launcher</artifactId>
            <version>1.7.1</version>
          </dependency>
          <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant-nodeps</artifactId>
            <version>1.7.1</version>
          </dependency>
          <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant-apache-bsf</artifactId>
            <version>1.7.1</version>
          </dependency>
    
    <dependency>
            <groupId>com.bea.wli</groupId>
            <artifactId>sb-kernel-impl</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/lib/sb-kernel-impl.jar</systemPath>
          </dependency>
    
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>configjar</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/tools/configjar/configjar.jar</systemPath>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>weblogic.server.modules_10.3.6.0</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/../modules/features/weblogic.server.modules_10.3.6.0.jar</systemPath>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>weblogic</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/../wlserver_10.3/server/lib/weblogic.jar</systemPath>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>oracle.http_client_11.1.1</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/../oracle_common/modules/oracle.http_client_11.1.1.jar</systemPath>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>xmlparserv2</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/../oracle_common/modules/oracle.xdk_11.1.0/xmlparserv2.jar</systemPath>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>orawsdl</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/../oracle_common/modules/oracle.webservices_11.1.1/orawsdl.jar</systemPath>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>wsm-dependencies</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/../oracle_common/modules/oracle.wsm.common_11.1.1/wsm-dependencies.jar</systemPath>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>osb.server.modules_11.1.1.7</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/modules/features/osb.server.modules_11.1.1.7.jar</systemPath>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>oracle.soa.common.adapters</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/soa/modules/oracle.soa.common.adapters_11.1.1/oracle.soa.common.adapters.jar</systemPath>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>log4j_1.2.8</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/lib/external/log4j_1.2.8.jar</systemPath>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>alsb</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/lib/alsb.jar</systemPath>
          </dependency>
        </dependencies>
      </plugin>
   
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>deploy</id>
            <phase>pre-integration-test</phase>
            <configuration>
              <executable>java</executable>
       <commandlineArgs>    
    weblogic.WLST  ${basedir}/import.py ${targetHome}/import.properties
   </commandlineArgs>
            </configuration>
            <goals>
              <goal>exec</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
  
    </plugins>
  </build>
</project>
Settings.xml
<?xml version="1.0" encoding="UTF-8" ?>
<p:configjarSettings xmlns:p="http://www.bea.com/alsb/tools/configjar/config">
  <p:source>
    <p:project dir="$BUILDDIR$"/>
     <p:fileset>
      <p:exclude name="*/.settings/**" />
   <p:exclude name="*/target/**" />
      <p:exclude name="*/alsbdebug.xml" />
      <p:exclude name="*/configfwkdebug.xml" />
      <p:exclude name="*/pom.xml" />
      <p:exclude name="*/settings.xml" />
    </p:fileset>
 
  </p:source>
  <p:configjar jar="$TARGETDIR$/$ARTIFACTID$-$VERSION$.jar">
    <p:projectLevel includeSystem="false">
      <p:project>$ARTIFACTID$</p:project>
    </p:projectLevel>
  </p:configjar>

 </p:configjarSettings>
Undeploy.py
import wlstModule
 
from java.util import Collections
from com.bea.wli.sb.util import Refs
from com.bea.wli.config import Ref
from java.io import FileInputStream
from com.bea.wli.sb.management.configuration import SessionManagementMBean
from com.bea.wli.sb.management.configuration import ALSBConfigurationMBean
#from com.bea.wli.config.component import AlreadyExistsException
 
import sys
 
 
#=======================================================================================
# Entry function to delete a  project from the alsbConfiguration 
#=======================================================================================
def deleteProject(alsbConfigurationMBean,projectName):
     try:
          print "Trying to deleteProject:remove " + projectName
          projectRef = Ref(Ref.PROJECT_REF, Ref.DOMAIN, projectName)      
          if alsbConfigurationMBean.exists(projectRef):
               print "#### removing OSB project: " + projectName
               alsbConfigurationMBean.delete(Collections.singleton(projectRef))
               print "#### removed project: " + projectName
          else:
               failed = "OSB project <" + projectName + "> does not exist"
               print failed
          print
     except:
          print "Error whilst removing project:", sys.exc_info()[0]
          raise
          
#=======================================================================================
# Entry function to undeploy a project from an OSB Configuration
#=======================================================================================
def undeployProjectFromOSBDomain(importConfigFile):
     try:
          print "Trying to remove "
          print 'Loading Deployment config from :', importConfigFile
          exportConfigProp = loadProps(importConfigFile)
          adminUrl = exportConfigProp.get("adminUrl")
          importUser = exportConfigProp.get("importUser")
          importPassword = exportConfigProp.get("importPassword")
 
          projectName = exportConfigProp.get("project")
        
          connectToServer(importUser, importPassword, adminUrl)
          sessionName = createSessionName()        
          print "Trying to remove " + projectName
          sessionManagementMBean = findService(SessionManagementMBean.NAME,SessionManagementMBean.TYPE)                                     
          print "SessionMBean started session"
          sessionManagementMBean.createSession(sessionName)
          print 'Created session <', sessionName, '>'
          alsbConfigurationMBean = findService("ALSBConfiguration." + sessionName.toString(),"com.bea.wli.sb.management.configuration.ALSBConfigurationMBean")
          print 'Created ALSB Bean'
          deleteProject(alsbConfigurationMBean,projectName)   
          sessionManagementMBean.activateSession(sessionName, "Complete project removal with customization using wlst")
     except:
          print "Error whilst removing project:", sys.exc_info()[0]
          discardSession(sessionManagementMBean, sessionName)
          raise
          
#=======================================================================================
# Connect to the Admin Server
#=======================================================================================
 
def connectToServer(username, password, url):
    connect(username, password, url)
    domainRuntime()

def discardSession(SessionMBean, sessionName):
     if SessionMBean != None:
          if SessionMBean.sessionExists(sessionName): 
               SessionMBean.discardSession(sessionName)
               print "Session discarded"
#=======================================================================================
# Utility function to create an arbitrary session name
#=======================================================================================
def createSessionName():
    sessionName = String("SessionScript"+Long(System.currentTimeMillis()).toString())
    return sessionName

#=======================================================================================
# Utility function to load properties from a config file
#=======================================================================================
 
def loadProps(configPropFile):
    propInputStream = FileInputStream(configPropFile)
    configProps = Properties()
    configProps.load(propInputStream)
    return configProps
    
def main():
  undeployProjectFromOSBDomain(sys.argv[1])
# Call the main function
main()

No comments: