Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MindTree TechDays 3.0 -- Building Location Awar...

MindTree TechDays 3.0 -- Building Location Aware Application using MongoDB

MindTree TechDays 3.0 -- Building Location Aware Application using MongoDB

Shekhar Gulati

May 02, 2013
Tweet

More Decks by Shekhar Gulati

Other Decks in Programming

Transcript

  1. WHO AM I? • Shekhar Gulati -- OpenShift Developer Evangelist

    • Java / NoSQL / Cloud Guy • Learning JavaScript these days :) • Twitter Handle : shekhargulati • Facebook : shekhar.gulati.1 • Github https://github.com/shekhargulati • Slides https://speakerdeck.com/shekhargulati
  2. WHAT WILL YOU LEARN? • What is MongoDB • MongoDB

    Geo spatial basics • What is PaaS • What is OpenShift • How to use OpenShift for deployment https://localjobs-t20.rhcloud.com/
  3. ASSUMPTIONS • You want to learn how to use OpenShift

    • You can write or read Java • You have your own laptop • You will ask questions
  4. 10  Open Source NoSQL document datastore – JSON style

    documents  Schema-less – Each document is heterogeneous, and may have completely unique structure compared to other documents  Fast and horizontally scalable  Rich query language  Rich documents  Easy to get running  Geospatial indexing WHAT IS MONGODB
  5. Database → Database Table → Collection Row → Document Index

    → Index MONGODB TERMINOLOGY MONGODB TERMINOLOGY
  6. 14  What is it for?  Find all the

    MongoDB jobs near me – Proximity Queries  Find all the MongoDB jobs within Colombo – Bounded Queries  Find all the MongoDB job at this location – Exact Queries • Supports only two dimensional indexes.  You can only have one geospatial index per collection.  By default, 2d geospatial indexes assume longitude and latitude have boundaries of -180 inclusive and 180 non-inclusive (i.e. [-180, 180)) GEOSPATIAL INDEXING BASICS
  7. 15 1) Put your coordinates into an array { loc

    : [ 50 , 30 ] } //SUGGESTED OPTION { loc : { x : 50 , y : 30 } } { loc : { foo : 50 , y : 30 } } 1) { loc : { lon : 40.739037, lat: 73.992964 } } 2) Make a 2d index db.places.ensureIndex( { loc : "2d" } ) 3) If you use latitude and longitude as your coordinate system, always store longitude first. MongoDB’s 2d spherical index operators only recognize [ longitude, latitude] ordering. HOW TO MAKE IT WORK
  8. 16 • When you create the index, MongoDB converts location

    data to binary geohash values and calculates these values using the location data and the index’s location range • Geohashes have a precision that is determined by the number of bits in the hash. Default value 26 • More bits allow the index to provide results with greater precision • You can configure number of bits at index creation db.collection.ensureIndex( {<location field>: "2d"} , { bits: <bit precision> } ) GEOHASHES
  9. 17 • MongoDB supports compound geospatial indexes. • the field

    with location data is the first field db.jobs.ensureIndex( { location: "2d", skills: 1 } ) COMPOUND GEOSPATIAL INDEXES
  10. 20 Cloud Service Models STORAGE (RHS) HARDWARE (x86, Power, S/390)

    VIRTUALIZATION (RHEV) OPERATING SYSTEM (RHEL) APPLICATION PLATFORM (JBOSS, PHP, RUBY, ETC) APPLICATION Automated and Managed by the Public or Private Cloud Offering Managed and Controlled by Customer (IT, Dev, or User) IaaS PaaS SaaS Increased Control Increased Automation
  11. • Quickly build the Application that YOU need for •

    Your Group, your Enterprise, your next great idea! • Big data, mobile, social • You code the application, We run it for you • Leverage the ease, scale and power of the Cloud Code Deploy Enjoy PaaS
  12. EVERYONE GETS ALONG • Operations care about stability and performance

    • Developers just want environments without waiting OpenShift creates a peaceful environment for both parties
  13. 26  A free auto-scaling, cloud-based application platform from Red

    Hat.  Multi Language, Multi Frameworks, Multi Cartridges.  No proprietary software.  No Lock-in.  Open source – OpenShift Origin. INTRODUCING OPENSHIFT
  14. 31 • Can run any thing that's Java – Java

    EE or Spring does not matter. • Supports both Java 6 and Java 7 • Supports JBoss AS7, JBoss EAP 6.0, Tomcat 6 , and Tomcat 7 • Ability to write to persistent file system • Debugging support • Hot deployment • Eclipse tooling WHY OPENSHIFT IS BEST JAVA PAAS
  15. 34  OpenShift is free-as-in-beer & free-as-in-freedom  You get

    three free gears, each with 512MB memory and 1GB of disk space.  Need more resources, just ask!  The catch is we are in developer preview right now WHAT I GET
  16. 35 ➢ Login to OpenShift web console ➢ Click on

    “My Account” ➢ Namespace – mindtree3 – Unique per user CREATING NAMESPACE
  17. 37 Some terminology for today 1. Application – your web

    code and any data store. Has to be on 1 or more gears 2. Gear – is like a server. It can have only 1 language for the web programming. 3. Cartridge – it adds a language, a data store, or other functionality 4. Git – used for version control and managing code between server and your development machine 5. Ssh – command line tool to connect to your gear
  18. 38 Install Ruby 1.8.7 or greater Install Git Install rhc

    OpenShift gem Refer to documentation INSTALLING CLIENT TOOLS
  19. 41  MongoDB 2.2  OpenShift  Java 7 –

    Spring Framework – Spring MongoDB  GIT  SSH TECHNOLOGY CHOICES
  20. 42 $ rhc app create localjobs jbosseap mongodb-2.2 –from- code=git://github.com/shekhargulati/localjobs.git

    $ rhc app show -a localjobs $ scp jobs-data.json <ssh url>:app-root/data $ rhc app ssh -a localjobs $ cd app-root/data $ mongoimport -d localjobs -c jobs --file jobs-data.json -u $OPENSHIFT_MONGODB_DB_USERNAME -p $OPENSHIFT_MONGODB_DB_PASSWORD -h $OPENSHIFT_MONGODB_DB_HOST -port $OPENSHIFT_MONGODB_DB_PORT Instructions at https://github.com/shekhargulati/localjobs/blob/master/README.md DEMO : LOCALJOBS APP