2 Replies Latest reply on Sep 29, 2010 2:56 PM by rafaelcba

    bundles

    rafaelcba

      Hello!

       

      I want to use the new provisioning feature on RHQ 3/JON 2.4.

       

      I have a bundle with a Data Source definition, a WAR and the bundle recipe (deploy.xml). I want to update some tokens on DS xml and deploy the WAR inside JBoss deploy's directory.

       

      <?xml version="1.0"?>
      <project name="test-bundle" default="main"
          xmlns:rhq="antlib:org.rhq.bundle">

       

         <rhq:bundle name="POC-WAR-DEPLOY" version="3.0.0" description="Deploy de pacote WAR via Bundles">
             <rhq:input-property
                 name="dbUser"
                 description="database user"
                 required="true"
                 defaultValue="sa"
                 type="string">
            </rhq:input-property>
             <rhq:input-property
                 name="dbPWD"
                 description="dabase password"
                 required="true"
                 defaultValue="xxx"
                 type="string">
            </rhq:input-property>
             <rhq:input-property
                 name="dsMinPoolSize"
                 description="min pool size"
                 required="true"
                 defaultValue="2"
                 type="integer">
            </rhq:input-property>
             <rhq:input-property
                 name="dsMaxPoolSize"
                 description="max pool size"
                 required="true"
                 defaultValue="20"
                 type="integer">
            </rhq:input-property>

       

            <rhq:deployment-unit name="WAR">
               <rhq:file name="JSFTutorials-CDStore.war" destinationFile="JSFTutorials-CDStore.war" replace="true"></rhq:file>
               <rhq:file name="hsqldb-test-ds.xml" destinationFile="hsqldb-test-ds.xml" replace="true"></rhq:file>
            </rhq:deployment-unit>
         </rhq:bundle>

       

          <target name="main"></target>
      </project>

       

      The DataSource token process works fine but the WAR deploy fails because sounds like RHQ corrupt the WAR. After the RHQ finish the bundle process the WAR inside JBoss is corrupt.

       

      By the way I've tried use this form to update some tokens on web.xml inside a WAR. But RHQ deploy the WAR exploded in rhq.deploy.dir.

      There is a way to force RHQ to deploy the archieve in zipped form?

       

      <rhq:archive name="JSFTutorials-CDStore.war">
         <rhq:replace>
            <rhq:fileset>
               <include name="**/web.xml"/>
            </rhq:fileset>
         </rhq:replace>
      </rhq:archive>

       

      Thanks.

        • 1. Re: bundles
          mazz

          The problem is the recipe where you use the <file> tag to represent your WAR file. From the docs:

           

          http://rhq-project.org/display/JOPR2/Ant+Bundles#AntBundles-rhq%3Afile

           

          you'll see it says <file> represents "raw files" which are "copied as-is without attempting to "unpack" them (like would be done with zip or jar files)."

           

          <file> used together with replace="true" was meant to be used for files like .properties or .xml configuration files or any individual templatized file that is not an archive (like zip or jar).  What is happening is you are telling RHQ you have this raw file (your war) that needs to be "realized" (i.e. have its tokens replaced with its real replacement values) so RHQ scans the war file (it scans the actual raw bytes of the war file itself - because you said <file>, RHQ won't think its an archive and thus won't unpack it into its individual files and replace those files - read below for more on this) and any token it finds in the war's raw binary data will be replaced. Well, this will corrupt your war file and the war file will no longer be valid (as you have seen).

           

          If you have a jar file (like your war) that is templatized (that is, has tokens that need to be replaced), you need to use <archive> with child <replace> tags, as documented here:

           

          http://rhq-project.org/display/JOPR2/Ant+Bundles#AntBundles-rhq%3Areplace

           

          where it says: "The rhq:replace child tag of rhq:archive tells RHQ which files within the archive are templatized and thus which files need to have their replacement variables replaced with real property values."

           

          Now, of course, the <archive> tag tells RHQ to unpack that war file when it writes it out to your destination directory (like you have seen when you said you tried to use the <archive> but was deployed exploded), and from the sound of it, it doesn't seem like you want to deploy your war exploded (which is probably why you tried to use <file>, but unfortunately, that will not work as I mentioned above). A solution to this could be for your recipe Ant script to define a post-install target and have your custom target re-package your war file as a collapsed jar file. See the example recipe Ant script provided on that wiki page to see how to define pre and post install targets here: http://rhq-project.org/display/JOPR2/Ant+Bundles#AntBundles-AntRecipes

           

          This is actually very good feedback Rafael Can you enter an enhancement request to bugzilla? I think rather than ask users to write their own post-install target to do this repackaging, we probably should have something in the <archive> task that lets you signify that RHQ should re-archive the archve after it replaces the individual file tokens. I'm envisioning something like this:

           

          <rhq:archive name="JSFTutorials-CDStore.war" exploded="false">
             <rhq:replace>
          ...
             </rhq:replace>
          </rhq:archive>

           

          where the "exploded" attribute is optional and whose default value is "true" (which is how it works today). Allowing exploded="false" would tell RHQ that it should copy the archive to the destination as a single archive file - even if the war had to be unpacked to replace the tokens from the individual files. We'd have to do the re-packing after the replacement was done.

          • 2. Re: bundles
            rafaelcba

            Hi Mazz!

             

            First, many thanks by your reply.

             

            About this:

            <file> used together with replace="true" was meant to be used for  files like .properties or .xml configuration files or any individual  templatized file that is not an archive (like zip or jar).  What is  happening is you are telling RHQ you have this raw file (your war) that  needs to be "realized" (i.e. have its tokens replaced with its real  replacement values) so RHQ scans the war file (it scans the actual raw  bytes of the war file itself - because you said <file>, RHQ won't  think its an archive and thus won't unpack it into its individual files  and replace those files - read below for more on this) and any token it  finds in the war's raw binary data will be replaced. Well, this will  corrupt your war file and the war file will no longer be valid (as you  have seen).

            I was confused. I've guessed that property had intend to replace the destination file (if it already exist on destination path).

             

            This is actually very good feedback Rafael Can you enter an enhancement request to bugzilla?  I think rather than ask users to write their own post-install target to  do this repackaging, we probably should have something in the  <archive> task that lets you signify that RHQ should re-archive  the archve after it replaces the individual file tokens. I'm envisioning  something like this:

             

            <rhq:archive name="JSFTutorials-CDStore.war" exploded="false">
               <rhq:replace>
            ...
               </rhq:replace>
            </rhq:archive>

            Yes! Would be nice this option...

            I opened a feature request for this: https://bugzilla.redhat.com/show_bug.cgi?id=638730