13 Replies Latest reply on Jan 24, 2012 4:47 AM by marx3

    Deploy enabled datasource in JBoss 7.1.0.CR1b

    marx3

      Hello

      I'm trying to deploy datasource via Maven using JBoss Maven plugin (described here http://relation.to/Bloggers/UsingTheJbossasMavenPluginToDeployDataSourcesToAS7 ). It deploys ok, but datasource is disabled by default. As I see it's new "feature" of JBoss server that each deployed datasource must be additionally enabled. Hovewer plugin is older than JBoss and doesn't do it (despite configuring deployed datasource as enabled in pom.xml).

       

      Is it bug or plugin will be updated?

        • 1. Re: Deploy enabled datasource in JBoss 7.1.0.CR1b
          marx3

          Any help?

          • 2. Re: Deploy enabled datasource in JBoss 7.1.0.CR1b
            cirix

            For me the usage of plugin provided is pointless.cause if it's a datasource configure it once and you are done.Ok probably allows you to do changes

            while editing your pom but for me that's really not a good reason.Plus there is a problem in the plugin and will always set the ds by default enabled="false" ...so...

            • 3. Re: Deploy enabled datasource in JBoss 7.1.0.CR1b
              jaikiran

              I have requested the author(s) of the plugin to see if any changes are required.

              • 4. Re: Deploy enabled datasource in JBoss 7.1.0.CR1b
                marx3

                And what the author said?

                • 5. Re: Deploy enabled datasource in JBoss 7.1.0.CR1b
                  jaikiran

                  It was discussed on the AS7 IRC http://echelog.matzon.dk/logs/browse/jboss-as7/1325631600

                   

                  [20:58:37] <stuartdouglas> jamezp: hi

                  [20:58:58] <jamezp> Morning... ...got a quick question for you.

                  [21:00:13] <jamezp> It looks like now deployed datasources need to be enabled as a second step.

                  [21:00:48] <jamezp> Which I've done here https://github.com/jamezp/jboss-as-maven-plugin/commit/ab5c0cc99f1a8e83c70cb99702c1da74117a41c5

                  [21:00:49] <jbossbot> git [jboss-as-maven-plugin] ab5c0cc.. James Perkins The datasource needs to be enabled after the addition.

                  [21:01:09] <jamezp> stuartdouglas: Could you take a quick look to make sure I'm doing that correctly.

                  [21:01:39] <stuartdouglas> the thing is with that is that the add operation may not be a datasource

                  [21:01:57] <jamezp> Ah, right good point.

                  [21:02:04] <stuartdouglas> cause you can use AddResource to just add any generic think, like queue, mail sessions, whetever

                  [21:02:35] <jamezp> Makes sense... ...I wonder if we could/should add a enable-datasource option or something like that.

                  [21:02:45] <stuartdouglas> we may need to do thet

                  [21:02:58] <stuartdouglas> it seems ugly, but I can't think of anything better

                  [21:03:07] <stuartdouglas> personally I hate the way they are disabled by default

                  [21:03:14] <jamezp> :-)

                  [21:03:39] <jamezp> It threw me for a loop when I was trying to figure this out.

                  [21:04:04] <jamezp> Even when "<enabled>true</enabled>" was defined.

                  ...

                  [22:25:37] <jamezp> stuartdouglas: We could just support having an <enable>true</enable> attribute since that's a common operation.

                  [22:25:42] *** maschmid has quit IRC

                  [22:26:22] <jamezp> Or I suppose we could have an operation map like the properties that executes additional operations

                  [22:26:29] * jamezp is just thinking out loud.

                  [22:26:53] *** pilhuhn is now known as pil-gone

                  [22:27:14] <stuartdouglas> I might ask the JCA guys why they did it

                  [22:27:25] <stuartdouglas> I asked a while back and I can't remember the reason

                  [22:27:44] <stuartdouglas> but I think the real fix is just to change AS7 so you can just add an enabled datasource

                  [22:27:55] <stuartdouglas> as 99.9% of the time that is what users are going to want to do

                  [22:28:47] <jamezp> Agreed. I can't think of why you wouldn't want it enabled. Especially if you explicitly define it as enabled.

                  • 6. Re: Deploy enabled datasource in JBoss 7.1.0.CR1b
                    jbrow

                    I sent this to Stuart.  I don't know if he's had a chance to look at it or if it is of interest.  I'm currently using it as an interim solution until everything gets figured out.

                     

                    The attached file replaces AddResource.java in the jboss-as-maven-plugin source.  I modified the version in the pom to something custom for me and did a maven install.

                     

                    This AddResource adds two new parameters:

                     

                    <enable-resource>: boolean: If true, this will enable the resource after adding the resource and subresouces.

                    <subresources>: String array: adds subresource values.  each subresource is defined as:

                    <subresource>"address relative to parent","parameter"[,"parameter"...]</subresource>

                     

                    An example of using this in a pom:

                     

                    [code]

                      <enable-resource>true</enable-resource>

                      <subresources>

                         <subresource>xa-datasource-properties=IfxIFX_LOCK_MODE_WAIT,value=300</subresource>

                          <subresource>xa-datasource-properties=Description,value=MY Database</subresource>

                         <subresource>xa-datasource-properties=IfxSQLH_TYPE,value=FILE</subresource>

                         <subresource>xa-datasource-properties=IfxSQLH_FILE,value=FILE:///opt/informix/etc/sqlhosts</subresource>

                         <subresource>xa-datasource-properties=IfxSQLH_LOC,value=CLIENT</subresource>

                         <subresource>xa-datasource-properties=DatabaseName,value=myDB</subresource>

                         <subresource>xa-datasource-properties=ServerName,value=dbServer</subresource>

                      </subresources>

                    [/code]

                     

                    This is placed in the pom at the same level as the properties (in my pom, it's just below the </properties>).

                     

                     

                    If this is inappropriate, please feel free to delete this entry.  I just thought it might be helpful in the interim.

                    • 7. Re: Deploy enabled datasource in JBoss 7.1.0.CR1b
                      jamezp

                      Hello Jim,

                      Thanks for the patch, it's much appreciated! I do have a question on it.

                       

                      I'm a little confused on the subresources. Could you elaborate a little and maybe give a possible use-case?

                       

                      Thanks,

                      James R. Perkins

                      • 8. Re: Deploy enabled datasource in JBoss 7.1.0.CR1b
                        jbrow

                        Hi James,

                         

                        The only current use for subresources I know of is for xa-datasource-properties.  They now have to be added as separate subresources (see https://community.jboss.org/message/639893 ).  So, unless I'm missing something (always a possibility), there was no easy way to add them with jboss-as-maven-plugin -- especially if you wanted to also enable the resource at the same time.

                         

                        The way I chose to add these is somewhat of a shortcut given that the "xa-datasource-properties=..." is part of the address, and the "value=...." is a property. However, I was just looking for something to get maven to install the resources (so I didn't have to change our procedures down the road).  I figure it's just an interim solution, and I had to figure out maven plugin programming, the JBoss Management API, and the jboss-as-maven-plugin code so I wasn't that interested in figuring out the perfect solution for the subresources issue.

                        • 9. Re: Deploy enabled datasource in JBoss 7.1.0.CR1b
                          jamezp

                          Hello Jim,

                          Thanks for that information. Makes more sense to me now. We do have a release that should work for you now, jboss-as-maven-plugin-7.1.0.CR1b.


                          <dependency>
                            <groupId>org.jboss.as.plugins</groupId>
                            <artifactId>jboss-as-maven-plugin</artifactId>
                            <version>7.1.0.CR1b</version>
                          </dependency>
                          

                           

                          You will now be able to deploy multiple resources like this:

                           

                           ... 
                                              <execution>
                                                  <id>add-xa-datasource</id>
                                                  <phase>install</phase>
                                                  <configuration>
                                                      <address>subsystem=datasources</address>
                                                      <resources>
                                                          <resource>
                                                              <address>xa-data-source=java:jboss/datasources/postgresDS</address>
                                                              <enableResource>true</enableResource>
                                                              <properties>
                                                                  <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
                                                                  <jndi-name>java:jboss/datasources/postgresDS</jndi-name>
                                                                  <enabled>true</enabled>
                                                                  <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
                                                                  <pool-name>myPool</pool-name>
                                                                  <driver-name>postgresql.jar</driver-name>
                                                              </properties>
                                                          </resource>
                                                          <resource>
                                                              <address>xa-data-source=java:jboss/datasources/postgresDS,xa-datasource-properties=DatabaseName</address>
                                                              <properties>
                                                                  <value>myDatabase</value>
                                                              </properties>
                                                          </resource>
                                                          <resource>
                                                              <address>xa-data-source=java:jboss/datasources/postgresDS,xa-datasource-properties=ServerName</address>
                                                              <properties>
                                                                  <value>localhost</value>
                                                              </properties>
                                                          </resource>
                                                          <resource>
                                                              <address>xa-data-source=java:jboss/datasources/postgresDS,xa-datasource-properties=User</address>
                                                              <properties>
                                                                  <value>dbuser</value>
                                                              </properties>
                                                          </resource>
                                                          <resource>
                                                              <address>xa-data-source=java:jboss/datasources/postgresDS,xa-datasource-properties=Password</address>
                                                              <properties>
                                                                  <value>supersecret</value>
                                                              </properties>
                                                          </resource>
                                                      </resources>
                                                  </configuration>
                                                  <goals>
                                                      <goal>add-resource</goal>
                                                  </goals>
                                              </execution>
                          ...
                          

                           

                          For more information we have some maven plugin documentation here http://docs.jboss.org/jbossas/7/plugins/maven/latest/examples/add-resource-example.html

                           

                          Hopefully this gives you want you want.

                           

                          Thanks a lot for the patch BTW. It worked out perfectly.

                           

                          --

                          James R. Perkins

                          • 10. Re: Deploy enabled datasource in JBoss 7.1.0.CR1b
                            jbrow

                            Thanks for the info on 7.1.0CRb1, James!

                            • 11. Re: Deploy enabled datasource in JBoss 7.1.0.CR1b
                              marx3

                              I'm trying to deploy Postgres datasource but I have an error:

                               

                              [ERROR] Failed to execute goal org.jboss.as.plugins:jboss-as-maven-plugin:7.1.0.CR1b:add-resource (add-datasource) on project myapp: Could not execute goal add-resource. Reason: null is not a valid address segment -> [Help 1]

                               

                              Below is my configuration:

                               

                              {code}

                               

                              <execution>

                                  <id>add-datasource</id>

                                  <phase>package</phase>

                                  <goals>

                                      <goal>add-resource</goal>

                                  </goals>

                                  <configuration>

                                      <address>subsystem=datasources,data-source=PostgresDS</address>

                                      <resource>

                                          <enable-resource>true</enable-resource>

                                          <properties>

                                              <connection-url>jdbc:postgresql://localhost:5432/myapp</connection-url>

                                              <jndi-name>java:/PostgresDS</jndi-name>

                                              <enabled>true</enabled>

                                              <pool-name>PostgresDS_Pool</pool-name>

                                              <user-name>marx</user-name>

                                              <password>marx</password>

                                              <driver-name>postgresql.jar</driver-name>

                                          </properties>

                                      </resource>

                                  </configuration>

                              </execution>

                               

                              {code}

                              • 12. Re: Deploy enabled datasource in JBoss 7.1.0.CR1b
                                jamezp

                                Looks I messed up the documentation . It should be <enableResource>true</enableResource>.

                                 

                                As far as the NPE, I'll check that out. At the minimum there is a very simple work around. Just separate the address to look like the following.

                                 

                                <execution>
                                    <id>add-datasource</id>
                                    <phase>package</phase>
                                    <goals>
                                        <goal>add-resource</goal>
                                    </goals>
                                    <configuration>
                                        <address>subsystem=datasources</address>
                                        <resource>
                                            <address>data-source=PostgresDS</address>
                                            <enableResource>true</enableResource>
                                            <properties>
                                                <connection-url>jdbc:postgresql://localhost:5432/myapp</connection-url>
                                                <jndi-name>java:/PostgresDS</jndi-name>
                                                <enabled>true</enabled>
                                                <pool-name>PostgresDS_Pool</pool-name>
                                                <user-name>marx</user-name>
                                                <password>marx</password>
                                                <driver-name>postgresql.jar</driver-name>
                                            </properties>
                                        </resource>
                                    </configuration>
                                </execution>
                                

                                 

                                --

                                James R. Perkins

                                • 13. Re: Deploy enabled datasource in JBoss 7.1.0.CR1b
                                  marx3

                                  Thank you, at last it works!