Add and Remove targets
Retarget JDBC and JMS resources programmatically via WLST
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
-
## Written by Unni — don’t hesitate to add a comment to this post incase you have any queries or sugessions
-
## you can even write to me at unni@unnikrishnanpillai.tk
-
## please leave a comment if u find this post helpfull
-
edit()
-
startEdit()
-
cd(‘/JDBCSystemResources/DS1’)
-
jdbcDS1=cmo
-
cd(“/Servers/MS1”)
-
target=cmo
-
jdbcDS1.addTarget(target)
-
save()
-
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
-
## Written by Unni — don’t hesitate to add a comment to this post incase you have any queries or sugessions
-
## you can even write to me at unni@unnikrishnanpillai.tk
-
## please leave a comment if u find this post helpfull
-
edit()
-
startEdit()
-
cd(‘/JDBCSystemResources/DS1’)
-
jdbcDS1=cmo
-
cd(“/Servers/MS1”)
-
target=cmo
-
jdbcDS1.removeTarget(target)
-
save()
-
activate()
• You should be able to see the new target in the Admin Console (Service > JDBC > DataSources > DS1 > Targets Tab)
Holla :)
Unni,