StandAlone Scala Application

143 views
Skip to first unread message

Diego Ramirez

unread,
Apr 9, 2014, 10:03:47 PM4/9/14
to vcap...@cloudfoundry.org
Hey guys!!!

I've been working for a while with CF and recently at my work, they decided to migrate the whole enterprise platform to CouldFoundry. 
But here is the thing: we've got some applications which use Scala and Akka, and they are some kind of listener applications that fetch messages on a rabbitmq queue and store those on a Cassandra Database.
I've created a simple component to handle the VCAP_SERVICES variable content and "locally", it works great.
The problem comes in when I try to deploy it in CF using this command

cf push -f manifest.yaml -p target/universal/myapplication-0.0.1-SNAPSHOT.zip

And this is my manifest.yaml content

env:
  JAVA_HOME: .java
applications:
- name: myapplication
  memory: 1024M
  instances: 1
  command: ./bin/myapplication

my packaged zip contents's got this folder structure:

/bin
   myapplication
   myapplication.bat

/lib
  bunchofdependencies and bla bla bla

This structure was created by the distribution tool (http://www.scala-sbt.org/sbt-native-packager/) so when I run it locally, it works perfectly fine as well.

But the output of the deploy process is this:

Uploading myapplication...
Uploading from: /target/universal/myapplication-0.0.1-SNAPSHOT.zip
450.2K, 17 files
OK

Stopping app myapplication in org xxxx / space xx as xxx@XXXX
OK

Starting app myapplication in org xxxx / space xx as xxx@XXXX
OK
-----> Downloaded app package (24M)
Initialized empty Git repository in /tmp/buildpacks/null-buildpack/.git/
-----> Nothing to do.
-----> Uploading droplet (24M)

0 of 1 instances running, 1 down
0 of 1 instances running, 1 down
0 of 1 instances running, 1 down
0 of 1 instances running, 1 down
0 of 1 instances running, 1 down

and so on
I mean, the application never starts
Besides I decided to use that buildpack because I have no need for a special work, but just upgrade my zip file.

Do any of you have any experience deployment this kind of applications?

Txs in advanced

Diego

Diego Ramirez

unread,
Apr 9, 2014, 10:44:05 PM4/9/14
to vcap...@cloudfoundry.org
Got a new hint.

Taking a look on the logs I found out a message which told me that there is no start command. So I added, and now, starting fails because there is "no java installation detected". I'm really close now.
I guess I need a buildpack that install the Java JRE.


To unsubscribe from this group and stop receiving emails from it, send an email to vcap-dev+u...@cloudfoundry.org.

Ben Hale

unread,
Apr 10, 2014, 1:44:08 AM4/10/14
to vcap...@cloudfoundry.org
Taking a look on the logs I found out a message which told me that there is no start command. So I added, and now, starting fails because there is "no java installation detected". I'm really close now.
I guess I need a buildpack that install the Java JRE.

 The Java Buildpack (slightly-misnamed since it supports JVM languages other than Java) is the right avenue for this.  At the moment, however, we've never had a requirement for supporting sbt-native-packager and so, it probably won't work.  You can certainly fork the buildpack to add that support, or you can wait for us to add it.  Timing on the latter choice is unknown as we haven't seen much demand yet.

If you don't mind, can you elaborate a bit on the sbt-native-packager?  I'm looking to get an idea of how common its use is, what kind of applications it can package (just Akka apps, or all Scala apps?), and things like that.


-Ben Hale
Cloud Foundry Java Experience

Ben Hale

unread,
Apr 10, 2014, 1:54:53 AM4/10/14
to vcap...@cloudfoundry.org
At the moment, however, we've never had a requirement for supporting sbt-native-packager and so, it probably won't work.

Actually, upon further reflection it might work.  The structure you enumerated earlier looks a hell of a lot like what we expect from a Play Framework application (complete with bin/ and lib/ directories). I'd at least give it a try and possibly be surprised.  To run with the Java Buildpack you can do one of two things.  I'd begin with a fresh application by doing a `cf delete -f myapplication`.

If you want to push the application without a manifest file, you can run the following command, `cf push myapplication -p target/universal/myapplication-0.0.1-SNAPSHOT.zip -b https://github.com/cloudfoundry/java-buildpack.git`

If you want to push an application with a manifest file, you should create a manifest.yml file that looks like:

---
applications
:
- name: myapplication
  path
: target/universal/myapplication-0.0.1-SNAPSHOT.zip
  buildpack
: https://github.com/cloudfoundry/java-buildpack.git


and pushing the application would be the following command `cf push`.  Specifically, it's important to note that the Java Buildpack is designed so that you don't have to set a custom command or any environment variables.  Applications should run with a simple push.

Diego Ramirez

unread,
Apr 10, 2014, 7:42:19 AM4/10/14
to vcap...@cloudfoundry.org
Yup, Java buildpack was my first choice but take a look on the output

Starting app myapplication in org XXX / space xx as xxxx@xxxx...
OK
-----> Downloaded app package (24M)
Initialized empty Git repository in /tmp/buildpacks/java-buildpack/.git/
-----> Java Buildpack Version: 5fc79a0 | https://github.com/cloudfoundry/java-buildpack.git#5fc79a0
[Buildpack]                      ERROR Compile failed with exception #<RuntimeError: No container can run this application>
No container can run this application
/var/vcap/packages/dea_next/buildpacks/lib/installer.rb:19:in `compile': Buildpack compilation step failed: (RuntimeError)
from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:73:in `block in compile_with_timeout'
from /usr/lib/ruby/1.9.1/timeout.rb:68:in `timeout'
from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:72:in `compile_with_timeout'
from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:54:in `block in stage_application'
from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:50:in `chdir'
from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:50:in `stage_application'
from /var/vcap/packages/dea_next/buildpacks/bin/run:10:in `<main>'

It's likely to be failing because there are any container or framework in here.



To unsubscribe from this group and stop receiving emails from it, send an email to vcap-dev+u...@cloudfoundry.org.

Diego Ramirez

unread,
Apr 10, 2014, 7:46:09 AM4/10/14
to vcap...@cloudfoundry.org
On this kind of cases is mandatory to use a procfile, isn't i?

Ben Hale

unread,
Apr 10, 2014, 7:52:19 AM4/10/14
to vcap...@cloudfoundry.org
It's likely to be failing because there are any container or framework in here.

 Well damn.  It would appear that we do an explicit check for a Play JAR.  The good news is that this support is so close to what we already have, adding it would be quick.

As a separate question, is there a reason you chose to package the project like this instead of as a self-executable JAR?  I fully support the need to support many different types of application packaging, just wondering why you chose this one.

Ben Hale

unread,
Apr 10, 2014, 7:53:12 AM4/10/14
to vcap...@cloudfoundry.org
On this kind of cases is mandatory to use a procfile, isn't i?

Well, I dislike the use of a procfile file here because it only solves the problem for you.  Instead, we should be looking at how your requirements can help all users of the buildpack.

Diego Ramirez

unread,
Apr 10, 2014, 7:59:48 AM4/10/14
to vcap...@cloudfoundry.org
I didn't use the self-executable jar just for be a newbie :D. I don't know how CF would handle the dependencies, so, I decided to use this distribution method because it creates a Lib folder with full set of dependencies.



To unsubscribe from this group and stop receiving emails from it, send an email to vcap-dev+u...@cloudfoundry.org.

Ben Hale

unread,
Apr 10, 2014, 8:01:44 AM4/10/14
to vcap...@cloudfoundry.org
I didn't use the self-executable jar just for be a newbie :D. I don't know how CF would handle the dependencies, so, I decided to use this distribution method because it creates a Lib folder with full set of dependencies.

 Fair assessment.  I'm looking over what's required for distZip style support now.  https://www.pivotaltracker.com/story/show/69255612

Diego Ramirez

unread,
Apr 10, 2014, 8:05:38 AM4/10/14
to vcap...@cloudfoundry.org
You are the Man Ben!! Your efforts are highly appreciated.


To unsubscribe from this group and stop receiving emails from it, send an email to vcap-dev+u...@cloudfoundry.org.

Ben Hale

unread,
Apr 10, 2014, 9:50:04 AM4/10/14
to vcap...@cloudfoundry.org
You are the Man Ben!! Your efforts are highly appreciated.

Diego,

Any chance you can provide me with the content of the bin/myapplication script?  I want to throw it into our testing to ensure that it works as expected.

Diego Ramirez

unread,
Apr 10, 2014, 10:10:30 AM4/10/14
to vcap...@cloudfoundry.org
Yup sure.
Please let me know if you see it ok.


To unsubscribe from this group and stop receiving emails from it, send an email to vcap-dev+u...@cloudfoundry.org.

myapplication

Ben Hale

unread,
Apr 10, 2014, 10:11:52 AM4/10/14
to vcap...@cloudfoundry.org
Yup sure.
Please let me know if you see it ok.

Looks good.  Thanks.

Diego Ramirez

unread,
Apr 10, 2014, 10:12:04 AM4/10/14
to vcap...@cloudfoundry.org
Just in case, this script is generated for the same sbt plugin (sbt-native-package).
I guess it's ok because run perfectly fine in my local machine.

Ben Hale

unread,
Apr 10, 2014, 11:12:57 AM4/10/14
to vcap...@cloudfoundry.org
Diego,

I believe that the Java Buildpack will now do what you want it to.  If you follow my previous instructions, I believe that you'll see success.  Give it a go and let me know how you get on.

Diego Ramirez

unread,
Apr 10, 2014, 11:22:16 AM4/10/14
to vcap...@cloudfoundry.org
Should I refer to the same buildpack Url?


2014-04-10 12:12 GMT-03:00 Ben Hale <bh...@gopivotal.com>:

To unsubscribe from this group and stop receiving emails from it, send an email to vcap-dev+u...@cloudfoundry.org.

Ben Hale

unread,
Apr 10, 2014, 11:44:47 AM4/10/14
to vcap...@cloudfoundry.org
Should I refer to the same buildpack Url?

 Yup.  When you give Cloud Foundry a Git URI, it simply clones the HEAD commit out of it.  We also have support for specifying the branch by saying `cf push -b https://github.com/cloudfoundry/java-buildpack.git#BRANCH_NAME`.  So, since I pushed the distZip changes to master in that repo, they should be immediately available.

Diego Ramirez

unread,
Apr 10, 2014, 11:58:42 AM4/10/14
to vcap...@cloudfoundry.org
Wow!!! It's alive!!!
The deploy process works fine, but my application still fails, perhaps it's a little buggy yet, but it's my problem from now on.
Do you know If I need to take in account some kind ok keep-Alive check in order that CF doesn't try to restart the application all the time?



To unsubscribe from this group and stop receiving emails from it, send an email to vcap-dev+u...@cloudfoundry.org.

Ben Hale

unread,
Apr 10, 2014, 12:04:22 PM4/10/14
to vcap...@cloudfoundry.org
The deploy process works fine, but my application still fails, perhaps it's a little buggy yet, but it's my problem from now on.
Do you know If I need to take in account some kind ok keep-Alive check in order that CF doesn't try to restart the application all the time?

This thread describes some of what you need to take into account.  A rough approximation is that Cloud Foundry expects a process to always be running and listening on the port it assigns to $PORT.  You can use --no-route option and Cloud Foundry will no longer expect the application to listen on the port, but you are still required to ensure that your application stays alive.

James Bayer

unread,
Apr 10, 2014, 5:55:40 PM4/10/14
to vcap...@cloudfoundry.org
you can use the "-t" option with the v6 cli "push" command and specify up to 3 minutes of app start time, and it defaults to 60sec.

if you don't assign a route immediately when you push, then the app can take longer to start (watch the logs to confirm when it is ready) and then you can map a URL after the app has started.


To unsubscribe from this group and stop receiving emails from it, send an email to vcap-dev+u...@cloudfoundry.org.



--
Thank you,

James Bayer

Diego Ramirez

unread,
Apr 10, 2014, 9:29:17 PM4/10/14
to vcap...@cloudfoundry.org
Ok thanks for that. It seems pretty good.

So, I have another issue: the application actually never starts. Digging on the logs I found out something curious.

2014-04-10T22:15:29.11-0300 [API]     OUT App instance exited with guid 655a4d26-0556-46eb-b980-4123b9747539 payload: {"cc_partition"=>"default", "droplet"=>"655a4d26-0556-46eb-b980-4123b9747539", "version"=>"1499241e-de85-4957-ba18-2292eb8781f4", "instance"=>"6d0544472ad94995a1a9582ca8238203", "index"=>0, "reason"=>"CRASHED", "exit_status"=>127, "exit_description"=>"app instance exited", "crash_timestamp"=>1397178928}

It's likely to be it doen't find start command. here is my manifest file

---
applications:
- name: myapplication
  memory: 1024M
  no-route: true
  path: target/universal/myapplication-0.0.1-SNAPSHOT.zip
  instances: 1
  command: ./bin/myapplication

Then, when I tried to execute from my local machines it fails because has no execution permissions. 
Does it posible why it fails on the CF instance? Should I add this permission by hand?




To unsubscribe from this group and stop receiving emails from it, send an email to vcap-dev+u...@cloudfoundry.org.

James Bayer

unread,
Apr 11, 2014, 2:11:17 AM4/11/14
to vcap...@cloudfoundry.org

you can add the execute permissions manually before you upload your app.

you may also be specifying the wrong path to the command. you can use the absolute path like /app/somestartscript.sh

Ben Hale

unread,
Apr 11, 2014, 3:58:28 AM4/11/14
to vcap...@cloudfoundry.org
Actually, you shouldn't be specifying the command at all.  The buildpack is smart enough to determine what the command is supposed to be and executing it directly.


-Ben Hale
Cloud Foundry Java Experience

Diego Ramirez

unread,
Apr 11, 2014, 7:31:33 AM4/11/14
to vcap...@cloudfoundry.org
OK, but if you take a look on the logs I ssent you you can see that there is an error:
 "exit_status"=>127, "exit_description"=>"app instance exited",

This is the error code for path not found on linux, isn't it?

Diego Ramirez

unread,
Apr 11, 2014, 8:55:45 AM4/11/14
to vcap...@cloudfoundry.org
James: How I could set the permission? 
and one more thing: you told me that i should use the whole absolute path. My package's got two folders: bin and lib, my script location is on bin folder, so should it be something like this: app/bin/myapplication.sh? I mean, "app" is for real?

Ben Hale

unread,
Apr 11, 2014, 9:00:26 AM4/11/14
to vcap...@cloudfoundry.org
 "exit_status"=>127, "exit_description"=>"app instance exited",

This is the error code for path not found on linux, isn't it?

I'm not sure, but your manifest is listing a command (that likely isn't the proper path, as James points out).  If you remove that command and push it, the buildpack will find the proper script and execute it, so that you never need to know what the actual script path is.  If you want to see exactly what command is going to be run, you can do the following:

cf set-env myapplication JBP_LOG_LEVEL DEBUG
cf push
-p target/universal/myapplication-0.0.1-SNAPSHOT.zip -b https://github.com/cloudfoundry/java-buildpack.git



A ton of debug output will come out, but the final bit should show:

[Buildpack]                      DEBUG Release Payload ---
addons
: []
config_vars
: {}
default_process_types
:
  web
: SERVER_PORT=$PORT JAVA_HOME=$PWD/.java-buildpack/open_jdk_jre JAVA_OPTS="-Djava.io.tmpdir=$TMPDIR
    -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/killjava.sh -Xmx382293K
    -Xms382293K -XX:MaxPermSize=64M -XX:PermSize=64M -Xss995K"
$PWD/dist-zip-application-1.0.0.BUILD-SNAPSHOT/bin/dist-zip-application

If the buildpack is working properly with your application, you'll see it setting JAVA_HOME, JAVA_OPTS, and finally executing the application's script.

Aymen Medimagh

unread,
Apr 19, 2014, 9:30:06 PM4/19/14
to vcap...@cloudfoundry.org
Hi

Hope your issue is solved

I am having the same thing and I thing its question of jdk version

Diego Ramirez

unread,
Apr 21, 2014, 8:58:24 AM4/21/14
to vcap...@cloudfoundry.org
Hey Amen,
Yes, It's works like a charm.
There is no problem with the JDK version, the problem I had having was I messed up with the zip package name (I added SNAPSHOT), but using the versioning in proper way should work perfectly fine.

Thanks to all.

Aymen Medimagh

unread,
Apr 21, 2014, 12:58:20 PM4/21/14
to vcap...@cloudfoundry.org
Hi,

Did you check the log?

Regards
Reply all
Reply to author
Forward
0 new messages