Java EE 6 and NoSQL Workshop DevFest Austria
-
Upload
shekhar-gulati -
Category
Technology
-
view
550 -
download
2
description
Transcript of Java EE 6 and NoSQL Workshop DevFest Austria
![Page 1: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/1.jpg)
OPENSHIFTWorkshop
PRESENTEDBY
ShekharGulati
JEE6 and NoSQL in the Cloud
![Page 2: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/2.jpg)
WHO AM I?
• Shekhar Gulati -- OpenShift Developer Evangelist
• Java / JavaScript / Python / NoSQL / Cloud Guy
• Twitter Handle : shekhargulati
• Github https://github.com/shekhargulati
• Slides http://www.slideshare.net/shekhargulati
![Page 3: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/3.jpg)
● Get started with OpenShift● Develop a location aware application
– Java EE 6 – Middleware● JAX-RS 1.1 – Java API for REST WS● CDI – Context and Dependency Injection
– MongoDB – Database
– OpenShift – Deployment choice
AGENDA
http://sharemylocation-shekhargulati.rhcloud.com/
![Page 4: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/4.jpg)
CODE DU JOUR
https://github.com/shekhargulati/sharemylocation-demo
![Page 5: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/5.jpg)
OpenShift
OPENSHIFT OVERVIEW
![Page 6: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/6.jpg)
OpenShiftis
PaaS by Red Hat
Multi-language,Auto-Scaling,Self-service,
Elastic,Cloud Application
Platform
![Page 7: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/7.jpg)
● Supports MongoDB , PostgreSQL ,and MySQL
● Multi-language support. Supports Java, Node.js, Perl, Python, PHP and Ruby
● Extensible via DIY and cartridges
● No need to learn anything new
● Open source – OpenShift Origin
● Scalable
● FREE!
WHY OPENSHIFT?
![Page 8: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/8.jpg)
8
OUR STACK
![Page 9: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/9.jpg)
origin
Public Cloud Service
On-premise or Private Cloud Software
Open Source Project
FLAVORS OF OPENSHIFT
![Page 10: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/10.jpg)
10
OPENSHIFT – GETTING STARTED
Go tohttps://openshift.redhat.com/app/account/new
Promo code is DEVFEST2013
Verify Email
![Page 11: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/11.jpg)
11
1. Eclipse for Java EE (Kepler)
2. Git
3. Modern browser
TOOLS REQUIREDTOOLS REQUIRED
![Page 12: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/12.jpg)
12
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. Make a change in index.html1. Commit the change using Git Staging view
2. Publish the change
4.View application in browser
LAB 1 : HELLO OPENSHIFT
![Page 13: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/13.jpg)
13
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.
LAB 2 : HOT DEPLOYMENT
![Page 14: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/14.jpg)
14
LAB 3 : SET UP JAX RS
![Page 15: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/15.jpg)
15
1. HTTP used right
2. Defines set of RESTful constraints1. Everything is a resource
1. Eg. Post , Tweet , User , etc.
2. 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
5. Hypermedia as the engine of application state
LAB 3 : REST INTRODUCTION
![Page 16: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/16.jpg)
16
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
LAB 3 JAX-RS INTRODUCTION
In this workshop we will be talking about JAX-RS 1.1
![Page 17: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/17.jpg)
17
1. Update to Java 7
2. Update Maven war plugin to 2.3
3. Create JAX-RS configuration class.
4. Write PingResource
git remote add upstream -m master https://github.com/shekhargulati/sharemylocation-demo.git
git fetch –all
git reset --hard upstream/lab3
LAB 3 : SET UP JAX RS
![Page 18: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/18.jpg)
18
LAB 4 : CONFIGURE CDI AND MONGODB
![Page 19: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/19.jpg)
19
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 to1. WEB-INF of WAR
2. META-INF of JAR
6. Beans can be injected at method , field , or constructor.
CDI
![Page 20: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/20.jpg)
20
CDI EXAMPLE
![Page 21: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/21.jpg)
MONGODB
![Page 22: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/22.jpg)
22
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
![Page 23: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/23.jpg)
Database → Database
Table → Collection
Row → Document
Index → Index
MONGODB TERMINOLOGYMONGODB TERMINOLOGY
![Page 24: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/24.jpg)
24
// 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"]}})
SOME QUERIES
![Page 25: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/25.jpg)
25
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. Team > Reset > Remote Tracking > upstream/lab4
LAB 4 : ENABLE CDI AND MONGODB CONFIGURATION
![Page 26: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/26.jpg)
26
1. Creates Status domain class
2. Creates converter for Status to DBObject and vice versa
3. Creates StatusResource with create and find all endpoints.
4. Creates ApplicationDao with create and findAll methods.
5. Creates Twitter Bootstrap and Backbonejs front end for create and find all functionalities.
Right click on project – Team > Reset > Remote Tracking > upstream/lab5
LAB 5 : IMPLEMENT CREATE AND FIND ALL STATUS
![Page 27: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/27.jpg)
27
1. Creates findNear and findGeoNear methods in ApplicationDao
2. Creates near and geonear search REST endpoints in StatusResource
3. Implements backbone views for search endpoints
4. Create Index1. db.statuses.ensureIndex({“location”:”2dsphere”})
Right click on project – Team > Reset > Remote Tracking > upstream/lab6
LAB 6 : IMPLEMENT NEAR AND GEONEAR FEATURES
![Page 28: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/28.jpg)
QUESTIONS?
![Page 29: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/29.jpg)
DONE!
![Page 30: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/30.jpg)
30
STEP 1 : CHOOSE OPENSHIFT TOOLS
![Page 31: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/31.jpg)
31
STEP 1 : SEARCH JBOSS TOOLS
![Page 32: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/32.jpg)
32
What is it for? 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
● 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
![Page 33: Java EE 6 and NoSQL Workshop DevFest Austria](https://reader034.fdocuments.net/reader034/viewer/2022051514/54c2e76c4a79599d628b4640/html5/thumbnails/33.jpg)
33
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