I am trying to dockerize my Java application which tries to connect to a Rabbitmq server. I have passed the Rabbitmq Url via docker env variable and readig the same url using
System.getenv("RABBITMQ_URL")
, but it came out to be null. Is there anything wrong with the way I am reading the docker env variable ? Here is my Docker create command :
docker service create --name xxx --env
RABBITMQ_URL=amqp://rabbitmq:xxxx --network msgq --with-registry-auth
${imageName}
This is weird but, restarting the docker container just worked fine for me. Turns out , i have to restart the container when ever I update the network connection using "--network". Thanks
Seems to work just fine for me. Please see below:
>> cat Dockerfile
FROM java
COPY Test.java /Test.java
RUN javac Test.java
CMD java Test
>> cat Test.java
class Test {
public static void main(String[] j) {
System.out.println(System.getenv("RABBITMQ_URL"));
while (true) {}
}
}
>> docker build -t testj .
Sending build context to Docker daemon 6.656kB
Step 1/4 : FROM java
---> d23bdf5b1b1b
Step 2/4 : COPY Test.java /Test.java
---> Using cache
---> 2333685c6488
Step 3/4 : RUN javac Test.java
---> Using cache
---> 8d1e98d604b9
Step 4/4 : CMD java Test
---> Using cache
---> 6f9625f04966
Successfully built 6f9625f04966
Successfully tagged testj:latest
>> docker service create --name xxx --env RABBITMQ_URL=amqp://rabbitmq:xxxx --detach testj
937rbfctrds0z1mhpk1e7dlja
>> docker service logs xxx
xxx.1.acv6mqqy38pf#moby | amqp://rabbitmq:xxxx
>>
Related
Currently my tech stack is Java, Spring Boot.
I am using application-dev.properties to keep the AWS access key and secret key.
In application-dev.properties to inject the keys I have:
#This property provide access key details
com.abc.sqs.accesskey = AWS_ACCESS_KEY
#This property provide secret key details
com.abc.sqs.secretkey = AWS_SECRET_KEY
Now from GitLab CICD .gitlab-ci.yml file while I am trying to smoke test of the application .jar I have something like this (stage is smoke test) -
smoke test:
stage: smoke-test
image: openjdk:12-alpine
before_script:
- apk add --update curl && rm -rf /var/cache/apk/*
script:
- ls -la ./app-service/target/
- sed -i "s/AWS_ACCESS_KEY/$AWS_ACCESS_KEY_ID/" ./app-service/src/main/resources/application-dev.properties
- sed -i "s/AWS_SECRET_KEY/$AWS_SECRET_ACCESS_KEY/" ./app-service/src/main/resources/application-dev.properties
- java -jar -Dspring.profiles.active=dev ./app-service/target/app-service.jar &
- sleep 30
- curl http://localhost:5000/actuator/health | grep "UP"
- curl -i -X POST http://localhost:5000/actuator/shutdown
Here I am bringing $AWS_ACCESS_KEY_ID and $AWS_SECRET_ACCESS_KEY from GitLab CICD environment variables and trying to replace AWS_ACCESS_KEY and AWS_SECRET_KEY of properties file. But this way I am not able to inject during start of the server.
While trying to test the jar getting following exception:
Caused by: com.amazonaws.services.sqs.model.AmazonSQSException: The
security token included in the request is invalid. (Service:
AmazonSQS; Status Code: 403; Error Code: InvalidClientTokenId;
Please need your suggestion.
Advance thanks.
If you want to override properties in a properties file, instead of using sed, you can simply declare an environment variable or a JVM variable with a similar name. It will have the priority over properties declare in file.
For instance:
com.abc.sqs.accesskey = AWS_ACCESS_KEY
Can become with a JVM variable:
java -jar -Dspring.profiles.active=dev -Dcom.abc.sqs.accesskey=$AWS_ACCESS_KEY_ID ./app-service/target/app-service.jar
This will override the value of the properties file, and this will be available on application startup.
I used Docker for Selenium Grid Hub and Nodes to collect data, including
selenium/hub: 3.141.59-iron
selenium/node-fire_fox 3.141.59-iron
but one day after running, selenium-hub hung the following exception:
INFO exited: selenium-hub (exit status 137; not expected)
selenium/node-fire_fox exception is:
INFO [SelfRegisteringRemote$1.run] - Couldn't register this node: The hub is down or not responding: Failed to connect to selenium-hub/172.24.0.2:4444
What should I do?
This is not a problem related to Selenium, but an issue with Docker.
The following link has a summary of root causes for the error exit status 137; not expected:
https://success.docker.com/article/what-causes-a-container-to-exit-with-code-137
In short, for some reason, Docker is killing the process, in your case, selenium-hub.
For Mac and Windows, you probably need to increase the memory dedicated to Docker in Docker preferences.
This answer here on SO has a screenshot showing how to do it.
if you are using docker I dont understand why are you leaving you hub up and running .
checkout their hub page : https://github.com/SeleniumHQ/docker-selenium/tree/master/Hub
hub launch : docker run -d -p 4444:4444 --name selenium-hub selenium/hub
nodes launch :
$ docker run -d --link selenium-hub:hub -v /dev/shm:/dev/shm selenium/node-chrome
$ docker run -d --link selenium-hub:hub -v /dev/shm:/dev/shm selenium/node-firefox
I would write a pipeline and define my hubimage and node images which I bring up at the beginning of the test session and remove the images at the end of the session.
try{
hubimage
nodeimage
runtests
} catch(anything){
throw anything;
} finally {
sh "docker rmi \$(docker inspect --format='{{range .RepoTags}} {{.}} {{end}}' ${hubimage});"
sh "docker rmi \$(docker inspect --format='{{range .RepoTags}} {{.}} {{end}}' ${nodeimage});"
}
see more informations about pipelines : https://jenkins.io/doc/book/pipeline/
I am trying to setup the Apache Druid on a single machine following quickstart guide here. When I start historical server, it shows io.druid.java.util.common.IOE: No known server exception on screen.
Command:
java `cat conf-quickstart/druid/historical/jvm.config xargs` \
-cp "conf-quickstart/druid/_common:conf-quickstart/druid/historical:lib/*" \
io.druid.cli.Main server historical
Full stack-trace-
2018-04-07T18:23:40,234 WARN [main]
io.druid.java.util.common.RetryUtils - Failed on try 1, retrying in
1,246ms. io.druid.java.util.common.IOE: No known server at
io.druid.discovery.DruidLeaderClient.getCurrentKnownLeader(DruidLeaderClient.java:276)
~[druid-server-0.12.0.jar:0.12.0] at
io.druid.discovery.DruidLeaderClient.makeRequest(DruidLeaderClient.java:128)
~[druid-server-0.12.0.jar:0.12.0] at
io.druid.query.lookup.LookupReferencesManager.fetchLookupsForTier(LookupReferencesManager.java:569)
~[druid-server-0.12.0.jar:0.12.0] at
io.druid.query.lookup.LookupReferencesManager.tryGetLookupListFromCoordinator(LookupReferencesManager.java:420)
~[druid-server-0.12.0.jar:0.12.0] at
io.druid.query.lookup.LookupReferencesManager.lambda$getLookupListFromCoordinator$4(LookupReferencesManager.java:398)
~[druid-server-0.12.0.jar:0.12.0] at
io.druid.java.util.common.RetryUtils.retry(RetryUtils.java:63)
[java-util-0.12.0.jar:0.12.0] at
io.druid.java.util.common.RetryUtils.retry(RetryUtils.java:81)
[java-util-0.12.0.jar:0.12.0] at
io.druid.query.lookup.LookupReferencesManager.getLookupListFromCoordinator(LookupReferencesManager.java:388)
[druid-server-0.12.0.jar:0.12.0]
I have tried to setup from scratch many times with exactly the same steps mentioned on quick-start guide, but I am unable to resolve this error. How to resolve this error?
If you already tried to start druid, then delete the druid-X.Y.Z/log and druid-X.Y.Z/var folders.
Start zookeeper ./zookeeper-X.Y.Z/bin/zkServer.sh start
Recreate those folders you erased with druid-X.Y.Z/bin/init
Run each command in a new tab in this order
java `cat conf-quickstart/druid/coordinator/jvm.config | xargs` -cp "conf-quickstart/druid/_common:conf-quickstart/druid/coordinator:lib/*" io.druid.cli.Main server coordinator
java `cat conf-quickstart/druid/overlord/jvm.config | xargs` -cp "conf-quickstart/druid/_common:conf-quickstart/druid/overlord:lib/*" io.druid.cli.Main server overlord
java `cat conf-quickstart/druid/broker/jvm.config | xargs` -cp "conf-quickstart/druid/_common:conf-quickstart/druid/broker:lib/*" io.druid.cli.Main server broker
java `cat conf-quickstart/druid/historical/jvm.config | xargs` -cp "conf-quickstart/druid/_common:conf-quickstart/druid/historical:lib/*" io.druid.cli.Main server historical
java `cat conf-quickstart/druid/middleManager/jvm.config | xargs` -cp "conf-quickstart/druid/_common:conf-quickstart/druid/middleManager:lib/*" io.druid.cli.Main server middleManager
You should now have 1 tab open for each of those commands (so 5).
Insert the data curl -X 'POST' -H 'Content-Type:application/json' -d #quickstart/wikiticker-index.json localhost:8090/druid/indexer/v1/task
You will then see {"task":"index_hadoop_wikiticker_2018-06-06T19:17:51.900Z"}
I have the problem when I add a java file to my project,the project struct is as below:
ScreenLockTes.java is the new java file and DisplayTest.java is the original one :
Before I added the ScreenLockTes.java my project works fine ,but after I added that file and rebuild the project I got the problem.
my build and test step is :
1、android create uitest-project -t 2 -n screenlocktest -p
E:\Users\ss\workspace\DisplayUIAutomationTestCses
2、ant clean build
3、adb push
E:\Users\ss\workspace\DisplayUIAutomationTestCses/bin/screenlocktest.jar /data/local/tmp
4、adb shell uiautomator runtest screenlocktest.jar -c ScreenLockTest
when I use the above step 4 command to run the test I got the Didn't find class " on path: DexPathList error.
However,when I chang the command to "adb shell uiautomator runtest screenlocktest.jar -c com.android.uiautomator.ScreenLockTest#SwipScreenLockTest" the test can run correctly .And I find that eventhough the test can run.
It seems that the setUp() and tearDown() function attched to the SwipScreenLockTest() function did not run at all.
What is wrong with my project?Do I have some wrong project configuration?
Steps:
create new project with start.spring.io
run it localy - works
run gradle task jar
push jar to bluemix cf push demoWar.jar
Downloaded app package (20.1M) Staging... None of the buildpacks
detected a compatible application Exit status 222 Staging failed:
Exited with status 222 Destroying container
FAILED Error restarting application: NoAppDetectedError
TIP: Buildpacks are detected when the "cf push" is executed from
within the dire ctory that contains the app source code.
Try two things:
1. Use the -p command to target your deployable artifact. This would look something like cf p APP_NAME -p PATH_TO_YOUR_WAR. I usually chain my build and deploy commands so: mvn clean package && cf p APP_NAME -p PATH_TO_YOUR_WAR.
If this doesn't work then you can specify a build pack. So cf p APP_NAME -p PATH_TO_YOUR_WAR -b SOME_BUILDPACK. You can see the available build packs by calling cf buildpacks.
Hope this helps.
When deploying first time your app on cloud foundry then following command will not work
cf push TestService
you need to use following command
cf push -p TestService-0.0.1-SNAPSHOT.jar testService
Useful link :
https://discuss.pivotal.io/hc/en-us/articles/226273647-Troubleshooting-error-None-of-the-buildpacks-detected-a-compatible-application-exit-status-222-
https://docs.cloudfoundry.org/buildpacks/detection.html
Else add manifest.yml on root
applications:
- name: Demo
memory: 2G
disk_quota: 2G
instances: 1
path: target/demo-local-0.0.1-SNAPSHOT.jar
env:
SPRING_PROFILES_ACTIVE : "dev"
routes:
- route: demo.app.dev.vk.vaquar.khan.com
after that go to path and run cf push < JAR_NAME>