SlideShare a Scribd company logo
1 of 46
Download to read offline
Writing applications for Cloud Foundry
        using Spring and MongoDB

        Thomas Risberg, VMware
                                            <trisberg@vmware.com> - @trisberg
        Jared Rosoff, 10gen
                                                     <jsr@10gen.com> - @forjared




         © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.

Wednesday, October 26, 11                                                                        1
Outline

     What we will cover:
     • Introduction to Cloud Foundry
     • Introduction to MongoDB
     • Spring Data support for MongoDB
           – Using the MongoTemplate
           – Using the Mongo Repository support
     • Why run MongoDB in the cloud?




    2

Wednesday, October 26, 11                         2
What is Cloud Foundry?

     • Cloud Foundry is a PaaS
           – The application platform will be delivered as a service in the
             cloud era
           – The industry calls this platform as a service (PaaS)
     • PaaS makes it much easier to deploy, run and scale
       applications
     • But PaaS solutions in the market have fatal flaws today
           – Limited in framework, application services and/or cloud support
     • Cloud Foundry aim to fix that…




    3

Wednesday, October 26, 11                                                      3
Characteristics of PaaS

     The application platform for the cloud era
     • Integrated software stack
     • Application execution engine
     • Self-service application deployment
     • Automated application infrastructure provisioning
     • Curated, updated and operated as a service




    4

Wednesday, October 26, 11                                  4
Cloud Foundry – The first open PaaS

     • Self-service application execution engine
           – Build applications with latest high productivity frameworks
     • Automation engine for deployment and lifecycle
       management
           – Deploy and cloud-scale applications in seconds
     • Open architecture
           – Choice of clouds for deployment
           – Choice of industry-standard frameworks
           – Choice of application infrastructure services
           – Extensible architecture to “digest” future cloud innovation
           – Available as open source



    5

Wednesday, October 26, 11                                                  5
Choice of frameworks

                            .js




    6

Wednesday, October 26, 11         6
Choice of application services

                                                                       .js
                                        Ap
                                         pli
                                          ca


                        Data Services
                                                tio
                                                    n
                                                   Se
                                                        rvi
                                                         ce



                                 Msg Services
                                                            Int
                                                              er
                                                                 fa
                                                                  ce




                                                  Other
                                                 Services




    7

Wednesday, October 26, 11                                                    7
Choice of clouds

                                                                                           .js
                                        Ap
                                         pli




                                                                                       ce
                                                                                                 Private
                                          ca




                                                                                      rfa
                        Data Services
                                                tio




                                                                                     nte
                                                                                                 Clouds
                                                    n




                                                                                   rI
                                                   Se




                                                                              ide
                                                        rvi



                                                                                           Public


                                                                              ov
                                                         ce



                                 Msg Services




                                                                            Pr
                                                                                           Clouds           Partners
                                                            Int




                                                                          d
                                                                       ou
                                                              er




                                                                                                           .COM
                                                                 fa


                                                                       Cl

                                                                               Micro
                                                                  ce




                                                  Other
                                                 Services
                                                                               Clouds



    8

Wednesday, October 26, 11                                                                                              8
9

Wednesday, October 26, 11   9
MongoDB


                                  Application       Document
                                                    Oriented
              High                                   { author: “steve”,
                                                       date: new Date(),

          Performance                                  text: “About MongoDB...”,
                                                       tags: [“tech”, “database”]}




                            Horizontally Scalable
    10

Wednesday, October 26, 11                                                            10
Why MongoDB

     •   Double click serving 400,000 ads / second
     •   People writing their own datastores
     •   Caching is de rigueur
     •   Complex ORM frameworks
     •   Computer architecture trends
     •   Cloud computing




    11

Wednesday, October 26, 11                            11
Costs go up!




                       Launch
                                +90 Days
                                           +1 Year


    12

Wednesday, October 26, 11                            12
Productivity


                            Great!

                             Denormalize
                             data model

                                     Stop using
                                        joins

                                            Custom
                                            caching

                                                      Custom
                                                      sharding
      Project Start
                            +90 Days
                                                          +1 Year
    13

Wednesday, October 26, 11                                           13
Data models




    14

Wednesday, October 26, 11   14
From tables to Documents



                                {
                                    title: ‘MongoDB’,
                                    contributors: [
                                       { name: ‘Eliot Horowitz’,
                                         email: ‘eh@10gen.com’ },
                                       { name: ‘Dwight Merriman’,
                                         email: ‘dm@10gen.com’ }
                                    ],
                                    model: {
                                        relational: false,
                                        awesome: true
                                    }




    15

Wednesday, October 26, 11                                           15
Documents




                   > p = {author:   “roger”,
                            date:   new Date(),
                            text:   “about mongoDB...”,
                            tags:   [“tech”, “databases”]}

                   > db.posts.save(p)




    16

Wednesday, October 26, 11                                    16
Querying



                   > db.posts.find()

                   >        { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"),
                            author : "roger",
                              date : "Sat Jul 24 2010 19:47:11",
                              text : "About MongoDB...",
                              tags : [ "tech", "databases" ] }




    17

Wednesday, October 26, 11                                                   17
Secondary Indexes




                            //   1 means ascending, -1 means descending
                            > db.posts.ensureIndex({author: 1})
                            > db.posts.find({author: 'roger'})

                   >        { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"),
                            author : "roger",
                             ... }




    18

Wednesday, October 26, 11                                                   18
Conditional Query Operators


                       $all, $exists, $mod, $ne, $in, $nin, $nor,
                       $or, $size, $type, $lt, $lte, $gt, $gte

                   // find posts with any tags
                   > db.posts.find( {tags: {$exists: true }} )

                   // find posts matching a regular expression
                   > db.posts.find( {author: /^rog*/i } )

                   // count posts by author
                   > db.posts.find( {author: ‘roger’} ).count()




    19

Wednesday, October 26, 11                                           19
Atomic Updates


                       $set, $unset, $inc, $push, $pushAll,
                       $pull, $pullAll, $bit


                   > comment = { author: “fred”,
                                 date: new Date(),
                                 text: “Best Movie Ever”}

                   > db.posts.update( { _id: “...” },
                   	 	 	 	       $push: {comments: comment} );




    20

Wednesday, October 26, 11                                        20
Nested Documents


                      {     _id : ObjectId("4c4ba5c0672c685e5e8aabf3"),
                            author : "roger",
                            date : "Sat Apr 24 2011 19:47:11",
                            text : "About MongoDB...",
                            tags : [ "tech", "databases" ],
                            comments : [
                  	                {
                  	                	 author : "Fred",
                                   	
                  	                	 date : "Sat Apr 25 2010 20:51:03 GMT-0700",
                                   	
                  	                	 text : "Best Post Ever!"
                                   	
                  	                	
                                   }
                             ]
                  }




    21

Wednesday, October 26, 11                                                          21
Advanced indexing


                   // Index nested documents
                   > db.posts.ensureIndex( “comments.author”: 1)
                   > db.posts.find({‘comments.author’:’Fred’})

                   // Index on tags (multi-key index)
                   > db.posts.ensureIndex( tags: 1)
                   > db.posts.find( { tags: ‘tech’ } )

                   // geospatial index
                   > db.posts.ensureIndex( “author.location”: “2d” )
                   > db.posts.find( “author.location”: { $near : [22,42] } )




    22

Wednesday, October 26, 11                                                      22
Rich Documents

                   {        _id : ObjectId("4c4ba5c0672c685e5e8aabf3"),

                            line_items : [ { sku: ‘tt-123’,
                                             name: ‘Coltrane: Impressions’ },
                                           { sku: ‘tt-457’,
                                             name: ‘Davis: Kind of Blue’ } ],

                            address : { name: ‘Banker’,
                                        street: ‘111 Main’,
                                        zip: 10010 },

                            payment: { cc: 4567,
                                       exp: Date(2011, 7, 7) },

                            subtotal: 2355
                   }



    23

Wednesday, October 26, 11                                                       23
Demo

        Cloud Foundry and Mongo DB




  24    © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.

Wednesday, October 26, 11                                                                       24
Spring Data Intoduction



      What is Spring Data all about?
      • Bring classic Spring value propositions to NOSQL
            – Productivity
            – Programming model consistency
      • Support for a wide range of NOSQL databases
      • Also, support for new features for JDBC and JPA
      • Support for other data related projects like Hadoop and
        Gemfire



    25

Wednesday, October 26, 11                                         25
Spring Data MongoDB Support

      Spring Data support for MongoDB:
      • MongoTemplate
            ✓MongoConverter interface for mapping Mongo documents
                  • Built-in Advanced Mapping
                        – Annotation based (@Document, @Id, @DbRef)
                  • MappingMongoConverter for POJO mapping support
                  • Leverage Spring 3.0 TypeConverters and SpEL
            ✓Exception translation
            ✓Java based Query, Criteria, and Update DSLs
      • MongoRepository
            ✓Built on Spring Data JPA (Hades) support for JPA Repositories
            ✓QueryDSL integration to support type-safe queries.


    26

Wednesday, October 26, 11                                                    26
Working with POJOs
     @Document
     public class           Book {
     	
     	    private           String title;
     	
     	    @DBRef
                                                      @Document
     	    private           Author author;
                                                      public class Author {
     	
                                                      	
     	    @Id
                                                      	    @Id @SuppressWarnings("unused")
     	    private           String isbn;
                                                      	    private String id;
     	
                                                      	
     	    private           BigDecimal price;
                                                      	    private String name;
     	
     	    private           Date published;
                                                      	   public String getName() {
     	
                                                      	   	    return name;
     	    private           Set<String> categories;
                                                      	   }

     	        // getters and setters
                                                      	   public void setName(String name) {
     }
                                                      	   	    this.name = name;
                                                      	   }
                                                      }



    27

Wednesday, October 26, 11                                                                      27
Mongo Template CRUD Methods

            Mongo mongo = new Mongo("localhost", 27017);
            MongoDbFactory mongoDbFactory =
                  new SimpleMongoDbFactory(mongo, "db");
            MongoTemplate mongoTemplate = new
            MongoTemplate(mongoDbFactory);



            mongoTemplate.insert(book);

            List<Book> books = mongoTemplate.findAll(Book.class);

            Book book = mongoTemplate.findOne(query, Book.class);

            mongoTemplate.save(book);

            mongoTemplate.remove(query, Book.class);


    28

Wednesday, October 26, 11                                           28
Querying
      public List<Book> findByCategoriesOrYear(Set<String> categories, String year) {
      !     String[] categoriesToMatch;
      !     if (categories == null) {
      !     !      categoriesToMatch = new String[] {};
      !     }
      !     else {
      !     !      categoriesToMatch = categories.toArray(new String[categories.size()]);
      !     }
      !     Date startDate = null;
      !     if (year != null && year.length() == 4) {
      !     !      DateFormat formatter = new SimpleDateFormat("yyyy-dd-MM");
      !     !      try {
      !     !      !     startDate = formatter.parse(year + "-01-01");
      !     !      } catch (ParseException e) {}
      !     }
      !     Criteria searchCriteria = null;
      !     if (startDate != null) {
      !        !       searchCriteria =
                          Criteria.where("published").gte(startDate);
      !        }
      !        else {
      !        !      searchCriteria = new Criteria();
      !        }
      !        if (categoriesToMatch.length > 0) {! !
      !        !       searchCriteria
                          .and("categories").in((Object[])categoriesToMatch);
      !        }
      !        Query query = new Query(searchCriteria);
      !        return mongoTemplate.find(query, Book.class);
      }



    29

Wednesday, October 26, 11                                                                   29
Cloud Foundry MongoDB Support

          Namespace support for MongoDB
      <cloud:mongo-db-factory id="mongoDbFactory" write-concern="FSYNC_SAFE">
          <cloud:mongo-options connections-per-host="10" max-wait-time="2000" />
      </cloud:mongo-db-factory>


            <dependency>
                <groupId>org.cloudfoundry</groupId>
                <artifactId>cloudfoundry-runtime</artifactId>
                <version>0.8.1</version>
            </dependency>

            <repository>
                <id>org.springframework.maven.milestone</id>
                <name>Spring Framework Maven Milestone Repository</name>
                <url>http://maven.springframework.org/milestone</url>
            </repository>

    30

Wednesday, October 26, 11                                                          30
Demo

        MongoTemplate example:
        https://github.com/trisberg/springone-mongotemplate




  31    © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.

Wednesday, October 26, 11                                                                       31
Spring Data Repository

     Spring Data Repository basics:
     • Generic repository implementation
     • Basic CRUD (create, read, update and delete) methods
     • Generating code for queries defined in repository interface
           – findAll
           – findByName ...
     • Pagination and sorting support
     • Currently has JPA and Mongo implementations




    32

Wednesday, October 26, 11                                           32
Spring Data Repository Interfaces
   CrudRepository




                                     PagingAndSortingRepository




    33

Wednesday, October 26, 11                                         33
Spring Data Repository Query Methods

   Spring Data Repository query methods:




      and more, see reference docs ...



    34

Wednesday, October 26, 11                   34
Mongo Repository Example

     public interface BookRepository extends Repository<Book, String> {
     	
     	   Book save(Book book);
     	
     	   Book findOne(String isbn);
     	
     	   void delete(String isbn);
     	
     	   List<Book> findAll();

     	        List<Book> findByPublishedGreaterThan(Date date);
     	
     	        List<Book> findByCategoriesIn(String[] categories);

     	        List<Book> findByPublishedGreaterThanAndCategoriesIn(
                                Date date, String[] categories);

     }


    35

Wednesday, October 26, 11                                                 35
Demo

        Mongo Repository example:
        https://github.com/trisberg/springone-repository




  36    © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.

Wednesday, October 26, 11                                                                       36
QueryDSL Repository

     QueryDSL allows you to build typesafe queries using Java for
        JPA, SQL, MongoDB and more
     • Generic repository implementation
     • Code completion in IDE
     • No Strings
           – reference types and properties safely
           – easier refactoring
     • Incremental query definition is easier
     • Annotation preprocessor generates query types




    37

Wednesday, October 26, 11                                           37
Demo

        Mongo QueryDSL Repository example:
        https://github.com/trisberg/springone-repo-qdsl




  38    © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.

Wednesday, October 26, 11                                                                       38
Why run MongoDB in the cloud?




    39

Wednesday, October 26, 11            39
Typical scaling approaches don’t work




    40

Wednesday, October 26, 11                    40
MongoDB scales out




    41

Wednesday, October 26, 11   41
MongoDB scales out




    42

Wednesday, October 26, 11   42
MongoDB scales out




    43

Wednesday, October 26, 11   43
MongoDB scales out




    44

Wednesday, October 26, 11   44
MongoDB in the cloud

     • Elastic database capacity
           – Add more storage, compute, memory dynamically
     • Portable across environments
           – Public cloud
           – Private cloud
           – Micro cloud
     • Simplifies operations
           – No need to engineer solutions for one-off hardware platforms
           – “Just another VM”




    45

Wednesday, October 26, 11                                                   45
Q&A




  46    © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission.

Wednesday, October 26, 11                                                                       46

More Related Content

Similar to SpringOne 2GX 2011 - Writing applications for Cloud Foundry using Spring and MongoDB

Cloudcamp Ghent - Cloud foundry-20111121
Cloudcamp Ghent - Cloud foundry-20111121Cloudcamp Ghent - Cloud foundry-20111121
Cloudcamp Ghent - Cloud foundry-20111121Lode Vermeiren
 
Cloud Foundry: Inside the Machine
Cloud Foundry: Inside the MachineCloud Foundry: Inside the Machine
Cloud Foundry: Inside the MachineDerek Collison
 
Cloud Foundry Architecture and Overview
Cloud Foundry Architecture and OverviewCloud Foundry Architecture and Overview
Cloud Foundry Architecture and Overviewrajdeep
 
PaaS Parade - Cloud Foundry
PaaS Parade - Cloud FoundryPaaS Parade - Cloud Foundry
PaaS Parade - Cloud Foundrymartinlippert
 
Building an Open Cloud Ecosystem with Cloud Foundry
Building an Open Cloud Ecosystem with Cloud FoundryBuilding an Open Cloud Ecosystem with Cloud Foundry
Building an Open Cloud Ecosystem with Cloud FoundryAndy Piper
 
Cloud Foundry for Java devs
Cloud Foundry for Java devsCloud Foundry for Java devs
Cloud Foundry for Java devsPeter Ledbrook
 
Portrait of the developer as The Artist - SpringOne India 2012
Portrait of the developer as The Artist - SpringOne India 2012Portrait of the developer as The Artist - SpringOne India 2012
Portrait of the developer as The Artist - SpringOne India 2012Patrick Chanezon
 
Hands On CloudFoundry
Hands On CloudFoundryHands On CloudFoundry
Hands On CloudFoundryEric Bottard
 
Breaking through the Clouds
Breaking through the CloudsBreaking through the Clouds
Breaking through the CloudsAndy Piper
 
Cloud foundry - the building of the open paas presentation
Cloud foundry - the building of the open paas presentationCloud foundry - the building of the open paas presentation
Cloud foundry - the building of the open paas presentationXianzhu Yue
 
Cloud Foundry Introduction - Canada - October 2012
Cloud Foundry Introduction - Canada - October 2012Cloud Foundry Introduction - Canada - October 2012
Cloud Foundry Introduction - Canada - October 2012Patrick Chanezon
 
Spring Data and MongoDB
Spring Data and MongoDBSpring Data and MongoDB
Spring Data and MongoDBOliver Gierke
 
Making a Cleaner Cloud with Open Source
Making a Cleaner Cloud with Open SourceMaking a Cleaner Cloud with Open Source
Making a Cleaner Cloud with Open SourceAndy Piper
 
Migrating to Cloud Foundry
Migrating to Cloud FoundryMigrating to Cloud Foundry
Migrating to Cloud FoundryPeter Ledbrook
 
Oracle+cloud+computing+ +iasa+thailand+2011
Oracle+cloud+computing+ +iasa+thailand+2011Oracle+cloud+computing+ +iasa+thailand+2011
Oracle+cloud+computing+ +iasa+thailand+2011Software Park Thailand
 
Portrait of the Developer as the Artist - OpenTour Sofia
Portrait of the Developer as the Artist - OpenTour SofiaPortrait of the Developer as the Artist - OpenTour Sofia
Portrait of the Developer as the Artist - OpenTour SofiaPatrick Chanezon
 
Market Research Report : Cloud Computing Market in India 2010
Market Research Report : Cloud Computing Market in India 2010Market Research Report : Cloud Computing Market in India 2010
Market Research Report : Cloud Computing Market in India 2010Netscribes, Inc.
 

Similar to SpringOne 2GX 2011 - Writing applications for Cloud Foundry using Spring and MongoDB (20)

Cloudcamp Ghent - Cloud foundry-20111121
Cloudcamp Ghent - Cloud foundry-20111121Cloudcamp Ghent - Cloud foundry-20111121
Cloudcamp Ghent - Cloud foundry-20111121
 
Cloud Foundry: Inside the Machine
Cloud Foundry: Inside the MachineCloud Foundry: Inside the Machine
Cloud Foundry: Inside the Machine
 
Cloud Foundry Architecture and Overview
Cloud Foundry Architecture and OverviewCloud Foundry Architecture and Overview
Cloud Foundry Architecture and Overview
 
PaaS Parade - Cloud Foundry
PaaS Parade - Cloud FoundryPaaS Parade - Cloud Foundry
PaaS Parade - Cloud Foundry
 
Building an Open Cloud Ecosystem with Cloud Foundry
Building an Open Cloud Ecosystem with Cloud FoundryBuilding an Open Cloud Ecosystem with Cloud Foundry
Building an Open Cloud Ecosystem with Cloud Foundry
 
Cloud Foundry for Java devs
Cloud Foundry for Java devsCloud Foundry for Java devs
Cloud Foundry for Java devs
 
RubyWorld 2011
RubyWorld 2011RubyWorld 2011
RubyWorld 2011
 
Portrait of the developer as The Artist - SpringOne India 2012
Portrait of the developer as The Artist - SpringOne India 2012Portrait of the developer as The Artist - SpringOne India 2012
Portrait of the developer as The Artist - SpringOne India 2012
 
Hands On CloudFoundry
Hands On CloudFoundryHands On CloudFoundry
Hands On CloudFoundry
 
Breaking through the Clouds
Breaking through the CloudsBreaking through the Clouds
Breaking through the Clouds
 
Cloud foundry - the building of the open paas presentation
Cloud foundry - the building of the open paas presentationCloud foundry - the building of the open paas presentation
Cloud foundry - the building of the open paas presentation
 
OSCON 2011
OSCON 2011OSCON 2011
OSCON 2011
 
Cloud Foundry Introduction - Canada - October 2012
Cloud Foundry Introduction - Canada - October 2012Cloud Foundry Introduction - Canada - October 2012
Cloud Foundry Introduction - Canada - October 2012
 
Spring Data and MongoDB
Spring Data and MongoDBSpring Data and MongoDB
Spring Data and MongoDB
 
Making a Cleaner Cloud with Open Source
Making a Cleaner Cloud with Open SourceMaking a Cleaner Cloud with Open Source
Making a Cleaner Cloud with Open Source
 
Migrating to Cloud Foundry
Migrating to Cloud FoundryMigrating to Cloud Foundry
Migrating to Cloud Foundry
 
Oracle+cloud+computing+ +iasa+thailand+2011
Oracle+cloud+computing+ +iasa+thailand+2011Oracle+cloud+computing+ +iasa+thailand+2011
Oracle+cloud+computing+ +iasa+thailand+2011
 
Evento sap
Evento sapEvento sap
Evento sap
 
Portrait of the Developer as the Artist - OpenTour Sofia
Portrait of the Developer as the Artist - OpenTour SofiaPortrait of the Developer as the Artist - OpenTour Sofia
Portrait of the Developer as the Artist - OpenTour Sofia
 
Market Research Report : Cloud Computing Market in India 2010
Market Research Report : Cloud Computing Market in India 2010Market Research Report : Cloud Computing Market in India 2010
Market Research Report : Cloud Computing Market in India 2010
 

Recently uploaded

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
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
 
"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
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
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
 
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
 
"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
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 

Recently uploaded (20)

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
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
 
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
 
"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
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
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
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
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
 
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
 
"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
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
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
 

SpringOne 2GX 2011 - Writing applications for Cloud Foundry using Spring and MongoDB

  • 1. Writing applications for Cloud Foundry using Spring and MongoDB Thomas Risberg, VMware <trisberg@vmware.com> - @trisberg Jared Rosoff, 10gen <jsr@10gen.com> - @forjared © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission. Wednesday, October 26, 11 1
  • 2. Outline What we will cover: • Introduction to Cloud Foundry • Introduction to MongoDB • Spring Data support for MongoDB – Using the MongoTemplate – Using the Mongo Repository support • Why run MongoDB in the cloud? 2 Wednesday, October 26, 11 2
  • 3. What is Cloud Foundry? • Cloud Foundry is a PaaS – The application platform will be delivered as a service in the cloud era – The industry calls this platform as a service (PaaS) • PaaS makes it much easier to deploy, run and scale applications • But PaaS solutions in the market have fatal flaws today – Limited in framework, application services and/or cloud support • Cloud Foundry aim to fix that… 3 Wednesday, October 26, 11 3
  • 4. Characteristics of PaaS The application platform for the cloud era • Integrated software stack • Application execution engine • Self-service application deployment • Automated application infrastructure provisioning • Curated, updated and operated as a service 4 Wednesday, October 26, 11 4
  • 5. Cloud Foundry – The first open PaaS • Self-service application execution engine – Build applications with latest high productivity frameworks • Automation engine for deployment and lifecycle management – Deploy and cloud-scale applications in seconds • Open architecture – Choice of clouds for deployment – Choice of industry-standard frameworks – Choice of application infrastructure services – Extensible architecture to “digest” future cloud innovation – Available as open source 5 Wednesday, October 26, 11 5
  • 6. Choice of frameworks .js 6 Wednesday, October 26, 11 6
  • 7. Choice of application services .js Ap pli ca Data Services tio n Se rvi ce Msg Services Int er fa ce Other Services 7 Wednesday, October 26, 11 7
  • 8. Choice of clouds .js Ap pli ce Private ca rfa Data Services tio nte Clouds n rI Se ide rvi Public ov ce Msg Services Pr Clouds Partners Int d ou er .COM fa Cl Micro ce Other Services Clouds 8 Wednesday, October 26, 11 8
  • 10. MongoDB Application Document Oriented High { author: “steve”, date: new Date(), Performance text: “About MongoDB...”, tags: [“tech”, “database”]} Horizontally Scalable 10 Wednesday, October 26, 11 10
  • 11. Why MongoDB • Double click serving 400,000 ads / second • People writing their own datastores • Caching is de rigueur • Complex ORM frameworks • Computer architecture trends • Cloud computing 11 Wednesday, October 26, 11 11
  • 12. Costs go up! Launch +90 Days +1 Year 12 Wednesday, October 26, 11 12
  • 13. Productivity Great! Denormalize data model Stop using joins Custom caching Custom sharding Project Start +90 Days +1 Year 13 Wednesday, October 26, 11 13
  • 14. Data models 14 Wednesday, October 26, 11 14
  • 15. From tables to Documents { title: ‘MongoDB’, contributors: [ { name: ‘Eliot Horowitz’, email: ‘eh@10gen.com’ }, { name: ‘Dwight Merriman’, email: ‘dm@10gen.com’ } ], model: { relational: false, awesome: true } 15 Wednesday, October 26, 11 15
  • 16. Documents > p = {author: “roger”, date: new Date(), text: “about mongoDB...”, tags: [“tech”, “databases”]} > db.posts.save(p) 16 Wednesday, October 26, 11 16
  • 17. Querying > db.posts.find() > { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author : "roger", date : "Sat Jul 24 2010 19:47:11", text : "About MongoDB...", tags : [ "tech", "databases" ] } 17 Wednesday, October 26, 11 17
  • 18. Secondary Indexes // 1 means ascending, -1 means descending > db.posts.ensureIndex({author: 1}) > db.posts.find({author: 'roger'}) > { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author : "roger", ... } 18 Wednesday, October 26, 11 18
  • 19. Conditional Query Operators $all, $exists, $mod, $ne, $in, $nin, $nor, $or, $size, $type, $lt, $lte, $gt, $gte // find posts with any tags > db.posts.find( {tags: {$exists: true }} ) // find posts matching a regular expression > db.posts.find( {author: /^rog*/i } ) // count posts by author > db.posts.find( {author: ‘roger’} ).count() 19 Wednesday, October 26, 11 19
  • 20. Atomic Updates $set, $unset, $inc, $push, $pushAll, $pull, $pullAll, $bit > comment = { author: “fred”, date: new Date(), text: “Best Movie Ever”} > db.posts.update( { _id: “...” }, $push: {comments: comment} ); 20 Wednesday, October 26, 11 20
  • 21. Nested Documents { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author : "roger", date : "Sat Apr 24 2011 19:47:11", text : "About MongoDB...", tags : [ "tech", "databases" ], comments : [ { author : "Fred", date : "Sat Apr 25 2010 20:51:03 GMT-0700", text : "Best Post Ever!" } ] } 21 Wednesday, October 26, 11 21
  • 22. Advanced indexing // Index nested documents > db.posts.ensureIndex( “comments.author”: 1) > db.posts.find({‘comments.author’:’Fred’}) // Index on tags (multi-key index) > db.posts.ensureIndex( tags: 1) > db.posts.find( { tags: ‘tech’ } ) // geospatial index > db.posts.ensureIndex( “author.location”: “2d” ) > db.posts.find( “author.location”: { $near : [22,42] } ) 22 Wednesday, October 26, 11 22
  • 23. Rich Documents { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), line_items : [ { sku: ‘tt-123’, name: ‘Coltrane: Impressions’ }, { sku: ‘tt-457’, name: ‘Davis: Kind of Blue’ } ], address : { name: ‘Banker’, street: ‘111 Main’, zip: 10010 }, payment: { cc: 4567, exp: Date(2011, 7, 7) }, subtotal: 2355 } 23 Wednesday, October 26, 11 23
  • 24. Demo Cloud Foundry and Mongo DB 24 © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission. Wednesday, October 26, 11 24
  • 25. Spring Data Intoduction What is Spring Data all about? • Bring classic Spring value propositions to NOSQL – Productivity – Programming model consistency • Support for a wide range of NOSQL databases • Also, support for new features for JDBC and JPA • Support for other data related projects like Hadoop and Gemfire 25 Wednesday, October 26, 11 25
  • 26. Spring Data MongoDB Support Spring Data support for MongoDB: • MongoTemplate ✓MongoConverter interface for mapping Mongo documents • Built-in Advanced Mapping – Annotation based (@Document, @Id, @DbRef) • MappingMongoConverter for POJO mapping support • Leverage Spring 3.0 TypeConverters and SpEL ✓Exception translation ✓Java based Query, Criteria, and Update DSLs • MongoRepository ✓Built on Spring Data JPA (Hades) support for JPA Repositories ✓QueryDSL integration to support type-safe queries. 26 Wednesday, October 26, 11 26
  • 27. Working with POJOs @Document public class Book { private String title; @DBRef @Document private Author author; public class Author { @Id @Id @SuppressWarnings("unused") private String isbn; private String id; private BigDecimal price; private String name; private Date published; public String getName() { return name; private Set<String> categories; } // getters and setters public void setName(String name) { } this.name = name; } } 27 Wednesday, October 26, 11 27
  • 28. Mongo Template CRUD Methods Mongo mongo = new Mongo("localhost", 27017); MongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(mongo, "db"); MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory); mongoTemplate.insert(book); List<Book> books = mongoTemplate.findAll(Book.class); Book book = mongoTemplate.findOne(query, Book.class); mongoTemplate.save(book); mongoTemplate.remove(query, Book.class); 28 Wednesday, October 26, 11 28
  • 29. Querying public List<Book> findByCategoriesOrYear(Set<String> categories, String year) { ! String[] categoriesToMatch; ! if (categories == null) { ! ! categoriesToMatch = new String[] {}; ! } ! else { ! ! categoriesToMatch = categories.toArray(new String[categories.size()]); ! } ! Date startDate = null; ! if (year != null && year.length() == 4) { ! ! DateFormat formatter = new SimpleDateFormat("yyyy-dd-MM"); ! ! try { ! ! ! startDate = formatter.parse(year + "-01-01"); ! ! } catch (ParseException e) {} ! } ! Criteria searchCriteria = null; ! if (startDate != null) { ! ! searchCriteria = Criteria.where("published").gte(startDate); ! } ! else { ! ! searchCriteria = new Criteria(); ! } ! if (categoriesToMatch.length > 0) {! ! ! ! searchCriteria .and("categories").in((Object[])categoriesToMatch); ! } ! Query query = new Query(searchCriteria); ! return mongoTemplate.find(query, Book.class); } 29 Wednesday, October 26, 11 29
  • 30. Cloud Foundry MongoDB Support Namespace support for MongoDB <cloud:mongo-db-factory id="mongoDbFactory" write-concern="FSYNC_SAFE">     <cloud:mongo-options connections-per-host="10" max-wait-time="2000" /> </cloud:mongo-db-factory> <dependency>     <groupId>org.cloudfoundry</groupId>     <artifactId>cloudfoundry-runtime</artifactId>     <version>0.8.1</version> </dependency> <repository>     <id>org.springframework.maven.milestone</id>     <name>Spring Framework Maven Milestone Repository</name>     <url>http://maven.springframework.org/milestone</url> </repository> 30 Wednesday, October 26, 11 30
  • 31. Demo MongoTemplate example: https://github.com/trisberg/springone-mongotemplate 31 © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission. Wednesday, October 26, 11 31
  • 32. Spring Data Repository Spring Data Repository basics: • Generic repository implementation • Basic CRUD (create, read, update and delete) methods • Generating code for queries defined in repository interface – findAll – findByName ... • Pagination and sorting support • Currently has JPA and Mongo implementations 32 Wednesday, October 26, 11 32
  • 33. Spring Data Repository Interfaces CrudRepository PagingAndSortingRepository 33 Wednesday, October 26, 11 33
  • 34. Spring Data Repository Query Methods Spring Data Repository query methods: and more, see reference docs ... 34 Wednesday, October 26, 11 34
  • 35. Mongo Repository Example public interface BookRepository extends Repository<Book, String> { Book save(Book book); Book findOne(String isbn); void delete(String isbn); List<Book> findAll(); List<Book> findByPublishedGreaterThan(Date date); List<Book> findByCategoriesIn(String[] categories); List<Book> findByPublishedGreaterThanAndCategoriesIn( Date date, String[] categories); } 35 Wednesday, October 26, 11 35
  • 36. Demo Mongo Repository example: https://github.com/trisberg/springone-repository 36 © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission. Wednesday, October 26, 11 36
  • 37. QueryDSL Repository QueryDSL allows you to build typesafe queries using Java for JPA, SQL, MongoDB and more • Generic repository implementation • Code completion in IDE • No Strings – reference types and properties safely – easier refactoring • Incremental query definition is easier • Annotation preprocessor generates query types 37 Wednesday, October 26, 11 37
  • 38. Demo Mongo QueryDSL Repository example: https://github.com/trisberg/springone-repo-qdsl 38 © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission. Wednesday, October 26, 11 38
  • 39. Why run MongoDB in the cloud? 39 Wednesday, October 26, 11 39
  • 40. Typical scaling approaches don’t work 40 Wednesday, October 26, 11 40
  • 41. MongoDB scales out 41 Wednesday, October 26, 11 41
  • 42. MongoDB scales out 42 Wednesday, October 26, 11 42
  • 43. MongoDB scales out 43 Wednesday, October 26, 11 43
  • 44. MongoDB scales out 44 Wednesday, October 26, 11 44
  • 45. MongoDB in the cloud • Elastic database capacity – Add more storage, compute, memory dynamically • Portable across environments – Public cloud – Private cloud – Micro cloud • Simplifies operations – No need to engineer solutions for one-off hardware platforms – “Just another VM” 45 Wednesday, October 26, 11 45
  • 46. Q&A 46 © 2011 SpringOne 2GX 2011. All rights reserved. Do not distribute without permission. Wednesday, October 26, 11 46