Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Cloud Foundry Bootcamp

4,504 views

Published on

Heard about Cloud Foundry? Already a Spring, Grails, Ruby, Node.js, Scala, or generalist programmer looking to understand what Cloud Foundry, the open source PaaS from VMware, means to you? Are you an architect trying to understand where PaaS fits it, and what it brings to the table? If you answered "yes" to any of those questions, then join the experts in this bootcamp to Cloud Foundry.

Published in: Technology, Business
  • Be the first to comment

Cloud Foundry Bootcamp

  1. 1. Cloud Foundry BootcampPortland, 2012Written by: Chris RichardsonPresented By: Monica Wilkinson & Josh Long© 2012 VMware, Inc. All rights reserved
  2. 2. About Monica Wilkinson Loves the web and data portability. Developer Advocate @ Cloud Foundry 12 years development experience. Last 5 years in Social Web Open Web Standards Advocate @ciberch mwilkinson@vmware.com CONFIDENTIAL 2
  3. 3. About Josh Long Spring Developer Advocate @starbuxman josh.long@springsource.com th si is im po rta nt ! Free Book! SpringSource.org/roo CONFIDENTIAL 3
  4. 4. Will Work for Donuts... CONFIDENTIAL 4
  5. 5. AgendaWhy PaaS matters to developersOverview of Cloud FoundryGetting started with Cloud FoundryCloud Foundry architectureUsing Micro Cloud FoundryConsuming Cloud Foundry services 5
  6. 6. Traditional web application architecture Web Application StoreFront Accounting Service MySQL Desktop Database Apache Browser InventoryService Shipping ServiceSimple to Container (e.g. Tomcat) develop test deploy scale 6
  7. 7. Traditional web application architecture Web Application StoreFront Accounting Service MySQL Desktop Database Apache Browser InventoryService Shipping ServiceSimple to Container (e.g. Tomcat) develop test deploy scale Or is it? 6
  8. 8. Let’s imagine you want to run aperformance test... ?How long to get the servers?Who is going to set up the servers?Who is going to set up Apache,Tomcat, and MySQL?
  9. 9. And things are changing:This simple, monolithic architecture is inadequate 8
  10. 10. New kinds of clients Smart phones overtake PCs in Q4 2010 9
  11. 11. Users expect a rich, dynamic and interactive experience on mobile devices and desktop HTTP Request Desktop Web Application Browser HTML/Javascript 10
  12. 12. Users expect a rich, dynamic and interactive experience on mobile devices and desktop h oug d en oo ’t g HTTP Request e isn r ctu Desktop Web Application e hit Browser HTML/Javascript I arc ty le U s Old 10
  13. 13. Need to handle massive loads and the data explosion Need scalable architectures Application tier: • Replicated/clustered servers • Modular so that components can be scaled differently • Asynchronous architecture - communication via a message broker Database tier: • Replication • Sharding • Polyglot persistence: Relational, NoSQL, NewSQL databases 11
  14. 14. Scaling development Web application StoreFront Accounting Service Scalable != InventoryService development Shipping Service Strongly coupled components makes development difficult Forces multiple developers/teams to synchronize development efforts Obstacle to frequent, independent deployments Increases risk of failure - need to redeploy everything to change one thing 12
  15. 15. Modern application architecture billing web applicationDesktop AccountingBrowser Service StoreUINative Mobile NodeJS NodeJS inventory web applicationApplication front-end MySQL application StoreUI StoreUI InventoryServiceHTML5 mobileapplication StoreUI Redis shipping web application RabbitMQ Mongo ShippingService 13
  16. 16. Developing and testing these applications is even more challenging 14
  17. 17. Let’s imagine you are fixing a bugand want to run some JUnitintegration tests... ?Who is going to setup your sandbox:MySQL, RabbitMQ, MongoDB, ....?
  18. 18. Let’s imagine you have fixed a bugand want to run some functionaltests... ?How long to purchase the servers?Who is going to set up the servers?Who is going to setup MySQL,RabbitMQ, MongoDB, ....?
  19. 19. Platform-as-a-Service is the solution Deployment ServicesEasy deployment SQL databasesApplication management + NoSQL databasesEasy scaling up and down Message Broker 17
  20. 20. AgendaWhy PaaS matters to developersOverview of Cloud FoundryGetting started with Cloud FoundryCloud Foundry architectureUsing Micro Cloud FoundryConsuming Cloud Foundry services 18
  21. 21. The Open Platform as a ServiceDeploy and scale applications inseconds, without locking yourself p en, e, O lable Simpl Sca Flex ible, 19
  22. 22. Cloud Foundry open PaaS - Choice of frameworks
  23. 23. Cloud Foundry open PaaS - Choice of frameworks OSS community
  24. 24. Cloud Foundry open PaaS - Choice of application services Ap p lic Data at Services io n Se r vic e In te Msg rfa Services ce Other Services
  25. 25. Cloud Foundry open PaaS - Choice of application services vFabricPostgres Ap p lic Data at Services io n Se r vic vFabric e In te RabbitMQTM Msg rfa Services ce Other Services Additional partners services …
  26. 26. Cloud Foundry open PaaS - Choice of clouds Ap p Private lic Data at Services Clouds io n Se ce r vic rfa e te In In te Public er Msg rfa vid Services Clouds ce o Pr ud o Cl Micro Other Clouds Services
  27. 27. Cloud Foundry open PaaS - Choice of clouds d Avoi n Ap p Lo ck-i Private lic Data at Services Clouds io n Se ce r vic rfa e te In In te Public er Msg rfa vid Services Clouds ce o Pr ud o Cl Micro Other Clouds Services
  28. 28. Multi-cloud flexibility is critical to your long-term success 23
  29. 29. Multi-cloud flexibility is critical to your long-term success Make use of both public and private clouds without rewriting your applications 23
  30. 30. Multi-cloud flexibility is critical to your long-term success Make use of both public and private clouds without rewriting your applications Protect against vendor lock-in 23
  31. 31. Multi-cloud flexibility is critical to your long-term success Make use of both public and private clouds without rewriting your applications Protect against vendor lock-in Meet different compliance and geographical needs 23
  32. 32. Multi-cloud flexibility is critical to your long-term success Make use of both public and private clouds without rewriting your applications Protect against vendor lock-in Meet different compliance and geographical needs Accommodate peak loads while optimizing costs 23
  33. 33. Multi-cloud flexibility is critical to your long-term success Make use of both public and private clouds without rewriting your applications Protect against vendor lock-in Meet different compliance and geographical needs Accommodate peak loads while optimizing costs Manage your growth and changing needs over time 23
  34. 34. CloudFoundry.COM - Multi-tenant PaaS operated by VMware CloudFoundry.COM (beta) Runtimes & Frameworks Services vCenter / vSphere Infrastructure 24
  35. 35. Micro Cloud FoundryTM – Industry first downloadable PaaS Micro Cloud Foundry Runtimes & Frameworks Services Your Laptop/PC Single VM instance of Cloud Foundry that runs on a developer’s MAC or PC 25
  36. 36. CloudFoundry.ORG - Community open-source project CloudFoundry.ORG Your Infrastructure Download Setup Setup Deploy Behind Code Environment Scripts Firewall Apache2 license 26
  37. 37. Cloud Foundry: you can trade-off effort vs flexibility Less Less Public PaaS .... .COM Private PaaSEffort .... Flexibility Custom Private PaaS git clone git://github.com/cloudfoundry/ More More 27
  38. 38. Cloud Foundry Resources Primary Site : cloudfoundry.com Open Source Site : cloudfoundry.org Twitter : @cloudfoundry Blog : blog.cloudfoundry.com FB : facebook.com/cloudfoundry Documentation: start.cloudfoundry.com Support : support.cloudfoundry.com • Knowledge Base • Q & A / Forums 28
  39. 39. AgendaWhy PaaS matters to developersOverview of Cloud FoundryGetting started with Cloud FoundryCloud Foundry architectureUsing Micro Cloud FoundryConsuming Cloud Foundry services 29
  40. 40. Register http://cloudfoundry.com/signup Use promo code CFOpenTour2012 30
  41. 41. Welcome email 31
  42. 42. Ways to use Cloud Foundry 32
  43. 43. Ways to use Cloud Foundry 32
  44. 44. Ways to use Cloud Foundry 32
  45. 45. Ways to use Cloud Foundry 32
  46. 46. Ways to use Cloud Foundry 32
  47. 47. Ways to use Cloud Foundry 32
  48. 48. Installing vmc on Windows 33
  49. 49. Installing vmc on Windows Install the vmc gem 33
  50. 50. Installing vmc on Mac OSXUse Ruby Version Manager http://beginrescueend.com/$ bash -s stable <<(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer) 34
  51. 51. Installing vmc on Mac OSXUse Ruby Version Manager http://beginrescueend.com/$ bash -s stable <<(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)$ rvm install 1.9.2$ rvm use 1.9.2 34
  52. 52. Installing vmc on Mac OSXUse Ruby Version Manager http://beginrescueend.com/$ bash -s stable <<(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)$ rvm install 1.9.2$ rvm use 1.9.2$ gem install vmc 34
  53. 53. Example vmc commands $ vmc target <any cloud> $ vmc login <credentials> $ vmc push <my-app> ! > bind services? Yes $ vmc update <my-app> $ vmc instances <my-app> +100 35
  54. 54. VMC CLI DEMO 36
  55. 55. VMC MANIFEST DEMO check out code deploy 37
  56. 56. Scale the application$ vmc instances cf1 +2Scaling Application instances up to 3: OK$ vmc stats cf1+----------+-------------+----------------+--------------+--------------+| Instance | CPU (Cores) | Memory (limit) | Disk (limit) | Uptime |+----------+-------------+----------------+--------------+--------------+| 0 | 1.2% (4) | 90.6M (512M) | 8.5M (2G) | 0d:0h:3m:3s || 1 | 9.5% (4) | 60.9M (512M) | 8.4M (2G) | 0d:0h:0m:17s || 2 | 9.4% (4) | 55.5M (512M) | 8.4M (2G) | 0d:0h:0m:17s |+----------+-------------+----------------+--------------+--------------+
  57. 57. http://www.springsource.com/downloads/sts
  58. 58. Install the Cloud Foundry plugin.... 40
  59. 59. ... 41
  60. 60. ... 42
  61. 61. STS DEMO 43
  62. 62. Recap so far… Understand PaaS Register for Cloud Foundry Installed the Cloud Foundry Plugin Logged In/Authenticated Create a Spring MVC App Deployed MVC App to Cloud Foundry Hit URL from STS and Viewed MVC App Learned about vmc 45
  63. 63. AgendaWhy PaaS matters to developersOverview of Cloud FoundryGetting started with Cloud FoundryCloud Foundry architectureUsing Micro Cloud FoundryConsuming Cloud Foundry services 46
  64. 64. Cloud Foundry - Architecture Message Bus Message Bus Web Web Message Bus (NATS) (NATS) (NATS)100’s of DEAs App Load Balancers Load Balancers App Load Balancers App DEAs DEAs DEAs Routers Routers Routers Cloud Cloud Controllers Cloud Controllers DB Controllers DB DB Web Service API Services Health Health Services Health Manager Services Manager Manager Client, e.g.VMC
  65. 65. Application deployment flow VMC Cloud Controller DEA DEA Application Router Router 48
  66. 66. Application deployment flowvmc push VMC Cloud Controller DEA DEA Application Router Router 48
  67. 67. Application deployment flowvmc push VMC Cloud Controller DEA DEA Application Framework detection Router Router 48
  68. 68. Application deployment flowvmc push create app VMC Cloud Controller DEA DEA Application Framework detection Router Router 48
  69. 69. Application deployment flowvmc push create app VMC Cloud Controller DEA DEA Application Framework detection Framework specific staging plugin Creates Droplet Router Router 48
  70. 70. Application deployment flow find DEA for appvmc push create app VMC Cloud Controller DEA DEA Application Framework detection Framework specific staging plugin Creates Droplet Router Router 48
  71. 71. Application deployment flow find DEA for appvmc push I’m available create app VMC Cloud Controller DEA DEA Application Framework detection Framework specific staging plugin Creates Droplet Router Router 48
  72. 72. Application deployment flow find DEA for appvmc push I’m available create app VMC Cloud Controller DEA DEA Application deploy droplet Framework detection Framework specific staging plugin Creates Droplet Router Router 48
  73. 73. Application deployment flow find DEA for appvmc push I’m available create app VMC Cloud Controller start DEA DEA Application deploy droplet Framework detection Framework specific staging plugin Creates Droplet Router Router 48
  74. 74. Application deployment flow find DEA for appvmc push I’m available create app VMC Cloud Controller start DEA DEA Application deploy droplet Framework detection Framework specific staging plugin update routes Creates Droplet Router Router 48
  75. 75. About the staging plugin Framework specific Creates a zip file = black box • Contains everything necessary for DEA to run the application • Two scripts: start.sh, stop.sh 49
  76. 76. Staging plugin for the Spring framework Adds CloudAutoStagingBeanFactoryPostProcessor bean: • Modifies bean definitions • Implements auto-reconfiguration Defines CloudApplicationContextInitializer in web.xml • Activates cloud profile • Defines PropertySource for CloudEnvironment properties 50
  77. 77. VCAP_APPLICATION environment variable{ "instance_id": "598f4af3b49ed5fc9bd19bef67650f61", "instance_index": 0, "name": "myapplication", "uris": ["myapp.cloudfoundry.com"], "users": ["crichardson@vmware.com"], "version": "6126ec0a1ea366c61635398f1d2824086e40aec4-1", "start": "2012-02-24 06:39:17 +0000", "runtime": "node", "state_timestamp": 1330065557, "port": 21059, "limits": { Tells your application about "fds": 256, where it is running "mem": 67108864, "disk": 2147483648 }, "host": "172.30.50.10"} String value = System.getenv("VCAP_APPLICATION") 51
  78. 78. Custom Application environment variables$ vmc env-add cf1 PAYMENT_SVC=http://...Adding Environment Variable [PAYMENT_SVC=http://...]: OKStopping Application: OKStaging Application: OKStarting Application: OK String value = System.getenv("PAYMENT_SVC") @Value("#{systemEnvironment[PAYMENT_SVC]}") private String envVariable;
  79. 79. Request handling flow Load Balancer Router Application Load Balancer Router DEA 53
  80. 80. Request handling flowHTTP Request Load Balancer Router Application Load Balancer Router DEA 53
  81. 81. Request handling flowHTTP Request HTTP Request Load Balancer Router Application Load Balancer Router DEA 53
  82. 82. Request handling flowHTTP Request HTTP Request HTTP Request Load Balancer Router Application Load Balancer Router DEA 53
  83. 83. Self Healing Infrastructure If an application instance crashes • DEA detects unexpected exit => DEA broadcasts message • Routers remove instance from routing • Health manager notifies Cloud Controller • Cloud Controller re-launches instance If an DEA VM crashes • Application instances become unavailable • Health Manager notices the missing instances and notifies the Cloud Controller • Cloud Controller requests application instances to be started • Existing DEA will reply and start the applications
  84. 84. But where are the VMs?!? Cloud Foundry has a layered architecture • Cloud Controller, DEA, … layer = processes • VM management layer Benefits: decoupling, simplicity, …. CloudFoundry.com creates vSphere VMs running different Cloud Foundry components
  85. 85. Recap DEAs Service Gateways NATS Cloud Controllers Routing/Load Balancing Health Manager 56
  86. 86. Agenda Why PaaS matters to developers Overview of Cloud Foundry Getting started with Cloud Foundry Cloud Foundry architecture Using Micro Cloud Foundry Consuming Cloud Foundry services 57
  87. 87. What is in Micro Cloud Foundry? App Instances Services Open source Platform as a Service project 10.04 A cloud packaged as a VMware Virtual Machine Use as a developer sandbox • Use the services from Junit integration tests • Deploy your application for functional testing • Remote debugging from STS 58
  88. 88. Pre-requisites for using Micro Cloud Foundry Minimum 1 GB Minimum 8 GB Internet Connectivity RAM Disk (w/DHCP is ideal) VMC STS Command line GUI 59
  89. 89. Configuring Micro Cloud Foundry 60
  90. 90. Register and login to CloudFoundry.com 61
  91. 91. Select a domain name*.cloudfoundry.me => IP address of your machine where Micro Cloud Foundry is running 62
  92. 92. Remember the configuration token 63
  93. 93. Download, unzip and open micro.vmx 64
  94. 94. Configure Micro Cloud Foundry 65
  95. 95. Configure Micro Cloud Foundry Pick password 65
  96. 96. Configure Micro Cloud Foundry Pick password Enter token 65
  97. 97. Logging into Micro Cloud Foundry 66
  98. 98. Logging into Micro Cloud Foundry$ vmc target api.cer-micro1.cloudfoundry.meSuccessfully targeted to [http://api.cer-micro1.cloudfoundry.me] 66
  99. 99. Logging into Micro Cloud Foundry$ vmc target api.cer-micro1.cloudfoundry.meSuccessfully targeted to [http://api.cer-micro1.cloudfoundry.me]$ vmc registerEmail: crichardson@vmware.comPassword: ********Verify Password: ********Creating New User: OKAttempting login to [http://api.cer-micro1.cloudfoundry.me]Successfully logged into [http://api.cer-micro1.cloudfoundry.me] 66
  100. 100. Micro Cloud Foundry has all the services$ vmc services============== System Services ==============+------------+---------+---------------------------------------+| Service | Version | Description |+------------+---------+---------------------------------------+| mongodb | 1.8 | MongoDB NoSQL store || mysql | 5.1 | MySQL database service || postgresql | 9.0 | PostgreSQL database service (vFabric) || rabbitmq | 2.4 | RabbitMQ messaging service || redis | 2.2 | Redis key-value store service |+------------+---------+---------------------------------------+=========== Provisioned Services ============$ 67
  101. 101. Deploy an application in the usual way 68
  102. 102. Deploy an application in the usual way$ vmc push --path targetApplication Name: DemoWebappApplication Deployed URL [DemoWebapp.cer-micro1.cloudfoundry.me]:Detected a Java Web Application, is this correct? [Yn]:Memory Reservation (64M, 128M, 256M, 512M, 1G) [512M]:Creating Application: OKWould you like to bind any services to DemoWebapp? [yN]:Uploading Application: Checking for available resources: OK Packing application: OK Uploading (3K): OKPush Status: OKStaging Application: OKStarting Application: OK 68
  103. 103. Deploy an application in the usual way$ vmc push --path targetApplication Name: DemoWebappApplication Deployed URL [DemoWebapp.cer-micro1.cloudfoundry.me]:Detected a Java Web Application, is this correct? [Yn]:Memory Reservation (64M, 128M, 256M, 512M, 1G) [512M]:Creating Application: OKWould you like to bind any services to DemoWebapp? [yN]:Uploading Application: Checking for available resources: OK Packing application: OK Uploading (3K): OKPush Status: OKStaging Application: OKStarting Application: OK$ curl DemoWebapp.cer-micro1.cloudfoundry.me<html><body><h2>Hello World!</h2></body></html>Chriss-MacBook-Pro:demowebapp cer$ 68
  104. 104. Offline Micro Cloud Foundry The problem: • Cloud Foundry accessed via hostname, which is pretty cool • Hostname resolved by DNS server ==> laptop needs to be online The solution: • Micro Cloud Foundry now supports true offline mode • New command:vmc micro • Reconfigures DNS on your machine to resolve *.cloudfoundry.me locally • Requires: vmc 0.3.16.beta4 or higher, on Mac VMware Fusion 4.x 69
  105. 105. Offline Micro Cloud Foundry: vmc micro status saved in ~/.vmc_micro$ vmc micro --vmx /MyVirtualMachines/micro.vmx --vmrun /Applications/VMware Fusion.app/Contents/Library/vmrun statusPlease enter your Micro Cloud Foundry VM password (vcap user) password: ********Micro Cloud Foundry VM is not running. Do you want to start it? (y, n): yStarting Micro Cloud Foundry VM: doneMicro Cloud Foundry VM currently in online modeVMX Path: /Users/cer/Downloads/microCloudFoundry/micro/micro.vmxDomain: cer-micro1.cloudfoundry.meIP Address: 192.168.253.128 70
  106. 106. Offline Micro Cloud Foundry: vmc micro offline/online 71
  107. 107. Offline Micro Cloud Foundry: vmc micro offline/online$ vmc micro offlinePlease enter your Micro Cloud Foundry VM password (vcap user) password: ********Setting Micro Cloud Foundry VM to offline mode: doneSetting host DNS server: done Reconfigures DNS to use Micro Cloud Foundry as one of the DNS servers Resolves cer-micro1.cloudfoundry.me to 192.168.253.128 71
  108. 108. Offline Micro Cloud Foundry: vmc micro offline/online$ vmc micro offlinePlease enter your Micro Cloud Foundry VM password (vcap user) password: ********Setting Micro Cloud Foundry VM to offline mode: doneSetting host DNS server: done Reconfigures DNS to use Micro Cloud Foundry as one of the DNS servers Resolves cer-micro1.cloudfoundry.me to 192.168.253.128$ vmc micro onlinePlease enter your Micro Cloud Foundry VM password (vcap user) password: ********Unsetting host DNS server: doneSetting Micro Cloud Foundry VM to online mode: done Undoes the change to DNS configuration 71
  109. 109. Recap… Installed the Micro Cloud Foundry Got a Token Configured Micro Cloud Foundry Registered Logged In/Authenticated Created a Spring MVC App Deployed MVC App to Micro Cloud Foundry Set a breakpoint, hit URL from STS and viewed MVC App 72
  110. 110. Agenda Why PaaS matters to developers Overview of Cloud Foundry Getting started with Cloud Foundry Cloud Foundry architecture Using Micro Cloud Foundry Consuming Cloud Foundry services 73
  111. 111. Current Services Available on Cloud Foundry 74
  112. 112. Creating a service instance$ vmc create-service mysql --name mysql1Creating Service: OK$ vmc services============== System Services ==============+------------+---------+---------------------------------------+| Service | Version | Description |+------------+---------+---------------------------------------+| mongodb | 1.8 | MongoDB NoSQL store || mysql | 5.1 | MySQL database service || postgresql | 9.0 | PostgreSQL database service (vFabric) || rabbitmq | 2.4 | RabbitMQ messaging service || redis | 2.2 | Redis key-value store service |+------------+---------+---------------------------------------+=========== Provisioned Services ============+-------------+---------+| Name | Service |+-------------+---------+| mysql1 | mysql |+-------------+---------+
  113. 113. Binding a service to an application$ vmc push cer-spring --path web/target/Application Deployed URL [cer-spring.cloudfoundry.com]:Detected a Java SpringSource Spring Application, is this correct? [Yn]:Memory Reservation (64M, 128M, 256M, 512M, 1G) [512M]:Creating Application: OKWould you like to bind any services to cer-spring? [yN]: yWould you like to use an existing provisioned service? [yN]: yThe following provisioned services are available1: mysql12: mysql-135e0Please select one you wish to use: 1Binding Service [mysql1]: OKUploading Application: Checking for available resources: OK Processing resources: OK Packing application: OK Uploading (12K): OK
  114. 114. Binding a service to an application $ vmc push cer-spring --path web/target/ Application Deployed URL [cer-spring.cloudfoundry.com]: Detected a Java SpringSource Spring Application, is this correct? [Yn]: Memory Reservation (64M, 128M, 256M, 512M, 1G) [512M]: Creating Application: OKWould you like to bind any services to cer-spring? [yN]: y [yN]: y Would you like to bind any services to cer-spring?Would you like to use anan existing provisioned service? [yN]: y Would you like to use existing provisioned service? [yN]: yThe The following provisioned servicesavailable following provisioned services are are available1: mysql1 1: mysql12: mysql-135e0 2: mysql-135e0Please select one you wish to use:use: 1 Please select one you wish to 1Binding Service [mysql1]: OK OK Binding Service [mysql1]: Uploading Application: Checking for available resources: OK Processing resources: OK Packing application: OK Uploading (12K): OK
  115. 115. Binding a service to an application$ vmc push cer-spring --path web/target/Application Deployed URL [cer-spring.cloudfoundry.com]:Detected a Java SpringSource Spring Application, is this correct? [Yn]:Memory Reservation (64M, 128M, 256M, 512M, 1G) [512M]:Creating Application: OKWould you like to bind any services to cer-spring? [yN]: yWould you like to use an existing provisioned service? [yN]: yThe following provisioned services are available1: mysql12: mysql-135e0Please select one you wish to use: 1Binding Service [mysql1]: OKUploading Application: Checking for available resources: OK Processing resources: OK Packing application: OK Uploading (12K): OK
  116. 116. Binding a service to an application$ vmc bind-service mysql1 myappBinding Service [mysql1]: OKStopping Application myapp: OKStaging Application myapp: OKStarting Application myapp: OK$
  117. 117. Binding in STS78
  118. 118. Survey application demo 79
  119. 119. Uses MySQL and MongoDB @Entity public class Customer { Stored in MySQL @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String firstName; private String lastName; Stored in Mongo @RelatedDocument private SurveyInfo surveyInfo;public class SurveyInfo { public class Survey { private List<Survey> questionsAndAnswers = new ArrayList<Survey>(); String question; public List<Survey> getQuestionsAndAnswers() { String answer; return questionsAndAnswers; } 80
  120. 120. Bindings exposed through VCAP_SERVICES environment variable{ "mysql-5.1": [{ "name": "mysql1", "label": "mysql-5.1", "plan": "free", "tags": ["mysql", "mysql-5.1", "relational"], "credentials": { "name": "da81b57c25cca4c65929a223f0ed068a0", "host": "172.99.99.99", "port": 3306, "username": "secretusername", "password": "secretuserpassword" .... } }]} 82
  121. 121. Accessing bound services - low-level var services = JSON.parse(process.env.VCAP_SERVICES); var creds = services[mysql-5.1][0].credentials configure do services = JSON.parse(ENV[VCAP_SERVICES]) mysql_key = services.keys.select { |svc| svc =~ /mysql/i }.first mysql = services[mysql_key].first[credentials] mysql_conf = {:host => mysql[hostname], :port => mysql[port], :username => mysql[user], :password => mysql[password]} @@client = Mysql2::Client.new mysql_conf end 83
  122. 122. Accessing bound services - high-level, Spring/Java 84
  123. 123. Accessing bound services - high-level, Spring/JavaCloudEnvironment environment = new CloudEnvironment();RdbmsServiceInfo mysqlSvc = environment.getServiceInfo("mysqlService", RdbmsServiceInfo.class);RdbmsServiceCreator dataSourceCreator = new RdbmsServiceCreator();DataSource dataSource = dataSourceCreator.createService(mysqlSvc); 84
  124. 124. Accessing bound services - high-level, Spring/JavaCloudEnvironment environment = new CloudEnvironment();RdbmsServiceInfo mysqlSvc = environment.getServiceInfo("mysqlService", RdbmsServiceInfo.class);RdbmsServiceCreator dataSourceCreator = new RdbmsServiceCreator();DataSource dataSource = dataSourceCreator.createService(mysqlSvc);<cloud:data-source id="dataSource" service-name="mysql1"> <cloud:pool pool-size="1-5"/> <cloud:connection properties="charset=utf-8"/></cloud:data-source>... 84
  125. 125. Accessing bound services - high-level, Spring/JavaCloudEnvironment environment = new CloudEnvironment();RdbmsServiceInfo mysqlSvc = environment.getServiceInfo("mysqlService", RdbmsServiceInfo.class);RdbmsServiceCreator dataSourceCreator = new RdbmsServiceCreator();DataSource dataSource = dataSourceCreator.createService(mysqlSvc);<cloud:data-source id="dataSource" service-name="mysql1"> <cloud:pool pool-size="1-5"/> <cloud:connection properties="charset=utf-8"/></cloud:data-source>... reconfigured automatically <bean id="dataSource" class="…"> … DataSource for MySQL instance … </bean> 84
  126. 126. Accessing bound services - high-level, Ruby reconfigured automaticallyRedisHost = "127.0.0.1"RedisPort = 10000$r = Redis.new(:host => RedisHost, :port => RedisPort) if !$r rewritten automaticallyproduction: adapter: sqlite3 database: db/production.sqlite3 85
  127. 127. Recap… Services : • SQL and NoSQL databases • Message broker • ... Service Bindings • VCAP_SERVICES environment variable • JSON Format Framework-dependent ways of accessing the bindings: • Parse JSON • ... • Spring, Sinatra and Rails have auto-reconfiguration 86
  128. 128. Services are great but what if we want to Use database tools?Use the services from JUnit integration tests? 87
  129. 129. Using Caldecott to tunnel into your services 88
  130. 130. Caldecott Demo 89
  131. 131. Running JUnit test with Caldecott Configure your test code to use port + connection info 91
  132. 132. Summary 92
  133. 133. Cloud Foundry is aremarkably easy way todeploy your applications 93
  134. 134. Cloud Foundry = Choice 94
  135. 135. .js Ap ce Private p lic Data rfaServices Clouds at te io In n er Se vid r Public vic o Clouds e Pr Msg Services In ud te o rfa Cl ce Other Micro Services Clouds
  136. 136. Questions?Signup @ www.cloudfoundry.com using promo code: CFOpenTour2012
  137. 137. Folks to meet•Adron Hall Iron Foundry Lead •@adron• Jeremy Voorhis Senior CF Developer @ App Fog •@jvoorhis© 2012 VMware, Inc. All rights reserved
  138. 138. Thank YouCloudFoundry Spring Source Samples: http://bit.ly/cloudfoundry-sampleshttp://cloudfoundry.comQuestions: @cloudfoundry•Josh -> @starbuxman or josh.long@springsource.com•Monica -> @ciberch or mwilkinson@cloudfoundry.com© 2012 VMware, Inc. All rights reserved

×