Cannot resolve system property when using referencing it using jboss-cli - jboss

I am attempting to flush a JNDI datasource using the jboss-cli, but the datasource is defined using a ${jndi.prefix} variable, and the CLI can't seem to be able to resolve it.
Here is my datasource in standalone.xml:
<datasource jndi-name="${jndi.prefix}/CORE" pool-name="${jndi.prefix}/CORE_Pool" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:sqlserver://10.222.255.100;DatabaseName=CORE</connection-url>
<driver>sqlserver</driver>
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>10</max-pool-size>
<prefill>true</prefill>
</pool>
<security>
<user-name>CORE_DBO</user-name>
<password>password</password>
</security>
</datasource>
and jndi.prefix is defined in system-properties:
<system-properties>
<property name="jndi.prefix" value="java:"/>
</system-properties>
I can see it using the CLI, but when trying to resolve it, I am told that it is unrecognized:
[standalone#localhost:9990 /] cd system-property
[standalone#localhost:9990 system-property] cd jndi.prefix
[standalone#localhost:9990 system-property=jndi.prefix] ls
value=java:
[standalone#localhost:9990 system-property=jndi.prefix] /subsystem=datasources/data-source=${jndi.prefix}\/CORE_Pool/:read-resource
Unrecognized system property jndi.prefix
I have tried swapping the ${jndi.prefix} in the datasource with the literal value java: and that worked, but we have tons of environments that would have to be updated, so I am not fond of that solution.
Why can't the CLI resolve this variable when it is clearly defined?

The system properties you can use in the CLI aren't the ones defined in your Wildfly configuration :
System property values used in management CLI commands must have already been defined in order to be resolved. You must either pass in a properties file (--properties=/path/to/file.properties) or property value pairs (-Dkey=value) when starting your management CLI instance. The properties file uses a standard KEY=VALUE syntax.
(source for EAP, but it's most probably the same for Wildfly)

Related

jboss standalone-full.xml ,min-pool-size and max-pool-size issue

need a help, i have a java application which is running on jboss -6. recently we got a requirement to keep our min-pool-size and max-pool-size same, along with prefill value should be "true'.
<pool>
<min-pool-size>100</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>true</prefill>
</pool>
By default our standalone-full.xml has following datasource:
<datasource jta="false" jndi-name="java:jboss/<datasourcename>" pool-name="<datasourcename>" enabled="true" use-java-context="true" statistics-enabled="true">
<connection-url>jdbc:mysql://<dbhostip>:<port>/<dbdetailsForconnection></connection-url>
<driver>mysql</driver>
<pool>
<max-pool-size>100</min-pool-size>
<prefill>true</prefill>
</pool>
we have requirement to set pool size like below:
<pool>
<min-pool-size>100</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>true</prefill>
</pool>
but every time when we make changes , our war files failed to get deployed. We are getting following error:
IJ000610: Unable to fill pool: javax.resource.ResourceException: Could not create connection
When we define our connection pool setting like below:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Too many connections
Approaches I tried:
*remove datasource from jboss-cli and add datasource again
*directly edit standalone-full.xml
*after every change :reload it.
*do the deployment and then edit xml ,reload afterward
*before deployment ,edit, reload
Solution: I have two solution to make it work :
min pool should be less than max
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>true</prefill>
</pool>
Remove profill, as it will take min pool size as default to fill up the connection
<pool>
<min-pool-size>100</min-pool-size>
<max-pool-size>100</max-pool-size>
</pool>
but these solution are against the requirement.
After lots of head scratching, finally i have resolved this issue by increasing max connection limit in my db serveri.e mysql .
after set max_connection limit. it start working

How to enable failover for a postgresql jdbc data source

I have a data source defined in a Liberty application server for postgresql
<dataSource jdbcDriverRef="PostgreSQLDriver" ...>
<properties password="..." user="admin" serverName="server" portNumber="2020" databaseName="dbname" ssl="false"
</dataSource>
I see that I can enable failover on a jdbc connection by specifying a url like:
jdbc:postgresql://host1:port,host2:port,host3:port/dbname
Is there any way that this failover url can be provided to a application server datasource?
Yes, you can specify any key/value pair on the <properties> element and Liberty will supply it to the vendor data source class. In this case, the property would be URL="jdbc:postgresql://host1:port,host2:port,host3:port/dbname"
Also, note that in more recent versions of Liberty, there is a properties.postgresql which is specific to Postgres and better documents the available settings for it.
Here is an example,
<dataSource jdbcDriverRef="PostgreSQLDriver" ...>
<properties.postgresql password="..." user="admin" URL="jdbc:postgresql://host1:port,host2:port,host3:port/dbname" ssl="false"
</dataSource>

Set system properties in standalone-full.xml in wildfly 8.2

I have added system-properties tag in standalone-full.xml, but its not working in standalone mode. However, if I add the same tag in domain.xml it's working for domain mode.
<?xml version='1.0' encoding='UTF-8'?>
<server xmlns="urn:jboss:domain:2.2">
<extensions>
....
</extensions>
<system-properties>
<property name="java.util.Arrays.useLegacyMergeSort" value="true"/>
</system-properties>
</server>
According to this article on jBoss General configuration concepts
System property values can be set in a number of places in domain.xml, host.xml and standalone.xml.
Then what about standalone-full.xml?
I don't want to set it through command line and not even in java code.
In standalone it's probably too late to set it in the configuration files. You'll need to add it to the standalone.conf or standalone.conf.bat in the JAVA_OPTS environment variable. A global property like that needs to be set before anything else attempts to use java.util.Arrays.
If you have started the Wildfly server with standalone-full.xml instead of standalone.xml(the default) than this should be reflected in the start of the server:
standalone.sh -b <hostIP> -c standalone-full.xml -Dorg...
Then this will have effect on first start.
If you change something in this config file, you will need to reload Wildfly(configuration) from jboss cli:
[standalone#localhost:9990 /] :reload
For Wildfly 10 it's working nontheless. I was able to read the property for an instance started with the standalone-full.xml containing some properties.
The manual must be outdated then I guess? Because even Wildfly itself inserts a new property in the standalone-full.xml when using the Wildfly admin webinterface: http://localhost:9990 > Configuration > System Properties (Wildfly will add the property of course to the xml config which was used to start the instance). That's enough proof for me.

Loading properties from a file in a JBoss 6 Web Application

Can I dump a properties file somewhere in one of the JBoss 6 directories, and pick it up from the classpath?
Or even better, does anybody know the mechanism behind a configuration file like $JBOSS_HOME/server/default/deploy/jboss-logging.xml? Changes to this file seem to trigger an event, so that a running instance can process the modifications (without having to bounce the AS).
A possibility is to configure SystemPropertiesService in ./conf/jboss-service.xml.
This allows you to configure system properties in-place, or load them from a properties file:
<server>
<mbean code="org.jboss.varia.property.SystemPropertiesService"
name="jboss.util:type=Service,name=SystemProperties">
<!-- Load properties from each of the given comma seperated URLs -->
<attribute name="URLList">
http://somehost/some-location.properties,
./conf/somelocal.properties
</attribute>
<!-- Set propertuies using the properties file style. -->
<attribute name="Properties">
property1=This is the value of my property
property2=This is the value of my other property
</attribute>
</mbean>
</server>
For more details, refer to: http://docs.jboss.org/jbossas/admindevel326/html/ch10.html
They have made this even easier in JBoss EAP 6 (AS 7).
Pass Property File as Startup Parameter
This can be added within the main start up script or passed as parameter
./standalone.sh --properties=/Users/john.galt/dev/config/ds/jboss.properties
If these properties are read, they will be rendered in the server log as the first statement.
3:58:41,633 DEBUG [org.jboss.as.config] (MSC service thread 1-6) Configured system properties:
DSsettings.password = password
DSsettings.user-name = admin
DSsettings.connection-url = jdbc:oracle:fat:#activedb:1521:DEV
[Standalone] =
awt.nativeDoubleBuffering = true
NOTE: As these settings are logged in server log, ensure no clear text passwords are in the property files in production
Use passed in system properties
You could use these system properties with following syntax.
Example Usage in a data source file
<xa-datasource jndi-name="java:jboss/ds" pool-name="cPool" jta="true" enabled="true" use-ccm="true">
<xa-datasource-property name="URL">
${DSsettings.connection_url}
</xa-datasource-property>
<driver>oracle</driver>
...
<security>
<user-name>${DSsettings.user-name}</user-name>
<password>${DSsettings.password}</password>
</security>
...
</xa-datasource>
In JBoss 6 use: ./deploy/properties-service.xml
On JBoss AS7 properties-service.xml no longer exist, the below is the solution:
http://www.mastertheboss.com/jboss-server/jboss-configuration/how-to-inject-system-properties-into-jboss

How to make use of variables in Wildfly configuration file?

I am setting up a common standalone-full.xml file for all server environments, and therefore need to have variables for database URL's (and such), instead of hard coding them.
One such section in the configuration file might look like this:
<datasource jta="true" jndi-name="java:/somename" pool-name="somename" enabled="true" use-ccm="false">
<connection-url>jdbc:mysql://${SOMENAME_DB_URL}</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver>mysql</driver>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>15</max-pool-size>
</pool>
<security>
<user-name>${DB_USERNAME}</user-name>
<password>${DB_PASSWORD}</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
However, upon starting the server with this config file it simply throws an "Unable to resolve expression" error for all such sections.
I've tried putting the variables in /etc/environment, as well as in the .jbossclirc file in /bin using set DB_USERNAME=mydbusername, but to no avail.
As you can see I'm fumbling a bit in the dark here since I haven't been able to find any proper documentation on how to do this. I'm not even sure if it's actually possible. Any help is greatly appreciated.
You should use Java system properties instead of environment variables.
You can also pass these properties as -D arguments to standalone.sh, e.g.
bin/standalone.sh -DDB_USERNAME=me -DDB_PASSWORD=secret
Alternatively, you can define your properties in a properties file and pass that to the startup script with a -P option:
bin/standalone.sh -P database.properties
Does overriding standard properties from Wildfly work that way?
For example jboss.http.port from standalone.xml
<socket-binding name="http" port="${jboss.http.port:8080}"/>
One possibilty is to call standalone.sh -Djboss.http.port=8081. Then, Wildfly http port should be on 8081.
It should also work for your own variables.