Leaflet, Java EE, and MongoDB with Docker containers and Openshift


Presented by:

Steven Pousty

talks.thesteve0.com/jeemapv3

@TheSteve0 on Twitter, IRC, Instagram, Ingress, SmugMug, and Github

Agenda

  1. A little about MongoDB Spatial
  2. Some JEE
  3. Learn a bit about PaaS
  4. You deploy

Assumptions

  1. You write Java code
  2. You will ask questions

What's the scenario

  • We work for a Vendor that sells Beers at Baseball stadiums
  • We are making a check in service to help drive traffic to our crappy beer stands
  • We want FOSS on the whole stack - NO LOCK IN
  • Due next week
  • Types of NoSQL datastores

    TYPEDocumentKey-ValueGraphData ProcessingMisc
    EXAMPLE MongoDB, Couchbase Redis, Riak, Memcahe Neo4J Hadoop, Cassandra, Voldemort Lucene/Solr/ElasticSearch, VoltDB
    USE-CASE Document storage and search Caching or Object Store Relationships between "things" Large data processing Depends

    On to Mongo

     

    A bit about MongoDB

    • A document is just a bunch of attributes and values - think of it like HashMap
    • Can be nested - helps avoid joins
    • Schemaless
    • Really good at fast writes - but you give up immediate consistency
    • Easy to horizontally scale

    Now some spatial

    The spatial functionality Mongo currently has is:

    1. Near ($near)
    2. Containment ($geoWithin)
    3. Intersection ($geoIntersects )


    Two types of indices:

    1. 2D - for flat surfaces
    2. 2dsphere - helps with coords on an earth like sphere

    Good to Know

    How do you make it work

    1a. Put coordinates into an array

    
    { loc : [ 50 , 30 ] }    
        If you use lattitude and longitude with a default index 
               make sure to put [lon, lat]
    				    

    1b. Put coordinates in a GeoJSON format

    
    { loc : { type : "Point" ,
          coordinates : [ 40, 5 ]
    		} 
    }
    				    

    Make it work (cont.)

    2a. Make a 2DSphere index

    
    				    	db.places.ensureIndex( { loc : "2dsphere" } )
    				    	can be a compound index
    				    

    2b. Make a 2D index

    
    				    	db.places.ensureIndex( { loc : "2d" } )
    				    

    JEE - CDI and JAX-RS

    • Context Dependency Injection - allows you to make classes availble whenever you need them and let the calling class decide which class it wants
    • JAX-RS - the antiSOAP (three cheers). Makes it super easy to write REST like architectures

    Time for Leaflet

     

    Quick intro

    1. Lighweight JS client side library for doing great maps
    2. Works out of the box with OpenStreetMap (OSM) - as well as others
    3. Mobile ready
    4. Has a rich library of Plugins

    Time for you to work

    1. Open this repo in your browser https://github.com/gshipley/openshift3mlbparks
    2. Open the web console https://openshift-master.devconf.openshift3roadshow.com
    3. FOLLOW ALONG (if you want)

    Let's wrap it up

    1. Spatial is easy and fun with MongoDB, JavaEE, & Leaflet
    2. @ghaff - So simple even a marketing person can do it :-) http://wwos-bitmason.rhcloud.com

    Slides URL:

    talks.thesteve0.com/jeemapv3

    Come hang out with us:
    #openshift on freenode irc
    OR
    users@lists.openshift.redhat.com