6 Replies Latest reply on Jun 26, 2019 3:47 PM by Brian Stansberry

    Can't query datasource from cli when it is defined as a variable

    fibber Newbie

      I am using EAP 7 (7.2.0 specifically).  I am using a system variable to define the name of my datasource, with the value passed in to the standalone.sh script (i.e. standalone.sh -Ddatasource=OracleDS ...)

       

      <datasources>

           <datasource jndi-name="java:jboss/datasources/${datasource}" pool-name="${datasource}" enabled="true" use-ccm="false">

               <connection-url> ... </connection-url>

               <driver>oracle</driver>

               ...

          </datasource>

      </datasources>

       

       

      The system log shows that OracleDS is being created

       

      INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) WFLYJCA0001: Bound data source [java:jboss/datasources/OracleDS]

       

      But when I try to use the command line client to query statistics or test a connection for this datasource, it tells me that it doesn't exist:

       

      /subsystem=datasources/data-source=OracleDS:test-connection-in-pool

      {

          "outcome" => "failed",

          "failure-description" => "WFLYCTL0216: Management resource '[

          (\"subsystem\" => \"datasources\"),

          (\"data-source\" => \"OracleDS\")

      ]' not found",

          "rolled-back" => true

      }

       

       

      Strangely enough, if I pass in the raw variable name (without it being defined for the cli script), it works:

       

      /subsystem=datasources/data-source=\${datasource}:test-connection-in-pool

       

      Is this a bug in the command line client, or am I simply doing something that shouldn't be done with the datasource definition?

        • 1. Re: Can't query datasource from cli when it is defined as a variable
          Jaikiran Pai Master

          Looking at the code of datasources subsystem, the "pool-name" XML attribute, is being used as the resource address and doesn't actually have a model attribute associated for it.

          In other words, there doesn't seem to be a way to use expressions (like the ${...}) for the value of that attribute. So the value of that XML attribute is actually taken literally and hence you are expected to pass the literal value for it for model operations.

           

          Having said that I don't know if WildFly model processing has the ability to warn in cases where expressions are used for attributes when the underlying model doesn't support it. Maybe brian.stansberry would have some inputs here.

           

          For now, don't use the ${datasource} for the pool-name attribute and instead use the actual value. I know it kind of defeats the purpose of making this dynamic, but I don't know if you really want to make the pool name dynamic or if you are just interested in making the jndi name to which it gets bound dynamic.

          • 2. Re: Can't query datasource from cli when it is defined as a variable
            fibber Newbie

            Jaikiran, that makes sense and is consistent with how JBoss is acting.  It would be nice to know which fields do not support expressions, as you mentioned.

             

            I wanted to make both the pool-name and the JNDI name dynamic, so I can use the same XML configuration file / template for a dozen different applications - it is much quicker and easier to pass in a different configuration parameter on startup than to run the dozens of CLI command to customize (and hard-code) each instance for the various apps.  For now, I can make the pool name a literal value because my applications using this template solution only need 1 datasource.

             

            The current behavior is not what I expected, but I am on the fence about it being an actual bug, or just an annoying feature.

            • 3. Re: Can't query datasource from cli when it is defined as a variable
              fibber Newbie

              Jaikiran - I am assuming you're talking about DsParser.java in the parseDataSource_1_2 method where it says:

               

                 case JNDI_NAME: {

                    final String jndiName = rawAttributeText(reader, JNDI_NAME.getXmlName());

                    JNDI_NAME.parseAndSetParameter(jndiName, operation, reader);

                    break;

                }

                case POOL_NAME: {

                    poolName = rawAttributeText(reader, POOLNAME_NAME);

                    break;

                }

               

              This code makes it quite obvious that it doesn't attempt to parse a variable used for the pool-name attribute, but does allow variables in the JNDI name.

              • 4. Re: Can't query datasource from cli when it is defined as a variable
                Jaikiran Pai Master

                fibber  wrote:

                 

                Jaikiran, that makes sense and is consistent with how JBoss is acting.  It would be nice to know which fields do not support expressions, as you mentioned.

                The WildFly model does describe which (model) attributes support expressions and which dont. This can in fact be checked using the CLI, by operations like read-resource-description. In fact, you will find that this will list "jndi-name" model attribute as one which supports expressions:

                 

                "jndi-name" => {

                                "type" => STRING,

                                "description" => "Specifies the JNDI name for the datasource",

                                "expressions-allowed" => true,

                 

                The pool-name is an odd one. As I noted previously, it doesn't have a corresponding model attribute and instead the value is used as the address identifier of the resource.

                 

                I wanted to make both the pool-name and the JNDI name dynamic

                The JNDI name can be made dynamic, but I don't see a way to make pool-name dynamic.

                The current behavior is not what I expected, but I am on the fence about it being an actual bug, or just an annoying feature.

                I'm not 100% sure either.

                • 5. Re: Can't query datasource from cli when it is defined as a variable
                  fibber Newbie

                  Running the read-resource command against my JBoss EAP 7.2.0 instance, the "pool-name" attribute isn't even listed.

                  /subsystem=datasources/data-source=Oracle:read-resource

                  {

                      "outcome" => "success",

                      "result" => {

                          "allocation-retry" => undefined,

                          "allocation-retry-wait-millis" => undefined,

                          "allow-multiple-users" => false,

                          "authentication-context" => undefined,

                          "background-validation" => false,

                          "background-validation-millis" => undefined,

                          "blocking-timeout-wait-millis" => undefined,

                          "capacity-decrementer-class" => undefined,

                          "capacity-decrementer-properties" => undefined,

                          "capacity-incrementer-class" => undefined,

                          "capacity-incrementer-properties" => undefined,

                          "check-valid-connection-sql" => undefined,

                          "connectable" => false,

                          "connection-listener-class" => undefined,

                          "connection-listener-property" => undefined,

                          "connection-url" => expression "${app.db.url}",

                          "credential-reference" => undefined,

                          "datasource-class" => undefined,

                          "driver-class" => undefined,

                          "driver-name" => "oracle",

                          "elytron-enabled" => false,

                          "enabled" => true,

                          "enlistment-trace" => false,

                          "exception-sorter-class-name" => "org.jboss.jca.adapters.jdbc.extensions.oracle.OracleExceptionSorter",

                          "exception-sorter-properties" => undefined,

                          "flush-strategy" => undefined,

                          "idle-timeout-minutes" => 5L,

                          "initial-pool-size" => undefined,

                          "jndi-name" => expression "java:jboss/datasources/${app.db.datasource}",

                          "jta" => true,

                          "max-pool-size" => expression "${app.db.pool.max}",

                          "mcp" => "org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool",

                          "min-pool-size" => expression "${app.db.pool.min}",

                          "new-connection-sql" => undefined,

                          "password" => expression "${app.db.password:${${app.db.vault}}}",

                          "pool-fair" => undefined,

                          "pool-prefill" => undefined,

                          "pool-use-strict-min" => undefined,

                          "prepared-statements-cache-size" => undefined,

                          "query-timeout" => undefined,

                          "reauth-plugin-class-name" => undefined,

                          "reauth-plugin-properties" => undefined,

                          "security-domain" => undefined,

                          "set-tx-query-timeout" => false,

                          "share-prepared-statements" => false,

                          "spy" => false,

                          "stale-connection-checker-class-name" => "org.jboss.jca.adapters.jdbc.extensions.oracle.OracleStaleConnectionChecker",

                          "stale-connection-checker-properties" => undefined,

                          "statistics-enabled" => true,

                          "track-statements" => "NOWARN",

                          "tracking" => false,

                          "transaction-isolation" => undefined,

                          "url-delimiter" => "|",

                          "url-selector-strategy-class-name" => undefined,

                          "use-ccm" => false,

                          "use-fast-fail" => false,

                          "use-java-context" => true,

                          "use-try-lock" => undefined,

                          "user-name" => expression "${app.db.username}",

                          "valid-connection-checker-class-name" => "org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker",

                          "valid-connection-checker-properties" => undefined,

                          "validate-on-match" => true,

                          "connection-properties" => undefined,

                          "statistics" => {

                              "jdbc" => undefined,

                              "pool" => undefined

                          }

                      }

                  }

                  After running some tests, it appears that the pool name, which comes from the -name parameter of the add-datasource command, is written to the XML configuration file as the "pool-name" attribute, but otherwise disappears from the model.  A simple command such as:

                   

                  data-source add --name==foo --jndi-name=java:jboss/datasources/foo --driver-name=oracle  { more stuff here }

                  will create the correct pool-name entry:

                  <datasource jndi-name="java:jboss/datasources/foo" pool-name="foo"  ....  >

                   

                  But neither the "name" nor the "pool-name" attributes are returned by read-resource or read-resource-description, which prevents me from discovering if they support expressions.   These missing attributes are now starting to look more like a bug, while the lack of expressions are most definitely an annoying feature.

                  • 6. Re: Can't query datasource from cli when it is defined as a variable
                    Brian Stansberry Master

                    The 'pool-name' XML attribute is a case (unfortunate IMHO) where an internal implementation detail crept into our configuration.  If it had simply been called 'name' it would have been a lot clearer.  There are very many XML attributes in our config file called 'name' where the value of the attribute ends up as part of the management resource name. People seem to be able to understand that relationship readily enough. This one is the same situation, it's just that the xml attribute is called 'pool-name' instead of 'name'.  It's been that way since AS 7 and is likely referenced in tons of documentation, so it's hard to change.

                     

                    Any XML attribute whose value ends up as part of a resource address can't have an expression for its value.