Slide 1

Slide 1 text

OPENSHIFT Workshop PRESENTED BY Shekhar Gulati Thinking Beyond RDBMS : Building Polyglot Persistence Java Applications

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

AGENDA

Slide 4

Slide 4 text

WHO ARE YOU?

Slide 5

Slide 5 text

There are no stupid questions only stupid answers. So ask questions ASK QUESTIONS

Slide 6

Slide 6 text

http://nosql-database.org/ lists 150 databases NOW WE HAVE CHOICES ...

Slide 7

Slide 7 text

● Widely used and understood ● Tested in real environments ● Efficient use of storage space if data normalized properly ● Great tools support ● ACID semantics ● Incredibly flexible and powerful query language ● Great framework support WHY RDBMS?

Slide 8

Slide 8 text

● Complex object graphs does not map very well with flat tables. ● Difficult to evolve Schema with time. ● Data constraints and JOINs can be expensive at runtime. ● Difficult to scale horizontally. RDBMS LIMITATIONS

Slide 9

Slide 9 text

NoSQL Databases to rescue

Slide 10

Slide 10 text

● Schema-less ● Eventual consistent ● Scales writes and reads ● Easy to scale horizontally to add processing power and storage ● Tries to solve few practical use-cases NoSQL TO RESCUE

Slide 11

Slide 11 text

Using multiple data storage technologies, chosen based upon the way data is being used by individual applications or components of single application. Martin Fowler http://martinfowler.com/articles/nosql-intro.pdf POLYGLOT PERSISTENCE

Slide 12

Slide 12 text

http://martinfowler.com/articles/nosql-intro.pdf HYPOTHETICAL EXAMPLE

Slide 13

Slide 13 text

GET MORE INFO AT

Slide 14

Slide 14 text

APPLICATION http://localjobs-cix.rhcloud.com/

Slide 15

Slide 15 text

● OpenShift ● MongoDB ● MySQL ● Java – Spring framework , Spring Social, Spring MongoDB, Spring Security etc. ● Searchify : Full-text Search as a Service ● Git ● Twitter Bootstrap ● Backbone.js TECHNOLOGY CHOICES

Slide 16

Slide 16 text

● Document Oriented database – 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 MONGODB

Slide 17

Slide 17 text

Database → Database Table → Collection Row → Document Index → Index MONGODB TERMINOLOGY MONGODB TERMINOLOGY

Slide 18

Slide 18 text

● Easy to get running ● Open Source ● Active community ● Rich documents ● Geospatial indexing ● Writes are very fast. You can customize it using WriteConcern WHY MONGODB?

Slide 19

Slide 19 text

RICH DOCUMENT

Slide 20

Slide 20 text

20  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

Slide 21

Slide 21 text

21 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

Slide 22

Slide 22 text

OpenShift is PaaS by Red Hat Multi-language, Auto-Scaling, Self-service, Elastic, Cloud Application Platform

Slide 23

Slide 23 text

● 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?

Slide 24

Slide 24 text

origin Public Cloud Service On- premise or Private Cloud Software Open Source Project FLAVORS OF OPENSHIFT

Slide 25

Slide 25 text

Developer IDE Integrations Web Browser Console Command Line Tooling REST APIs INTERACTIONS

Slide 26

Slide 26 text

26 Let's build the application

Slide 27

Slide 27 text

27 https://openshift.redhat.com/app/account/new Promo code is JAVAONEIN13 CREATING OPENSHIFT ACCOUNT

Slide 28

Slide 28 text

28 ➢ Login to OpenShift web console ➢ Click on “My Account” ➢ Namespace – javaonein – Unique per user CREATING NAMESPACE

Slide 29

Slide 29 text

29 Install Ruby 1.8.7 or greater Install Git Install rhc OpenShift gem Refer to documentation INSTALLING CLIENT TOOLS

Slide 30

Slide 30 text

30 $ rhc app create localjobs jbosseap mongodb-2.2 mysql-5.1 -s OR Lot of other tasks you can do with rhc – tail log, app management, cartridge management , ssh management , namespace management, etc. Run rhc -h for details DEMO : LOCALJOBS APP RHC is only required for infrastructure tasks rhc app create localjobs jbosseap rhc cartridge add mongodb-2.2 --app localjobs rhc cartridge add mysql-5.1 --app localjobs

Slide 31

Slide 31 text

31 $ git rm -rf src pom.xml $ git commit -am “delete template app” $ git remote add upstream -m master git://github.com/shekhargulati/localjobs-demo.git $ git pull -s recursive -X theirs upstream master ITS All GIT Source code https://github.com/shekhargulati/localjobs-demo

Slide 32

Slide 32 text

32 $ rhc app show -a localjobs $ scp jobs-data.json :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 LOADING DATA IN MONGODB

Slide 33

Slide 33 text

33 git push

Slide 34

Slide 34 text

34 Code Walkthrough

Slide 35

Slide 35 text

QUESTIONS?

Slide 36

Slide 36 text

DONE!