← All posts

Add and Remove targets

Retarget JDBC and JMS resources programmatically via WLST

Unni Pillai
Unni Pillai

Add and Remove targets from a Deploy-able system resource:

@Deepti : i wrote this post for you babie… 

• Any deploy-able weblogic system resource (JDBC Data Source, JMS Connection Factory, JMS Servers, JDBC Multi Pools, Web deployment, etc) implement the ‘DeploymentMBean’ interface.

• A deploy-able Systme resource is any MBean that may be deployed on one or more targets, such as a JMS Front-end or back-end or a JDBC connection pool.

• Any deploy-able resource (MBean) has targets, which specify which servers the deployment should be deployed / pinned on.

• All these deploy-able resources (MBean) leverage ‘addTarget’ and ‘removeTarget’ methods , which they inherit from the ‘DeploymentMBean’ interface.

o addTarget(target)

- This method adds a target to specify additional servers / clusters on which the deployable Mbean can be deployed

- here, target - is the reference variable of type: TargetMBean, [a server MBean is acceptable], see example below

o removeTarget(target)

- This method removes the value of the addTarget attribute

- here, target - is the reference variable of type: TargetMBean, [a server MBean is acceptable], see example below

o In this example we will use a JDBC Data Source to demonstrate this:

o Prerequisites

- WebLogic Domain with an admin server and a managed server named ‘MS1’

- Create a JDBC Datasource named ‘DS1’, and deploy it ONLY on ‘Admin Server’

- Make sure that both the servers are running and DS1 is also running

o Demonstration for adding a target to a Data Source:

- open a command window (CMD)

- set the environment by running the ‘setdomainenv.cmd’ from the ‘domain\bin’ dir

- execute ‘java weblogic.WLST’

- connect to the Admin Server using ‘connect’ command

Code written using online editor Pastebin.com - Download Raw

  1. ##      Written by Unni — don’t hesitate to add a comment to this post incase you have any queries or sugessions

  2. ##      you can even write to me at unni@unnikrishnanpillai.tk

  3. ##      please leave a comment if u find this post helpfull

  4. edit()

  5. startEdit()

  6. cd(‘/JDBCSystemResources/DS1’)

  7. jdbcDS1=cmo

  8. cd(“/Servers/MS1”)

  9. target=cmo  

  10. jdbcDS1.addTarget(target)

  11. save()

  12. activate()

o  You should be able to see the new target in the Admin Console (Service > JDBC > DataSources > DS1 > Targets Tab)

o  Demonstration for removing a target to a Data Source:

- open a command window (CMD)

- set the environment by running the ‘setdomainenv.cmd’ from the ‘domain\bin’ dir

- execute ‘java weblogic.WLST’

- connect to the Admin Server using ‘connect’ command

Code written using online editor Pastebin.com - Download Raw

  1. ##      Written by Unni — don’t hesitate to add a comment to this post incase you have any queries or sugessions

  2. ##      you can even write to me at unni@unnikrishnanpillai.tk

  3. ##      please leave a comment if u find this post helpfull

  4. edit()

  5. startEdit()

  6. cd(‘/JDBCSystemResources/DS1’)

  7. jdbcDS1=cmo

  8. cd(“/Servers/MS1”)

  9. target=cmo  

  10. jdbcDS1.removeTarget(target)

  11. save()

  12. activate()

•  You should be able to see the new target in the Admin Console (Service > JDBC > DataSources > DS1 > Targets Tab)

Holla :)

Unni,

unni@unnikrishnanpillai.tk