Migrating to Cloud Foundry
Peter Ledbrook - VMware
t: @pledbrook
e: pledbrook@vmware.com




© 2012 VMware, Inc. All rights reserved.
What’s happening with applications today?
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


                                                       2
The promise of PaaS

           App 1             App 2          App 3




                            Platform
        Servlet Container   Database     Other services


                        Infrastructure
                CPU          Memory        OS


      • Zero config
      • Automatic provisioning

                                                          3
The Open
        Platform as a Service

 Deploy and scale applications in
seconds, without locking yourself
        into a single cloud

                                 Open,
                            ple,     ble
                       Sim , Scala
                       lexible
                      F
Choice of frameworks, services & clouds
                                      OSS community
               ne!
             lo
          da
        an
      St
  +




                                                  5
Choice of frameworks, services & clouds
                                                                   OSS community
                e!
              on
            al
        a nd
      St
  +


  vFabric
  Postgres
                                    Ap
                                       p
                     Data
                                           lica
                     Services
                                            'o
                                              n *S

           vFabric
                                                  erv


           RabbitMQTM           Msg
                                                     ice


                                Services
                                                        *In
                                                        ter
                                                           fac
                                                              e*



                                              Other
                                             Services

                     Additional partners
                     services …




                                                                               6
Choice of frameworks, services & clouds
                                                                                               OSS community
               ne!
             lo
          da
        an
      St
  +


  vFabric
  Postgres
                                    Ap




                                                                                    e(
                                                                                           Private((
                                       p




                                                                                 fac
                     Data
                                           lica
                     Services
                                                                                           Clouds((




                                                                              ter
                                            'o




                                                                              r(In
                                              n *S

           vFabric




                                                                           ide
                                                  erv


           RabbitMQTM                                                                Public(




                                                                         ov
                                Msg
                                                     ice




                                                                      (Pr
                                Services
                                                                                     Clouds(            Partners(
                                                        *In




                                                                    ud
                                                        ter




                                                                   Cl o
                                                           fac



                                                                                                       .COM
                                                                            Micro(
                                                              e*



                                              Other
                                             Services                       Clouds(
                     Additional partners
                     services …
                                                                                                       A void
                                                                                                       Lo ck-in


                                                                                                              7
Real choice of provider

 Choice of Private    Choice of Public   Choice of Cloud
Cloud Distributions   Cloud Providers     Infrastructure




                         .COM




                                            Bare metal




                                                           8
Deployment tools


          vmc (command line)




                               9
Core services




                10
Developer Perspective
• Program to standard APIs
  – SQL drivers
  – Mongo client libraries
  – ...
• Connection settings from VCAP_SERVICES environment
  variable




                                                       11
When you’re ready to deploy...
     !
     !
       !$!vmc!target!<any!cloud>!
     !!
       !$!vmc!push!<my6app>!
     !
       !!!>!bind!services?!Yes!
     !
       !$!vmc!instances!<my6app>!+100!!
     !
     !
     !     That’s all folks!
                                          12
The sample application

• http://grails.org
• Built with Grails
  – JVM web framework
  – Spring MVC under the hood
  – Groovy as the main development language




                                              13
14
15
16
17
Architecture
                       HTTP



        Controller              View


                                                      Twitter
         Service              REST


                                       Async Plugin
                                         Update
     GORM/Hibernate



            Database
                                                      Forum
                              + Jobs
                                                                18
Single instance


                     Cache
                             Search
               Job
                             indices
                     App
                     Node




           Local, embedded ehcache



                                       19
Single instance


                    Cache
                            Search
              Job
                            indices
                    App
                    Node




             Local Lucene indexes



                                      20
Single instance


                     Cache
                             Search
               Job
                             indices
                     App
                     Node




             Single job of each type



                                       21
Multi-instance


       Cache                         Cache                      Cache
               Search                           Search                   Search
Job                       Job                             Job
               indices                          indices                  indices
       App                           App                        App
       Node                          Node                       Node



3. Return                2. Return                                 3. Return
                                             1. Update
stale data               latest                                    stale data




                                                                                22
Multi-instance


       Cache                         Cache                         Cache
                 Search                        Search                        Search
Job                         Job                             Job
                 indices                       indices                       indices
       App                          App                            App
       Node                         Node                           Node




      Mail Job                    Mail Job                        Mail Job


                           Jobs are executed three times?

                                                                               23
Caching




          Caching shared data
                  ==
             Shared cache




                                24
Ehcache


           Simple & effective
           Distributed mode
           But...



     No multicast on Cloud Foundry!


                                      25
So, what do we use?




•   Key-value store
•   In-memory with persistence (fast)
•   Pub-sub
•   Single service for all app instances




                                           26
Grails Cache plugin

• Based on Spring 3.1 cache abstraction
  – @Cacheable
  – @CacheEvict
• Ehcache & Redis providers
  – Spring Data RedisCacheManager
• <cache:block>
• <cache:render template=”...”>




                                          27
28
HTTP session




               Sticky sessions!




                                  29
HTTP session




         Or consider Redis for
         distributed session store




                                     30
Jobs

• @Scheduled, Quartz, etc.
• Which node runs a job?



        Local data             Shared data




       Do nothing        Quartz JDBC    Worker
                            Store

                                                 31
Distribution with workers
                            Worker
                            Worker
                             Worker




                      ?



    App             App      App
    Node            Node     Node


                                      32
Distribution with workers
                                     Worker
                                     Worker
                                      Worker




                     Node-specific
                        data



    App             App               App
    Node            Node              Node


                                               33
Jobs


                     Pros                   Cons

            Efficient in-JVM       Extra burden on web
            processing             server
  Quartz    Tried & tested
            Relatively simple

            Use right language for Counts against your
            the job                 quota
  Workers   Distribute the workload




                                                         34
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


                                          35
Synchronisation with an event bus


      Distribute                                   Distribute

                   Distribute

                                        Initiate
                                        event




    Event                       Event                    Event
     bus                         bus                      bus




                                                                 36
Event bus


                                             Update    Call REST
                     Save entity    Index   read DBs    service




Spring Integration                  Event Bus                      AMQP




                        Plugins
                         Plugins
                          Plugins               Application




                                                                          37
Event bus

• Platform Core plugin
  – Event API + simple in-memory implementation
• Events Si plugin
  – Event bus implementation using Spring Integration
• Events Push plugin
  – Bridge events to browser via Atmosphere
• Potentially the standard cloud architecture
  – Message passing (relatively) easy to scale horizontally




                                                              38
Schrödinger’s Cat




            Is the cat alive or dead?

                                        39
Schrödinger’s Cat




           Resolved only when we look

                                        40
Local filesystem
                                  There’s a file in here!




            Does the file exist or not?

                                                       41
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




                                                            42
Wiki images       mongo-file plugin
                    for example


                                  Blob store
                      GridFS




              Controller




                       Upload



               User

                                               43
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?




                                                   44
Distributed logging              Node.js +
                                 SockJS +
                                 MongoDB




    AMQP               AMQP              AMQP
   Appender           Appender          Appender



    App               App               App
    Node              Node              Node


                                                   45
Config


              Package in the app?


               Store in database?


         Inject via environment variable?




                                            46
Dynamic config load

                            Config.groovy




                      ConfigLoader.groovy




                                       47
Mail

• No SMTP - oh no!
• HTTP providers
  – SendGrid
  – Mailgun
  – Amazon Simple Email Service




                                  48
Easy HTTP Mail
                 resources.groovy




                 MailerJob.groovy




                                    49
Data


       How do we load initial data?


       Perform data migrations?


             Back data up?




                                      50
Access your services

                   Mongo Client




                    vmc tunnel




                     (SSH Tunnel)




                   Cloud Foundry

        MongoDB
         service


                                    51
Import/export




         Import == mysql < data.sql



         Export == mysqldump




                                      52
Application (WIP*)




   Source     https://github.com/grails-samples/grails-website



   Live       http://grails-website.cloudfoundry.com/




* Work in Progress

                                                                 53
Summary

• PaaS is the application platform for the Cloud era
• Cloud Foundry can support real applications
• 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




                                                         54
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




                                               55
Q&A

Migrating to CloudFoundry

  • 1.
    Migrating to CloudFoundry Peter Ledbrook - VMware t: @pledbrook e: pledbrook@vmware.com © 2012 VMware, Inc. All rights reserved.
  • 2.
    What’s happening withapplications today? 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 2
  • 3.
    The promise ofPaaS App 1 App 2 App 3 Platform Servlet Container Database Other services Infrastructure CPU Memory OS • Zero config • Automatic provisioning 3
  • 4.
    The Open Platform as a Service Deploy and scale applications in seconds, without locking yourself into a single cloud Open, ple, ble Sim , Scala lexible F
  • 5.
    Choice of frameworks,services & clouds OSS community ne! lo da an St + 5
  • 6.
    Choice of frameworks,services & clouds OSS community e! on al a nd St + vFabric Postgres Ap p Data lica Services 'o n *S vFabric erv RabbitMQTM Msg ice Services *In ter fac e* Other Services Additional partners services … 6
  • 7.
    Choice of frameworks,services & clouds OSS community ne! lo da an St + vFabric Postgres Ap e( Private(( p fac Data lica Services Clouds(( ter 'o r(In n *S vFabric ide erv RabbitMQTM Public( ov Msg ice (Pr Services Clouds( Partners( *In ud ter Cl o fac .COM Micro( e* Other Services Clouds( Additional partners services … A void Lo ck-in 7
  • 8.
    Real choice ofprovider Choice of Private Choice of Public Choice of Cloud Cloud Distributions Cloud Providers Infrastructure .COM Bare metal 8
  • 9.
    Deployment tools vmc (command line) 9
  • 10.
  • 11.
    Developer Perspective • Programto standard APIs – SQL drivers – Mongo client libraries – ... • Connection settings from VCAP_SERVICES environment variable 11
  • 12.
    When you’re readyto deploy... ! ! !$!vmc!target!<any!cloud>! !! !$!vmc!push!<my6app>! ! !!!>!bind!services?!Yes! ! !$!vmc!instances!<my6app>!+100!! ! ! ! That’s all folks! 12
  • 13.
    The sample application •http://grails.org • Built with Grails – JVM web framework – Spring MVC under the hood – Groovy as the main development language 13
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
    Architecture HTTP Controller View Twitter Service REST Async Plugin Update GORM/Hibernate Database Forum + Jobs 18
  • 19.
    Single instance Cache Search Job indices App Node Local, embedded ehcache 19
  • 20.
    Single instance Cache Search Job indices App Node Local Lucene indexes 20
  • 21.
    Single instance Cache Search Job indices App Node Single job of each type 21
  • 22.
    Multi-instance Cache Cache Cache Search Search Search Job Job Job indices indices indices App App App Node Node Node 3. Return 2. Return 3. Return 1. Update stale data latest stale data 22
  • 23.
    Multi-instance Cache Cache Cache Search Search Search Job Job Job indices indices indices App App App Node Node Node Mail Job Mail Job Mail Job Jobs are executed three times? 23
  • 24.
    Caching Caching shared data == Shared cache 24
  • 25.
    Ehcache Simple & effective Distributed mode But... No multicast on Cloud Foundry! 25
  • 26.
    So, what dowe use? • Key-value store • In-memory with persistence (fast) • Pub-sub • Single service for all app instances 26
  • 27.
    Grails Cache plugin •Based on Spring 3.1 cache abstraction – @Cacheable – @CacheEvict • Ehcache & Redis providers – Spring Data RedisCacheManager • <cache:block> • <cache:render template=”...”> 27
  • 28.
  • 29.
    HTTP session Sticky sessions! 29
  • 30.
    HTTP session Or consider Redis for distributed session store 30
  • 31.
    Jobs • @Scheduled, Quartz,etc. • Which node runs a job? Local data Shared data Do nothing Quartz JDBC Worker Store 31
  • 32.
    Distribution with workers Worker Worker Worker ? App App App Node Node Node 32
  • 33.
    Distribution with workers Worker Worker Worker Node-specific data App App App Node Node Node 33
  • 34.
    Jobs Pros Cons Efficient in-JVM Extra burden on web processing server Quartz Tried & tested Relatively simple Use right language for Counts against your the job quota Workers Distribute the workload 34
  • 35.
    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 35
  • 36.
    Synchronisation with anevent bus Distribute Distribute Distribute Initiate event Event Event Event bus bus bus 36
  • 37.
    Event bus Update Call REST Save entity Index read DBs service Spring Integration Event Bus AMQP Plugins Plugins Plugins Application 37
  • 38.
    Event bus • PlatformCore plugin – Event API + simple in-memory implementation • Events Si plugin – Event bus implementation using Spring Integration • Events Push plugin – Bridge events to browser via Atmosphere • Potentially the standard cloud architecture – Message passing (relatively) easy to scale horizontally 38
  • 39.
    Schrödinger’s Cat Is the cat alive or dead? 39
  • 40.
    Schrödinger’s Cat Resolved only when we look 40
  • 41.
    Local filesystem There’s a file in here! Does the file exist or not? 41
  • 42.
    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 42
  • 43.
    Wiki images mongo-file plugin for example Blob store GridFS Controller Upload User 43
  • 44.
    Logging • View logswith `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? 44
  • 45.
    Distributed logging Node.js + SockJS + MongoDB AMQP AMQP AMQP Appender Appender Appender App App App Node Node Node 45
  • 46.
    Config Package in the app? Store in database? Inject via environment variable? 46
  • 47.
    Dynamic config load Config.groovy ConfigLoader.groovy 47
  • 48.
    Mail • No SMTP- oh no! • HTTP providers – SendGrid – Mailgun – Amazon Simple Email Service 48
  • 49.
    Easy HTTP Mail resources.groovy MailerJob.groovy 49
  • 50.
    Data How do we load initial data? Perform data migrations? Back data up? 50
  • 51.
    Access your services Mongo Client vmc tunnel (SSH Tunnel) Cloud Foundry MongoDB service 51
  • 52.
    Import/export Import == mysql < data.sql Export == mysqldump 52
  • 53.
    Application (WIP*) Source https://github.com/grails-samples/grails-website Live http://grails-website.cloudfoundry.com/ * Work in Progress 53
  • 54.
    Summary • PaaS isthe application platform for the Cloud era • Cloud Foundry can support real applications • 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 54
  • 55.
    What’s next? • Signup - 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 55
  • 56.