Slide 1

Slide 1 text

1 Building Location Aware Applications with OpenShift and MongoDB Shekhar Gulati @shekhargulati OpenShift Evangelist, Red Hat

Slide 2

Slide 2 text

2 About Me ➢ OpenShift Evangelist at Red Hat ➢ Hands-on Developer ➢ Active Blogger http://whyjava.wordpress.com/ https://openshift.redhat.com/community/blogs ➢ Written Technical Articles on various technology portals. ➢ Active Speaker JUDCon, Red Hat Developer Day, JBoss World, MongoDB Meetups, etc ➢ Twitter Handle : shekhargulati ➢ Trying to learn and improve every day

Slide 3

Slide 3 text

3

Slide 4

Slide 4 text

4 Agenda • What is PaaS? • Let's become friends with OpenShift • What does development look like ? • Getting your hands dirty Tweet about the event with #openshift

Slide 5

Slide 5 text

5 Cloud Service Models STORAGE (RHS) HARDWARE (x86, Power, S/390) VIRTUALIZATION (RHEV) OPERATING SYSTEM (RHEL) APPLICATION PLATFORM (JBOSS, PHP, RUBY, ETC) APPLICATION Automated and Managed by the Public or Private Cloud Offering Managed and Controlled by Customer (IT, Dev, or User) IaaS PaaS SaaS Increased Control Increased Automation

Slide 6

Slide 6 text

6 What is PaaS?

Slide 7

Slide 7 text

7 PaaS = Platform as a Service A Cloud Application Platform Code Deploy Enjoy Save Time and Money Code your app Push-button Deploy, and your App is running in the Cloud!

Slide 8

Slide 8 text

8

Slide 9

Slide 9 text

9 Streamlining App Dev with PaaS With PaaS How to Build an App: 1. Have Idea 2. Get Budget 3. Code 4. Test 5. Launch 6. Automatically Scale How to Build an App: 1. Have Idea 2. Get Budget 3. Submit VM Request request 4. Wait 5. Deploy framework/appserver 6. Deploy testing tools 7. Test testing tools 8. Code 9. Configure Prod VMs 10. Push to Prod 11. Launch 12. Request More Prod VMs to meet demand 13. Wait 14. Deploy app to new VMs 15. Etc. Today How to Build an App: 1. Have Idea 2. Get Budget 3. Submit hardware acquisition request 4. Wait 5. Get Hardware 6. Rack and Stack Hardware 7. Install Operating System 8. Install Operating System Patches/Fix-Packs 9. Create user Accounts 10. Deploy framework/appserver 11. Deploy testing tools 12. Test testing tools 13. Code 14. Configure Prod servers (and buy them if needed) 15. Push to Prod 16. Launch 17. Order more servers to meet demand 18. Wait… 19. Deploy new servers 20. Etc. Yesterday “The use of Platform-as-a-Service technologies will enable IT organizations to become more agile and more responsive to the business needs.” –Gartner*

Slide 10

Slide 10 text

10 Why PaaS?  Lets developer focus on his job i.e. to write code.  You develop “Cloud Aware” applications from the beginning.  Improves developer productivity.  Reduces cost and time to market.  Brings agility to product development.  Gives developers the power to prototype their ideas rapidly.

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

12 Introducing OpenShift  A free auto-scaling, cloud-based application platform from Red Hat.  Multi Language, Multi Frameworks, Multi Cartridges.  No proprietary software.  No Lock-in.  Open source – OpenShift Origin.

Slide 13

Slide 13 text

13 Why OpenShift? ● Strength. OpenShift is built on proven Red Hat technologies. ● Freedom. In OpenShift, work the way you want. ● Choice of Interface: Web Console, Command-line, or IDE ● Choice of Middleware: Java(EE6), Ruby, Node.js, PHP, Python, and Perl ● Choice of Cloud: Public, Private, or Hybrid Cloud ● Choice of Elasticity: Automatic application scaling when needed ● Openness. OpenShift’s open source software stack ensures application portability and No Lock-In.

Slide 14

Slide 14 text

14 1. Strength. OpenShift is Built on Red Hat Goodness…

Slide 15

Slide 15 text

15

Slide 16

Slide 16 text

16

Slide 17

Slide 17 text

17

Slide 18

Slide 18 text

18

Slide 19

Slide 19 text

19

Slide 20

Slide 20 text

20

Slide 21

Slide 21 text

21 2. Freedom. To Work The Way You Want To Work

Slide 22

Slide 22 text

22 Developers Choose How To Work with OpenShift Developer IDE Integrations Web Browser Console Command Line Tooling REST APIs

Slide 23

Slide 23 text

23 OpenShift’s Intuitive and “Responsive” Web Console Runs on Any Device

Slide 24

Slide 24 text

24 Are You a Command-Line Fan? OpenShift’s RHC CLI Tools 1) Create App rhc app create -a javasample -t jbossas-7 2) Add MongoDB rhc cartridge add -a javasample –c mongodb-2.2 3) Add add WAR file to your deployments directory cd javasample cp /path/to/war/ROOT.war ./deployments 4) Add the WAR file to git git add ./deployments/ROOT.war 5) Push your code git push 6) Done

Slide 25

Slide 25 text

25 And, of Course, a Powerful JBoss Dev Studio IDE Integration

Slide 26

Slide 26 text

26 Developers Choose Languages, Frameworks and Middleware

Slide 27

Slide 27 text

27 3. Openness. And of course, OpenShift is Open Source…

Slide 28

Slide 28 text

28 OpenShift Origin The upstream project for the OpenShift PaaS platform •Apache 2.0 License •Available as: • Source, RPMs • .ISO, LiveCD (run your own) •IRC, email, forums https://openshift.redhat.com/community/open-source https://github.com/openshift

Slide 29

Slide 29 text

29 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

Slide 30

Slide 30 text

30 1. OpenShift Web console demo 2. OpenShift Eclipse Integration demo 3. Developing Location Aware Job search application Note : The promo code is DELHI Demo

Slide 31

Slide 31 text

31 Some terminology for today 1. Application – your web code and any data store. Has to be on 1 or more gears 2. Gear – is like a server. It can have only 1 language for the web programming. 3. Cartridge – it adds a language, a data store, or other functionality 4. Git – used for version control and managing code between server and your development machine 5. Ssh – command line tool to connect to your gear

Slide 32

Slide 32 text

32 Let's get our hands dirty

Slide 33

Slide 33 text

33 Create OpenShift Account https://openshift.redhat.com/app/account/new Promo code is DELHI

Slide 34

Slide 34 text

34 Demo 1 - Web Console Wordpress in less than two minutes Default username/password is admin/OpenShiftAdmin

Slide 35

Slide 35 text

35 Installing Client Tools Install Ruby 1.8.7 or greater Install Git Install rhc OpenShift gem Refer to documentation

Slide 36

Slide 36 text

36 Setup your OpenShift Environment rhc setup -l -> ask for namespace -> ask to upload ssh keys

Slide 37

Slide 37 text

37 Demo 2 – Eclipse Integration Two ways to use with Eclipse 1) Using Eclipse Plugin 2) Using JBoss Developer Studio – Eclipse with JBoss Goodness

Slide 38

Slide 38 text

38 Installing Eclipse JBoss Tools Plugin

Slide 39

Slide 39 text

39 Configure SSH Keys

Slide 40

Slide 40 text

40 Create OpenShift Application

Slide 41

Slide 41 text

41 Sign in to OpenShift

Slide 42

Slide 42 text

42 Set up OpenShift Application

Slide 43

Slide 43 text

43 Set up Project Configuration

Slide 44

Slide 44 text

44 Import the OpenShift Application

Slide 45

Slide 45 text

45 Let's see it in action

Slide 46

Slide 46 text

46 Building A Location Aware Job Search App

Slide 47

Slide 47 text

47 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.

Slide 48

Slide 48 text

48 Technology Choices  MongoDB 2.2  OpenShift  Java 6 – Spring 3.1.2.RELEASE – Spring MongoDB 1.1.0.M1  GIT  SSH

Slide 49

Slide 49 text

49 Why MongoDB ?  Easy to get running  Open Source  Active community  Rich documents  Geospatial indexing  Writes are very fast. You can customize it using WriteConcern

Slide 50

Slide 50 text

50 Rich Document

Slide 51

Slide 51 text

51 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

Slide 52

Slide 52 text

52 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" } )

Slide 53

Slide 53 text

53 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!

Slide 54

Slide 54 text

54 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

Slide 55

Slide 55 text

55 You need to understand at least 3 commands in Git 1. Git add . (means add all new 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)

Slide 56

Slide 56 text

56 Creating an OpenShift Application rhc app create -a localjobs -t jbossews-1.0 Some other options -d, -s, -g Some other types : jbossas-7, jbosseap-6, ruby-1.9, python-2.6,nodej-0.6, php-5.3

Slide 57

Slide 57 text

57 Look at the generated code

Slide 58

Slide 58 text

58 Application Deployments Options OpenShift supports two types of deployment options 1) Source code deployment 2) Binary deployment – war,ear

Slide 59

Slide 59 text

59 Other Application Commands App Details – rhc app show -a localjobs Delete App – rhc app delete -a localjobs App Status – rhc app show --state -a localjobs Start App – rhc app start -a localjobs Stop App – rhc app stop -a localjobs Restart App – rhc app restart -a localjobs Clean App – rhc app tidy -a localjobs

Slide 60

Slide 60 text

60 Adding MongoDB and RockMongo Cartridge rhc cartridge add -a localjobs -c mongodb-2.2 rhc cartridge add -a localjobs -c rockmongo-1.1

Slide 61

Slide 61 text

61 Other Cartridge Commands List all Cartridges : rhc cartridge list Cartridge Details : rhc cartridge show -a app -c mongodb-2.2 Remove Cartridge : rhc cartridge remove -a app -c mongodb-2.2 Start Cartridge : rhc cartridge start -a app -c mongodb-2.2 Stop Cartridge : rhc cartridge stop -a app -c mongodb-2.2 Restart Cartridge : rhc cartridge restart -a app -c mongodb-2.2 Cartridge Status : rhc cartridge status -a app -c mongodb-2.2

Slide 62

Slide 62 text

62 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

Slide 63

Slide 63 text

63 Pulling the code from GitHub git 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

Slide 64

Slide 64 text

64 Let's look at jobs-data.json

Slide 65

Slide 65 text

65 Importing Data into MongoDB rhc app show -a localjobs -l scp jobs-data.json :app-root/data ssh 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 db.jobs.ensureIndex({"location":"2d"})

Slide 66

Slide 66 text

66 Show some geospatial queries

Slide 67

Slide 67 text

67 Code Walkthrough

Slide 68

Slide 68 text

68 Deploy the code to OpenShift git push

Slide 69

Slide 69 text

69 Other Useful Commands 1) rhc tail -a app -o “-n 100” 2) rhc snapshot -a app 3) rhc threaddump -a app 4) rhc sshkey list/show/add/remove -l 5) rhc port-forward -a app 6) rhc alias add/remove

Slide 70

Slide 70 text

70 Adding Jenkins Support

Slide 71

Slide 71 text

71 Command to Add Jenkins Support Jenkins Server rhc app create -a jenkins -t jenkins-1.4 Jenkins Client rhc cartridge add -a app -c jenkins-client-1.4

Slide 72

Slide 72 text

72 1. OpenShift makes life great for you 2. The tools are easy to use 3. You should be ready to write services 4. Almost anything you need on a server 5. Did I mention – Free 6. Source code https://github.com/shekhargulati/localjobs Conclusion