© 2012 VMware, Inc. All rights reserved Ramnivas Laddad @ramnivas Framework Integration in Cloud Foundry
© 2012 VMware, Inc. All rights reserved
Ramnivas Laddad
@ramnivas
Framework Integration in Cloud Foundry
2
CONFIDENTIAL
@ramnivas
Spring framework committer
Cloud Foundry committer
Main interests
• Cloud computing
• Aspect-oriented programming
• Scala and functional programming
Author of books and articles
• AspectJ in Action (1st and 2nd edition)
Speaker at many professional conferences
• JavaOne, JavaPolis, SpringOne, Software Development, No Fluff Just Stuff, EclipseCon, O’Reilly OSCON etc.
Active involvement in AspectJ, Spring, and Cloud Foundry since their early form
3
CONFIDENTIAL
Technologies “Я” Us
RabbitMQ
Postgres
REST
MySQLJPA
HibernateJDBC
Django
node.jsRedis
JTA
JMS
Web Services
Spring
Security
Caching
Mongo AMQP
Neo4j
JSF
Sinatra
TestingScripting
HTML5
RailsLift
Batch Job
LDAP
Grails
Ruby
Java
Python
AkkaScala
Closure
Hadoop
4
CONFIDENTIAL
Technologies “Я” Us
Monitoring
Hardware failures
Backups
Rolling Updates
Patches
Security DoS
OS
DNSStorage
Routing
DBA
Network
Load balancing
User managementAuditing
Access logs
5
CONFIDENTIAL
More functionality
Time to market pressure
Complex integration
Higher stake in quality
Facets of complexity: Product
6
CONFIDENTIAL
Sound architecture: future proofing without overdoing
Unit and integration tests
Responding to changing business needs
Confusing technology landscape
Facets of complexity: Development
7
CONFIDENTIAL
Choosing the right hardware, operating system, web server
Monitoring applications
Responding to scalability needs
Dealing with hardware- and system-level failures
Upgrading without substantial down time
Facets of complexity: Deployment and operation
8
CONFIDENTIAL
Inherent vs. Apparent Complexity
ImplementationFunctional logic
Implementation overhead
Inherent
complexity
Apparent
complexity
What can we do about this?
9
CONFIDENTIAL
What can we do?
?
10
CONFIDENTIAL
SaaSSoftware as a Service
PaaSPlatform as a Service
IaaSInfrastructure as a
Service
Three layers of Cloud Computing
11
CONFIDENTIAL
Clou
d Pr
ovid
er In
terfa
ce
Application Service Interface
Private Clouds
PublicClouds
Micro Clouds
Cloud Foundry open PaaS - Choice of clouds
Data Services
Other Services
Msg Services
12
CONFIDENTIAL
Clou
d Pr
ovid
er In
terfa
ce
Application Service Interface
Private Clouds
PublicClouds
Data Services
Other Services
Msg Services
Partners
Apache2 license
Cloud Foundry open PaaS - Choice of clouds
Micro Clouds
13
CONFIDENTIAL
Frameworks in Cloud Foundry
14
CONFIDENTIAL
Community and Partner contributions
The Cloud Foundry Universe
Core Frameworks
15
CONFIDENTIAL
Java
• Spring
• Grails
• Lift
Ruby
• Rails
• Sinatra
• Rack
Node.js (Community lead: Joyent)
Core Runtimes and Frameworks
16
CONFIDENTIAL
Python
• Django
• WSGI
Erlang OTP/Rebar
PHP
Perl
.Net
• On Iron Foundry
Community and partners contributions
17
CONFIDENTIAL
The Platinum Rule
Treat each framework
the way it will like to be treated!
18
CONFIDENTIAL
Common Framework Support
19
CONFIDENTIAL
Create apps and services
Update bindings, memory etc.
Scale instances
Command-line access
$ vmc push conference
$ vmc create-service mysql conf-db
$ vmc bind-service conf-db conference
$ vmc instances conference +2
20
CONFIDENTIAL
Access to services and app info through environment variables
• Service host, port, credentials
• App ip and port
Access to services and app info
VCAP_SERVICES: {
"postgresql-9.0": [{
"name": "env-postgresql",
"label": "postgresql-9.0",
"plan": "free",
"credentials": {
"name": "de24667f9344b4eeaad6b5a2326d52faa",
"host": "172.30.48.122",
"port": 5432,
"user": "u50ce600bba434bacbc99e034bb415644",
"password": "pf4dca5bd449d4732841f0c4ae3f299d0"
}
}]
}
21
CONFIDENTIAL
A runtime library to access service and app info
Auto-reconfiguration for typical apps
• Node.js coming soon
Simplified app configration
22
CONFIDENTIAL
Access to service through Caldecott
$ vmc tunnel conf-dbBinding Service [conf-db]: OKStopping Application 'caldecott': OKStaging Application 'caldecott': OK Starting Application 'caldecott': OK Getting tunnel connection info: OK Service connection info: username : uG5jVXaBPmjl6 password : pE3HOwIwGgkbv name : d76e62447a4c04f2b8e7b79f41c450aa0 Starting tunnel to conf-db on port 10000.1: none2: mysql3: mysqldumpWhich client would you like to start?: 2
23
CONFIDENTIAL
Access to service through Caldecott
Launching 'mysql --protocol=TCP --host=localhost --port=10000 --user=uG5jVXaBPmjl6 --password=pE3HOwIwGgkbv d76e62447a4c04f2b8e7b79f41c450aa0' ... mysql> select * from users;
24
CONFIDENTIAL
Manifest Support---
applications:
.:
name: conference
url: ${name}.${target-base}
framework:
name: rails3
info:
mem: 256M
description: Rails Application
exec:
mem: 256M
instances: 1
services:
conf-db:
type: mysql
25
CONFIDENTIAL
Spring
26
CONFIDENTIAL
IDE integration
• SpringSource Tools Suite and Eclipse
• Open source
Auto-reconfiguration by hooking into Spring application context
<cloud:> namespace
Spring 3.1 profile support
Maven plugin
The Platinum Rule: Spring and Grails
27
CONFIDENTIAL
IDE Integration
28
CONFIDENTIAL
Auto-Reconfiguration: Relational DB Detects beans of type javax.sql.DataSource
Connects to MySQL or PostgreSQL services
• Specifies driver, url, username, password, validation query
Creates Commons DBCP or Tomcat DataSource
<bean class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close" id="dataSource">
<property name="driverClassName" value="org.h2.Driver" />
<property name="url" value="jdbc:h2:mem:" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
29
CONFIDENTIAL
<cloud:service-scan>
Scans all services bound to the application and creates a bean of an appropriate type for each
• Same bean types as auto-reconfiguration
Useful during early development phases
<beans …>
<cloud:service-scan/>
</beans>
30
CONFIDENTIAL
<cloud:service-scan> Autowire Dependencies
Created beans can be autowired as dependencies
Use @Qualifier with service name if multiple services of same type bound to app
@Autowired(required=false) private ConnectionFactory rabbitConnectionFactory;
@Autowired private RedisConnectionFactory redisConnectionFactory;
@Autowired @Qualifier("test_mysql_database")
private DataSource mysqlDataSource;
@Autowired(required=false) @Qualifier("test_postgres_database")
private DataSource postgresDataSource;
31
CONFIDENTIAL
<cloud:data-source>
Configures a DataSource bean
• Commons DBCP or Tomcat DataSource
Basic attributes:
• id: defaults to service name
• service-name: only needed if you have multiple relational database services bound to the app
<cloud:data-source id="dataSource"/>
32
CONFIDENTIAL
Isolating Cloud Foundry Configuration
<bean class="org.sf.orm.jpa.LocalContainerEntityManagerFactoryBean"
id="entityManagerFactory">
<property name="dataSource" ref="dataSource"/>
</bean>
<beans profile="cloud">
<cloud:data-source id="dataSource" />
</beans>
<beans profile="default">
<bean class=”o.a.commons.dbcp.BasicDataSource" id="dataSource">
<property name="url" value="jdbc:mysql://localhost/inventory" />
</bean>
</beans>
33
CONFIDENTIAL
Scala/Lift Auto-reconfiguration for Scala Lift apps
PostgreSQL support coming soon
34
CONFIDENTIAL
Ruby
35
CONFIDENTIAL
Bundle support
• Just include a Gemfile.lock
Rails console
• Debugging
Auto-reconfiguration through meta-programming
cf-runtime gem
The Platinum Rule: Rails, Sinatra, Rack
36
CONFIDENTIAL
$ vmc rails-console conf
Connecting to 'conf' console: OK
irb():001:0> u = User.find_by_email('[email protected]')
=> #<User id: 1, email: "[email protected]", reason: "It is cool!", created_at: "2012-03-29 23:10:34", updated_at: "2012-03-29 23:10:34">
irb():002:0> u.email = "[email protected]"
=> "[email protected]"
irb():003:0> u.save
=> true
irb():004:0> u = User.find_by_email('[email protected]')
=> #<User id: 1, email: "[email protected]", reason: "It is cool!", created_at: "2012-03-29 23:10:34", updated_at: "2012-03-29 23:14:17">
Rails Console
37
CONFIDENTIAL
require 'mongo' module Demo class App < Sinatra::Base configure do mongo = Mongo::Connection.new(:host => '127.0.0.1', :port => 27017) db = mongo['db'] end ... endend
Ruby auto-reconfiguration
38
CONFIDENTIAL
cf-runtime: Ruby Runtime Gem
require 'cfruntime/mongodb'
connection =
CFRuntime::MongoClient.create_from_svc('docs')
db = connection.db
...
39
CONFIDENTIAL
Running locally and in Cloud Foundry
require 'cfruntime/mongodb'
...
db = CFRuntime::MongoClient.create.db
rescue Mongo::Connection.new("localhost",
27017)
.db("db”)
...
40
CONFIDENTIAL
Taking full control
if CFRuntime::CloudApp.running_in_cloud? @service_props = CFRuntime::CloudApp.service_props('docs’)else @service_props = {} @service_props[:host] = 'localhost' @service_props[:port] = 27017 @service_props[:db] = 'testdb'enddb = Mongo::Connection.new(@service_props[:host], @service_props[:port]) .db(@service_props[:db])if CFRuntime::CloudApp.running_in_cloud? db.authenticate(@service_props[:username], @service_props[:password])end
41
CONFIDENTIAL
Node.js
42
CONFIDENTIAL
NPM support
• Coming soon!
Debugging using node-inspector
Auto-reconfiguration and runtime package
• Coming soon!
The Platinum Rule: Node.js
43
CONFIDENTIAL
Debugging node.js apps
44
CONFIDENTIAL
Auto-reconfiguration in node.jsvar host = 'localhost', port = 3000, url = require('url'); var client = require("redis").createClient(); require('http').createServer(function (req, res) { ...
45
CONFIDENTIAL
var cfruntime = require('cfruntime'), host = cfruntime.CloudApp.host || 'localhost', port = cfruntime.CloudApp.port || 3000, url = require('url'); if (cfruntime.CloudApp.runningInCloud) { var client = cfruntime.RedisClient.create();} else { var client = require("redis").createClient();} require('http').createServer(function (req, res) { ...
Accessing apps and services info
46
CONFIDENTIAL
Peeking into future
47
CONFIDENTIAL
Bring your own container
• Jetty
• Netty
• …
Non-web apps
• Resque workers
• Spring Batch
• Spring Integration
Still to come
• Short-running apps
• Scheduled tasks
Standalone apps
48
CONFIDENTIAL
Lift updated support
Play!
Akka
Enhanced Scala Support
49
CONFIDENTIAL
Revamped vmc
• Embeddable core
• Scripting friendly
• Even more intuitive user interaction
Eclipse plugin
• Enhanced wizard with service requirement detection
• Manifest support
• Caldecott integration
Improved Tools
© 2012 VMware, Inc. All rights reserved
Ramnivas Laddad
@ramnivas
Questions?