2. @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
CONFIDENTIAL
2
4. Technologies “Я” Us
Access logs Network
Routing
Hardware failures DNS
Storage
Load balancing
Auditing Rolling Updates
User management
Security DoS
Backups DBA
OS Monitoring
Patches
CONFIDENTIAL
4
5. Facets of complexity: Product
More functionality
Time to market pressure
Complex integration
Higher stake in quality
CONFIDENTIAL
5
6. Facets of complexity: Development
Sound architecture: future proofing without overdoing
Unit and integration tests
Responding to changing business needs
Confusing technology landscape
CONFIDENTIAL
6
7. Facets of complexity: Deployment and
operation
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
CONFIDENTIAL
7
8. Inherent vs. Apparent Complexity
What can we do
about this?
Implementation overhead
Apparent
Implementation complexity
Inherent
Functional logic complexity
CONFIDENTIAL
8
20. Access to services and app info
Access to services and app info through environment variables
• Service host, port, credentials
• App ip and port
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"
}
}]
CONFIDENTIAL
} 20
21. Simplified app configration
A runtime library to access service and app info
Auto-reconfiguration for typical apps
• Node.js coming soon
CONFIDENTIAL
21
22. Access to service through Caldecott
$ vmc tunnel conf-db
Binding Service [conf-db]: OK
Stopping Application 'caldecott': OK
Staging 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: none
2: mysql
3: mysqldump
Which client would you like to start?: 2
CONFIDENTIAL
22
23. Access to service through Caldecott
Launching 'mysql --protocol=TCP --host=localhost --port=10000
--user=uG5jVXaBPmjl6
--password=pE3HOwIwGgkbv
d76e62447a4c04f2b8e7b79f41c450aa0'
...
mysql> select * from users;
CONFIDENTIAL
23
26. The Platinum Rule: Spring and Grails
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
CONFIDENTIAL
26
28. 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>
CONFIDENTIAL
28
29. <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>
CONFIDENTIAL
29
30. <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;
CONFIDENTIAL
30
31. <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"/>
CONFIDENTIAL
31
35. The Platinum Rule: Rails, Sinatra, Rack
Bundle support
• Just include a Gemfile.lock
Rails console
• Debugging
Auto-reconfiguration through meta-programming
cf-runtime gem
CONFIDENTIAL
35
37. Ruby auto-reconfiguration
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
...
end
end
CONFIDENTIAL
37
39. Running locally and in Cloud Foundry
require 'cfruntime/mongodb'
...
db = CFRuntime::MongoClient.create.db
rescue Mongo::Connection.new("localhost",
27017)
.db("db”)
...
CONFIDENTIAL
39
40. 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'
end
db = 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
CONFIDENTIAL
40