Slide 1

Slide 1 text

OPENSHIFT Workshop PRESENTED BY Shekhar Gulati JEE6 and NoSQL in the Cloud

Slide 2

Slide 2 text

AGENDA ➔ Java EE 6 and NoSQL in Cloud Part 1 - Getting Started with Java EE 6 ➔ Java EE 6 and NoSQL in Cloud Part 2 - Getting Started with MongoDB ➔ Java EE 6 and NoSQL in Cloud Part 3 - Getting Started with OpenShift Cloud

Slide 3

Slide 3 text

WHO AM I? • Shekhar Gulati – Works at Red Hat • Principal OpenShift Developer Evangelist • Java / Python/ JavaScript / NoSQL / Cloud Guy • Twitter Handle : shekhargulati • Email : [email protected] • Github https://github.com/shekhargulati • Slides https://speakerdeck.com/shekhargulati • For anything else just Google “Shekhar Gulati”

Slide 4

Slide 4 text

WHO ARE YOU?

Slide 5

Slide 5 text

Write an application and host it on internet http://localjobs-shekhargulati.rhcloud.com/ GOAL

Slide 6

Slide 6 text

● You use web 2.0 applications like Facebook , Twitter , LinkedIn , blogs etc. ● You know how to write code ● You know Java ● You want to become Software Engineer ASSUMPTIONS

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

Don't assume you will learn everything that I will talk ASK QUESTIONS

Slide 9

Slide 9 text

Steps To Create A Web Application?

Slide 10

Slide 10 text

1.Idea 2.Choose a programming language 3.Setup local development environment 4.Choose a database 5.Write application code 6.Test the application 7.Deploy application to production server STEPS

Slide 11

Slide 11 text

LocalJobs : Location Aware Job Search App Functionalities or User stories or Features 1. As an Employer , I should be able to register my company 2. As an Employer, I should be able to post jobs 3. As a Job seeker , I should be able to register myself with application 4. As a Job seeker , I should be able to search jobs near to my current location. 5. As a Job seeker , I should be able to apply a job 6. Etc... STEP 1 : DEFINE YOUR IDEA

Slide 12

Slide 12 text

Prioritize the functionalities or user stories or features – As an Employer, I should be able to post jobs – As a Job seeker , I should be able to search jobs near to my current location. – As a Job seeker , I should be able to apply a job STEP 1 : PRIORITIZE

Slide 13

Slide 13 text

Estimate the functionalities or user stories – As an Employer, I should be able to post jobs – 1 day – As a Job seeker , I should be able to search jobs near to my current location. - 3 days – As a Job seeker,I should be able to apply a job - 1 day STEP 1 : ESTIMATION

Slide 14

Slide 14 text

STEP 2 : CHOOSE PROGRAMMING LANGUAGE A programming language is a computer language programmers use to develop applications, scripts, or other set of instructions for a computer to execute.

Slide 15

Slide 15 text

● There are thousands of programming languages. ● Programming languages are classified four classes. STEP 2 : CHOOSE PROGRAMMING LANGUAGE Declarative Language Object Oriented Language Functional Language Imperative Language Declarative programming languages describe a problem but they usually do not say how the problem should be solved. Examples are Prolog, XSLT, LISP and SQL Object-oriented programming languages place data and functions that change data into a single unit. This unit is called an object. Most modern programming languages are object- oriented. Examples are Java , C++ , C# etc. Functional programming looks at programming like a function in mathematics. The program receives input, some information, and uses this information to create output. Examples are Scala , Clojure , F# etc You always write what is supposed to happen next. Even if there are more choices, e.g. based on the user's input, it is always: you ask about the input when you want to ask, then you choose what happens next based on the answer you received. For example C , Basic , etc.

Slide 16

Slide 16 text

● PHP is your teenage sweetheart .. ● Perl is PHP's older sister ... ● Ruby is the cool girl ● Python is Ruby's more sensible sister ... ● Java is a successful career woman .. ● C++ is Java's cousin ... ● C is C++'s mom... ● Haskell, Clojure, Scheme and their friends are those hipster, artsy, intellectual girls .. http://b.qr.ae/RUc3w7 STEP 2 : PROGRAMMING LANGUAGE IN LAYMAN TERMS

Slide 17

Slide 17 text

STEP 2 : TIOBE PROGRAMMING COMMUNITY INDEX

Slide 18

Slide 18 text

WE ARE USING JAVA TO BUILD THE APPLICATION STEP 2 : JAVA AS PROGRAMMING LANGUAGE CHOICE

Slide 19

Slide 19 text

● Java is a general-purpose, concurrent, class-based, object- oriented computer programming language. ● Java applications are typically compiled to bytecode (class file) that can run on any Java virtual machine (JVM) regardless of computer architecture. ● Java was originally developed by James Gosling at Sun Microsystems – JDK 1.0 (January 21, 1996) , JDK 1.1 (February 19, 1997) , J2SE 1.2 (December 8, 1998) , J2SE 1.3 (May 8, 2000) , J2SE 1.4 (February 6, 2002) , Java 5.0 (September 30, 2004) , Java SE 6 (December 11, 2006) , Java SE 7 (July 28, 2011) You can also try Java Online http://www.tryjava8.com/ STEP 2 : JAVA FACTS

Slide 20

Slide 20 text

● The Java Platform, Enterprise Edition (Java EE) provides a standards-based platform for developing web and enterprise application. ● Java EE extends the Java Platform, Standard Edition (Java SE), providing an API for object-relational mapping, distributed and multi-tier architectures, and web services. ● Consists of 28 specifications (Thousands of pages) ● Convention over configuration ● Less boilerplate code ● Promotes POJO programming model ● Annotations and types over XML STEP 2 : JAVA EE

Slide 21

Slide 21 text

STEP 2 : Client Server Architecture

Slide 22

Slide 22 text

STEP 2 : Multi-Tier Architecture http://en.wikipedia.org/wiki/Multitier_architecture Typically Java EE Applications are multi-tier

Slide 23

Slide 23 text

STEP 2 : 31 JAVA EE 6 SPECS Java EE platform defines API for different components in each tier

Slide 24

Slide 24 text

We will cover only following specifications ● Servlet 3.0 ● JAX RS ● CDI STEP 2 : JAVA EE 6 SPECS

Slide 25

Slide 25 text

● Install Oracle JDK 7 ● Download and install Eclipse ● Download and install Maven ● Download and install JBoss application server. STEP 3 : GETTING STARTED

Slide 26

Slide 26 text

● Servlet is a web component hosted in a servlet container. ● It generates dynamic content ● Client interacts using request/response pattern STEP 3 : SERVLET

Slide 27

Slide 27 text

STEP 3 : DEMO TIME 1. Create Servlet using Eclipse 2. Create Job 3. View Job

Slide 28

Slide 28 text

● JAX-RS: Java API for RESTful Web Services ● It is a Java programming language API that provides support in creating web services according to the Representational State Transfer (REST) architectural pattern. ● POJO based annotation heavy ● Everything is a resource STEP 3 : JAX - RS

Slide 29

Slide 29 text

DEMO TIME STEP 3 : DEMO TIME

Slide 30

Slide 30 text

● Stands for Context and Dependency Injection ● Type safe dependency injection in Java EE platform. ● Provide two main things – Dependency Injection – Manages components in scope ● Leads to loose coupling and strong typing using annotations STEP 3 : CDI

Slide 31

Slide 31 text

DEMO TIME STEP 3 : DEMO TIME

Slide 32

Slide 32 text

STEP 4 : MONGODB

Slide 33

Slide 33 text

33  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 STEP 4 : WHAT IS MONGODB

Slide 34

Slide 34 text

Database → Database Table → Collection Row → Document Index → Index STEP 4 : MONGODB TERMINOLOGY

Slide 35

Slide 35 text

DEMO TIME

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

37 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 38

Slide 38 text

38 STEP 5 : APP DEVELOPMENT

Slide 39

Slide 39 text

39 APPLICATION DEPLOYMENT

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

What is PaaS?

Slide 42

Slide 42 text

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 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

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 46

Slide 46 text

OpenShift OPENSHIFT OVERVIEW

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

48 OUR STACK

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

● Free! No time limit ● 3 gears (like servers) - each 512 Mb RAM, 1 Gb disk ● Auto-scaling ● Simple pricing ● We are coming out of developer preview this summer BUT WAIT – THERE's MORE

Slide 51

Slide 51 text

51 Let's build the application

Slide 52

Slide 52 text

52 $ rhc app create localjobs jbosseap mongodb-2.2 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

Slide 53

Slide 53 text

53 $ git remote add upstream -m master git://github.com/shekhargulati/localjobs-jee.git $ git pull -s recursive -X theirs upstream master ITS All GIT Source code is managed using Git Source code https://github.com/shekhargulati/localjobs-jee

Slide 54

Slide 54 text

54 $ 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 55

Slide 55 text

55 git push

Slide 56

Slide 56 text

56 Code Walkthrough

Slide 57

Slide 57 text

QUESTIONS?

Slide 58

Slide 58 text

DONE!