Your SlideShare is downloading. ×
0
Java(EE)OPENSHIFT
MongoDB Applications
in the Cloud
Workshop

PRESENTED
BY

Shekhar
Gulati
WHO AM I?

• 

	
  
• 

	
  
• 

	
  
• 

• 

Shekhar	
  Gula+	
  -­‐-­‐	
  OpenShi1	
  Developer	
  Evangelist	
  
Java	
...
AGENDA


l 

Get	
  started	
  with	
  OpenShi1	
  

l 

Develop	
  a	
  loca+on	
  aware	
  applica+on	
  
- 

Java	
  ...
CODE DU JOUR

https://github.com/shekhargulati/sharemylocation-demo
OpenShift

OPENSHIFT	
  OVERVIEW	
  
OpenShift
is

PaaS by Red Hat

Multi-language,
Auto-Scaling,
Self-service,
Elastic,
Cloud Application Platform
WHY OPENSHIFT?


l 

l 

Supports	
  MongoDB	
  ,	
  PostgreSQL	
  ,and	
  MySQL	
  
Mul+-­‐language	
  support.	
  Supp...
OUR STACK


8
FLAVORS OF OPENSHIFT

Open
Source
Project

Public
Cloud
Service

origin

Onpremise
or Private
Cloud
Software
OPENSHIFT – GETTING
STARTED


Go to
https://openshift.redhat.com/app/account/new

Promo code is JUDCON-IN14

Verify Email
...
TOOLS REQUIRED

1.  Eclipse for Java EE
(Kepler)
2.  Git
3.  Modern browser

11
LAB 1 : HELLO OPENSHIFT

1.  Install OpenShift Eclipse plugin
2.  Create new application with JBoss EAP and MongoDB
cartri...
LAB 2 : HOT DEPLOYMENT

1.  Right click on your project and then go to
OpenShift > Configure Markers
2.  Choose Hot Deploy...
LAB 3 : SET UP JAX RS

14
LAB 3 : REST INTRODUCTION

1.  HTTP used right
2.  Defines set of RESTful constraints
1. 

Everything is a resource
1. 

2...
LAB 3 JAX-RS INTRODUCTION

1.  Java API for REST Services
2.  POJO based
3.  Annotation heavy
4.  HTTP Centric
5.  Format ...
LAB 3 : SET UP JAX RS

1.  Update to Java 7
2.  Delete web.xml
3.  Update Maven war plugin to 2.3
4.  Create JAX-RS config...
LAB 3 : ADDING GIT REMOTE

git remote add upstream -m master https://github.com/
shekhargulati/sharemylocation-demo.git
gi...
LAB 4 : CONFIGURE CDI AND
MONGODB 

19
CDI


1.  CDI stands for Context and Dependency Injection
2.  CDI simplifies and sanitizes the API for DI and AOP
like JPA...
CDI EXAMPLE


21
MONGODB
WHAT IS MONGODB


l 

Open Source NoSQL document datastore
– 

l 

JSON style documents

Schema-less
– 

Each document i...
MONGODB TERMINOLOGY

	
  
Database	
  	
  	
  →

	
  	
  Database	
  

Table	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  →	
  	...
SOME QUERIES


// Find all the jobs with skill as mongodb

db.jobs.find({"skills":"mongodb"})
// Find all the jobs with py...
LAB 4 : ENABLE CDI AND
MONGODB CONFIGURATION

1.  Create beans.xml in src/main/WEB-INF folder
2.  Create ApplicationScoped...
LAB 5 : IMPLEMENT CREATE
AND FIND ALL STATUS

1.  Create Status domain class
2.  Create converter for Status to DBObject a...
LAB 6 : IMPLEMENT NEAR AND
GEONEAR FEATURES

1.  Create findNear and findGeoNear methods in
ApplicationDao
2.  Create near...
QUESTIONS?
DONE!
STEP 1 : CHOOSE OPENSHIFT
TOOLS

31
STEP 1 : SEARCH JBOSS
TOOLS

32
GEOSPATIAL INDEXING
BASICS


What is it for?

l 

l 
l 

l 

Find all the MongoDB jobs near me – Proximity Queries
Fin...
HOW TO MAKE IT WORK


1)  Put your coordinates into an array
{ loc : [ 50 , 30 ] } //SUGGESTED OPTION
{ loc : { x : 50 , y...
Upcoming SlideShare
Loading in...5
×

Java(ee) mongo db applications in the cloud

1,815

Published on

Published in: Technology, Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,815
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
36
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Java(ee) mongo db applications in the cloud "

  1. 1. Java(EE)OPENSHIFT MongoDB Applications in the Cloud Workshop PRESENTED BY Shekhar Gulati
  2. 2. WHO AM I? •    •    •    •  •  Shekhar  Gula+  -­‐-­‐  OpenShi1  Developer  Evangelist   Java  /  JavaScript  /  Python  /  NoSQL  /  Cloud  Guy   TwiEer  Handle  :  shekhargula*   Github  :  h,ps://github.com/shekhargula*   Author  of  30  technologies  in  30  days  blog  series   h,ps://www.openshi9.com/blogs/learning-­‐30-­‐ technologies-­‐in-­‐30-­‐days-­‐a-­‐developer-­‐challenge  
  3. 3. AGENDA l  Get  started  with  OpenShi1   l  Develop  a  loca+on  aware  applica+on   -  Java  EE  6  –  Middleware   l  JAX-­‐RS  1.1  –  Java  API  for  REST  WS   l  CDI  –  Context  and  Dependency  Injec+on   -  Eclipse  Kepler  –  IDE   -  MongoDB  –  Database   -  OpenShi1  –  Deployment  choice   http://sharemylocation-shekhargulati.rhcloud.com/
  4. 4. CODE DU JOUR https://github.com/shekhargulati/sharemylocation-demo
  5. 5. OpenShift OPENSHIFT  OVERVIEW  
  6. 6. OpenShift is PaaS by Red Hat Multi-language, Auto-Scaling, Self-service, Elastic, Cloud Application Platform
  7. 7. WHY OPENSHIFT? l  l  Supports  MongoDB  ,  PostgreSQL  ,and  MySQL   Mul+-­‐language  support.  Supports  Java,  Node.js,  Perl,  Python,   PHP  and  Ruby   l  Extensible  via  DIY  and  cartridges   l  No  need  to  learn  anything  new   l  Open  source  –  OpenShi1  Origin   l  Scalable   l  FREE!   l  Produc+on  Ready  
  8. 8. OUR STACK 8
  9. 9. FLAVORS OF OPENSHIFT Open Source Project Public Cloud Service origin Onpremise or Private Cloud Software
  10. 10. OPENSHIFT – GETTING STARTED Go to https://openshift.redhat.com/app/account/new Promo code is JUDCON-IN14 Verify Email 10
  11. 11. TOOLS REQUIRED 1.  Eclipse for Java EE (Kepler) 2.  Git 3.  Modern browser 11
  12. 12. LAB 1 : HELLO OPENSHIFT 1.  Install OpenShift Eclipse plugin 2.  Create new application with JBoss EAP and MongoDB cartridges. 1.  Sign up for OpenShift(if not already) 2.  Create domain name or namespace 3.  Upload SSH keys to OpenShift 4.  Fill application creation wizard 5.  Finish 3.  Show OpenShift Explorer View and Server’s View 4. Make a change in index.html 1.  2.  12 Commit the change using Git Staging view Publish the change
  13. 13. LAB 2 : HOT DEPLOYMENT 1.  Right click on your project and then go to OpenShift > Configure Markers 2.  Choose Hot Deploy marker 3.  Commit to git repository 4.  Go to servers view and publish your changes. 13
  14. 14. LAB 3 : SET UP JAX RS 14
  15. 15. LAB 3 : REST INTRODUCTION 1.  HTTP used right 2.  Defines set of RESTful constraints 1.  Everything is a resource 1.  2.  Eg. Post , Tweet , User , etc. Every resource has an identifier 1.  Eg. http://api/twitter.com/tweets/1000011111 3.  Resource can have multiple representations 1.  JSON , XML , YAML , etc. 4.  All resources expose a uniform interface 1.  GET , POST , PUT , DELETE 15
  16. 16. LAB 3 JAX-RS INTRODUCTION 1.  Java API for REST Services 2.  POJO based 3.  Annotation heavy 4.  HTTP Centric 5.  Format independent 6.  Container independent 7.  Included with Java EE 6 In this workshop we will be talking about JAX-RS 1.1 16
  17. 17. LAB 3 : SET UP JAX RS 1.  Update to Java 7 2.  Delete web.xml 3.  Update Maven war plugin to 2.3 4.  Create JAX-RS configuration class. 5.  Write PingResource 17
  18. 18. LAB 3 : ADDING GIT REMOTE git remote add upstream -m master https://github.com/ shekhargulati/sharemylocation-demo.git git fetch –all git reset --hard upstream/lab3 18
  19. 19. LAB 4 : CONFIGURE CDI AND MONGODB 19
  20. 20. CDI 1.  CDI stands for Context and Dependency Injection 2.  CDI simplifies and sanitizes the API for DI and AOP like JPA did for ORM -- CDI Tutorial by Rick Hightower 3.  Type safe approach to Dependency Injection 4.  Strong typing and loose coupling 5.  To configure CDI add beans.xml to 1.  WEB-INF of WAR 2.  META-INF of JAR 6.  Beans can be injected at method , field , or constructor. 20
  21. 21. CDI EXAMPLE 21
  22. 22. MONGODB
  23. 23. WHAT IS MONGODB l  Open Source NoSQL document datastore –  l  JSON style documents Schema-less –  Each document is heterogeneous, and may have completely unique structure compared to other documents l  l  Rich query language l  Rich documents l  Easy to get running l  23 Fast and horizontally scalable Geospatial indexing
  24. 24. MONGODB TERMINOLOGY   Database      →    Database   Table                    →          Collec+on   Row                        →    Document   Index                    →            Index  
  25. 25. SOME QUERIES // Find all the jobs with skill as mongodb db.jobs.find({"skills":"mongodb"}) // Find all the jobs with python as skill and near to given location db.jobs.find({"lngLat":{$near : [139.69 , 35.68]}, "skills":"python"}) // Find all the python or mongodb jobs near to given location db.jobs.find({"lngLat":{$near : [139.69 , 35.68]}, "skills":{$in : ["mongodb","python"]}}) 25
  26. 26. LAB 4 : ENABLE CDI AND MONGODB CONFIGURATION 1.  Create beans.xml in src/main/WEB-INF folder 2.  Create ApplicationScoped bean for configuring MongoDB 3.  PingResource writes a document to dummy collection 4.  Open Eclipse Remote System Explorer perspective and connect to gear. Right click on project 1.  26 Team > Reset > Remote Tracking > upstream/lab4
  27. 27. LAB 5 : IMPLEMENT CREATE AND FIND ALL STATUS 1.  Create Status domain class 2.  Create converter for Status to DBObject and vice versa 3.  Create StatusResource with create and find all endpoints. 4.  Create ApplicationDao with create and findAll methods. 5.  Create Twitter Bootstrap and Backbonejs front end for create and find all functionalities. Right click on project -  27 Team > Reset > Remote Tracking > upstream/lab5
  28. 28. LAB 6 : IMPLEMENT NEAR AND GEONEAR FEATURES 1.  Create findNear and findGeoNear methods in ApplicationDao 2.  Create near and geonear search REST endpoints in StatusResource 3.  Implement backbone views for search endpoints 4.  Create Index 1.  db.statuses.ensureIndex({“location”:”2dsphere”}) Right click on project -  28 Team > Reset > Remote Tracking > upstream/lab6
  29. 29. QUESTIONS?
  30. 30. DONE!
  31. 31. STEP 1 : CHOOSE OPENSHIFT TOOLS 31
  32. 32. STEP 1 : SEARCH JBOSS TOOLS 32
  33. 33. GEOSPATIAL INDEXING BASICS What is it for? l  l  l  l  Find all the MongoDB jobs near me – Proximity Queries Find all the MongoDB jobs within Bangalore – Bounded Queries Find all the MongoDB job at this location – Exact Queries l  Supports only two dimensional indexes. l  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)) l  33
  34. 34. 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 } } 1)  { loc : { lon : 40.739037, lat: 73.992964 } } 2)  Make a 2d index db.places.ensureIndex( { loc : "2d" } ) 3) 34 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.
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×