7 Replies Latest reply on Jan 20, 2005 5:45 PM by ccrouch

    Hot deploy/redeploy datasources

    ccrouch

      The JBossAS Admin Console has the requirement to enable users to create/update datasources within JBoss AS without restarting the actual instance. My question is to what extent are these operations feasible in the current 3.2.x/4.0.x JBoss AS architecture?

      Virtually every reference I've found says that the driver .jar file should be put in server/xxx/lib and then the -ds.xml file in the server/xxx/deploy. This clearly is not suitable in this case since JBoss AS needs to be restarted to see the .jar in server/xxx/lib.

      Scott refered to a possible solution while talking on a slightly different topic at http://sourceforge.net/mailarchive/message.php?msg_id=6481814. I tested this approach in 3.2.6 using a full -service.xml config file, rather than a -ds.xml file, with an included element pointing to the driver .jar file. See below:

      <?xml version="1.0"?>
      <server>
       <classpath codebase="deploy/datasources" archives="mysql-connector-java-3.1.0-alpha-bin.jar"/>
       <mbean code="org.jboss.resource.connectionmanager.TxConnectionManager" display-name="ConnectionManager for DataSource MySQLDS" name="jboss.jca:service=LocalTxCM,name=mysql">
       <attribute name="TrackConnectionByTx">true</attribute>
       <attribute name="LocalTransactions">true</attribute>
      
       <depends optional-attribute-name="ManagedConnectionPool">
       <mbean code="org.jboss.resource.connectionmanager.JBossManagedConnectionPool" name="jboss.jca:service=LocalTxPool,name=MySLQDS">
       <depends optional-attribute-name="ManagedConnectionFactoryName">
       <mbean code="org.jboss.resource.connectionmanager.RARDeployment" name="jboss.jca:service=LocalTxPF,name=MySQLDS">
       <depends optional-attribute-name="OldRarDeployment">jboss.jca:service=RARDeployment,name=JBoss LocalTransaction JDBC Wrapper</depends>
       <attribute name="ManagedConnectionFactoryProperties">
       <properties>
       <config-property name="ConnectionURL" type="java.lang.String">jdbc:mysql://localhost:3306/mysql</config-property>
       <config-property name="DriverClass" type="java.lang.String">com.mysql.jdbc.Driver</config-property>
       <config-property name="UserName" type="java.lang.String">root</config-property>
       <config-property name="Password" type="java.lang.String">blah</config-property>
       </properties>
       </attribute>
       </mbean>
       </depends>
       <attribute name="MinSize">0</attribute>
       <attribute name="MaxSize">50</attribute>
       <attribute name="BlockingTimeoutMillis">5000</attribute>
       <attribute name="IdleTimeoutMinutes">1</attribute>
       <attribute name="Criteria">ByNothing</attribute>
       </mbean>
       </depends>
      
       <attribute name="JndiName">MySQLDS</attribute>
       <depends optional-attribute-name="CachedConnectionManager">jboss.jca:service=CachedConnectionManager</depends>
       <depends optional-attribute-name="TransactionManagerService">jboss:service=TransactionManager</depends>
       </mbean>
      </server>
      


      This enabled a new datasource, referencing server/xxx/deploy/datasources/mysql-connector-java-3.1.0-alpha-bin.jar, to be created dynamically in the JBoss AS. No JBoss AS restart, nor jars in server/xxx/lib required. Updates can also obviously be made to the -service.xml without any need to restart the instance. However, on Windows at least, a lock is kept to the driver .jar file preventing it from being moved or deleted until JBoss AS is stopped.

      Does anyone know of an alternative approach which does not cause the file lock? Obviously updating the driver .jar being used could be managed by updating the classpath element and specifying a new driver file name, but I was just wondering if there was a way to avoid the lock.

      Thanks
      Charles


        • 1. Re: Hot deploy/redeploy datasources
          starksm64

          The lock is created deep within the java.net.URLClassLoader and as yet no one has suggested how to avoid this issue. There is a bug report on sun about this which I thought had simply been closed as won't fix.

          • 2. Re: Hot deploy/redeploy datasources
            ccrouch

            So for where we stand right now, the approach described in the the original post is the best bet for hot deploy/undeploy of datasources?

            If so, do you see any merit in updating the stylesheet described here http://jboss.org/wiki/Wiki.jsp?page=ConfigConnectionFactoryDeployer so that a classpath element could be added to a -ds.xml rather than needing to create the full -service.xml in order to harness this capability?

            Thanks
            Charles

            • 3. Re: Hot deploy/redeploy datasources

              This is an old FAQ.

              JDBC drivers CANNOT be hot deployed, or more accuratly redeployed.

              The class java.sql.DriverManager does some horrible classloader caching.
              If you change Sun's class to use the thread context classloader rather
              than Class.forName() then it becomes possible to redeploy jdbc driver classes.

              The only workaround is to redeploy JBoss's local jdbc resource adapter
              when you want to redeploy a driver (which doesn't work very well if there is no more
              than driver).

              I don't see the need to add

              <classpath/>
              tag to the -ds.xml
              since you get much better semantics by creating a sar that contains
              both the -ds.xml and the driver jar. But still no hotredeploy.

              • 4. Re: Hot deploy/redeploy datasources
                ccrouch

                 

                "adrian@jboss.org" wrote:

                The only workaround is to redeploy JBoss's local jdbc resource adapter
                when you want to redeploy a driver (which doesn't work very well if there is no more than driver).


                Could you expand briefly on what you mean here? Is it that redeploying jboss-local-jdbc.rar won't work if we have more than one datasource/driver? Just throwing out an idea, apologies if it doesn't make sense: Is it possible to bundle a version of jboss-local-jdbc.rar inside a .sar, along with the -ds.xml and the driver. Would that help toward hot redeploy?

                Thanks
                Charles

                • 5. Re: Hot deploy/redeploy datasources
                  ccrouch

                   

                  "adrian@jboss.org" wrote:

                  I don't see the need to add
                  <classpath/>
                  tag to the -ds.xml
                  since you get much better semantics by creating a sar that contains
                  both the -ds.xml and the driver jar. But still no hotredeploy.



                  Thanks Adrian for the suggestion. Hot deploying a datasource using a sar works great, where the sar looks like this:
                  mydatasource.sar/
                   META-INF/jboss-service.xml = <?xml version="1.0"?><server></server>
                   my-ds.xml
                   mydriver.jar


                  One interesting thing I found is that if I deployed it exploded, I can't then delete it, there is a lock on the META-INF folder? There is no problem deleting it when archived. So in effect "hot undeploy" also works: removing the .sar unbinds the datasource it created.

                  Also when I delete one .sar and replace it with another one, (same sar name, just new driver) I get the following logged to the console: "INFO [JCAResource] Registration is not done -> stop". Regardless of this, as we would expect, after restarting the server the new driver is picked up perfectly.


                  Thanks

                  • 6. Re: Hot deploy/redeploy datasources

                     

                    "charles.crouch@jboss.com" wrote:

                    One interesting thing I found is that if I deployed it exploded, I can't then delete it, there is a lock on the META-INF folder? There is no problem deleting it when archived. So in effect "hot undeploy" also works: removing the .sar unbinds the datasource it created.


                    Report it as a bug.


                    Also when I delete one .sar and replace it with another one, (same sar name, just new driver) I get the following logged to the console: "INFO [JCAResource] Registration is not done -> stop". Regardless of this, as we would expect, after restarting the server the new driver is picked up perfectly.

                    Known issue: http://jira.jboss.com/jira/browse/JBAS-1281

                    • 7. Re: Hot deploy/redeploy datasources
                      ccrouch

                       

                      "adrian@jboss.org" wrote:
                      "charles.crouch@jboss.com" wrote:

                      One interesting thing I found is that if I deployed it exploded, I can't then delete it, there is a lock on the META-INF folder?


                      Report it as a bug.



                      My bad, I couldn't reproduce this problem.