Env variables with Jelastic Spring Boot - jelastic

I'm using the new Spring Boot node in Jelastic.
Previously under a Tomcat node I had;
server/variables.conf
-Dspring.profiles.active=sandbox
Now under the Spring Boot node the default is;
conf/variables.conf
export JAVA_OPTS="-Xms32M -Xmn30M -Xmx1638M -Xminf0.1 -Xmaxf0.3 -XX:+UseG1GC -XX:+UseCompressedOops"
Question is, where do I put my "-Dspring.profiles.active=sandbox"?
Adding it into the export line like so doesn't seem to work?
conf/variables.conf
export JAVA_OPTS="-Dspring.profiles.active=sandbox -Xms32M -Xmn30M -Xmx1638M -Xminf0.1 -Xmaxf0.3 -XX:+UseG1GC -XX:+UseCompressedOops"
Nor on a line of its own.
Ideas?

Ah figured it out; some shells don't allow dots!
So solution now looks like;
conf/variables.conf
export JAVA_OPTS="-Dspring.profiles.active=sandbox -Xms32M -Xmn30M -Xmx1638M -Xminf0.1 -Xmaxf0.3 -XX:+UseG1GC -XX:+UseCompressedOops"
export SPRING_PROFILES_ACTIVE=sandbox

Related

how can spring boot get spring datasource config value from os environment variable?

this is my spring datasource config
spring:
datasource:
driver-class-name: org.mariadb.jdbc.Driver
url: ex.com
username: exId
password: exPw
and we know we can use os environment variable for spring datasource config like this
# export SPRING_DARASOURCE_URL=ex.com
But we can not export SPRING_DARASOURCE_DRIVER-CLASS-NAME because of '-' like this
# export SPRING_DARASOURCE_DRIVER-CLASS-NAME=org.mariadb.jdbc.Driver
So if i wanna get spring.datasource.driver-class-name via os environment variable,
what i have to do?
In most cases, any punctuation like those hyphens can be converted to underscores for the system environment variable, e.g. SPRING_DATASOURCE_DRIVER_CLASS_NAME. In some earlier versions of Spring this wasn't exactly standardized yet and some properties might drop the hyphens entirely, e.g. SPRING_DATASOURCE_DRIVERCLASSNAME.
Another approach: set the system env var, JAVA_TOOL_OPTIONS, with any desired Java/JVM options like:
JAVA_TOOL_OPTIONS=-server -Xmx1g -Dspring.datasource.driver-class-name=com.mysql.jdbc.Driver

How to set -javaagent in spark-submit

I have used aspect-oriented programming to do the logging in a Java Maven project.
While running it through eclipse I have to initialize javaagent in vmargs, as follows:
-javaagent:lib/aspectjweaver-1.9.1.jar
Now I want to submit the jar produced to a Spark worker. I have written a shell script to do it. I am able to run but unable to initialize javaagent.
export SPARK_PATH=/xyz
export SPARK_URL=spark://abc:0000
export JAVA_OPTS="$JAVA_OPTS -javaagent:../aspectweaver-1.9.1.jar"
$SPARK_PATH/spark-submit --master $SPARK_URL --jars --class com.main.index ../index-0.0.1-SNAPSHOT.jar
I have tried number of examples like setting JAVA_OPTS and CATALINE_OPTS, creating spark-env.sh and setting it. But none of this worked. Struggling from last 3 days.
I checked few similar questions on stackoverflow but none of the were helpful in setting javaagent. Help.
Thanks.
EDIT:
I am checking if javaagent is initialized in code using below code:
try {
org.aspectj.weaver.loadtime.Agent.getInstrumentation();
} catch (NoClassDefFoundError | UnsupportedOperationException e) {
System.out.println(e);
}
I get the NoClassDefFoundError. Which concludes that javaagent is not set.
I got the answer for this, I had to use "--driver-java-options". Below is the updated script.
$SPARK_PATH/spark-submit --master $SPARK_URL --driver-java-options "-javaagent:../aspectjweaver-1.9.1.jar" --class com.main.index ../index-0.0.1-SNAPSHOT.jar "$1"

Spring PropertySource based on environment

I would like to use a dynamic placeholder inside the PropertySource value options.
This is in order to have the ability to have one file for each environment which overrides the default one. Just like application.properties and application-dev.properties.
Current setup:
#PropertySource("classpath:ione.properties")
I would like to have something like
#PropertySource("classpath:ione-{optionalEnvName}.properties")
Thus reading the --spring.profiles.active=dev option.
Thanks!
Run with:
-Dspring.profiles.active=dev
and then:
#PropertySource("classpath:ione-${spring.profiles.active}.properties")
should work

Set logfile location based on OS in spring boot application.properties/.yml

I'm wondering if there's a nice clean way to set logging location based on OS just using the application.properties file in Spring Boot?
For instance is it possible to use a regex matcher on ${os.name} or would I just need to go ahead and create a groovy script or something?
My ideal solution is something like
logging:
file: ${os.name}.test(/*window*/gi) ? C:/ProgramData/Logs/ : /var/log/
You can take advantage of spring profiles and pick configurations according to the -Dspring.profile.active=some_profile system property or SPRING_PROFILES_ACTIVE=some_profile env variable.
Yaml file could be
# a safe default relative to app root
logging:
file: logs
----
spring:
profiles: nix
logging:
file: /var/log/myapp
----
spring:
profiles: win
logging:
file: C:/ProgramData/Logs/
App is executed as
java -Dspring.profile.active=nix <more opts> MyAppMain
or also:
SPRING_PROFILES_ACTIVE=nix java <more opts> MyAppMAin

Inject external properties for Apache Storm Flux

I am using Flux 1.0.0 and I have rewritten my topology into a YAML file. But I have some properties that used to be part of the configuration that I used the Storm driver to run with.
storm.Driver --config myConfig/config.conf
Now with Storm Flux, how can I inject the properties that are in config.conf into my topology?
I am currently doing java -cp myStormJar org.apache.sotrm.flux.Flux --local /src/main/resources/myTopology.yaml
I tried to use --resources option, followed by the path to the conf file, but it does not inject it.
Add the filter --resources placeholders ${resource.filter} to your yaml file.
To make the property available in the stormConf - re-declare the filter resource in config: properties.
name: "storm-topology"
config:
kafka.mapper.zkPort: ${kafka.mapper.zkPort}
kafka.mapper.zkServers: ${kafka.mapper.zkServers}
You can also review the simple_hdfs.yaml example at: https://github.com/ptgoetz/flux/tree/master/flux-examples

Resources