Bringing Spatial Love to your Java Application
description
Transcript of Bringing Spatial Love to your Java Application
![Page 1: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/1.jpg)
1
Bring Spatial Love to your Java Application
Shekhar Gulati@shekhargulatiOpenShift Evangelist, Red Hat
![Page 2: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/2.jpg)
2
Building A Location Aware Job Search App
![Page 3: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/3.jpg)
3
User Stories
As a User, I should be able to find all the jobs. As a User, I should be able to find all the jobs near to
my location. As a User, I should be able to find all MongoDB (or
any skill) jobs near to my location. As a User, I should be able to find all the MongoDB (or
any other skill) jobs near to my location with distance.
![Page 4: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/4.jpg)
4
Want to prototype quickly
Need quick feedback
Don't want to manage infrastructure Don't want to spend much money on infrastructure. Or, even
better, you want it to be free.
Use your existing knowledge
Should be able to use the best tool for the job
Assumptions: as a developer ...
![Page 5: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/5.jpg)
5
Technology Choices MongoDB OpenShift Java 6
Spring 3.1.2.RELEASE Spring 1.1.0.M1
GIT SSH
![Page 6: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/6.jpg)
6
Why MongoDB ? Easy to get running Open Source Active community Rich documents Geospatial indexing. Writes are very fast. You can customize it using
WriteConcern.
![Page 7: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/7.jpg)
7
Rich Document
![Page 8: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/8.jpg)
8
Geospatial Indexing Basics What is it for?
Find all the MongoDB jobs near me Find all the MongoDB jobs within Pune
Supports only two dimensional indexes. You can only have one geospatial index per collection. The spatial functionality MongoDB currently has is:
Near Containment
http://www.mongodb.org/display/DOCS/Geospatial+Indexing
![Page 9: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/9.jpg)
9
How to make it work
1) Put your coordinates into an array{ loc : [ 50 , 30 ] } //SUGGESTED OPTION
{ loc : { x : 50 , y : 30 } }
{ loc : { foo : 50 , y : 30 } }
{ loc : { lon : 40.739037, lat: 73.992964 } }
1) Make a 2d index
db.places.ensureIndex( { loc : "2d" } )
![Page 10: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/10.jpg)
10
Why OpenShift ? Supports MongoDB. Also supports MySQL and
PostgreSQL. Multi-language support. Supports Java, Node.js, Perl,
Python, PHP and Ruby. No need to learn anything new. Scalable. FREE!
![Page 11: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/11.jpg)
11
![Page 12: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/12.jpg)
12
What else do I get and what is the catch?
• 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
![Page 13: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/13.jpg)
13
Let's get our hands dirty
![Page 14: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/14.jpg)
14
Create an OpenShift Accounthttps://openshift.redhat.com/app/account/newPromo code is bangalore
![Page 15: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/15.jpg)
15
Installing Client ToolsInstall Ruby 1.8.7 or greater
Install Git
Install rhc OpenShift gem
Refer to documentation
![Page 16: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/16.jpg)
16
Setup your OpenShift Environment
rhc setup -l <openshift_login>
![Page 17: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/17.jpg)
17
Creating an OpenShift Application
rhc app create -a localjobs -t jbossas-7 -d
![Page 18: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/18.jpg)
18
Adding MongoDB and RockMongo Cartridge
rhc app cartridge add -a localjobs -c mongodb-2.0
rhc app cartridge add -a localjobs -c rockmongo-1.1
![Page 19: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/19.jpg)
19
Play with MongoDB running in the Cloud
ssh into instance
Type mongo on the shell
Create a sample db
Insert some documents in the collection
Run some queries
![Page 20: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/20.jpg)
20
Let's take a look at GIT
Distributed version control
A local repository – on your laptop
A remote repository – on some other machine, usually a server
![Page 21: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/21.jpg)
21
You need to understand at least 3 commands in Git
1. Git add . (means add all news files as being tracked in the local repository)
2. Git commit –am “your message” (means commit all my changes to the local repository with this message)
3. Git push (means push from your local repository to the repository on your OpenShift gear)
![Page 22: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/22.jpg)
22
Pulling the code from GitHubgit rm -rf src pom.xml
git commit -am “removed default files”
git remote add localjobs -m master git://github.com/shekhargulati/localjobs.git
git pull -s recursive -X theirs localjobs master
![Page 23: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/23.jpg)
23
Importing Data into MongoDBrhc app show -a localjobs -l <openshift_login_email>
scp -r jobs-data.json <instance_ssh_access>:localjobs/data
ssh <instance_ssh_access>
mongoimport -d localjobs -c jobs --file jobs-data.json -u $OPENSHIFT_NOSQL_DB_USERNAME -p $OPENSHIFT_NOSQL_DB_PASSWORD -h $OPENSHIFT_NOSQL_DB_HOST -port $OPENSHIFT_NOSQL_DB_PORT
db.jobs.ensureIndex({"location":"2d"})
![Page 24: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/24.jpg)
24
Show some geospatial queries
![Page 25: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/25.jpg)
25
Deploy the code to OpenShift
git push
![Page 26: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/26.jpg)
26
Code Walkthrough
![Page 27: Bringing Spatial Love to your Java Application](https://reader033.fdocuments.us/reader033/viewer/2022052523/555146b1b4c905bd1c8b5055/html5/thumbnails/27.jpg)
27
1. MongoDB makes it very easy to build location aware applications.
2. OpenShift is very easy to use and embraces rapid development.
3. Did I mention – Free?
4. What are you waiting for? Try it out.
Conclusion