Well the expected way to define datasources is to do what the template
example I provided does, in which case the image will actually generate the
entire datasource definition for you.

I'm not sure if the v3 images have the same behavior as v2 with respect to
env variables (in v2 we would scan the entire app server config file for
any references to an env variable, and perform substitution).  I thought
that behavior was carried to v3, but not sure and maybe there are only some
files it scans and some it doesn't.

Rob Cernich might be able to shed more light on the expected behavior there.



On Wed, Feb 17, 2016 at 9:39 AM, [email protected] <[email protected]>
wrote:

> Hello,
>
> I have deployed my aplication like this:
>
> oc new-app --name myadmin jboss-webserver30-tomcat7-openshift~http://
> <...>MYADMIN.git
>
> I set the following environment variable:
>
> oc env dc/myadmin MYADMINDB_PORT=3306
>
> And i check that the environment variable is set:
>
> oc get pods
> NAME                READY     STATUS    RESTARTS   AGE
> myadmin-4-x2kw7     1/1       Running   0          1m
> myadmindb-2-8jc15   1/1       Running   0          2h
>
> oc env pods/myadmin-4-x2kw7 --list
> # pods myadmin-4-x2kw7, container myadmin
> MYADMINDB_PORT=3306
>
> In my Java proyect, i have the file:
>
> configuration/context.xml
>
> with the following JNDI datasource definition:
>
> <Resource name="jdbc/myadmin1"
> url="jdbc:mysql://myadmindb:${MYADMINDB_PORT}/myadmin"
> driverClassName="com.mysql.jdbc.Driver"
> username="myiadminuser"
> password="myadminpass"
> auth="Container"
> type="javax.sql.DataSource"
> maxActive="20"
> maxIdle="5"
> maxWait="10000"
> />
>
> When i deploy the POD the logs are:
>
> ...
> Caused by:
> com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
> Cannot load connection class because of underlying exception:
> 'java.lang.NumberFormatException: For input string: "${MYADMINDB_PORT}"'.
>         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> Method)
>         at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
>         at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
>         at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
>         at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
>         at com.mysql.jdbc.Util.getInstance(Util.java:386)
>         at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
>         at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
>         at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
>         at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
>         at
> com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:359)
>         at
> org.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
>         at
> org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
>         at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1558)
>         at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1547)
>         ... 117 more
> Caused by: java.lang.NumberFormatException: For input string: "${
> MYADMINDB_PORT}"
>         at
> java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
>         at java.lang.Integer.parseInt(Integer.java:569)
>         at java.lang.Integer.parseInt(Integer.java:615)
>         at
> com.mysql.jdbc.NonRegisteringDriver.port(NonRegisteringDriver.java:882)
>         at
> com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:350)
>         ... 121 more
> ...
>
> So, it shows there is no replacement of the TOKEN ${MYADMINDB_PORT} with
> its environment value 3306.
>
> I set explicitly the value 3306, and rebuild, this JNDI datasource works.
>
> NOTE: In this example, i have reduced the tokens in the JNDI datasource
> just to MYADMINDB_PORT for testing porpuse. I real world the JNDI
> datasource shouldn't have any explicit value, just the tokens to be
> replaced by environment variables.
>
> Thanks,
>
> Andrés.
>
> El 11/02/2016 a las 21:08, Ben Parees escribió:
>
> You can always add the appropriate env variables to your "myadmin"
> deployment config using the "oc env" command, and then redeploy it.
>
>
> On Thu, Feb 11, 2016 at 2:52 PM, Andres <[email protected]> wrote:
>
>> Hello,
>>
>> In this template you can create at the same time a MySQL server and a
>> Tomcat7. The Tomcat7 DataSource is configured with the environment
>> variables at the creation time.
>>
>> But my case is that i have already deployed and configured the MySQL
>> server with:
>>
>> oc new-app --name mydb mysql-persistent -p DATABASE_SERVICE_NAME=xxx -p
>> MYSQL_USER=xxx -p MYSQL_PASSWORD=xxx -p MYSQL_DATABASE=xxx
>>
>> And i want to deploy some separate build just with a Tomcat7, for exaple
>> with:
>>
>> oc new-app --name myadmin jboss-webserver30-tomcat7-openshift~http://
>> <...>/MYADMIN.git
>>
>> Or other posible situation could be to need several datasources defined
>> in context.xml pointing to diferent DDBB.
>>
>> Thanks,
>>
>> Andrés.
>>
>>
>> El 09/02/2016 a las 18:59, Ben Parees escribió:
>>
>> This template illustrates it:
>>
>> https://github.com/jboss-openshift/application-templates/blob/master/webserver/jws30-tomcat7-mysql-persistent-s2i.json
>>
>> Specifically this section defines the env variables that will be used to
>> define the datasource:
>>
>> https://github.com/jboss-openshift/application-templates/blob/master/webserver/jws30-tomcat7-mysql-persistent-s2i.json#L454-L485
>>
>> That should result in a datasource named ${APPLICATION_NAME}-mysql being
>> constructed using the various DB_XXX env variable content, where "DB" comes
>> from the "=DB" portion of the DB_SERVICE_PREFIX_MAPPING.
>>
>> Kevin, is this behavior documented somewhere?  I didn't see it in the
>> openshift image docs.
>>
>>
>>
>> On Tue, Feb 9, 2016 at 10:55 AM, [email protected] <[email protected]
>> > wrote:
>>
>>> Hi,
>>>
>>> In Openshift2, you could reference a MySQL DB from a Tomcat cartridge
>>> just defining some environment variables, that were replaced automatically
>>> in the JNDI definition at the context.xml.
>>>
>>> <Resource name="jdbc/piadmin"
>>> url="jdbc:mysql://*${OPENSHIFT_MYSQL_DB_HOST}*:
>>> *${OPENSHIFT_MYSQL_DB_PORT}*/*${OPENSHIFT_APP_NAME}*"
>>> driverClassName="com.mysql.jdbc.Driver"
>>> username="*${OPENSHIFT_MYSQL_DB_USERNAME}*"
>>> password="*${OPENSHIFT_MYSQL_DB_PASSWORD}*"
>>> auth="Container"
>>> type="javax.sql.DataSource"
>>> maxActive="20"
>>> maxIdle="5"
>>> maxWait="10000"
>>> />
>>>
>>> In OpenShift3, this doesnt work. The tokens in context.xml are not
>>> replaced by their corresponding environment variable values. What is then
>>> the correct way to connect a JNDI datasource in a Tomcat S2I like
>>> jboss-webserver30-tomcat7-openshift?
>>>
>>> Thanks,
>>>
>>> Andrés.
>>>
>>>
>>> _______________________________________________
>>> users mailing list
>>> [email protected]
>>> http://lists.openshift.redhat.com/openshiftmm/listinfo/users
>>>
>>>
>>
>>
>> --
>> Ben Parees | OpenShift
>>
>>
>>
>> Este correo electrónico se ha enviado desde un equipo libre de virus y
>> protegido por Avast.
>> www.avast.com <https://www.avast.com/sig-email>
>>
>
>
>
> --
> Ben Parees | OpenShift
>
>
>


-- 
Ben Parees | OpenShift
_______________________________________________
users mailing list
[email protected]
http://lists.openshift.redhat.com/openshiftmm/listinfo/users

Reply via email to