Share
Embed
Transcript
58 slides
-
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 -
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” -
• 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 -
There are no stupid questions only stupid answers. So ask
questions ASK QUESTIONS -
Don't assume you will learn everything that I will talk
ASK QUESTIONS -
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 -
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 -
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 -
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 -
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. -
• 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. -
• 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 -
WE ARE USING JAVA TO BUILD THE APPLICATION STEP 2
: JAVA AS PROGRAMMING LANGUAGE CHOICE -
• 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 -
• 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 -
STEP 2 : 31 JAVA EE 6 SPECS Java EE
platform defines API for different components in each tier -
We will cover only following specifications • Servlet 3.0 •
JAX RS • CDI STEP 2 : JAVA EE 6 SPECS -
• Install Oracle JDK 7 • Download and install Eclipse
• Download and install Maven • Download and install JBoss application server. STEP 3 : GETTING STARTED -
• Servlet is a web component hosted in a servlet
container. • It generates dynamic content • Client interacts using request/response pattern STEP 3 : SERVLET -
STEP 3 : DEMO TIME 1. Create Servlet using Eclipse
2. Create Job 3. View Job -
• 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 -
• 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 -
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 -
Database → Database Table → Collection Row → Document Index
→ Index STEP 4 : MONGODB TERMINOLOGY -
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 -
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 -
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! -
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. -
47 OpenShift is PaaS by Red Hat Multi-language, Auto-Scaling, Self-service,
Elastic, Cloud Application Platform -
• 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 -
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 -
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 -
54 $ rhc app show -a localjobs $ scp jobs-data.json
<ssh url>: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