9 Replies Latest reply on Dec 30, 2013 1:57 PM by Roberto Cortez

    Can I write CLI to create datasource if not defined?

    Steven Boscarine Apprentice

      Can I write:

      if (data source doesn't exist)

           create datasource

      else

           message out to user that datasource already exists and won't be created.

       

      Hello All,

      I want to write a script to automate our JBoss EAP (6.0.1) deployments.  My current script is:

       

      #(I'd like to run this only if the module is not yet defined)
      
      #Register driver as JBoss module (update path to ojdbc6.jar)
      module add --name=com.oracle.jdbc --resources=ojdbc6.jar --dependencies=javax.api,javax.transaction.api
      
      #(I'd like to run this only if the driver is not yet registered) 
      #Register module as driver
      /subsystem=datasources/jdbc-driver=oracle:add(driver-module-name=com.oracle.jdbc,driver-name=oracle,driver-xa-datasource-class-name=oracle.jdbc.xa.client.OracleXADataSource)
      
      #(I'd like to run this only if the datasource doesn't exist)
      #Register module as driver
      #Create our main DataSource
      /subsystem=datasources/data-source=my-data_source:add( \
          jndi-name=java:/drm-data_source, \
          #CHANGE ME!
          connection-url=jdbc:oracle:thin:@localhost:1521:XE,\
          #CHANGE ME! 
          user-name=ChangeMePlease, \
          #CHANGE ME!
          password=ChangeMePlease, \
          min-pool-size=2,\
          max-pool-size=50,\
          driver-name=oracle,\
          flush-strategy=FailingConnectionOnly)
      
      

       

      Is there a way to:

      • Only run the DataSource creation if it doesn't exist?  Right now, I run /subsystem=datasources/data-source=my-data_source:read-resource with some very sloppy Groovy and the Java CLI API
      • Only run the driver and module creation code if those resources aren't there?
      • Print messages to the user?

       

      I do all this in Groovy now, but it's very sloppy and would not be as standarized or easy to read as an actual CLI script,  It would be nice to move this to pure CLI so my users can tweak it if they're familiar with the JBoss management API.

       

      Any leads are greatly appreciated!

      Steven