Play 2 & Cloudbees: Could not resolve substitution to a value - cloudbees

I am deploying my Play! 2.1 application on Cloudbees.
I have in my application.conf:
# Database configuration
# ~~~~~
db.default.driver=com.mysql.jdbc.Driver
db.default.url=${MYSQL_URL_DB}
db.default.user=${MYSQL_USERNAME_DB}
db.default.password=${MYSQL_PASSWORD_DB}
I defined those values in Cloudbees configuration:
$ bees config:list -a myself/my-app
Application Parameters:
proxyBuffering=false
MYSQL_URL_DB=jdbc:cloudbees://my-app
MYSQL_USERNAME_DB=my-app
MYSQL_PASSWORD_DB=yummy
Runtime Parameters:
java_version=1.7
I publish my app using git (git push cloudbees cloudbees:master) which triggers Jenkins. But when it comes to deploying application, I get in Jenkins logs:
[error] (compile:compile)
com.typesafe.config.ConfigException$UnresolvedSubstitution:
conf/application.conf: 16: Could not resolve substitution to a value:
${MYSQL_PASSWORD_DB}
Is there anything else to do to make Jenkins aware of the configuration? Did I misunderstand something?
Thanks for your help!
Alban

You can add "?" to the beginning, so it will be treated as an override.
db.default.url=${?MYSQL_URL_DB}
You can also handle fallback situations with this approach, if you like.
db.default.url=mysql://fallback_url
db.default.url=${?MYSQL_URL_DB}
If MYSQL_URL_DB does not exist, fallback_url will be used.

This configuration is injected at runtime, not build time. You have to find a way to make the sbt build ignore unresolved substitution.
It seems a possible workaround is to set MYSQL_URL_DB=foo, etc as build environment variables, so that the check don't break, as they won't be actually injected in your configuration

I use a config like this:
https://github.com/CloudBees-community/play2-clickstart/blob/master/conf/application.conf
and a build command like this:
java -Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=384M -jar /opt/sbt/sbt-launch-0.11.3-2.jar -Dsbt.log.noformat=true clean compile test dist
And it does not worry about the missing environment variables.
My guess is that there is a scala macro or something that triggers the compiler to resolve those variables. Adding them in is fine.
I have amended the clickstart to set default values in case they are needed.

Related

Spring Profiles in combination with ConfigServer

I have a very basic Spring Boot Config Server (just added the dependency and annotated mainclass with #EnableConfigServer).
In general I would like to support multiple environments with different propertysources for each of my applications, here is the example of the ConfigServer itself:
Profile: default (application.yml on classpath):
Profile: docker (application-docker.yml on classpath):
Profile: default (application.yml in repository of ConfigServer):
So in my case all of the properties from all of the three screenshots should be active, I'd expect the order/priority as follows:
application.yml from classpath
application-ANY_PROFILE.yml from classpath
application.yml from config repo
APP-NAME.yml from config repo (does not exists in this case)
So far this works flawlessly, except the issue that I'm having is that my application-docker.yml on classpath is beeing ignored when I start the application with the command (of course inside the container):
java -jar -Dspring-boot.run.profiles=docker *.jar
as you can see here:
My question is, even when I provide the profile as command line argument its not beeing picked up.
Why is that?
UPDATE, here is the Dockerfile and entrpoint.sh:
To activate one or more profiles do one of the following:
Activate using the VM parameters -Dspring.profiles.active=<profiles>
Activate using program arguments --spring.profiles.active=<profiles>
Following your example, the following should work:
java -jar -Dspring.profiles.active=docker *.jar

Increase memory allocated to application deployed to payara micro

Am running my application from a payara micro UberJar and would like to increase the memory allocated to the application. How can I do this at the point of creating the uberJar?
There are a couple of ways you can do this. The first way I'll mention is the preferred way:
1. Use asadmin commands
The latest edition of Payara Micro introduces an option called --postbootcommandfile which allows you to run asadmin commands against Payara Micro. Your file should include something like this:
delete-jvm-options -Xmx=512m
create-jvm-options -Xmx=1g
create-jvm-options -Xms=1g
You will need to make sure you delete the existing options before applying new ones.
You can then use the file similar to this:
java -jar payara-micro.jar --postbootcommandfile myCommands.txt --deploy myApp.war --outputuberjar myPayaraMicroApp.jar
Your settings should now persist in the resulting Uber JAR.
2. Supply a custom domain.xml
The alternative to this would be modifying a domain.xml of your own and overriding the in-built domain.xml with your own.
You can use the --rootdir option to get Payara Micro to output its configuration to a directory so you can make changes there. This process is outlined in this blog:
http://blog.payara.fish/working-with-external-configuration-files-in-payara-micro
If you already have a custom domain.xml to hand, you can use the --domainconfig property to supply it, as follows:
java -jar payara-micro.jar --domainconfig myCustomDomain.xml --deploy myApp.war --outputuberjar myPayaraMicroApp.jar
After following either of these methods, you can simply start the resulting JAR and all the settings and configuration will be applied:
java -jar myPayaraMicroApp.jar
Payara Micro uber JAR is a plain JAR and it doesn't start a new JVM like Payara Server does. Therefore there's no way to modify JVM memory settings from within the JAR as the JVM is already started. Although it's possible to add the JVM settings into the Payara Micro configuration, they are ignored and not applied. Those configuration values are only used within Payara Server.
With Payara Micro uber JAR, you need to specify the JVM options on the command line, like this:
java -Xmx=1g -Xms=1g -jar myPayaraMicroApp.jar
If you need to specify JVM arguments in the uber JAR, you need to use a solution like capsule.io to wrap the JAR into a launcher JAR that would spawn a separate JVM for Payara Micro and pass the arguments to it.

IntelliJ HTTP-Proxy works but fails at gradle dependencies

so currently at work I face the problem, that I cannot build projects, which use global dependencies. We use an auto-config proxy script, which I already set in the File->Settings->Appearance & Behaviour->System Settings->HTTP Proxy and tested with the Check Connection-function.
The check connection function is working for any arbitrary html and also for the needed gradle-file (jcenter.bintray.com/com/android/tools/build/gradle/2.0.0/gradle-2.1.0-javadoc.jar).
For solutions I already tried to:
set the Proxy Information into the gradle.properties
tried to set http and/or https proxy settings
* systemProp.http(s).proxyHost=linktoproxyconfig.org
* systemProp.http(s).proxyPort=xxxx
* systemProp.http(s).proxyUser=xxxx
* systemProp.http(s).proxyPassword=xxxx
changing the repository direction (jcenter() vs. jcenter{url http://jcenter.bintray.com}
I am aware of the fact, that one can work offline, downloading the gradle locally. But to prevent the additional maintenance of gradle versions on different machines I would like to restrain from the work offline option.
Edit: Maybe I should also add the error message:
Gradle sync failed: Connection timed out: connect. If you are behind an HTTP proxy, please configure the proxy settings either in IDE or Gradle.
I would be most grateful if someone has an idea about a solution.
IntelliJ IDEA 2017.3 does not seem to respect the proxy options for downloading Gradle. So add the proxy options to both gradle.properties and gradle-wrapper.properties, and then run ./gradlew in a terminal. This will download Gradle. After that, IntelliJ will work.
It also happend to me and the problem was that Gradle installation was wrong. I added a GRADLE_HOME environment variable and appended %GRADLE_HOME%/bin to PATH. I restarted the IDE and it worked! :)
Source: https://docs.gradle.org/current/userguide/installation.html#sec:installation_environment_variables
Another possible caveat:
Check if your environment variables for GRADLE_USER_HOME is set. Gradle will look for the gradle.properties in this directory.
I am facing the same problem because I using the proxy in Windows 10. Going to set the auto dectect the proxy fixed the connection timeout problem:
version IntelliJ IDEA 2022.1.2 (Community Edition).

How to run Apache Tomcat 8 in debug mode?

I am trying to run Apache Tomcat 8.0.21 in debug mode.
When I give the command
sh catalina.sh jpda start
it gives this error.
error message
ERROR: Cannot load this JVM TI agent twice, check your java command
line for duplicate jdwp options. Error occurred during initialization
of VM agent library failed to init: jdwp
Can anyone help ?
Either
unset CATALINA_OPTS
unset JPDA_ADDRESS
unset JPDA_OPTS
unset JPDA_TRANSPORT
catalina.sh jpda start
Or
# in .bashrc, .profile etc.
export CATALINA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000 -Djava.security.egd=file:/dev/urandom -Denv=dev -Xms1024M -Xmx2048M -XX:PermSize=256M -XX:MaxPermSize=768m"
# At your shell prompt
./startup.sh
Explanation
As Arnab said in the comments, if your shell configuration includes environment variables mentioning jdpw (such as CATALINA_OPTS, JDPA_ADDRESS, JPDA_OPTS), just launch using ./startup.sh as if you were not trying to do remote debugging and the script will pick up the jdpw option from your environment variables.
The launch option syntax catalina.sh jpda start should only be used if you don't have any environment variables that already specified a remote debug port. It's meant to be convenient but if you've previously configured your shell to support java remote debugging you're probably mixing the two alternative approaches.
You can just add env variable and run the tomcat as usual
Debug port is 8000 in this case
export CATALINA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n"
Then run the tomcat
sh ./catalina.sh start
This happened to me with Eclipse when I tried to add the debugging parameters (-Xdebug -agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=y) so I could suspend Tomcat on start. Unfortunately I then launched my Tomcat (within Eclipse) using the Debug button.
Why this is a problem
When you are launching Tomcat in Debug mode Eclipse itself inserts the debug parameters. When you have your own debug parameters in the launch configuration you are indeed passing them twice.
So if you need to launch Tomcat from within Eclipse and suspend it on start (so you can connect with debugger) you need to:
- add the debugging parameters to the "Arguments -> VM arguments" box of your launch config,
- and then Run this config, not Debug.
This way only the debugging parameters from your launch config are added.
There is alternative approach, recommended in 'catalina.sh':
"Do not set the variables in this script. Instead put them into a script
setenv.sh in CATALINA_BASE/bin to keep your customizations separate."
For Windows, the file name with environment variables will be 'setenv.bat'.
Thank you mr Dimitar II
Verified this works perfectly and is consumed automatically when running startup.bat
file: setenv.bat
#echo off
rem The proper way to set environment up for running Catalina
set "CATALINA_OPTS=-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n"

How to run WildFly with standalone-full.xml from IntelliJ IDEA?

I'm trying to run Wildfly 8.0 from Intellij IDEA. When starting WildFly through commmand-line I can use the -c standalone-full.xml parameter to use the standalone-full.xml configuration file. How can I specify this when running WildFly from Intellij IDEA?
In my opinion switch -c standalone-full.xml is not a VM Option so I will post a little bit different solution:
In the Run/Debug configuration for your server in the tab Startup/Connection you have the ability to set Startup script: On the end of line there is checkbox Use default. Please unselect it and paste on the end of the input -c standalone-full.xml
Adding -Djboss.server.default.config=standalone-full.xml to VM_OPTIONS is the equivalent of running standalone -c standalone-full.xml from a shell
As said by Mike Holdsworth -Djboss.server.default.config=standalone-full.xml works perfectly.
But there is another advantage over the -c standalone-full.xml method.
When you rename your standalone.xml file to create custom configuration files for multiple environments. Like env1.xml, env2.xml, etc.
If you use -c env1.xml, Intellij will give you the following message:
Error: HTTP management port configuration not found.
So you have to put a basic standalone.xml who will be overriden at the startup by the one you give with the -c option.
The -Djboss.server.default.config=env1.xml will prevent it.
Look out for different startup scripts for "Run" and "Debug" in Intellij IDEA. If you don't uncheck "Use default" in both of them then you can end up with two different profiles on "Run" and "Debug". It is easy to forget and annoying to figure it out.
If you want to run it by default w/o passing any command line parameters than go
to standalone.(bat|sh)
Append to the SERVER_OPTS variable: --server-config=standalone-full.xml
At least now you'll run it in full mode from any place (ide, service, command line)
I'm on a cross-platform team and we share our run configs. Modifying the startup script could cause problems (other teammate's paths and startup scripts are different), so my solution was:
Made a backup of standalone.xml
Renamed standalone-full.xml to standalone.xml
This doesn't answer the OP's question directly, but may be helpful for folks.
In the Run/Debug configuration for your server you have the ability to set VM options. You can put your switch in there. You may have problems however with jboss identifying the correct path for the file, so you may have to play with that a little bit before it works for you.
Run -> Edit configurations -> Click '+' in the top left corner -> JBoss Server -> Local
There you can configure your JBoss instance and set VM options and so on.