SlideShare a Scribd company logo
1 of 62
Download to read offline
MongoDB App Duet
          Ruby and Java on Cloud Foundry

          By Monica Wilkinson and Josh Long
           Cloud Foundry, Developer Relations




                           © 2012 VMware, Inc. All rights reserved   MongoLA 2012
Thursday, January 19, 12
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

Thursday, January 19, 12
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

Thursday, January 19, 12
Cloud Foundry




                               CONFIDENTIAL
                                              4

Thursday, January 19, 12
About Cloud Foundry                                 The first Open PaaS

                           Multi(n) Languages, Frameworks,
                                   Services & Clouds
                                    Open Source




                                       CONFIDENTIAL
                                                                        5

Thursday, January 19, 12
STEP 1 - Get a Cloud Foundry account
   https://my.cloudfoundry.com/signup/MongoLA




                           CONFIDENTIAL
                                                 6

Thursday, January 19, 12
STEP 2 - Download VMC


      •sudo gem
        install vmc
      •vmc login
        <username>




                           CONFIDENTIAL
                                          7

Thursday, January 19, 12
STEP 3: Push your app to Cloud Foundry
     vmc push --runtime=ruby19




                           CONFIDENTIAL
                                          8

Thursday, January 19, 12
You are done
  Service gets created and bound

  Code gets pushed

  App is Live immediately at the
   url you requested


                           © 2012 VMware, Inc. All rights reserved

Thursday, January 19, 12
Every day development
   Debugging and accessing the data locally
         • Caldecott --> Service tunneling. Access your Cloud Foundry service as if it was local.




                                               CONFIDENTIAL
                                                                                                    10

Thursday, January 19, 12
Tunneling
  gem install
  caldecott




  vmc tunnel
  <mongodb>




                           CONFIDENTIAL
                                          11

Thursday, January 19, 12
Using your favorite tools




                           CONFIDENTIAL
                                          12

Thursday, January 19, 12
CONFIDENTIAL
                                          13

Thursday, January 19, 12
Why MongoDB?




                                                                     14
                           © 2012 VMware, Inc. All rights reserved

Thursday, January 19, 12
Data Access Challenge #1: Scale Horizontally




                           CONFIDENTIAL
                                                 15

Thursday, January 19, 12
Data Access Challenge #2: Heterogeneous




                           CONFIDENTIAL
                                            16

Thursday, January 19, 12
New demands on data
                            access
   •... until we needed
   inexpensive horizontal
   scaling for some large web
   based applications ...
   • ... and we needed to
   deploy our apps in the
   cloud ...

                              CONFIDENTIAL   * image courtesy of Bitcurrent
                                                                              17

Thursday, January 19, 12
NoSQL offers several data store categories


Key-Value                  Column               Document      Graph




     Redis,                Cassandra,              MongoDB   Neo4J
     Riak                  HBase




                                        CONFIDENTIAL
                                                                      18

Thursday, January 19, 12
About Mongo DB

   1. No-SQL database                        development : {

   2. Stores JSON-style                           tools: many,
      documents                                   language_support: superb,



                              =
   3. Horizontally scalable                       agility: high
                                             },
   4. Full Indexing Support                  production: {
   5. Open Source                                 speed: fast
                                                  fault_tolerance: true
   6. Great Community(You!)
                                                  scalability: high




                              CONFIDENTIAL
                                                                              19

Thursday, January 19, 12
NoSQL offers several data store categories


Key-Value                  Column           Document                             Graph




                                                   MongoDB
                                                   (who cares about the rest?)




                                    CONFIDENTIAL
                                                                                         20

Thursday, January 19, 12
Mongo and Ruby
                              Deep Dive




                              CONFIDENTIAL
                                             21

Thursday, January 19, 12
Integration with Box(.net)




                           CONFIDENTIAL
                                          22

Thursday, January 19, 12
Box Sample App Creation Wizard
  • Requirement: Clone sample Box app for developers into their own Cloud Foundry
   account so they can learn how to use the BOX Api.




                                       CONFIDENTIAL
                                                                                23

Thursday, January 19, 12
Challenges
  •   No command to download all the files for an app or copy it to another account.




       •Solution:    The Cloud
           •Get   the code for an app from: GitHub
           •Use   vmc gem to upload the contents to your desired cloud


                                            CONFIDENTIAL
                                                                                       24

Thursday, January 19, 12
VMC as a gem

   Can be used to authenticate users and
      exchange their credentials for an API token
   Edit Applications and Services from your
      code
      • Files
      • Environment Variables
   Start and Stop Apps

                            CONFIDENTIAL
                                                    25

Thursday, January 19, 12
How we used VMC on this project
      def create()
         begin
           @vmcclient.create_app(@manifest["name"], @manifest)
         rescue RuntimeError => ex
           if (ex.message =~ /Error 701/)
             new_candidate = @generator.next
             unless new_candidate.nil?
               change_name! new_candidate
               create
             else
               # Format is "Error #{parsed_body[:code]}: #{desc}"
               raise "App Url: #{@uri} is already taken"
             end
           else
             raise ex
           end
         end
       end

       def delete()
         @vmcclient.delete_app(@manifest["name"])
       end

       def copy_code()
         @vmcclient.upload_app(@manifest["name"], @app_meta.build!)
       end

                                             CONFIDENTIAL
                                                                      26

Thursday, January 19, 12
More Challenges

   External Models we didn’t control
      • Cloud Foundry Apps: Files, Runtime, Services, Env Vars,
        etc

      • GitHub Repositories: Files, Commits, branches, tags
      • Solution
         • Use an Object Document Mapper. I chose Mongoid
         • Easy to add new objects and properties
         • No Migrations !


                                  CONFIDENTIAL
                                                                  27

Thursday, January 19, 12
CONFIDENTIAL
                                          28

Thursday, January 19, 12
Things you should know about Mongoid
   Project Page - http://mongoid.org.
   Features:
    • Uses Active Model (Dirty Tracking, Mass Assignment
      Security, Validations, Callbacks, JSON/XML Serialization)
    • Indexing
    • Supports identity map, replica sets and sharding
    • Custom field serialization
         • A Range in Ruby 1...3 could be stored in MongoDB as a Hash { :min =>
           1, :max => 3 }
      • Localization Support:(Translated Fields, i18n Fallbacks)
      • Inheritance



                                      CONFIDENTIAL
                                                                             29

Thursday, January 19, 12
How we used Mongoid
  module CloudFoundry
    class AppInfo
      include TmpZip
      include Mongoid::Document

      embeds_many :app_clone_requests
      belongs_to :repo, :class_name => "GitHub::RepositorySnapshot"

      field    :display_name, :type => String
      field    :description, :type => String
      field    :instances, :type => Integer, :default => 1
      field    :memory, :type => Integer, :default => 128
      field    :runtime, :type => String
      field    :framework, :type => String
      field    :env_vars, :type => Hash
      field    :thumb_url, :type => String
      field    :browseable, :type => Boolean
      field    :cloneable, :type => Boolean
      field    :starting_url, :type => String

      index :display_name, :unique => true

      validates_presence_of :display_name, :runtime, :framework
      validates_presence_of :repo, :if => :cloneable



                                               CONFIDENTIAL
                                                                      30

Thursday, January 19, 12
How we used Mongoid
   module GitHub
     class RepositorySnapshot
       include TmpZip
       include Mongoid::Document

       field    :url, :type => String
       field    :name, :type => String
       field    :parent, :type => String
       field    :branch, :type => String, :default => 'master'
       field    :tag, :type => String
       field    :commit, :type => String

       index :url, :unique => true

       validates_presence_of :url, :name, :parent, :commit, :branch

       def url=(value)
         parts = value.gsub(/https://github.com//, '').split('/')
         if (parts.length == 2)
           write_attribute(:parent, parts[0])
           write_attribute(:name, parts[1])
         else
           write_attribute(:parent, nil)
           write_attribute(:name, nil)
         end
         write_attribute(:url, value)
       end                                    CONFIDENTIAL
                                                                        31

Thursday, January 19, 12
Getting your ruby app to use the proper
  module CloudFoundry

    class Mongo

        def self.config

          Mongoid.configure do |config|

            conn_info = nil

            dbname = 'db'

            if ENV['VCAP_SERVICES']

              services = JSON.parse ENV['VCAP_SERVICES']

              services.each do |service_version, bindings|

                mongo_binding = bindings.find {|binding| binding['label'] =~ /mongo/i}

                conn_info = mongo_binding['credentials'] if mongo_binding

              end

              raise "ERROR - Could not find connection info for mongo" unless conn_info

            else

              conn_info = {'hostname' => 'localhost', 'port' => 27017}

              dbname = "gallery_db"

            end
                                             CONFIDENTIAL
             @@cnx = Mongo::Connection.new conn_info['hostname'], conn_info['port'], :pool_size =>
                                                                                              32
   5, :timeout => 5
Thursday, January 19, 12
Demo




                           CONFIDENTIAL
                                          33

Thursday, January 19, 12
Durran, creator of Mongoid detailed for us:
    Full atomic update support out of the box for *all* MongoDB
    atomic operations, either explicitly or handled under the
    covers by Mongoid itself with support for embedded n levels
    deep. ie:


    model = Model.find(id)
    model.field = “value”
    model.relations.build(field: “value”)
    model.save
    #=> Does
    { field: { “$set” : “value” },
    relations: { “$push” : { field: “value” }}} for
    you.
                       *or things like*
    model.add_to_set(field: “value”)  CONFIDENTIAL
                                                                  34

Thursday, January 19, 12
Durran, creator of Mongoid detailed for us

      “Smart memory management during
      iteration and working with relations:

      Mongoid never loads everything into
      memory unless you specifically want it
      to. It can handle working with millions
      of documents without putting stress on
      the server/RAM.”

                           CONFIDENTIAL
                                                35

Thursday, January 19, 12
More Challenges
   Make app fast.
      • Downloading and copying files from app to app is not cheap
      • Solution
         • Avoid downloading the build if it has not changed
         • Local cache using Mongo GridFS




                                               CONFIDENTIAL
                                                                     36

Thursday, January 19, 12
Working with GridFS
    Saving and Reading files
   Once you have a Grid object, you can start saving data to it.
   @db = Mongo::Connection.new.db('social_site')
   @grid = Grid.new(@db)

   # On this Cloud Foundry App
   @grid = Mongo::GridFileSystem.new(Mongoid.database)

   # Saving IO data and including the optional filename
   image = File.open("me.jpg")
   id    = @grid.put(image, :filename => "me.jpg")
   Grid#put returns an object id, which you can use to retrieve the file:
   # Get the file we saved
   image = @grid.get(id)
    Deleting files
   Deleting a file is as simple as providing the id:
   @grid.delete(id2)
                                       CONFIDENTIAL
                                                                           37

Thursday, January 19, 12
Spring Data on Cloud Foundry Deep Dive




                           CONFIDENTIAL
                                                   38

Thursday, January 19, 12
Spring Framework
            built-in data access support
     •Transaction abstractions
     •Common data access exception hierarchy
     •JDBC - JdbcTemplate
     •ORM - Hibernate, JPA support
     •OXM - Object to XML mapping
     •Serializer/Deserializer strategies (Spring 3.0)
     •Cache support (Spring 3.1)

                                       CONFIDENTIAL
                                                        39

Thursday, January 19, 12
Spring Data Building Blocks



     •Low level data access APIs
            ✓MongoTemplate, RedisTemplate ...
     •Object Mapping (Java and GORM)
     •Cross Store Persistence Programming model
     •Generic Repository support
     •Productivity support in Roo and Grails

                                     CONFIDENTIAL
                                                    40

Thursday, January 19, 12
Spring Data Document
                           Mongo
  •MongoTemplate
     •MongoConverter interface for mapping Mongo documents
     •SimpleMongoConverter for basic POJO mapping support
     •Leverage Spring 3.0 TypeConverters and SpEL
     •Exception translation
  •Advanced Mapping
     •Annotation based (@Document, @Id, @DbRef)
  •MongoRepository
     •Built on Hades support for JPA Repositories
                               CONFIDENTIAL
                                                             41

Thursday, January 19, 12
Simple Domain Class




                           CONFIDENTIAL
                                          42

Thursday, January 19, 12
Mongo Template
 Direct Usage of the Mongo Template:




                                  CONFIDENTIAL
                                                 43

Thursday, January 19, 12
Mongo Template
 Direct Usage of the Mongo Template:




                           Insert into “Person”
                               Collection




                                              CONFIDENTIAL
                                                             43

Thursday, January 19, 12
Mongo Template
 Direct Usage of the Mongo Template:




                     findOne using query: { "name" : "Joe"}
                           in db.collection: database.Person




                                                 CONFIDENTIAL
                                                                43

Thursday, January 19, 12
Mongo Template
 Direct Usage of the Mongo Template:




                   Dropped collection [database.person]




                                            CONFIDENTIAL
                                                           43

Thursday, January 19, 12
Generic Repository
  Interface for generic CRUD operations on a repository for a specific type




                                     CONFIDENTIAL
                                                                              44

Thursday, January 19, 12
Paging and Sorting Repository
    Paging and Sorting Repository:                  Extends “CrudRepository”




                                     CONFIDENTIAL
                                                                               45

Thursday, January 19, 12
Paging and Sorting Repository
    Paging and Sorting Repository:                  Extends “CrudRepository”




     Usage:




                                     CONFIDENTIAL
                                                                               45

Thursday, January 19, 12
Custom Repository
 Custom Repository:




                           CONFIDENTIAL
                                          46

Thursday, January 19, 12
Custom Repository
 Custom Repository:




   Keywords :
   Keyword                 Sample                                  Logical result
   GreaterThan             findByAgeGreaterThan(int age)           {"age" : {"$gt" : age}}

   LessThan                findByAgeLessThan(int age)              {"age" : {"$lt" : age}}

   Between                 findByAgeBetween(int from, int to)      {"age" : {"$gt" : from, "$lt" : to}}

   NotNull                 findByFirstnameNotNull()                {”firstname" : {"$ne" : null}}

   Null                    findByFirstnameNull()                   {”firstname" : null}

   Like                    findByFirstnameLike(String name)
                                                    CONFIDENTIAL   "firstname" : firstname} (regex)
                                                                                                          46

Thursday, January 19, 12
JPA and MongoDB
     JPA “Customer” with a “SurveyInfo” Document




                                   CONFIDENTIAL
                                                   47

Thursday, January 19, 12
Using a Cross-Store
      Saving a Customer with a SurveryInfo




                                    CONFIDENTIAL
                                                   48

Thursday, January 19, 12
Using a Cross-Store
      Saving a Customer with a SurveryInfo
                               Create Customer




                                    CONFIDENTIAL
                                                   48

Thursday, January 19, 12
Using a Cross-Store
      Saving a Customer with a SurveryInfo

                                Create SurveyInfo




                                    CONFIDENTIAL
                                                    48

Thursday, January 19, 12
Using a Cross-Store
      Saving a Customer with a SurveryInfo




                           Assign Survey to Customer




                                               CONFIDENTIAL
                                                              48

Thursday, January 19, 12
Using a Cross-Store
      Saving a Customer with a SurveryInfo




                             Save




                                    CONFIDENTIAL
                                                   48

Thursday, January 19, 12
Using a Cross-Store
      Saving a Customer with a SurveryInfo




                             Save




      Mongo Document:




                                    CONFIDENTIAL
                                                   48

Thursday, January 19, 12
Accessing Services Bound to Cloud Foundry
  private String mongoDatabaseServiceName = "survey-mongo";

  @Bean
  public CloudEnvironment cloudEnvironment() {
  	   return new CloudEnvironment();
  }

  @Bean
  public MongoServiceInfo mongoServiceInfo() {
  	   return cloudEnvironment().getServiceInfo(
         mongoDatabaseServiceName, MongoServiceInfo.class);
  }

  @Bean
  public MongoDbFactory mongoDbFactory() {
  	   MongoServiceCreator msc = new MongoServiceCreator();
  	   MongoDbFactory db = msc.createService(mongoServiceInfo());
  }


                                  CONFIDENTIAL
                                                                   49

Thursday, January 19, 12
Accessing Services Bound to Cloud Foundry
  @Inject private Mongo mongo ;

  @Inject private MongoTemplate mongoTemplate;




                                  CONFIDENTIAL
                                                 50

Thursday, January 19, 12
Demo 2




                           CONFIDENTIAL
                                          51

Thursday, January 19, 12
Thank You
                           CloudFoundry Spring Source Samples:
                             http://bit.ly/cloudfoundry-samples


                           http://cloudfoundry.com
                           Questions: @cloudfoundry
                           •Josh -> @starbuxman or josh.long@springsource.com
                           •Monica -> @ciberch or mwilkinson@cloudfoundry.com


                           © 2012 VMware, Inc. All rights reserved

Thursday, January 19, 12

More Related Content

Similar to MongoLA - Cloud Foundry

Semantic Web Landscape 2009
Semantic Web Landscape 2009Semantic Web Landscape 2009
Semantic Web Landscape 2009LeeFeigenbaum
 
Introducing Immutant
Introducing Immutant Introducing Immutant
Introducing Immutant Jim Crossley
 
Chris Kemp Nebula Keynote
Chris Kemp Nebula KeynoteChris Kemp Nebula Keynote
Chris Kemp Nebula Keynotelaurabeckcahoon
 
Cloud Foundry Japan Community Meetup
Cloud Foundry Japan Community MeetupCloud Foundry Japan Community Meetup
Cloud Foundry Japan Community MeetupPatrick Chanezon
 
Japan Developer Summit (en) - Cloud Foundry, the Open Platform As A Service
Japan Developer Summit (en) - Cloud Foundry, the Open Platform As A ServiceJapan Developer Summit (en) - Cloud Foundry, the Open Platform As A Service
Japan Developer Summit (en) - Cloud Foundry, the Open Platform As A ServicePatrick Chanezon
 
NCA GTUG 2012 - Cloud is such stuff as dreams are made on
NCA GTUG 2012 - Cloud is such stuff as dreams are made onNCA GTUG 2012 - Cloud is such stuff as dreams are made on
NCA GTUG 2012 - Cloud is such stuff as dreams are made onPatrick Chanezon
 
CloudFoundry and MongoDb, a marriage made in heaven
CloudFoundry and MongoDb, a marriage made in heavenCloudFoundry and MongoDb, a marriage made in heaven
CloudFoundry and MongoDb, a marriage made in heavenPatrick Chanezon
 
Cloud Foundry, Spring and Vaadin
Cloud Foundry, Spring and VaadinCloud Foundry, Spring and Vaadin
Cloud Foundry, Spring and VaadinJoshua Long
 
Cloud Camp Chicago Dec 2012 Slides
Cloud Camp Chicago Dec 2012 SlidesCloud Camp Chicago Dec 2012 Slides
Cloud Camp Chicago Dec 2012 SlidesRyan Koop
 
Cloud Camp Chicago Dec 2012 - All presentations
Cloud Camp Chicago Dec 2012 - All presentationsCloud Camp Chicago Dec 2012 - All presentations
Cloud Camp Chicago Dec 2012 - All presentationsCloudCamp Chicago
 
Cloud Foundry Bootcamp
Cloud Foundry BootcampCloud Foundry Bootcamp
Cloud Foundry BootcampAlvaro Videla
 
Cloud Foundry the Open PaaS - OpenTour Austin Keynote
Cloud Foundry the Open PaaS - OpenTour Austin KeynoteCloud Foundry the Open PaaS - OpenTour Austin Keynote
Cloud Foundry the Open PaaS - OpenTour Austin KeynotePatrick Chanezon
 
Dynamic DataCenter Converged London 2012 - Nebula CEO Chris Kemp
Dynamic DataCenter Converged London 2012 - Nebula CEO Chris KempDynamic DataCenter Converged London 2012 - Nebula CEO Chris Kemp
Dynamic DataCenter Converged London 2012 - Nebula CEO Chris KempNebula
 
Cloud Foundry, the Open Platform as a Service - Oscon - July 2012
Cloud Foundry, the Open Platform as a Service - Oscon - July 2012Cloud Foundry, the Open Platform as a Service - Oscon - July 2012
Cloud Foundry, the Open Platform as a Service - Oscon - July 2012Patrick Chanezon
 
Open Saas brings freedom to the Cloud
Open Saas brings freedom to the Cloud Open Saas brings freedom to the Cloud
Open Saas brings freedom to the Cloud Cyril Reinhard
 
Scaling the Cloud - Cloud Security
Scaling the Cloud - Cloud SecurityScaling the Cloud - Cloud Security
Scaling the Cloud - Cloud SecurityBill Burns
 
Cloud4all Architecture Overview
Cloud4all Architecture OverviewCloud4all Architecture Overview
Cloud4all Architecture Overviewicchp2012
 
Adopting Open Source Business Intelligence: Who, Why and How
Adopting Open Source Business Intelligence: Who, Why and HowAdopting Open Source Business Intelligence: Who, Why and How
Adopting Open Source Business Intelligence: Who, Why and Howmark madsen
 

Similar to MongoLA - Cloud Foundry (20)

Semantic Web Landscape 2009
Semantic Web Landscape 2009Semantic Web Landscape 2009
Semantic Web Landscape 2009
 
Introducing Immutant
Introducing Immutant Introducing Immutant
Introducing Immutant
 
Chris Kemp Nebula Keynote
Chris Kemp Nebula KeynoteChris Kemp Nebula Keynote
Chris Kemp Nebula Keynote
 
Cloud Foundry Japan Community Meetup
Cloud Foundry Japan Community MeetupCloud Foundry Japan Community Meetup
Cloud Foundry Japan Community Meetup
 
Japan Developer Summit (en) - Cloud Foundry, the Open Platform As A Service
Japan Developer Summit (en) - Cloud Foundry, the Open Platform As A ServiceJapan Developer Summit (en) - Cloud Foundry, the Open Platform As A Service
Japan Developer Summit (en) - Cloud Foundry, the Open Platform As A Service
 
NCA GTUG 2012 - Cloud is such stuff as dreams are made on
NCA GTUG 2012 - Cloud is such stuff as dreams are made onNCA GTUG 2012 - Cloud is such stuff as dreams are made on
NCA GTUG 2012 - Cloud is such stuff as dreams are made on
 
NATO IST Symposium 2013
NATO IST Symposium 2013NATO IST Symposium 2013
NATO IST Symposium 2013
 
CloudFoundry and MongoDb, a marriage made in heaven
CloudFoundry and MongoDb, a marriage made in heavenCloudFoundry and MongoDb, a marriage made in heaven
CloudFoundry and MongoDb, a marriage made in heaven
 
Cloud Foundry, Spring and Vaadin
Cloud Foundry, Spring and VaadinCloud Foundry, Spring and Vaadin
Cloud Foundry, Spring and Vaadin
 
Cloud Camp Chicago Dec 2012 Slides
Cloud Camp Chicago Dec 2012 SlidesCloud Camp Chicago Dec 2012 Slides
Cloud Camp Chicago Dec 2012 Slides
 
Cloud Camp Chicago Dec 2012 - All presentations
Cloud Camp Chicago Dec 2012 - All presentationsCloud Camp Chicago Dec 2012 - All presentations
Cloud Camp Chicago Dec 2012 - All presentations
 
Cloud Foundry Bootcamp
Cloud Foundry BootcampCloud Foundry Bootcamp
Cloud Foundry Bootcamp
 
Cloud Foundry the Open PaaS - OpenTour Austin Keynote
Cloud Foundry the Open PaaS - OpenTour Austin KeynoteCloud Foundry the Open PaaS - OpenTour Austin Keynote
Cloud Foundry the Open PaaS - OpenTour Austin Keynote
 
Dynamic DataCenter Converged London 2012 - Nebula CEO Chris Kemp
Dynamic DataCenter Converged London 2012 - Nebula CEO Chris KempDynamic DataCenter Converged London 2012 - Nebula CEO Chris Kemp
Dynamic DataCenter Converged London 2012 - Nebula CEO Chris Kemp
 
Cloud foundry and openstackcloud
Cloud foundry and openstackcloudCloud foundry and openstackcloud
Cloud foundry and openstackcloud
 
Cloud Foundry, the Open Platform as a Service - Oscon - July 2012
Cloud Foundry, the Open Platform as a Service - Oscon - July 2012Cloud Foundry, the Open Platform as a Service - Oscon - July 2012
Cloud Foundry, the Open Platform as a Service - Oscon - July 2012
 
Open Saas brings freedom to the Cloud
Open Saas brings freedom to the Cloud Open Saas brings freedom to the Cloud
Open Saas brings freedom to the Cloud
 
Scaling the Cloud - Cloud Security
Scaling the Cloud - Cloud SecurityScaling the Cloud - Cloud Security
Scaling the Cloud - Cloud Security
 
Cloud4all Architecture Overview
Cloud4all Architecture OverviewCloud4all Architecture Overview
Cloud4all Architecture Overview
 
Adopting Open Source Business Intelligence: Who, Why and How
Adopting Open Source Business Intelligence: Who, Why and HowAdopting Open Source Business Intelligence: Who, Why and How
Adopting Open Source Business Intelligence: Who, Why and How
 

Recently uploaded

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 

Recently uploaded (20)

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 

MongoLA - Cloud Foundry

  • 1. MongoDB App Duet Ruby and Java on Cloud Foundry By Monica Wilkinson and Josh Long Cloud Foundry, Developer Relations © 2012 VMware, Inc. All rights reserved MongoLA 2012 Thursday, January 19, 12
  • 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 Thursday, January 19, 12
  • 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 Thursday, January 19, 12
  • 4. Cloud Foundry CONFIDENTIAL 4 Thursday, January 19, 12
  • 5. About Cloud Foundry The first Open PaaS Multi(n) Languages, Frameworks, Services & Clouds Open Source CONFIDENTIAL 5 Thursday, January 19, 12
  • 6. STEP 1 - Get a Cloud Foundry account  https://my.cloudfoundry.com/signup/MongoLA CONFIDENTIAL 6 Thursday, January 19, 12
  • 7. STEP 2 - Download VMC •sudo gem install vmc •vmc login <username> CONFIDENTIAL 7 Thursday, January 19, 12
  • 8. STEP 3: Push your app to Cloud Foundry vmc push --runtime=ruby19 CONFIDENTIAL 8 Thursday, January 19, 12
  • 9. You are done Service gets created and bound Code gets pushed App is Live immediately at the url you requested © 2012 VMware, Inc. All rights reserved Thursday, January 19, 12
  • 10. Every day development  Debugging and accessing the data locally • Caldecott --> Service tunneling. Access your Cloud Foundry service as if it was local. CONFIDENTIAL 10 Thursday, January 19, 12
  • 11. Tunneling gem install caldecott vmc tunnel <mongodb> CONFIDENTIAL 11 Thursday, January 19, 12
  • 12. Using your favorite tools CONFIDENTIAL 12 Thursday, January 19, 12
  • 13. CONFIDENTIAL 13 Thursday, January 19, 12
  • 14. Why MongoDB? 14 © 2012 VMware, Inc. All rights reserved Thursday, January 19, 12
  • 15. Data Access Challenge #1: Scale Horizontally CONFIDENTIAL 15 Thursday, January 19, 12
  • 16. Data Access Challenge #2: Heterogeneous CONFIDENTIAL 16 Thursday, January 19, 12
  • 17. New demands on data access •... until we needed inexpensive horizontal scaling for some large web based applications ... • ... and we needed to deploy our apps in the cloud ... CONFIDENTIAL * image courtesy of Bitcurrent 17 Thursday, January 19, 12
  • 18. NoSQL offers several data store categories Key-Value Column Document Graph Redis, Cassandra, MongoDB Neo4J Riak HBase CONFIDENTIAL 18 Thursday, January 19, 12
  • 19. About Mongo DB 1. No-SQL database development : { 2. Stores JSON-style tools: many, documents language_support: superb, = 3. Horizontally scalable agility: high }, 4. Full Indexing Support production: { 5. Open Source speed: fast fault_tolerance: true 6. Great Community(You!) scalability: high CONFIDENTIAL 19 Thursday, January 19, 12
  • 20. NoSQL offers several data store categories Key-Value Column Document Graph MongoDB (who cares about the rest?) CONFIDENTIAL 20 Thursday, January 19, 12
  • 21. Mongo and Ruby Deep Dive CONFIDENTIAL 21 Thursday, January 19, 12
  • 22. Integration with Box(.net) CONFIDENTIAL 22 Thursday, January 19, 12
  • 23. Box Sample App Creation Wizard • Requirement: Clone sample Box app for developers into their own Cloud Foundry account so they can learn how to use the BOX Api. CONFIDENTIAL 23 Thursday, January 19, 12
  • 24. Challenges • No command to download all the files for an app or copy it to another account. •Solution: The Cloud •Get the code for an app from: GitHub •Use vmc gem to upload the contents to your desired cloud CONFIDENTIAL 24 Thursday, January 19, 12
  • 25. VMC as a gem  Can be used to authenticate users and exchange their credentials for an API token  Edit Applications and Services from your code • Files • Environment Variables  Start and Stop Apps CONFIDENTIAL 25 Thursday, January 19, 12
  • 26. How we used VMC on this project def create()       begin         @vmcclient.create_app(@manifest["name"], @manifest)       rescue RuntimeError => ex         if (ex.message =~ /Error 701/)           new_candidate = @generator.next           unless new_candidate.nil?             change_name! new_candidate             create           else             # Format is "Error #{parsed_body[:code]}: #{desc}"             raise "App Url: #{@uri} is already taken"           end         else           raise ex         end       end     end     def delete()       @vmcclient.delete_app(@manifest["name"])     end     def copy_code()       @vmcclient.upload_app(@manifest["name"], @app_meta.build!)     end CONFIDENTIAL 26 Thursday, January 19, 12
  • 27. More Challenges  External Models we didn’t control • Cloud Foundry Apps: Files, Runtime, Services, Env Vars, etc • GitHub Repositories: Files, Commits, branches, tags • Solution • Use an Object Document Mapper. I chose Mongoid • Easy to add new objects and properties • No Migrations ! CONFIDENTIAL 27 Thursday, January 19, 12
  • 28. CONFIDENTIAL 28 Thursday, January 19, 12
  • 29. Things you should know about Mongoid  Project Page - http://mongoid.org.  Features: • Uses Active Model (Dirty Tracking, Mass Assignment Security, Validations, Callbacks, JSON/XML Serialization) • Indexing • Supports identity map, replica sets and sharding • Custom field serialization • A Range in Ruby 1...3 could be stored in MongoDB as a Hash { :min => 1, :max => 3 } • Localization Support:(Translated Fields, i18n Fallbacks) • Inheritance CONFIDENTIAL 29 Thursday, January 19, 12
  • 30. How we used Mongoid module CloudFoundry   class AppInfo     include TmpZip     include Mongoid::Document     embeds_many :app_clone_requests     belongs_to :repo, :class_name => "GitHub::RepositorySnapshot"     field :display_name, :type => String     field :description, :type => String     field :instances, :type => Integer, :default => 1     field :memory, :type => Integer, :default => 128     field :runtime, :type => String     field :framework, :type => String     field :env_vars, :type => Hash     field :thumb_url, :type => String     field :browseable, :type => Boolean     field :cloneable, :type => Boolean     field :starting_url, :type => String     index :display_name, :unique => true     validates_presence_of :display_name, :runtime, :framework     validates_presence_of :repo, :if => :cloneable CONFIDENTIAL 30 Thursday, January 19, 12
  • 31. How we used Mongoid module GitHub   class RepositorySnapshot     include TmpZip     include Mongoid::Document     field :url, :type => String     field :name, :type => String     field :parent, :type => String     field :branch, :type => String, :default => 'master'     field :tag, :type => String     field :commit, :type => String     index :url, :unique => true     validates_presence_of :url, :name, :parent, :commit, :branch     def url=(value)       parts = value.gsub(/https://github.com//, '').split('/')       if (parts.length == 2)         write_attribute(:parent, parts[0])         write_attribute(:name, parts[1])       else         write_attribute(:parent, nil)         write_attribute(:name, nil)       end       write_attribute(:url, value)     end CONFIDENTIAL 31 Thursday, January 19, 12
  • 32. Getting your ruby app to use the proper module CloudFoundry   class Mongo       def self.config         Mongoid.configure do |config|           conn_info = nil           dbname = 'db'           if ENV['VCAP_SERVICES']             services = JSON.parse ENV['VCAP_SERVICES']             services.each do |service_version, bindings|               mongo_binding = bindings.find {|binding| binding['label'] =~ /mongo/i}               conn_info = mongo_binding['credentials'] if mongo_binding             end             raise "ERROR - Could not find connection info for mongo" unless conn_info           else             conn_info = {'hostname' => 'localhost', 'port' => 27017}             dbname = "gallery_db"           end CONFIDENTIAL           @@cnx = Mongo::Connection.new conn_info['hostname'], conn_info['port'], :pool_size => 32 5, :timeout => 5 Thursday, January 19, 12
  • 33. Demo CONFIDENTIAL 33 Thursday, January 19, 12
  • 34. Durran, creator of Mongoid detailed for us: Full atomic update support out of the box for *all* MongoDB atomic operations, either explicitly or handled under the covers by Mongoid itself with support for embedded n levels deep. ie: model = Model.find(id) model.field = “value” model.relations.build(field: “value”) model.save #=> Does { field: { “$set” : “value” }, relations: { “$push” : { field: “value” }}} for you. *or things like* model.add_to_set(field: “value”) CONFIDENTIAL 34 Thursday, January 19, 12
  • 35. Durran, creator of Mongoid detailed for us “Smart memory management during iteration and working with relations: Mongoid never loads everything into memory unless you specifically want it to. It can handle working with millions of documents without putting stress on the server/RAM.” CONFIDENTIAL 35 Thursday, January 19, 12
  • 36. More Challenges  Make app fast. • Downloading and copying files from app to app is not cheap • Solution • Avoid downloading the build if it has not changed • Local cache using Mongo GridFS CONFIDENTIAL 36 Thursday, January 19, 12
  • 37. Working with GridFS  Saving and Reading files Once you have a Grid object, you can start saving data to it. @db = Mongo::Connection.new.db('social_site') @grid = Grid.new(@db) # On this Cloud Foundry App @grid = Mongo::GridFileSystem.new(Mongoid.database) # Saving IO data and including the optional filename image = File.open("me.jpg") id = @grid.put(image, :filename => "me.jpg") Grid#put returns an object id, which you can use to retrieve the file: # Get the file we saved image = @grid.get(id)  Deleting files Deleting a file is as simple as providing the id: @grid.delete(id2) CONFIDENTIAL 37 Thursday, January 19, 12
  • 38. Spring Data on Cloud Foundry Deep Dive CONFIDENTIAL 38 Thursday, January 19, 12
  • 39. Spring Framework built-in data access support •Transaction abstractions •Common data access exception hierarchy •JDBC - JdbcTemplate •ORM - Hibernate, JPA support •OXM - Object to XML mapping •Serializer/Deserializer strategies (Spring 3.0) •Cache support (Spring 3.1) CONFIDENTIAL 39 Thursday, January 19, 12
  • 40. Spring Data Building Blocks •Low level data access APIs ✓MongoTemplate, RedisTemplate ... •Object Mapping (Java and GORM) •Cross Store Persistence Programming model •Generic Repository support •Productivity support in Roo and Grails CONFIDENTIAL 40 Thursday, January 19, 12
  • 41. Spring Data Document Mongo •MongoTemplate •MongoConverter interface for mapping Mongo documents •SimpleMongoConverter for basic POJO mapping support •Leverage Spring 3.0 TypeConverters and SpEL •Exception translation •Advanced Mapping •Annotation based (@Document, @Id, @DbRef) •MongoRepository •Built on Hades support for JPA Repositories CONFIDENTIAL 41 Thursday, January 19, 12
  • 42. Simple Domain Class CONFIDENTIAL 42 Thursday, January 19, 12
  • 43. Mongo Template Direct Usage of the Mongo Template: CONFIDENTIAL 43 Thursday, January 19, 12
  • 44. Mongo Template Direct Usage of the Mongo Template: Insert into “Person” Collection CONFIDENTIAL 43 Thursday, January 19, 12
  • 45. Mongo Template Direct Usage of the Mongo Template: findOne using query: { "name" : "Joe"} in db.collection: database.Person CONFIDENTIAL 43 Thursday, January 19, 12
  • 46. Mongo Template Direct Usage of the Mongo Template: Dropped collection [database.person] CONFIDENTIAL 43 Thursday, January 19, 12
  • 47. Generic Repository Interface for generic CRUD operations on a repository for a specific type CONFIDENTIAL 44 Thursday, January 19, 12
  • 48. Paging and Sorting Repository Paging and Sorting Repository: Extends “CrudRepository” CONFIDENTIAL 45 Thursday, January 19, 12
  • 49. Paging and Sorting Repository Paging and Sorting Repository: Extends “CrudRepository” Usage: CONFIDENTIAL 45 Thursday, January 19, 12
  • 50. Custom Repository Custom Repository: CONFIDENTIAL 46 Thursday, January 19, 12
  • 51. Custom Repository Custom Repository: Keywords : Keyword Sample Logical result GreaterThan findByAgeGreaterThan(int age) {"age" : {"$gt" : age}} LessThan findByAgeLessThan(int age) {"age" : {"$lt" : age}} Between findByAgeBetween(int from, int to) {"age" : {"$gt" : from, "$lt" : to}} NotNull findByFirstnameNotNull() {”firstname" : {"$ne" : null}} Null findByFirstnameNull() {”firstname" : null} Like findByFirstnameLike(String name) CONFIDENTIAL "firstname" : firstname} (regex) 46 Thursday, January 19, 12
  • 52. JPA and MongoDB JPA “Customer” with a “SurveyInfo” Document CONFIDENTIAL 47 Thursday, January 19, 12
  • 53. Using a Cross-Store Saving a Customer with a SurveryInfo CONFIDENTIAL 48 Thursday, January 19, 12
  • 54. Using a Cross-Store Saving a Customer with a SurveryInfo Create Customer CONFIDENTIAL 48 Thursday, January 19, 12
  • 55. Using a Cross-Store Saving a Customer with a SurveryInfo Create SurveyInfo CONFIDENTIAL 48 Thursday, January 19, 12
  • 56. Using a Cross-Store Saving a Customer with a SurveryInfo Assign Survey to Customer CONFIDENTIAL 48 Thursday, January 19, 12
  • 57. Using a Cross-Store Saving a Customer with a SurveryInfo Save CONFIDENTIAL 48 Thursday, January 19, 12
  • 58. Using a Cross-Store Saving a Customer with a SurveryInfo Save Mongo Document: CONFIDENTIAL 48 Thursday, January 19, 12
  • 59. Accessing Services Bound to Cloud Foundry private String mongoDatabaseServiceName = "survey-mongo"; @Bean public CloudEnvironment cloudEnvironment() { return new CloudEnvironment(); } @Bean public MongoServiceInfo mongoServiceInfo() { return cloudEnvironment().getServiceInfo( mongoDatabaseServiceName, MongoServiceInfo.class); } @Bean public MongoDbFactory mongoDbFactory() { MongoServiceCreator msc = new MongoServiceCreator(); MongoDbFactory db = msc.createService(mongoServiceInfo()); } CONFIDENTIAL 49 Thursday, January 19, 12
  • 60. Accessing Services Bound to Cloud Foundry @Inject private Mongo mongo ; @Inject private MongoTemplate mongoTemplate; CONFIDENTIAL 50 Thursday, January 19, 12
  • 61. Demo 2 CONFIDENTIAL 51 Thursday, January 19, 12
  • 62. Thank You CloudFoundry Spring Source Samples: http://bit.ly/cloudfoundry-samples http://cloudfoundry.com Questions: @cloudfoundry •Josh -> @starbuxman or josh.long@springsource.com •Monica -> @ciberch or mwilkinson@cloudfoundry.com © 2012 VMware, Inc. All rights reserved Thursday, January 19, 12