Skip to content

Instantly share code, notes, and snippets.

@pburkholder
Last active August 1, 2018 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pburkholder/d6301d815e8d20ccf0f301e44c89c02a to your computer and use it in GitHub Desktop.
Save pburkholder/d6301d815e8d20ccf0f301e44c89c02a to your computer and use it in GitHub Desktop.
Working with Vaadin framework and Oracle on cloud.gov

I'm working in R.H. to get the Vaadin framework on cloud.gov to work with cloud.gov and oracleDB.

What we have:

  • cloud.gov + spring-music + postgres = works
  • cloud.gov + spring-music + oracle = works
  • cloud.gov + vaadinApp + jboss buildpack + H2 = works
  • cloud.gov + vaadinApp + jboss buildpack + postgres != works
    • I thought it worked but in fact it was just falling back to H2
  • cloud.gov + vaadinApp + jboss buildpack + oracle != works

The vaadinApp I'm deploying is git@github.com:vaadin/framework-bluemix-example.git (and my fork at git@github.com:pburkholder/framework-bluemix-example.git)

Some tacks to consider:

  • get vaadinApp + pg working on bluemix
  • get vaadinApp + pg working on cloud.gov
  • get access to the vaadin admin console so R.H. can set up connections

IBM Liberty buildpack and java

You'll need licenses. If you set set up your manifest.yml like this:

---
applications:
- name: vaadin-ora
  instances: 1
  memory: 1024M
  path: target/vaadin-jpa-application.war
  env:
    IBM_JVM_LICENSE:   foo
    IBM_LIBERTY_LICENSE:  bar
  services:
    - vaadinora
  random-route: true
  buildpack: https://github.com/cloudfoundry/ibm-websphere-liberty-buildpack.git

and when the push fails, you'll get the URL for license(s)

Bluemix notes.

From https://github.com/vaadin/framework-bluemix-example,

Name the database "vaadindb" and Bluemix will automatically configure driver, DataSource and setup a proper JNDI entry the database.

git clone bluemix vaadin example
export CF_HOME=~/.cf-bluemix/
cf login
...
cf create-service compose-for-postgresql Standard vaadindb

Bluemix no longer offers free pgsql plans

Update manifest.yml to not use declared services

cf push # works after fix for random-route
cf env vaadinApp
# get uri_direct_1
psql postgres://admin:PASSWORD@sl-us-south-1-portal.29.dblayer.com:50XX2/compose

Will it still work w/ OSS libery?

Append to manifest.yml:

  env:
    IBM_JVM_LICENSE:   L-SMKR-AVSEUH
    IBM_LIBERTY_LICENSE:  L-CTUR-AYBK6Z
  buildpack: https://github.com/cloudfoundry/ibm-websphere-liberty-buildpack.git

cf push output includes:

- buildpack:           Liberty for Java(TM) (WAR, liberty-18.0.0_2, buildpack-v3.23-20180628-1052, ibmjdk-1.8.0_20180524, env)
+ buildpack:           https://github.com/cloudfoundry/ibm-websphere-liberty-buildpack.git

....

The logs on BlueMix include:

   2018-07-21T15:05:36.06-0400 [APP/PROC/WEB/0] OUT [INFO    ] J2CA8050I: An authentication alias should be used instead of defining a user name and password on dataSource[compose-postgresql-vaadindb].
   2018-07-21T15:05:36.15-0400 [APP/PROC/WEB/0] OUT [WARNING ] DSRA8020E: Warning: The property 'id' does not exist on the DataSource class org.postgresql.ds.PGConnectionPoolDataSource.
   2018-07-21T15:05:36.22-0400 [APP/PROC/WEB/0] OUT [INFO    ] CWRLS0010I: Performing recovery processing for local WebSphere server (defaultServer).
   2018-07-21T15:05:36.26-0400 [APP/PROC/WEB/0] OUT [INFO    ] CWRLS0007I: No existing recovery log files found in /home/vcap/app/wlp/usr/servers/defaultServer/tranlog//tranlog. Cold starting the recovery log.
   2018-07-21T15:05:36.26-0400 [APP/PROC/WEB/0] OUT [INFO    ] CWRLS0006I: Creating new recovery log file /home/vcap/app/wlp/usr/servers/defaultServer/tranlog//tranlog/log1.
   2018-07-21T15:05:36.39-0400 [APP/PROC/WEB/0] OUT [INFO    ] CWRLS0006I: Creating new recovery log file /home/vcap/app/wlp/usr/servers/defaultServer/tranlog//tranlog/log2.
   2018-07-21T15:05:36.73-0400 [APP/PROC/WEB/0] OUT [INFO    ] CWRLS0007I: No existing recovery log files found in /home/vcap/app/wlp/usr/servers/defaultServer/tranlog//partnerlog. Cold starting the recovery log.
   2018-07-21T15:05:36.73-0400 [APP/PROC/WEB/0] OUT [INFO    ] CWRLS0006I: Creating new recovery log file /home/vcap/app/wlp/usr/servers/defaultServer/tranlog//partnerlog/log1.
   2018-07-21T15:05:36.73-0400 [APP/PROC/WEB/0] OUT [INFO    ] CWRLS0006I: Creating new recovery log file /home/vcap/app/wlp/usr/servers/defaultServer/tranlog//partnerlog/log2.
   2018-07-21T15:05:36.76-0400 [APP/PROC/WEB/0] OUT [INFO    ] WTRN0135I: Transaction service recovering no transactions.
   2018-07-21T15:05:36.76-0400 [APP/PROC/WEB/0] OUT [INFO    ] CWRLS0012I: All persistent services have been directed to perform recovery processing for this WebSphere server (defaultServer).

Then both entities have:

   2018-07-21T15:11:43.89-0400 [APP/PROC/WEB/0] OUT [INFO    ] CWWJP9990I: Detected server platform: org.eclipse.persistence.platform.server.was.WebSphere_Liberty_Platform.
   2018-07-21T15:11:43.90-0400 [APP/PROC/WEB/0] OUT [INFO    ] CWWJP9990I: EclipseLink, version: Eclipse Persistence Services - 2.6.6.WAS-v20180515-0ab4033

BlueMix:

   2018-07-21T15:05:39.31-0400 [APP/PROC/WEB/0] OUT [INFO    ] DSRA8203I: Database product name : PostgreSQL
   2018-07-21T15:05:39.31-0400 [APP/PROC/WEB/0] OUT [INFO    ] DSRA8204I: Database product version : 9.6.6
   2018-07-21T15:05:39.31-0400 [APP/PROC/WEB/0] OUT [INFO    ] DSRA8205I: JDBC driver name  : PostgreSQL Native Driver
   2018-07-21T15:05:39.31-0400 [APP/PROC/WEB/0] OUT [INFO    ] DSRA8206I: JDBC driver version  : PostgreSQL 9.4.1212
   2018-07-21T15:05:39.55-0400 [APP/PROC/WEB/0] OUT [INFO    ] CWWJP9990I: myapp/file:/home/vcap/app/wlp/usr/servers/defaultServer/apps/myapp.war/WEB-INF/classes/_customer-pu login successful

cloud.gov:

   2018-07-21T15:11:43.91-0400 [APP/PROC/WEB/0] OUT [INFO    ] CWWJP9990I: Not able to detect platform for vendor name [Generic Component Context DataSource0Generic Component Context DataSource : jdbc/vaadindb]. Defaulting to [org.eclipse.persistence.platform.database.DatabasePlatform]. The database dialect used may not match with the database you are using. Please explicitly provide a platform using property "eclipselink.target-database".

When you cf ssh vaadinApp in ~/app/wlp/usr/servers/defaultServer you'll find runtime-vars.xml in each entity but server.xml on BlueMix has:

    <dataSource id='compose-postgresql-vaadindb' jdbcDriverRef='compose-postgresql-driver' jndiName='jdbc/vaadindb' transactio
nal='true' type='javax.sql.ConnectionPoolDataSource'>
        <properties id='compose-postgresql-vaadindb-props' databaseName='${cloud.services.vaadindb.connection.db}' user='${clo
ud.services.vaadindb.connection.user}' password='${cloud.services.vaadindb.connection.password}' portNumber='${cloud.services.
vaadindb.connection.port}' serverName='${cloud.services.vaadindb.connection.host}' ssl='true' sslMode='verify-ca' sslRootCert=
'/home/vcap/app/.compose_postgresql/cacert.pem'/>
    </dataSource>
    <jdbcDriver id='compose-postgresql-driver' libraryRef='compose-postgresql-library' javax.sql.XADataSource='org.postgresql.
xa.PGXADataSource' javax.sql.ConnectionPoolDataSource='org.postgresql.ds.PGConnectionPoolDataSource'/>
    <library id='compose-postgresql-library'>
        <fileset id='compose-postgresql-fileset' dir='${server.config.dir}/lib' includes='postgresql-jdbc-9.4.1212.jar'/>
    </library>

So... seems Liberty detects some vars, but not ours.

Working with OracleDB

Since Oracle is not open-source there are fewer resources available online to get started working with OracleDB and Cloud Foundry. We provide a few tips here.

Notes

  • Creation of Oracle DBs can take 30-40m to provision

Demo with Spring Music and Oracle

To demonstrate the core Cloud Foundry / OracleDB functionality, we'll start by deploying the Spring Music app.

First, though, one needs the proprietary Oracle database drivers. Visit the Oracle drivers' site at http://www.oracle.com/technetwork/database/application-development/jdbc/downloads/index.html and download the ojdbc8.jar from the latest available release. You will need to have a valid Oracle profile account for the download.

Then, clone the repository and make a libs/ directory:

git clone https://github.com/cloudfoundry-samples/spring-music
cd spring-music
mkdir libs/

Copy the downloaded ojdbc8.jar to the libs/ directory of spring-music.

Edit build.grade to uncomment the OJDBC compilation, as with either of the following commands:

Powershell:

(Get-Content ./build.gradle).replace("// compile files('libs/ojdbc8.jar')","compile files('libs/ojdbc8.jar')") | Set-Content ./build.gradle

*nix Shells:

sed -i -e "s|// compile files('libs/ojdbc8.jar')|compile files('libs/ojdbc8.jar')|" build.gradle

After installing the 'cf' command-line interface for Cloud Foundry, and logging in to cloud.gov, cf login --sso -a https://api.fr.cloud.gov, the application can be built and pushed using these commands:

cf create-service aws-rds medium-oracle-se2 spring-oracle
./gradlew clean assemble
cf push --no-start
cf bind-service spring-music spring-oracle
cf restart spring-music

When the restart completes, you can visit the app and view in the upper-right-hand i button that it's now using an OracleDB, or view the /appinfo path, as in: curl https://spring-music-ADJECTIVE-ANIMAL.app.cloud.gov/appinfo

Connecting to Oracle

Install instantclient-basiclite and instantclient-sqlplus for your operating system.

Use cf env spring-music to find database connection information under System-Provided -> VCAP_SERVICES -> aws-rds. E.g.:

> cf env spring-music
Getting env variables for app spring-music in org test-org / space pdb-noaa as peter.burkholder@gsa.gov...
OK

System-Provided:
{
 "VCAP_SERVICES": {
  "aws-rds": [
   {
    "binding_name": null,
    "credentials": {
     "db_name": "ORCL",
     "host": "cg-aws-broker-prod.RANDOMSTRING.us-gov-west-1.rds.amazonaws.com",
     "password": "secretpassword",
     "port": "1521",
     "uri": "oracle://random-username:secretpassword@cg-aws-broker-prodRANDOMSTRING.us-gov-west-1.rds.amazonaws.com:1521/ORCL",
     "username": "random-username"
    },
...

Make an SSH tunnel from your workstation to Cloud Foundry to the OracleDB using the host: value, e.g. using port 15210 on the localhost:

cf ssh -N -L 15210:cg-aws-broker-prod.RANDOMSTRING.us-gov-west-1.rds.amazonaws.com:1521 spring-music

Now connect using sqlplus username/password@host:port/ORCL, where host is localhost and port is the first part of the -L connection string above. e.g.:

./sqlplus random-username/password@localhost:15210/ORCL

Then you can use SQLPLUS commands like SELECT table_name FROM user_tables;

Connecting to databases w/o a bound application

The above steps assume you have a working application to bind to the database. Suppose you're still debugging/experimenting and your application doesn't deploy? While you can obtain connection information with Cloud Foundry service keys, you need a running application for your cf ssh tunnel to work.

As a workaround, you can push a simple static site, bind the database to that application, and then follow the above steps. Here's an example:

mkdir sample
cd sample
echo 'Hello World' > index.html
touch Staticfile
cf push hello -m 64M
cf bind-service hello spring-oracle
cf env hello  # obtain connection information
cf ssh -N -L 1521:cg-aws-broker-prod.RANDOMSTRING.us-gov-west-1.rds.amazonaws.com:1521

In a separate shell, you can then run your sqlplus command.

Working with maven and Oracle's ojdbc8.jar

Download ojdbc8.jar

Install into local repository:

mvn install:install-file -Dfile=ojdbc8.jar -DgroupId=com.oracle -DartifactId=ojdbc8 -Dversion=12.2.0.1 -Dpackaging=jar

Add to pom.xml

Add this to pom.xml:

```xml
      <dependency>
          <groupId>com.oracle</groupId>
          <artifactId>ojdbc8</artifactId>
          <version>12.2.0.1</version>
      </dependency>
```>
@pburkholder
Copy link
Author

http://ryanjbaxter.com/2015/03/02/bluemix-java-developers-your-life-just-got-a-little-easier/

Some notes from Ramon:

Here are some of my research findings so far. I'm still looking into it, but I hope the Cloud.gov engineering group can make use of this information.

https://github.com/cloudfoundry/javabuildpack/issues/189

This is a request to see if it's possible to add jndi to the java build pack. They indicated that they would not be moving in that direction and other solutions such as spring cloud connector might be a better approach.

https/youtu.be/T8SPV4rnxjg -- this is a very good presentation from a conference that explains a lot of the concepts behind Spring cloud project and the integration with various cloud platforms such as cloud foundary and others.

The idea seems to be a little different from what people like myself, who have limited experience with cloud platforms, are uyse to doing. Normally we configure local application servers with data sources that provide access to some database. You create a jndi entry in the application, deploy to the same server and everything works.

The spring project seems to be able to parse the various cloud environmental vcap variables, etc and connect to the data service. Using the API from the project you would expose the data source directly in the application that you are deploying and the rest should work as before.

http://ryanjbaxter.com/2015/03/02/bluemix-java-developers-your-life-just-got-a-little-easier/

Simplify Cloud Applications using Spring Cloud Connectors

-- this is a project on ibm bluemix platform ( also cloud foundary) that builds on the spring cloud connector project. You can just add a maven entry to use it. You can also use Maven entries that point directly to the official spring cloud connector project.

The bluemix project is just an extension of the spring project the official spring project. It gives you all the functionality of the official project with some custom functionality on the bluemix platform.

This might be an interesting approach for Cloud.gov. If Cloud.gov published a similar library in the public maven repository, it would be a easy reference to find and hopefully use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment