This discussion is archived
2 Replies Latest reply: Feb 4, 2013 5:02 AM by pdegroot RSS

Restart JDBCSystemResource in WLST

pdegroot Newbie
Currently Being Moderated
I posted this question in the JDBC forum, but I realize it might me more appropriate here.

I'm trying to change the database connection for all existing JDBC Data Sources in WLST (Weblogic Server 10.3.4), to make it connect to a different database when the original database is being patched. I made the following script to do so:
edit()
startEdit()

# Change the URL for all Data Sources
for r in editService.getDomainConfiguration().getJDBCSystemResources():
   r.getJDBCResource().getJDBCDriverParams().setUrl('jdbc:oracle:thin:@somehost:1521/SOMEDB.world')

save()
activate()
The Admin Console tells me that this requires me to restart the changed JDBCResource, and allows me to do so in the View Changes and Restarts page. However, I need to implement this restart in my WLST script.

I tried to restart the Data Source with the following, but it just reconnects to the original database, not to the newly configured one:
# Restart the Data Sources
for server in domainRuntimeService.getServerRuntimes():
   dataSources = server.getJDBCServiceRuntime().getJDBCDataSourceRuntimeMBeans()
   for dataSource in dataSources:
      #dataSource.reset()
      dataSource.forceShutdown()
      dataSource.start()
How can I activate my changes/restart the JDBCResource in WLST?


Regards,
Peter.
  • 1. Re: Restart JDBCSystemResource in WLST
    RenévanWijk Oracle ACE
    Currently Being Moderated
    datasource.reset() should do the trick.

    From the documentation (http://docs.oracle.com/cd/E12839_01/apirefs.1111/e13951/mbeans/JDBCDataSourceRuntimeMBean.html)
    "Resets the connection pool in the data source by shutting down and recreating all available database connections in the pool.
    Use when a data source is in the health state of Unhealthy and needs to be reinitialized."

    But I think it just re-uses what is in memory (the mbean settings I mean).

    As you mentioned "The Admin Console tells me that this requires me to restart the changed JDBCResource, and allows me to do so in the View Changes and Restarts page"
    when you perform this in the console, does it actually connect to the other database (seen a number of occasions where that was not happening and had the restart the
    whole server).

    You can use the ServerLifeCycleRuntimeMBean (http://docs.oracle.com/cd/E12839_01/apirefs.1111/e13951/mbeans/ServerLifeCycleRuntimeMBean.html) to start and stop servers,
    an example is provided here http://middlewaremagic.com/weblogic/?p=8187 (see the 'Using Server Life Cycle Runtimes' section).
  • 2. Re: Restart JDBCSystemResource in WLST
    pdegroot Newbie
    Currently Being Moderated
    Hoi René,

    Thanks, you got me on the right track with the ServerLifeCycleRuntimeMBean, although mainly because it's accessed from the DomainRuntimeMBean, and the solution is there (http://docs.oracle.com/cd/E12839_01/apirefs.1111/e13951/mbeans/DomainRuntimeMBean.html). There's a restartSystemResource() operation in the DomainRuntimeMBean, which does what I need it to do:
    for jdbcSr in domainRuntimeService.getDomainConfiguration().getJDBCSystemResources():
       domainRuntimeService.getDomainRuntime().restartSystemResource(jdbcSr)
    Doing this disconnects the old database connections, and creates a new connection to the newly configured database.


    Groets,
    Peter.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points