2 Replies Latest reply on Feb 4, 2013 1:02 PM by Peter de Groot

    Restart JDBCSystemResource in WLST

    Peter de Groot
      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:
      # Change the URL for all Data Sources
      for r in editService.getDomainConfiguration().getJDBCSystemResources():
      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:
      How can I activate my changes/restart the JDBCResource in WLST?

        • 1. Re: Restart JDBCSystemResource in WLST
          René van Wijk
          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).
          1 person found this helpful
          • 2. Re: Restart JDBCSystemResource in WLST
            Peter de Groot
            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():
            Doing this disconnects the old database connections, and creates a new connection to the newly configured database.