0
votes

Goal: Run a standalone Java & Database application in the cloud for performance, scalability and high availability

Application Details

  • Spring Boot based Java application is git cloned in to a folder on the Google App Engine Standard Environment.
  • Google Cloud SQL 2nd generation instance created

Note: The Cloud Shell is in the same Google Cloud project as the Cloud SQL

Google Cloud Shell

user@${PROJECT_ID}:~$ cd git

user@${PROJECT_ID}:~$ cd myapplication

Running application using Maven throws exception not being able to connect to the Cloud SQL database

user@${PROJECT_ID}:~$ mvn exec:java

Using different JDBC connection strings and JDBC drivers did not help.

application.properties

# Use MySQL database
#etl.datasource.url=jdbc:mysql://${IP:Instance_name}/${database}?autoReconnect=true&useSSL=false
#etl.datasource.url=jdbc:google:mysql://${INSTANCE_CONNECTION_NAME}/${database}
etl.datasource.url=jdbc:mysql://google/${database}?cloudSqlInstance=${INSTANCE_CONNECTION_NAME}&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false
#etl.datasource.driver-class-name=com.mysql.jdbc.Driver
etl.datasource.driver-class-name=com.mysql.jdbc.GoogleDriver
etl.datasource.username=${user}
etl.datasource.password=${password}

2017-08-03 10:40:59.477 ERROR 381 --- [MyApplication.main()] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool. com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

2017-08-03 12:16:23.525 ERROR 1048 --- [MyApplication.main()] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool. java.sql.SQLException: Unable to load class: com.mysql.jdbc.GoogleDriver from ClassLoader:java.net.URLClassLoader@13b428de;ClassLoader:java.net.URLClassLoader@13b428de

Even adding a src/webapp/WEB-INF/appengine-web.xml did not help.

appengine-web.xml

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
    <threadsafe>true</threadsafe>
    <use-google-connector-j>true</use-google-connector-j>
</appengine-web-app>

Questions

  1. Is Google App Engine only for Web based applications?
  2. Is the Google App Engine Flexible environment suitable for non-web console based Java applications?
  3. Or should I be using the Google Compute Engine VM platform to run such non-web console applications and similar to running on my local computer?
  4. Is there a Maven dependency that can be added for com.mysql.jdbc.GoogleDriver?
1
Are your CloudSQL instance and App in the same GCP project?sharif9876
Is the application.properties file pasted above the one which is deployed? Or is it just a representative sample pasted as an examples?Dhruv Rai Puri

1 Answers

0
votes

What you're trying to do should be absolutely possible on App Engine. There is indeed a Maven dependency you can pull for the Google Driver:

    <dependency>
        <groupId>com.google.cloud.sql</groupId>
        <artifactId>mysql-socket-factory</artifactId>
    </dependency>

Also, since you're using Spring Boot, I would suggest you give Spring Cloud GCP a try. There is a simple Cloud SQL sample there that can get you started quickly.