blog single gear
Engineering

Cloud Foundry: Now Supporting Scala

Cloud Foundry, the open platform as a service, supports multiple frameworks, multiple application services and multiple clouds.

Cloud Foundry already supports multiple frameworks including Spring (Java), Grails (Groovy), Rails and Sinatra (Ruby) and Node.js with others on the way from the community. For each supported framework we provide an appropriate runtime (such as Java) and application server (such as Tomcat). Furthermore, we utilize each framework’s expected application structure to offer features such as auto-reconfiguration so you may deploy applications to CloudFoundry.com or to a local instance of Cloud Foundry with minimal changes.

Scala is a statically typed, JVM-based language that combines object-oriented and functional programming in a consistent manner. It allows writing compact and robust programs for greater focus on core business logic. As a JVM-based language it offers easy interoperability with the Java ecosystem and Java libraries (such as Spring). Further, Scala incorporates many innovations such as parallel programming and the actor-based concurrent programming model to allow developers to develop modern applications and easily take advantage of multi-core hardware.

Today, we are announcing Cloud Foundry support for Scala and a variety of associated frameworks.  Most Scala applications written to Lift and Spring will deploy seamlessly without modification to Cloud Foundry.  Other Scala applications may require minor modifications to bind with application services in the cloud.

How Does It Work?

Since Scala is a JVM-based language, you can write applications with any Java web framework or use a framework explicitly designed for Scala such as Lift. Cloud Foundry can now deploy such applications. This support is multi-faceted.

If a Scala web app uses no application services such as a database, regardless of the framework used (including no framework at all), you can deploy it without any changes. For example, see http://hello-lift.cloudfoundry.com, which is a basic Lift application.

Most applications do use services, and in these cases you will need to make a few changes as outlined below.

Scala applications using the Lift framework and the Lift guidelines to externalize services will deploy without modification (see the modified PocketChange app for an example).  You simply create a WAR file and deploy it.  For Lift applications that don’t externalize their services, it is possible to explicitly access them through code (see another modification to the PocketChange app):

[code language=”java” autolinks=”false” light=”true”]
import org.cloudfoundry.runtime.env._
import org.cloudfoundry.runtime.service.relational._
Full(new MysqlServiceCreator( new CloudEnvironment()).createSingletonService().service.getConnection()) [/code]

The application deployed at http://tpuf.cloudfoundry.com is a Lift application that explicitly declares its use of a Redis service. Please see its github repository for more details.

If a Scala application uses the Spring framework, it can leverage auto-reconfiguration support and require no changes to the application itself. The application deployed at http://hello-spring-scala.cloudfoundry.com is a basic Spring application written using Scala with Spring as the framework.

Scala Support in Action

Cloud Foundry strives to simplify application deployment so that developers can focus on application development. Here is the interaction using the PocketChange application.

  1. Develop a cool Scala app.
  2. Upload the app to Cloud Foundry through SpringSource Tool Suite (STS) or the command-line tool (‘vmc’). These tools will automatically detect that the application is using Lift. Here is an interaction with “vmc”.
$ mvn package
   ...
$ vmc push pocketchange --path target
Application Deployed URL: 'pocketchange.cloudfoundry.com'?
Detected a Scala Lift Application, is this correct? [Yn]:
Memory Reservation [Default:512M] (64M, 128M, 256M, 512M, 1G or 2G)
Creating Application: OK

When deploying through STS, it will detect the Lift framework when you start the application. Except for this change, the overall STS experience remains unchanged.

  1. Bind a relational database service if the app uses one. This, too, can be done using STS or ‘vmc’. Here is the interaction with ‘vmc’ continued.
Would you like to bind any services to 'pocketchange'? [yN]: y
The following system services are available:
1. mongodb
2. mysql
3. redis
Please select one you wish to provision: 2
Specify the name of the service [mysql-744ef]: pocketchange-db
Creating Service: OK
Binding Service: OK
  1. Now the application is ready to be deployed. In STS, you can simply click on the Start button. In ‘vmc’, continue following the prompts.
Uploading Application:
  Checking for available resources: OK
  Processing resources: OK
  Packing application: OK
  Uploading (4K): OK
Push Status: OK
Staging Application: OK
Starting Application: OK

During this deployment process, application bits are transferred to the cloud (notice the small upload size? This is due to the incremental update feature of Cloud Foundry). Once transferred, the application bits will be wrapped in a Tomcat container, services you provisioned will be bound (pocketchange-db, in this case), and a property file will be created with information needed to connect to the database. Currently, we auto-reconfigure only database services, but in the future we will extend this to all offered services.

  1. The application is now ready at http://pocketchange.cloudfoundry.com to track your pocket change!

Scala and Lift support is live on www.CloudFoundry.com and available in the Cloud Foundry repository on www.CloudFoundry.org.  If you have not already signed up for CloudFoundry.com, this would be a good time to ensure your account is ready when Scala support is live.  Please try your Scala applications on Cloud Foundry and let us know how we can improve the experience.

Scala developers, welcome to the cloud!