Play Framework [2.1.1-java] deployment error on Heroku - java

I developped my application locally with the default in memory h2 database. Everything works perfectly.
Now I tried to deploy my app by pushing to Heroku.
Before that I added a Procfile to my app's root folder with this line:
web: target/start -Dhttp.port=${PORT} -DapplyEvolutions.default=true -Ddb.default.url=${DATABASE_URL} -Ddb.default.driver=org.postgresql.Driver
My application.conf looks like:
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play;MODE=PostgreSQL"
So I pushed that and then, when I try to access my app i get:
Salieri:addressManager administrator$ heroku ps
=== web (1X): `target/start -Dhttp.port=${PORT} -DapplyEvolutions.default=true -Ddb.default.url=${DATABASE_URL} -Ddb.default.driver=org.postgresql.Driver`
web.1: crashed 2013/06/27 22:04:16 (~ 4m ago)
and in the heroku logs:
2013-06-27T20:04:14.511136+00:00 app[web.1]: [error] play - ERROR: syntax error at or near "user"
2013-06-27T20:04:14.515578+00:00 app[web.1]: at play.api.db.evolutions.Evolutions$.databaseEvolutions(Evolutions.scala:334)
2013-06-27T20:04:14.515153+00:00 app[web.1]: #6emdb57b1: Database 'default' is in inconsistent state!
I tried to delete the whole db with
heroku pg:reset HEROKU_POSTGRESQL_ROSE_URL
and then i pushed again, but no success.
I have to mention that I did a push before, and at that time my app was running on Heroku. The only problem was, that i couldn't log in with the credentials provided in my fixtures (Global.java file with a job on app start).
Any suggestions?

From this error:
ERROR: syntax error at or near "user"
I guess your Evolution scripts are wrong. User is a reserved word in SQL. PLease try to run the Evolution scripts locally in a dev PostgreSQL database. Once working, you can try to deploy again.
I'd also suggest disabling evolutions for production apps, it's a risky system sometimes.

PostgreSQL interprets user as a keyword. If you have an app/models/User class in your app, play will try to create a table named user. The easiest way to avoid this is to rename your User class to something like MyUser. (The same might happen if you use an attribute named user in one of your classes. Here, as well, you should rename it).
Then you should run your application locally and open it in the browser in order to get the evolution script file updated. You can then find the evolution script at conf/evolutions/default/1.sql. According to this example, it should create a table named my_user now.

Related

Elastic Beanstalk fails creating

I finally reached the point where my Elastic Beanstalk Instance / Environment got launched. (Java Corretto 11 Platform) Now it fails starting up the provided .jar file.
In the eb-engine.log file, I am not able to find any more error than this:
2021/05/27 11:36:25.889735 [INFO] Executing instruction: StageJavaApplication
2021/05/27 11:36:25.889871 [ERROR] An error occurred during execution of command [app-deploy] - [StageJavaApplication]. Stop running the command. Error: staging java app failed due to invalid zip file
The jar file is a Spring Boot application built with mvn -B package.
Locally the whole thing starts, but crashes afterwards because of not given environment variables (Expected behaviour).
But it seems AWS is not even starting the application..
Any suggestions on this?
Spring Boot apps run nicely on Elastic Beanstalk. However, you do need to set some variables. For example, have you set server-port variable to 5000?
And as you stated, to successfully use a Service Client, you can set environment variables for your creds. Here is an end to end walkthrough that shows how to successfully put a Spring BOOT app that invokes several AWS Services on Elastic Beanstalk.
Creating your first AWS Java web application
PS - your log file mentions a ZIP file. Be sure to create the JAR properly as discussed in the above example.
Just in case someone arrive here looking for an answer about this guy:
Error: staging java app failed due to invalid zip file
I was renaming my service jar in Gradle, using:
tasks.withType<org.springframework.boot.gradle.tasks.bundling.BootJar> {
archiveFileName.set("service.jar")
launchScript()
}
And ElasticBeanstalk was not happy about the renaming.
When I let it have the default name, then no zip issues and all worked like a charm.

Spring Boot War File Tomcat 9 Deployment Help Status 500 Error

UPDATE 8/12/2020 approx. 11:00 AM - I checked my logs folder catalina.2020-08-12.log log in the tomcat9 ($CATALINA_BASE) folder and I found three exceptions "org.apache.catalina.LifecycleException: Protocol handler intialization failed", "java.net.BindException: Address already in use (bind failed)","java.lang.IllegalArgumentException: Invalid character found in the HTTP protocol [HTTP/1.10x0aHost:]".
Here is the full error log here: https://drive.google.com/file/d/1pSk5ESHLIRP5Srxwr4R1Tp_1TTcYMf2Y/view?usp=sharing and https://drive.google.com/file/d/1C-RALR3066_hYKeoo4dIJqTKwNDOQ0R0/view?usp=sharing.
UPDATE 8/12/2020 approx. 11:30 AM - I found that there are two servlet dispatchers running by checking the localhost.2020-08-12.log log when I restarted tomcat and tried to access my api again: https://drive.google.com/file/d/1GFKUIDLtZrAraHyMjyyWV9kXK33gQ-Mu/view?usp=sharing.
UPDATE 8/12/2020 approx. 11:35 AM - HA HAAAA I looked in the catalina.out log (finally some of you guys were probably yelling at the screen like "CHECK THE CATALINA.OUT FILE"). I checked it and I found the exception: "java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required": https://drive.google.com/file/d/1A7ZLh70IHOmWXfQ56bgtq951EE_AX68P/view?usp=sharing. Now if I go to my PostgresDataSource class which is where my Hikari config is: https://drive.google.com/file/d/1lYN1dTqiAM4ZqliRGC5J5_VWhNeN-k2d/view?usp=sharing, and I review my application.yaml file from earlier: https://drive.google.com/file/d/1xvPhPneVjMU4BoN6F0Q63l2wCnF20BYq/view?usp=sharing, the jdbc url is present because it is the same one I used for developing. Now postgres is already set up and I manually made all of the tables on the ubuntu droplet. I did not download the jdbc postgresql driver for tomcat yet.
UPDATE 8/12/2020 approx. 1:20 PM - After setting up the jdbc driver now I get this error from catalina.out logs: " Failed to get driver instance for jdbcUrl=java:/comp/env/jdbc:postgresql://localhost:5432/****" and then I get "Caused by: java.sql.SQLException: No suitable driver". I used the postgresql section of this link to set it up: https://tomcat.apache.org/tomcat-9.0-doc/jndi-datasource-examples-howto.html.
Hi I am using Digital Ocean with apache tomcat 9 to deploy a war file that is generated using IntelliJ. I have the war file generated using mvn clean install and I get the default tomcat page when I go to the droplet IP address on port 8080. I am not sure why I get a 500 error with no stack trace information even though my spring boot application works fine when I run it in IntelliJ. My CSS styling also does not show up when I go to my hosted application I have tried to configure a few things in my application.yml file and it still does not work. I figured it might have to do with a spring security issue with CORS, but I am not knowledgeable enough in that area to know for sure. I started my server by using sudo $CATALINA_HOME/bin/startup.sh and it said tomcat started and it showed the default tomcat page when I went there in the browser. I used the hobynapi.war file in my target folder a picture of my target folder directory can be viewed here https://drive.google.com/file/d/1XXga1Bgf5-_81gceuWjpvVIX6J0jiNgQ/view?usp=sharing. I copied the war file that was generated after using mvn clean install to the /var/lib/tomcat9/webapps folder. I then ran sudo $CATALINA_HOME/bin/startup.sh again and it ran tomcat successfully again. Then the error happened as I tried to log in with the admin account with spring security basic authentication where I get the 500 error. I also have no artifacts in the artifact section of the project structure settings if that means anything.
UPDATE 8/12/2020 approx. 10:00 AM - I've removed the exclusions tag in the pom.xml file as well as the profiles tag at the bottom of the file. This is because I read here that using the spring-boot-starter-tomcat dependency removes the embedded server for you: https://developer.okta.com/blog/2019/04/16/spring-boot-tomcat.
This is the screen without the CSS styling that should be there:
https://drive.google.com/file/d/1CEKuB556ek8pTZspvprNTa9M5XCI7qtT/view?usp=sharing
This is the error I get without a stack trace:
https://drive.google.com/file/d/19gYGQFhZdZ_4IwwGE5tQzb4dTqlBpg9L/view?usp=sharing
These are pictures of my pom.xml file:
https://drive.google.com/file/d/1ir5uBuBuJqCb_U8Jarly9mraO468QA_y/view?usp=sharing
https://drive.google.com/file/d/1ma1_EPro4NvJiOy8lWPrAmGLMrVWHZPS/view?usp=sharing
https://drive.google.com/file/d/11NDIwA9g02zkCKnsmYSLSNF5R-BrFpgt/view?usp=sharing
https://drive.google.com/file/d/1p6T9-oOwyfj7NUsLxTRLtqXKHU4qHrZx/view?usp=sharing
https://drive.google.com/file/d/1spD7KT-3WBo7KFF0Hb_WgJ5dVKRHF-un/view?usp=sharing
https://drive.google.com/file/d/16QtJQtT9zaU7nGcpnm2KXJ6jiLywNt5s/view?usp=sharing
https://drive.google.com/file/d/1cnZJshFS5xW-HbeaH_C_e6KcDo9xYRdY/view?usp=sharing
This is my application.yml file:
https://drive.google.com/file/d/1xvPhPneVjMU4BoN6F0Q63l2wCnF20BYq/view?usp=sharing
https://drive.google.com/file/d/1B9_5WueRvqQv4ODsJAfbUzGIm-xaaSYV/view?usp=sharing
This is my main application java file:
https://drive.google.com/file/d/1K9lzzlzIKT8irqXsPY1WeiBvN-9vsoWT/view?usp=sharing
This is my web config file in my config package:
https://drive.google.com/file/d/19EYa2kkqqPu9Wh8nN-U02szSVBT30lOP/view?usp=sharing
https://drive.google.com/file/d/11Zw8dLrAu6c_OI29j0NsljvXdeDam0-t/view?usp=sharing
This is my spring security config file in my config package:
https://drive.google.com/file/d/1inqlTjfxahcF6ZeJ_xkJM18UgsDu119n/view?usp=sharing
https://drive.google.com/file/d/1nTeYiKhiNOH71Km-s_T4IT1BKRyJG4mS/view?usp=sharing
I hope that these pictures help for diagnosing the issue.
I figured it out. First I changed the postgres jdbc url back to the original one that I had and then I altered my data source config file to the following: https://drive.google.com/file/d/1Zmv8cfnVzW8NcQfjNxN14D4aKFaXpdfU/view?usp=sharing. One important thing I also messed up on was not setting a password for the default user "postgres" when downloading postgresql. I did this my calling "ALTER USER postgres PASSWORD 'myPassword';" in the postgresql command line. Also make sure that you use systemctl restart postgresql after any changes are made to postgresql in the postgresql command line.

Running tests on travis using mysql

I've been trying for the last week or so to make integration tests work on travis for a school project. I've debugged a fair bit of the project but now I'm blocked and need external help.
To give a bit of context, so far, I've debugged the java project so that the tests can be launched from eclipse or from maven in command line. I've worked on the travis file so that a database is created, the database scripts run and the java tests launch. However, the tests fail on travis because of a "table missing" in the database.
This is a link to our repo.
This is the travis.yml file's code:
language : java
jdk:
- oraclejdk8
service:
- mysql
before_script:
- mysql -e 'DROP DATABASE IF EXISTS koalatest'
- mysql -e 'CREATE DATABASE IF NOT EXISTS koalatest;'
- mysql -u root --default-character-set=utf8 koalatest < backend/koalacal-backend/koalacal.sql
script: cd backend && cd koalacal-backend && mvn test -X
after_success:
- bash <(curl -s https://codecov.io/bash)
The java project that is being built and run by maven is located under rootfolder -> backend -> koalacal-backend.
Here is a link to the error log maven produces on travis.
This line seems to be the source of the error:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'koalatest.Calendar' doesn't exist
I have two hypothesis:
1- The sql script that creates all the tables is not being run properly by travis.
To test this hypothesis, I changed the name of the script called by travis. As expected, I got an error saying that travis can't find the file. So at least, I know that this line of code causes travis to look up at an sql file.
- mysql -u root --default-character-set=utf8 koalatest < backend/koalacal-backend/koalacal.sql
That being said, I have no idea if the file is run properly on the database.
For the sake of putting all relevant informations in this post, here is a link to the database script.
2- The tests can't connect properly to the database.
Here is the config file that contain the info regarding which database to connect to:
TestInstance=true
user=root
password=
serverName=localhost
databaseName=koalacal
portNumber=3306
testUser=root
testPassword=
testServerName=127.0.0.1
testDatabaseName=koalatest
testPortNumber=3306</code>
If the parameter TestInstance is set to true, the tests take the informations testUser, testPassword, testServerName, testDatabaseName and testPortNumber to connect to the relevant database.
I believe the connection informations currently contained in the config file match how the travis documentation says we need to connect to a mysql database. I tried to change the testUser to something invalid (like root3) and got error messages as expected.
Maybe somehow the tests can't connect to the database and don't produce a related error message, but I doubt it.
Can someone look at my problem and see if I've missed something obvious (or not)? I don't know what else to try and I don't want to be blocked one more week on a technical issue.
For anyone who may google travis mysql and has a similar error to the one I had, I solved my problem.
The error was caused by a case sensitivity issue. The java code tried to connect to tables like 'Calendar' and 'Event' while the sql script created the tables 'calendar' and 'event'.
It took a long time to troubleshoot this because the case sensitivity didn't pose any problem on my machine. Maven can run its tests properly without any issue. It's only on the travis servers that case sensitivity of the tables started to matter.

Play Framework does not apply Evolutions in Production mode

I recently deployed my Play App to a Heroku-Server. Running the App in Production-Mode leads to the following Error for each db-table:
Caused by: javax.persistence.PersistenceException: Query threw SQLException:ERROR: relation "tablename" does not exist
Procfile
web: target/universal/stage/bin/myApp -Dhttp.port=${PORT} -DapplyEvolutions.default=true -DapplyDownEvolutions.default=false -Ddb.default.driver=org.postgresql.Driver -Ddb.default.url=${DATABASE_URL}
I had the same issue deploying the app on another (non-heroku) server. Solved it there by first running in dev-mode to apply the schema and then switch to production.
Is there a reason for having the -DapplyDownEvolutions.default=false in your Procfile command? I'm not sure how that might interact with the -DapplyEvolutions.default=true...it might be worth trying without it.
If that does not work, you could run the evolutions in a one-off process like so:
$ heroku run bash
...
~$ ./target/universal/stage/bin/myApp -DapplyEvolutions.default=true -DapplyDownEvolutions.default=false -Ddb.default.driver=org.postgresql.Driver -Ddb.default.url=${DATABASE_URL}
Once that completes, you're other dynos should be good to go. However, this creates a period in which the app is deployed, and the evolutions have not been run.

Service will not start: error 1067: the process terminated unexpectedly

We have a custom service that we install with our application. The only problem is that after it is installed, it will not start, generating the error above. I have tried to diagnose what the problem is, but can't seem to find any useful information as to why it is quitting. I have tried the same service on a non "R2" 2008 server, and manual it worked fine.
service simple java file running using batch file. Deamon service.
Has anyone had any experience troubleshooting this type of problem, where there are so few clues?
Goto:
Registry-> HKEY_LOCAL‌​_MACHINE-> System-> Cur‌​rentControlSet-> Servi‌​ces.
Find the concerned service & delete it. Close regedit. Reboot the PC & Re-install the concerned service. Now the error should be gone.
This is a problem related permission.
Make sure that the current user has access to the folder which contains installation files.
I resolved the problem.This is for EAServer Windows Service
Resolution is -->
Open Regedit in Run prompt
Under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\EAServer
In parameters, give SERVERNAME entry as EAServer.
[It is sometime overwritten with Envirnoment variable : Path value]
This error message appears if the Windows service launcher has quit immediately after being started.
This problem usually happens because the license key has not been correctly deployed(license.txt file in the license folder).
If service is not strtign with correct key, just put incorrect key and try to start. Once started, place the correct key, it will work.
I had this error, I looked into a log file C:\...\mysql\data\VM-IIS-Server.err and found this
2016-06-07 17:56:07 160c InnoDB: Error: unable to create temporary file; errno: 2
2016-06-07 17:56:07 3392 [ERROR] Plugin 'InnoDB' init function returned error.
2016-06-07 17:56:07 3392 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2016-06-07 17:56:07 3392 [ERROR] Unknown/unsupported storage engine: InnoDB
2016-06-07 17:56:07 3392 [ERROR] Aborting
The first line says "unable to create temporary file", it sounds like "insufficient privileges", first I tried to give access to mysql folder for my current user - no effect, then after some wandering around I came up to control panel->Administration->Services->Right Clicked MysqlService->Properties->Log On, switched to "This account", entered my username/password, clicked OK, and it woked!
In my case the error 1067 was caused with a specific version of Tomcat 7.0.96 32-bit in combination with AdoptOpenJDK. Spent two hours on it, un-installing, re-installing and trying different Java settings but Tomcat would not start. See...
ASF Bugzilla – Bug 63625
seems to point at the issue though they refer to seeing a different error.
I tried 7.0.99 32-bit and it started straight away with the same AdoptOpenJDK 32-bit binary install.
I solved this issue using Monitor Tomcat application. I ran it and after a few seconds its icon appeared in my system tray. I right clicked on the icon and clicked the start button and after a few seconds Apache Tomcat started.

Categories