Pages

Monday, February 20, 2012

Configure WebLogic Resource Adapters with ANT

When you use a JCA adapter in Oracle SOA Suite or OSB then you know that you need to configure a plan of some WebLogic Resource Adapter.  With this ANT script I tried to make this an easy task for you and which you can repeat on different WebLogic Domains. This ANT script can easily add multiple EIS entries to the following adapters: DbAdapter, AqAdapter and JmsAdapter in just one run. After these changes to the resource plans this script will redeploy only the changed Resource Adapter.

Special thanks for my colleague Michel Schildmeijer for inspiring me to make this flexible script and off course for the necessary WLST code.

Important to know.

  • Run this script on the AdminServer, else it won't find the Resource Adapter Plans
  • First you need to create a Plan for the 3 Resource Adapters (Db,Aq,Jms) and add a dummy entry, think how you name it and where you put it.
  • When a plan is changed and you have a soa cluster or the soa weblogic instance is running on a different server then you need to copy the plan to all servers or put it on a shared storage.    

If you don't like this then you can always create new Resource Adapters by following this blogpost.

Let's explain how it works

first you need to change some variables in this build.properties

default this scripts runs against the weblogic dev settings.  You can change this to your own and configure the dev entries ( dev entries at the bottom of the build.properties )

wls.environment=dev

Where are the adapter rars located in your FMW domain, this can be in your SOA or OSB Home of the FMW domain.
connectorLocation=C:/oracle/MiddlewarePS3/Oracle_SOA1/soa/connectors/

Then add your own EIS entries, these ones in this var will be added to weblogic.
resourceAdapterEntries=hrDB,hrAQ,cf1JMS,cf2JMS

Think if you need to set the XA or Not XA datasource property or in Jms the connectionFactoryLocation.
# AQ entry
hrAQ.type=aq
hrAQ.eisName=eis/AQ/hr2
hrAQ.property=xADataSourceName
hrAQ.value=jdbc/hrDS

# DB entry
hrDB.type=db
hrDB.eisName=eis/DB/hr2
hrDB.property=dataSourceName
hrDB.value=jdbc/hrDS

# JMS entries
cf1JMS.type=jms
cf1JMS.eisName=eis/JMS/hr3
cf1JMS.property=ConnectionFactoryLocation
cf1JMS.value=jms/MyCF

After you can run the ANT script 
ant -f build.xml createResourceAdapterEntries 

Here you can download the code on github

Here is the whole build.properties file 


The wlst part with the wlRedeployResourceAdapter and wlCreateResourceAdapter macrodefs


And at last the build.xml

38 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Hi,

      I don't think you got this soaps3 connection on your side
      [wlst] Connecting to t3://soaps3:7001 with userid weblogic ...

      thanks

      Delete
    2. This comment has been removed by the author.

      Delete
    3. hi,

      I think you are some ant libs jars or the ant contrib jar. put them in your ant lib or classpath.

      thanks

      Delete
    4. Hi Biemond,

      Could not load definitions from resource org/apach
      e/tools/ant/antlib.xml. It could not be found.
      where can find this lib iam unable to locate it...

      Delete
    5. It is located at the lib folder on github and loaded in the bat file.

      thanks

      Delete
    6. Hi Edwin,
      Iam able to execute the build successfully but the changes are not reflected on weblogic server, dont know where the problem is here pasting the log....

      Delete
    7. Hi,

      you must upgrade ANT and check your classpath and put contrib jar in the ant lib folder.

      thanks

      Delete
    8. This comment has been removed by the author.

      Delete
  3. Hi, Edwin,
    Thanks for share your code in GitHub, save me lots of time.
    1. I did little change for my env. It's not problem in my Linux with using PlanPath, but don't know why it's not working in my Windows. just return Plan.xml without path.
    planPath = get('/AppDeployments/'+appName+'/AbsolutePlanPath')

    2. The destroy exist Variable/assignment function is not working in makeDeploymentPlanVariable, because you introduce idRandom on the name param. Either change this idRandom to FIXED string/number, or using find() to filter the exist Variable then destroy that. Otherwise always create new Avariable with the same eisName.

    thanks

    ReplyDelete
    Replies
    1. Thanks for your input.

      I tested it on windows without any problem.

      Thanks

      Delete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Script ran SUCCESSFUL. But there is no new resource in DbAdapter(DbAdapter->Configuration->Outbound Connection Pools)(((

    Log:
    -----------------------------
    createResourceAdapter:
    [echo] Create Resource
    [echo] eisName eis/DB/hr
    [wlst] Connecting to t3://localhost:7001 with userid weblogic ...
    [wlst] Successfully connected to Admin Server 'AdminServer' that belongs to domain 'toyota_domain_2'.
    [wlst]
    [wlst] Warning: An insecure protocol was used to connect to the
    [wlst] server. To ensure on-the-wire security, the SSL port or
    [wlst] Admin port should be used instead.

    [wlst] Location changed to edit tree. This is a writable tree with
    [wlst] DomainMBean as the root. To make changes you will need to start
    [wlst] an edit session via startEdit().
    [wlst]
    [wlst] For more help, use help(edit)

    [wlst] Starting an edit session ...
    [wlst] Started edit session, please be sure to save and activate your
    [wlst] changes once you are done.
    [wlst] __ Using plan_2 C:\bea1031\osb_10.3\lib\transports\Plan.xml
    [wlst] Loading application from C:/BEA1031/wlserver_10.3/osb_10.3/lib/transports/jca/DbAdapter.rar ...
    [wlst] Edit session has been stopped successfully.
    [echo] check for adapter changes and redeploy
    [echo] found db
    [echo] found for DbAdapter DbAdapter
    [echo] redeploy DbAdapter
    [wlst] Connecting to t3://localhost:7001 with userid weblogic ...
    [wlst] Successfully connected to Admin Server 'AdminServer' that belongs to domain 'toyota_domain_2'.
    [wlst]
    [wlst] Warning: An insecure protocol was used to connect to the
    [wlst] server. To ensure on-the-wire security, the SSL port or
    [wlst] Admin port should be used instead.

    [wlst] Location changed to edit tree. This is a writable tree with
    [wlst] DomainMBean as the root. To make changes you will need to start
    [wlst] an edit session via startEdit().
    [wlst]
    [wlst] For more help, use help(edit)

    [wlst] Starting an edit session ...
    [wlst] Started edit session, please be sure to save and activate your
    [wlst] changes once you are done.
    [wlst] Edit session has been stopped successfully.

    BUILD SUCCESSFUL
    Total time: 12 seconds
    <10.08.2012 14:47:05 MSD>
    ------------------------------

    ReplyDelete
    Replies
    1. Hi,

      does the plan C:\bea1031\osb_10.3\lib\transports\Plan.xml not have any new entry and what are your ant property settings

      thanks

      Delete
    2. This comment has been removed by the author.

      Delete
    3. Edwin Biemond, thanks!!!
      I made error in build.properties file: have written incorrect connectorLocation(

      Delete
  6. C:\Users\vxvm\Desktop\biemondosb\soa_tools-master\ant_resourceAdapter>ant create
    ResourceAdapter
    Buildfile: build.xml

    createResourceAdapter:

    BUILD FAILED
    C:\Users\vxvm\Desktop\biemondosb\soa_tools-master\ant_resourceAdapter\build.xml:
    129: Property '${resourceAdapterEntry}.type' is not defined.

    ReplyDelete
    Replies
    1. Hi,

      Did you add your Resource Adapter values to the build.properties
      like this

      resourceAdapterEntries=hrDB,hrDB2,hrAQ,hrAQ2,cf1JMS,cf2JMS
      and add the right types to hrAQ entries etc
      hrAQ.type=aq

      and run this on the adminserver

      thanks

      Delete
  7. Hi Edwin Biemond

    Can you please help out in resolving the above issue,Thanks!

    ReplyDelete
    Replies
    1. Hi,

      did you add the ant contrib jar to your classpath or add this to the ant lib folder.

      thanks

      Delete
    2. Yes Edwin Biemond

      I added in my classpath and as well as in ant lib folder.

      Please find below classpath:

      C:\Users\vxvm\oracleosb\Middleware\wlserver_10.3\server\lib\weblogic.jar;C:\Users\vxvm\oracleosb\Middleware\Oracle_OSB1\lib\alsb.jar;C:\Users\vxvm\oracleosb\Middleware\Oracle_OSB1\modules\com.bea.common.configfwk_1.6.0.0.jar;C:\Users\vxvm\oracleosb\Middleware\Oracle_OSB1\lib\sb-kernel-impl.jar;C:\Users\vxvm\oracleosb\Middleware\modules\org.apache.ant_1.7.1\lib\ant.jar;C:\Users\vxvm\oracleosb\Middleware\Oracle_OSB1\lib\sb-kernel-api.jar;C:\Users\vxvm\Desktop\biemondosb\soa_tools-master\ant\lib\ant-contrib-1.0b3.jar;

      Thanks

      Delete
    3. Hi,

      I did a fresh pull from github and everything is working fine.
      can you check the following,

      run the start.bat or change it to a sh script.

      are you running this script on the osb server.
      did you already create the resource adapter plans for aq,jms and db.

      ant contrib is loaded in the build.xml ( from the lib folder )
      path id="antcontrib.path"
      pathelement path="lib/ant-contrib-1.0b3.jar"
      /path

      taskdef classpathref="antcontrib.path"
      resource="net/sf/antcontrib/antlib.xml"


      and does your connectorLocation=C:/oracle/MiddlewarePS5/Oracle_SOA1/soa/connectors/ exists

      thanks

      Delete
    4. Hi

      I'm running this on windows and i have osb server installed locally in my machine
      and resource adapters JMS,DB,AQ connection factory is established but data source is not configured

      Question:do I need to update antcontrib.path in the build.xml?

      Also the connectorLocation exists and here is the path:connectorLocation=C:/Users/vxvm/oracleosb/Middleware/Oracle_OSB1/soa/connectors/

      I'm running it from OSB domain


      Also is there a way I can send my artifacts as an attachment?

      Please clarify, Thanks!

      Delete
    5. Hi,

      I think it is an ant contrib problem, that supports the property copy and the foreach
      you can send it to biemond at gmail dot com

      thanks

      Delete
  8. Hi Edwin,
    I wrote the scripts based on your code. I put all python scripts in createAdapter.py and created target in build.xml to call this py script. After sucessfully run the script, the new resources is not showing in DbAdapter(DbAdapter->Configuration->Outbound Connection Pools). But new configuration is in DBplan.xml. After i run "updates" DbAdaper, I can see the new resources. looks like redeploy part is not picking up the new configuration from DBPlan.xml. below is my redeploy part code

    def redeployResourceAdapter(appName):
    planPath = get('/AppDeployments/'+appName+'/AbsolutePlanPath')
    print '__ redeployResourceAdapter '+appName+' Using plan ' + planPath+ ' ___'
    cd('/AppDeployments/'+appName+'/Targets');
    redeploy(appName, planPath,targets=cmo.getTargets());
    #updateApplication(appName, planPath)

    cd('/')

    and log after create adapter resources

    [wlst] ___ DONE change plan ___
    [wlst]
    [wlst] ++++++++++++++++++++++++++++++++++++++++++++++++++
    [wlst] Saving all your changes ...
    [wlst] Saved all your changes successfully.
    [wlst] Activating all your changes, this may take a while ...
    [wlst] The edit lock associated with this edit session is released
    [wlst] once the activation is completed.
    [wlst] Activation completed
    [wlst] --------------------------------------------------
    [wlst] __ redeployResourceAdapter DbAdapter Using plan /oracle/Middleware/Oracle_SOA1/soa/connectors/plan/DBPlan.xml ___
    [wlst] Redeploying application DbAdapter ...
    [wlst]
    [wlst] .Completed the redeployment of Application with status completed
    [wlst] Current Status of your Deployment:
    [wlst] Deployment command type: redeploy
    [wlst] Deployment State : completed
    [wlst] Deployment Message : no message
    [wlst] Disconnected from weblogic server: AdminServer
    [wlst] job finished successfully
    [wlst]

    BUILD SUCCESSFUL
    Total time: 14 seconds



    please help,

    Kevin

    ReplyDelete
    Replies
    1. Hi,

      It should works but maybe somehow it can't find the plan Path in your script for the redeployment.

      thanks

      Delete
  9. Hi,
    Thanks for your reply. was thinking about that, but you can see in the log

    [wlst] __ redeployResourceAdapter DbAdapter Using plan /oracle/Middleware/Oracle_SOA1/soa/connectors/plan/DBPlan.xml ___

    that's correct path.

    cheers

    kevin

    ReplyDelete
  10. Hi Edwin.

    Thanks for this great post.

    They were most helpful in creating our custom script.

    Could you please share information on how we can edit or delete entries through the script.

    ReplyDelete
    Replies
    1. Hi,

      You can better delete them (manually) and recreate them with this script. But deleting from WLST can't be that hard .

      thanks.

      Delete
  11. instead redeploy(appName, planPath,targets=cmo.getTargets()); can we use update(appName, planPath,targets=cmo.getsTargets()); ?? after config if i dont want to redeploy the adapter and only want to update it ??

    Will update works ?

    ReplyDelete
    Replies
    1. Hi,

      I think update should also work, I did not try it but from the weblogic console you can also do a update and this also works.

      Thanks

      Delete
    2. Hi Edwin
      this article really helped me a lot, I've trouble in creating multiple properties on an adapter.
      I'm trying to configure MQAdapter jca, as per your createresourceadaptor, takes only one param property.
      Can you give me some example please.
      Thanks
      Andy

      Delete
    3. Hi,

      never tried this but can you call this method again with your second param.
      makeDeploymentPlanVariable(myPlan, configProperty, cfName

      thanks

      Delete
  12. Hi Biemond,
    Thanks that was useful post. Does this work for remote server even ? . It works good with localserver but when i am trying it with remote server it throwing the following error at the line where loadApplication line exists

    Traceback (innermost last):
    File "", line 1, in ?
    File "", line 290, in loadApplication
    Use dumpStack() to view the full stacktrace
    at weblogic.management.scripting.ExceptionHandler.handleException(ExceptionHandler.java:59)
    at weblogic.management.scripting.WLSTUtils.throwWLSTException(WLSTUtils.java:181)
    at weblogic.management.scripting.JSR88DeployHandler.loadApplication(JSR88DeployHandler.java:196)
    at weblogic.management.scripting.WLScriptContext.loadApplication(WLScriptContext.java:787)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)

    weblogic.management.scripting.ScriptException: weblogic.management.scripting.ScriptException: Error occured while performing loadApplication : Could not read confi
    guration. : Exception in AppMerge flows' progression

    ReplyDelete
    Replies
    1. Hi,

      it doesn't , it searches for a local file ( the deployment plan on the server ) , probably only works in this situation when you have a shared storage ( NFS share )

      thanks

      Delete
  13. how can i assign controlDir to some shared location in eis/HAFileAdapter ? i went to this path in console Deployments->File Adapter->Configuration->Outbound Connection Pools->javax.resource.cci.ConnectionFactory->eisHAFileAdapter->controlDir but i couldn't understand what should i have to do for assign controlDir to some shared location.

    ReplyDelete
    Replies
    1. Hi,

      start an edit session , just click on the value , add your location, press enter and save

      Delete