Search code examples
javahibernatemavengoogle-app-enginegoogle-cloud-sql

Unable to launch in GAE


I'm trying to use the codebase to test connect a Google Cloud SQL instance with a GAE Application. I was able to run it successfully in local, but it seems that it gets deployed successfully also in AppEngine, but when I try to access myproject.appspot.com, I get a 404.

Following are the steps I followed (skipping the successful local related steps).

  1. Created a project myproject
  2. Created a Google Cloud SQL 2nd Generation instance, myproject-db
  3. Created a root user with a password.
  4. Used the connection string as indicated in Google Cloud Console "jdbc:google:mysql://myproject:us-central1:myproject-db/demo?user=root&password=PASSWORD;"
  5. appengine-web.xml looks like below

    <?xml version="1.0" encoding="utf-8"?>
    <appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
    <application>myproject</application>
    <version>1</version>
    <threadsafe>true</threadsafe>
    <use-google-connector-j>true</use-google-connector-j>
    
    <system-properties>
    <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
    <property name="cloudsql.url" value="jdbc:google:mysql://myproject:us-central1:myproject-db/demo?user=root&amp;password=PASSWORD;"/>
    <property name="cloudsql.url.dev" value="jdbc:mysql://localhost/demo?user=root&amp;useSSL=false"/>
    </system-properties>
    </appengine-web-app>
    
  6. The following code snippet is embedded in HibernateJPAServlet

    if (System.getProperty("com.google.appengine.runtime.version")
                .startsWith("Google App Engine/")) {
            Class.forName("com.mysql.jdbc.GoogleDriver");
            properties.put("javax.persistence.jdbc.driver",
              "com.mysql.jdbc.GoogleDriver");
            properties.put("javax.persistence.jdbc.url",
              System.getProperty("cloudsql.url"));
        }
    
  7. I've uploaded the code from my local to default myproject repository

    https://source.developers.google.com/p/myproject/r/default

  8. I launched the Google Cloud Platform Console from the "Development" view.

  9. Successfully ran mvn clean package and mvn appengine:update. I cannot perform a appengine:update from my local due to firewall/proxy restrictions.
  10. So, at this point, my understanding is, I am running a GAE application and GAE Cloud SQL instance for the same project. So http://myproject.appspot.com/ should host the application I uploaded Step 8. But when I access it says "404" - "The requested URL / was not found on this server."

Just in case the problem is we can't deploy it from Cloud Console, then what other alternative do I have? I absolutely can't change network/proxy rules.

Edit

I tried running and deploying the application with mvn gcloud:run and mvn gcloud:deploy from outside proxy/firewall restrictions. At the end it clearly stated "Deployed URL: [https://myproject.appspot.com]". But the same issue remains when I access the same Url through browser.

Edit 2

I am able to see the error trace from App Engine dashboard. It is saying

" org.hibernate.exception.JDBCConnectionException: Could not open connection
Caused by: org.hibernate.exception.JDBCConnectionException: Could not open connection
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost."

My connection string is "jdbc:google:mysql://myproject:us-central1:myproject-db/demo?user=root&password=PASSWD123&"


Solution

  • It was my Bad (also partially Documentation gap and I've given feedback too). Everytime we deploy the app through appengine or gcloud, the newly deployed version should be visible through the "App Engine > Versions" Tab. We should "Split Traffic" and give "100%" (for testing) to the Newly deployed version and then launch "https://myproject.appspot.com" to see the results we want to see.