migrating to cloud foundry
DESCRIPTION
Presentation at GOTO Amsterdam 2012 on how to migrate an existing servlet-based application to the Cloud Foundry PaaS.TRANSCRIPT
![Page 1: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/1.jpg)
© 2012 VMware, Inc. All rights reserved.
Migrating to Cloud Foundry
Peter Ledbrook - VMwaret: @pledbrooke: [email protected]
![Page 2: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/2.jpg)
What’s happening with applications today?
2
Frameworks are what really matter • Developer productivity and innovation
• Reduce time to market
New application types • Mobile, Social, SaaS
• Apps released early and often
Data intensive • Emerging requirements: elasticity, multi-cloud
• Web orientation drives exponential data volumes
Deployed on virtual and cloud infrastructures • Virtualization, Cloud, PaaS
![Page 3: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/3.jpg)
Deploy and scale applications in seconds, without locking yourself
into a single cloud
Simple, Open,
Flexible, Scalable
The Open Platform as a Service
![Page 4: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/4.jpg)
4
Choice of frameworks, services & cloudsOSS community
+ Standalone!
![Page 5: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/5.jpg)
5
Choice of frameworks, services & cloudsOSS community
Applica'on*Service*Interface*
Data Services
Other Services
Msg Services
vFabric Postgres
vFabric RabbitMQTM
Additional partners services …
+ Standalone!
![Page 6: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/6.jpg)
6
Choice of frameworks, services & cloudsOSS community
Applica'on*Service*Interface*
Data Services
Other Services
Msg Services
vFabric Postgres
vFabric RabbitMQTM
Additional partners services …
Private((Clouds((
Public(Clouds(
Micro(Clouds(
.COM
Partners(
Cloud(Provide
r(Interface(
Avoid
Lock-in
+ Standalone!
![Page 7: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/7.jpg)
Real choice of provider
7
Choice of Cloud Infrastructure
Bare metal
Choice of Private Cloud Distributions
Choice of Public Cloud Providers
.COM
![Page 8: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/8.jpg)
Deployment tools
8
vmc (command line)
![Page 9: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/9.jpg)
Core services
9
![Page 10: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/10.jpg)
Developer Perspective
• Program to standard APIs– SQL drivers– Mongo client libraries– ...
• Connection settings from VCAP_SERVICES environment variable
10
![Page 11: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/11.jpg)
When you’re ready to deploy...
11
!!!$!vmc!target!<any!cloud>!
!!!$!vmc!push!<my6app>!
!!!!>!bind!services?!Yes!
!!$!vmc!instances!<my6app>!+100!!
!!! That’s all folks!
![Page 12: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/12.jpg)
The sample application
• http://grails.org• Built with Grails
– JVM web framework– Spring MVC under the hood– Groovy as the main development language
12
![Page 13: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/13.jpg)
13
![Page 14: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/14.jpg)
14
![Page 15: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/15.jpg)
15
![Page 16: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/16.jpg)
16
![Page 17: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/17.jpg)
Architecture
17
Controller View
HTTP
Service
GORM/Hibernate
Database
REST
Async Plugin Update
Forum+ Jobs
![Page 18: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/18.jpg)
App Node
Cache
SearchindicesJob
Single instance
18
App Node
Cache
SearchindicesJob
App Node
Cache
SearchindicesJob
Local, embedded ehcache
![Page 19: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/19.jpg)
App Node
Cache
SearchindicesJob
Single instance
19
App Node
Cache
SearchindicesJob
App Node
Cache
SearchindicesJob
Local Lucene indexes
![Page 20: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/20.jpg)
App Node
Cache
SearchindicesJob
Single instance
20
App Node
Cache
SearchindicesJob
App Node
Cache
SearchindicesJob
Single job of each type
![Page 21: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/21.jpg)
App Node
Cache
SearchindicesJob
Multi-instance
21
App Node
Cache
SearchindicesJob
App Node
Cache
SearchindicesJob
1. Update2. Returnlatest
3. Returnstale data
3. Returnstale data
![Page 22: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/22.jpg)
App Node
Cache
SearchindicesJob
Multi-instance
22
App Node
Cache
SearchindicesJob
App Node
Cache
SearchindicesJob
Mail Job Mail Job Mail Job
Jobs are executed three times?
![Page 23: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/23.jpg)
Caching
23
Caching shared data==
Shared cache
![Page 24: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/24.jpg)
Ehcache
24
Simple & effectiveDistributed modeBut...
No multicast on Cloud Foundry!
![Page 25: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/25.jpg)
So, what do we use?
• Key-value store• In-memory with persistence (fast)• Pub-sub• Single service for all app instances
25
![Page 26: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/26.jpg)
Grails Cache plugin
• Based on Spring 3.1 cache abstraction– @Cacheable– @CacheEvict
• Ehcache & Redis providers– Spring Data RedisCacheManager
• <cache:block>• <cache:render template=”...”>
26
![Page 27: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/27.jpg)
27
![Page 28: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/28.jpg)
HTTP session
28
Sticky sessions!
![Page 29: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/29.jpg)
HTTP session
29
Or consider Redis fordistributed session store
![Page 30: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/30.jpg)
Jobs
• @Scheduled, Quartz, etc.• Which node runs a job?
30
Local data
Do nothing
Shared data
Quartz JDBC Store
Worker
![Page 31: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/31.jpg)
AppNode
Distribution with workers
31
AppNode
AppNode
WorkerWorkerWorker
?
![Page 32: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/32.jpg)
AppNode
Distribution with workers
32
AppNode
AppNode
WorkerWorkerWorker
Node-specificdata
![Page 33: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/33.jpg)
Jobs
33
Pros Cons
Quartz
Workers
Efficient in-JVM processingTried & testedRelatively simple
Extra burden on web server
Use right language for the jobDistribute the workload
Counts against your quota
![Page 34: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/34.jpg)
Search
• Compass 2.0– Lucene indexes on local file system– Indexes database data
• > 1 node == stale indexes• Search as a service
– Solr– Elastic Search– Index Tank– Amazon Cloud Search– Not on Cloud Foundry (yet)
• Synchronise indexes across nodes!– Eventual consistency is good enough
34
![Page 35: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/35.jpg)
Event bus
Synchronisation with an event bus
35
Event bus
Event bus
Initiate event
Distribute
Distribute
Distribute
![Page 36: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/36.jpg)
Schrödinger’s Cat
36
There’s a cat in here!
Is the cat alive or dead?
![Page 37: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/37.jpg)
Local filesystem
37
There’s a file in here!
Does the file exist or not?
![Page 38: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/38.jpg)
Ephemeral file system
• VMs are created and destroyed– => application file system created and destroyed– You can write to the local file system...– ...but you will probably lose that data at some point
• Don’t store persistent data on local FS!– File uploads
38
![Page 39: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/39.jpg)
Wiki images
39
Controller
User
Upload
GridFSBlob store
![Page 40: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/40.jpg)
Logging
• View logs with `vmc logs`• What if the application instance is restarted?
– Logs are gone• What about multiple application instances?
– `vmc logs --instance 1` or `vmc logs --all`– but 30 days after deployment?
40
![Page 41: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/41.jpg)
App Node
Distributed logging
41
App Node
App Node
AMQPAppender
AMQPAppender
AMQPAppender
Node.js +SockJS +MongoDB
![Page 42: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/42.jpg)
Config
42
Package in the app?
Store in database?
Inject via environment variable?
![Page 43: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/43.jpg)
Dynamic config load
43
Config.groovy
ConfigLoader.groovy
![Page 44: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/44.jpg)
• No SMTP - oh no!• HTTP providers
– SendGrid– Mailgun– Amazon Simple Email Service
44
![Page 45: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/45.jpg)
Easy HTTP Mail
45
resources.groovy
MailerJob.groovy
![Page 46: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/46.jpg)
Data
46
How do we load initial data?
Perform data migrations?
Back data up?
![Page 47: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/47.jpg)
Access your services
47
Mongo Client
vmc tunnel
Cloud Foundry
MongoDBservice
(SSH Tunnel)
![Page 48: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/48.jpg)
Import/export
48
Import == mysql < data.sql
Export == mysqldump
![Page 49: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/49.jpg)
Application (WIP*)
49
https://github.com/grails-samples/grails-website
http://grails-website.cloudfoundry.com/
Source
Live
* Work in Progress
![Page 50: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/50.jpg)
Summary
• PaaS is the application platform for the Cloud era• PaaS will change the way you write apps
– Design for horizontal scalability– Account for ephemeral file system– Rich set of services– Go polyglot!
• Tools & libraries are important– Spring for the win!
• Can use Redis in place of RabbitMQ for some patterns
50
![Page 51: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/51.jpg)
What’s next?
• Sign up - www.cloudfoundry.com• Get the source code - www.cloudfoundry.org• Download your Micro Cloud Foundry –
my.cloudfoundry.com/micro• Learn more on the Cloud Foundry blog -
blog.cloudfoundry.com• Follow us - @cloudfoundry
51
![Page 52: Migrating to Cloud Foundry](https://reader033.vdocument.in/reader033/viewer/2022052321/554f8d15b4c9052a518b51ed/html5/thumbnails/52.jpg)
Q&A