{"id":2116,"date":"2011-08-25T15:24:24","date_gmt":"2011-08-25T05:24:24","guid":{"rendered":"http:\/\/redstack.dev\/?p=2116"},"modified":"2013-04-16T09:13:01","modified_gmt":"2013-04-15T23:13:01","slug":"getting-started-with-continuous-integration-for-osb","status":"publish","type":"post","link":"https:\/\/redstack.dev\/2011\/08\/25\/getting-started-with-continuous-integration-for-osb\/","title":{"rendered":"Getting started with Continuous Integration for OSB"},"content":{"rendered":"<p>As a first step towards including Oracle Service Bus projects into our Continuous Integration environment, let&#8217;s look at how to script exporting some project(s) from Oracle Enterprise Pack for Eclipse (the IDE for OSB) and deploying those project(s) to an OSB server.\u00a0 Later, we will include this into the Maven\/Hudson environment we have been constructing in <a title=\"Continuous\u00a0Integration\" href=\"http:\/\/redstack.dev\/continuous-integration\/\">this series of posts<\/a> on continuous integration.<\/p>\n<p>Here is our script, right up front, then we will discuss it:<\/p>\n<p>[source language=&#8221;text&#8221;]<br \/>\n@echo Export project from eclipse<br \/>\njava ^<br \/>\n  -Dweblogic.home=c:\\oracle\\middleware\\wlserver_10.3 ^<br \/>\n  -Dosb.home=c:\\oracle\\middleware\\Oracle_OSB1 ^<br \/>\n  -Dosgi.bundlefile.limit=500 ^<br \/>\n  -Dharvester.home=c:\\oracle\\middleware\\Oracle_OSB1\\harvester ^<br \/>\n  -Dosgi.nl=en_US ^<br \/>\n  -Dsun.lang.ClassLoader.allowArraySyntax=true ^<br \/>\n  -jar c:\\Oracle\\OEPE\\oepe_11gR1PS4\\plugins\\org.eclipse.equinox.launcher_1.1.1.R36x_v20101122_1400.jar ^<br \/>\n  -data c:\\src\\osb\\notsvn ^<br \/>\n  -application com.bea.alsb.core.ConfigExport ^<br \/>\n  -configProject &quot;OSB Configuration 1&quot; ^<br \/>\n  -configJar c:\\src\\osb\\test_sbconfig.jar ^<br \/>\n  -configSubProjects &quot;OSB Project 1&quot; ^<br \/>\n  -includeDependencies true<\/p>\n<p>@echo Deploy &#8216;import&#8217; to Service Bus<br \/>\nc:\\oracle\\middleware\\oracle_common\\common\\bin\\wlst import.py import.properties<br \/>\n[\/source]<\/p>\n<p>First of all, if you have not seen them before, the &#8216;^&#8217; is a continuation character in Windows CMD files, such as this one, so that we can spread a command over many lines in our script, but it is executed as if it were all typed in on a single line.<\/p>\n<p>This script has not been made generic yet &#8211; it has a bunch of stuff hardcoded.\u00a0 Let&#8217;s take a look.<\/p>\n<p>First, we run <strong>java<\/strong> with a bunch of properties.\u00a0 You will need to set <strong>weblogic.home<\/strong>, <strong>osb.home<\/strong> and <strong>harvester.home<\/strong> to suit your environment.\u00a0 You can just include the others as they are.<\/p>\n<p>Following the properties, you see we point to a JAR file, this allows us to run eclipse in headless mode.\u00a0 The remainder of the parameters are passed to eclipse.\u00a0 You can see we need to specify the location of the workspace to use (in <strong>data<\/strong>) &#8211; this can also be the Subversion trunk (or similar).\u00a0 The <strong>application<\/strong> tells it to run the OSB exporter.<\/p>\n<p>The other important parameters are <strong>configProject<\/strong> which names the OSB Configuration project in the workspace you want to use, <strong>configSubProjects<\/strong> which is a comma separated list of the OSB projects you want to export, and <strong>configJar<\/strong> which is the name of the JAR file you want to create.<\/p>\n<p>If you want to know more about this command, take a look in the online help in your OSB IDE.\u00a0 Look under the OSB help topic, then &#8216;Tasks,&#8217; &#8216;Working with projects, folders, resources &amp; configurations,&#8217; &#8216;exporting resources,&#8217; &#8216;using command line,&#8217; and then the ANT topic.<\/p>\n<p>When this command has run, we will have an OSB configuration JAR file (<strong>test_sbconfig.jar<\/strong> in this case) which is ready to import into (deploy to) an OSB server.<\/p>\n<p>The second part is to perform the deployment (import).\u00a0 We will do this using a WLST script from Oracle, <strong>import.py<\/strong> (see below).\u00a0 This script also expects a properties file.\u00a0 We need to set up some details in the properties file so the script knows what to do.<\/p>\n<p>Let&#8217;s take a look at the properties file:<\/p>\n<p>[source language=&#8221;text&#8221;]<br \/>\n##################################################################<br \/>\n# OSB Admin Security Configuration                              #<br \/>\n##################################################################<br \/>\nadminUrl=t3:\/\/localhost:7001<br \/>\nimportUser=weblogic<br \/>\nimportPassword=welcome1<\/p>\n<p>##################################################################<br \/>\n# OSB Jar to be exported, optional customization file           #<br \/>\n##################################################################<br \/>\nimportJar=test_sbconfig.jar<br \/>\n#customizationFile=OSBCustomizationFile.xml<\/p>\n<p>##################################################################<br \/>\n# Optional passphrase and project name                           #<br \/>\n##################################################################<br \/>\n#passphrase=osb<br \/>\n#project=default<br \/>\n[\/source]<\/p>\n<p>You can see we have provided the URL for the Administration Server, and also the name of the OSB configuration JAR file (that we just created in the previous step).<\/p>\n<p>Here is the <strong>import.py<\/strong> sciript that WLST will run:<\/p>\n<p>[source language=&#8221;text&#8221;]<br \/>\nfrom java.util import HashMap<br \/>\nfrom java.util import HashSet<br \/>\nfrom java.util import ArrayList<br \/>\nfrom java.io import FileInputStream<\/p>\n<p>from com.bea.wli.sb.util import Refs<br \/>\nfrom com.bea.wli.config.customization import Customization<br \/>\nfrom com.bea.wli.sb.management.importexport import ALSBImportOperation<\/p>\n<p>import sys<\/p>\n<p>#=======================================================================================<br \/>\n# Entry function to deploy project configuration and resources<br \/>\n#        into a ALSB domain<br \/>\n#=======================================================================================<\/p>\n<p>def importToALSBDomain(importConfigFile):<br \/>\n    try:<br \/>\n        SessionMBean = None<br \/>\n        print &#8216;Loading Deployment config from :&#8217;, importConfigFile<br \/>\n        exportConfigProp = loadProps(importConfigFile)<br \/>\n        adminUrl = exportConfigProp.get(&quot;adminUrl&quot;)<br \/>\n        importUser = exportConfigProp.get(&quot;importUser&quot;)<br \/>\n        importPassword = exportConfigProp.get(&quot;importPassword&quot;)<\/p>\n<p>        importJar = exportConfigProp.get(&quot;importJar&quot;)<br \/>\n        customFile = exportConfigProp.get(&quot;customizationFile&quot;)<\/p>\n<p>        passphrase = exportConfigProp.get(&quot;passphrase&quot;)<br \/>\n        project = exportConfigProp.get(&quot;project&quot;)<\/p>\n<p>        connectToServer(importUser, importPassword, adminUrl)<\/p>\n<p>        print &#8216;Attempting to import :&#8217;, importJar, &quot;on ALSB Admin Server listening on :&quot;, adminUrl<\/p>\n<p>        theBytes = readBinaryFile(importJar)<br \/>\n        print &#8216;Read file&#8217;, importJar<br \/>\n        sessionName = createSessionName()<br \/>\n        print &#8216;Created session&#8217;, sessionName<br \/>\n        SessionMBean = getSessionManagementMBean(sessionName)<br \/>\n        print &#8216;SessionMBean started session&#8217;<br \/>\n        ALSBConfigurationMBean = findService(String(&quot;ALSBConfiguration.&quot;).concat(sessionName), &quot;com.bea.wli.sb.management.configuration.ALSBConfigurationMBean&quot;)<br \/>\n        print &quot;ALSBConfiguration MBean found&quot;, ALSBConfigurationMBean<br \/>\n        ALSBConfigurationMBean.uploadJarFile(theBytes)<br \/>\n        print &#8216;Jar Uploaded&#8217;<\/p>\n<p>        if project == None:<br \/>\n            print &#8216;No project specified, additive deployment performed&#8217;<br \/>\n            alsbJarInfo = ALSBConfigurationMBean.getImportJarInfo()<br \/>\n            alsbImportPlan = alsbJarInfo.getDefaultImportPlan()<br \/>\n            alsbImportPlan.setPassphrase(passphrase)<br \/>\n            alsbImportPlan.setPreserveExistingEnvValues(true)<br \/>\n            importResult = ALSBConfigurationMBean.importUploaded(alsbImportPlan)<br \/>\n            SessionMBean.activateSession(sessionName, &quot;Complete test import with customization using wlst&quot;)<br \/>\n        else:<br \/>\n            print &#8216;ALSB project&#8217;, project, &#8216;will get overlaid&#8217;<br \/>\n            alsbJarInfo = ALSBConfigurationMBean.getImportJarInfo()<br \/>\n            alsbImportPlan = alsbJarInfo.getDefaultImportPlan()<br \/>\n            alsbImportPlan.setPassphrase(passphrase)<br \/>\n            operationMap=HashMap()<br \/>\n            operationMap = alsbImportPlan.getOperations()<br \/>\n            print<br \/>\n            print &#8216;Default importPlan&#8217;<br \/>\n            printOpMap(operationMap)<br \/>\n            set = operationMap.entrySet()<\/p>\n<p>            alsbImportPlan.setPreserveExistingEnvValues(true)<\/p>\n<p>            #boolean<br \/>\n            abort = false<br \/>\n            #list of created ref<br \/>\n            createdRef = ArrayList()<\/p>\n<p>            for entry in set:<br \/>\n                ref = entry.getKey()<br \/>\n                op = entry.getValue()<br \/>\n                #set different logic based on the resource type<br \/>\n                type = ref.getTypeId<br \/>\n                if type == Refs.SERVICE_ACCOUNT_TYPE or type == Refs.SERVICE_PROVIDER_TYPE:<br \/>\n                    if op.getOperation() == ALSBImportOperation.Operation.Create:<br \/>\n                        print &#8216;Unable to import a service account or a service provider on a target system&#8217;, ref<br \/>\n                        abort = true<br \/>\n                elif op.getOperation() == ALSBImportOperation.Operation.Create:<br \/>\n                    #keep the list of created resources<br \/>\n                    createdRef.add(ref)<\/p>\n<p>            if abort == true :<br \/>\n                print &#8216;This jar must be imported manually to resolve the service account and service provider dependencies&#8217;<br \/>\n                SessionMBean.discardSession(sessionName)<br \/>\n                raise<\/p>\n<p>            print<br \/>\n            print &#8216;Modified importPlan&#8217;<br \/>\n            printOpMap(operationMap)<br \/>\n            importResult = ALSBConfigurationMBean.importUploaded(alsbImportPlan)<\/p>\n<p>            printDiagMap(importResult.getImportDiagnostics())<\/p>\n<p>            if importResult.getFailed().isEmpty() == false:<br \/>\n                print &#8216;One or more resources could not be imported properly&#8217;<br \/>\n                raise<\/p>\n<p>            #customize if a customization file is specified<br \/>\n            #affects only the created resources<br \/>\n            if customFile != None :<br \/>\n                print &#8216;Loading customization File&#8217;, customFile<br \/>\n                print &#8216;Customization applied to the created resources only&#8217;, createdRef<br \/>\n                iStream = FileInputStream(customFile)<br \/>\n                customizationList = Customization.fromXML(iStream)<br \/>\n                filteredCustomizationList = ArrayList()<br \/>\n                setRef = HashSet(createdRef)<\/p>\n<p>                # apply a filter to all the customizations to narrow the target to the created resources<br \/>\n                for customization in customizationList:<br \/>\n                    print customization<br \/>\n                    newcustomization = customization.clone(setRef)<br \/>\n                    filteredCustomizationList.add(newcustomization)<\/p>\n<p>                ALSBConfigurationMBean.customize(filteredCustomizationList)<\/p>\n<p>            SessionMBean.activateSession(sessionName, &quot;Complete test import with customization using wlst&quot;)<\/p>\n<p>        print &quot;Deployment of : &quot; + importJar + &quot; successful&quot;<br \/>\n    except:<br \/>\n        print &quot;Unexpected error:&quot;, sys.exc_info()[0]<br \/>\n        if SessionMBean != None:<br \/>\n            SessionMBean.discardSession(sessionName)<br \/>\n        raise<\/p>\n<p>#=======================================================================================<br \/>\n# Utility function to print the list of operations<br \/>\n#=======================================================================================<br \/>\ndef printOpMap(map):<br \/>\n    set = map.entrySet()<br \/>\n    for entry in set:<br \/>\n        op = entry.getValue()<br \/>\n        print op.getOperation(),<br \/>\n        ref = entry.getKey()<br \/>\n        print ref<br \/>\n    print<\/p>\n<p>#=======================================================================================<br \/>\n# Utility function to print the diagnostics<br \/>\n#=======================================================================================<br \/>\ndef printDiagMap(map):<br \/>\n    set = map.entrySet()<br \/>\n    for entry in set:<br \/>\n        diag = entry.getValue().toString()<br \/>\n        print diag<br \/>\n    print<\/p>\n<p>#=======================================================================================<br \/>\n# Utility function to load properties from a config file<br \/>\n#=======================================================================================<\/p>\n<p>def loadProps(configPropFile):<br \/>\n    propInputStream = FileInputStream(configPropFile)<br \/>\n    configProps = Properties()<br \/>\n    configProps.load(propInputStream)<br \/>\n    return configProps<\/p>\n<p>#=======================================================================================<br \/>\n# Connect to the Admin Server<br \/>\n#=======================================================================================<\/p>\n<p>def connectToServer(username, password, url):<br \/>\n    connect(username, password, url)<br \/>\n    domainRuntime()<\/p>\n<p>#=======================================================================================<br \/>\n# Utility function to read a binary file<br \/>\n#=======================================================================================<br \/>\ndef readBinaryFile(fileName):<br \/>\n    file = open(fileName, &#8216;rb&#8217;)<br \/>\n    bytes = file.read()<br \/>\n    return bytes<\/p>\n<p>#=======================================================================================<br \/>\n# Utility function to create an arbitrary session name<br \/>\n#=======================================================================================<br \/>\ndef createSessionName():<br \/>\n    sessionName = String(&quot;SessionScript&quot;+Long(System.currentTimeMillis()).toString())<br \/>\n    return sessionName<\/p>\n<p>#=======================================================================================<br \/>\n# Utility function to load a session MBeans<br \/>\n#=======================================================================================<br \/>\ndef getSessionManagementMBean(sessionName):<br \/>\n    SessionMBean = findService(&quot;SessionManagement&quot;, &quot;com.bea.wli.sb.management.configuration.SessionManagementMBean&quot;)<br \/>\n    SessionMBean.createSession(sessionName)<br \/>\n    return SessionMBean<\/p>\n<p># IMPORT script init<br \/>\ntry:<br \/>\n    # import the service bus configuration<br \/>\n    # argv[1] is the export config properties file<br \/>\n    importToALSBDomain(sys.argv[1])<\/p>\n<p>except:<br \/>\n    print &quot;Unexpected error: &quot;, sys.exc_info()[0]<br \/>\n    dumpStack()<br \/>\n    raise<br \/>\n[\/source]<\/p>\n<p>You need to put the original script, <strong>import.py<\/strong> and <strong>import.properties<\/strong> all in to the same directory.\u00a0 Now you can run our original script and it will perform the export from eclipse and the deployment to OSB.<\/p>\n<p>In a future post, we will be parameterizing this and folding it into our Hudson\/Maven oriented continuous integration environment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a first step towards including Oracle Service Bus projects into our Continuous Integration environment, let&#8217;s look at how to script exporting some project(s) from Oracle Enterprise Pack for Eclipse (the IDE for OSB) and deploying those project(s) to an &hellip; <a href=\"https:\/\/redstack.dev\/2011\/08\/25\/getting-started-with-continuous-integration-for-osb\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":4270085,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_crdt_document":"","advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1],"tags":[163615,1377995],"class_list":["post-2116","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-continuous-integration","tag-osb"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pgVeO-y8","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/redstack.dev\/wp-json\/wp\/v2\/posts\/2116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/redstack.dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/redstack.dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/redstack.dev\/wp-json\/wp\/v2\/users\/4270085"}],"replies":[{"embeddable":true,"href":"https:\/\/redstack.dev\/wp-json\/wp\/v2\/comments?post=2116"}],"version-history":[{"count":1,"href":"https:\/\/redstack.dev\/wp-json\/wp\/v2\/posts\/2116\/revisions"}],"predecessor-version":[{"id":2117,"href":"https:\/\/redstack.dev\/wp-json\/wp\/v2\/posts\/2116\/revisions\/2117"}],"wp:attachment":[{"href":"https:\/\/redstack.dev\/wp-json\/wp\/v2\/media?parent=2116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/redstack.dev\/wp-json\/wp\/v2\/categories?post=2116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/redstack.dev\/wp-json\/wp\/v2\/tags?post=2116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}