Student Team Presentation using AWS with Prophet on AFS

Download Report

Transcript Student Team Presentation using AWS with Prophet on AFS

CS 633 Final Project
Team A
Andrew Corea
Christopher Field
Gautham Mayyuri
Lokesh Dahiya
Nikhil Royal
Salman Virk
Shruti Chandrashekar
Project Summary
• Implementation of a Shopping Cart
o EZShop
• Front End
o Java Server Pages (JSPs) running on JBOSS Web Component
• Middleware
o JBOSS
 Enterprise Java Beans
 Stateless Session Beans
 Connect with ListCart.jsp over internet
o Java Server Page (ListCart.jsp) at web.njit.edu
 Speaks with database
• Database Layer
 Oracle at prophet.njit.edu:5560/isqlplus
Outline
•
•
•
•
•
•
•
•
Middleware Integration
Amazon Web Services
Designs
Screenshots
Problems Encountered
Lessons Learned
Implementation Details
AWS Utilization Ideas
Why JBOSS?
• Free
• Popular so there is a good body of information to search on for assistance
o In reality the latest version is a major change over previous ones and the
online documentation has not yet caught up.
• It provides both the web container and the EJB container instead of having
to try to make two different products work together.
Why Prophet?
• The project presentation said this is a distributed systems class
and a 3 tier client/server architecture was encouraged.
• We REALLY distributed our system between AWS, the client,
web.njit.edu and prophet.njit.edu
Why use JSPs on the back end
• NJIT states tomcat is only rebooted 3x per day
http://web.njit.edu/all_topics/Servers/Tomcat/
o Unacceptable development/debug cycle waiting for reboot
• JSPs show the changes as soon as you do it, just change file and
save no need to compile, just change, save, and refresh.
Amazon Web Services Exec. Summary
•
•
•
•
AWS is much easier to use than the AFS environment
We get root access to a Linux box in the cloud
Dr. Wolosh can open ports on AWS if we ask him to
No chance of conflicts with other people using the same ports for
their projects
• No tiny memory or disk space limits like in the AFS environment
What is an AMI?
Amazon machine image. Basically each team's Linux box is a
machine image. A machine image is like what we would refer to as a
physical computer.
You can get AMI's with software already installed on them like
JBOSS, Oracle, etc.. or you can start with just Linux or windows/etc...
An Instance of an AMI is a running computer from an AMI, there can
be many of these. Similar to how one physical computer can run
multiple virtual machine images with each one seeming like its own
computer.
What is the Elastic Compute Cloud (EC2)
• A data center managed on Amazon's computers
o to a developer each AMI Instance is little different from a Virtual
Machine in their local data center.
• You only pay for what you use. You can scale up to 1,000 AMI's or you can
scale down to 10 AMI's only paying for the computer time you use, not
needing to buy hardware, rent hardware, or buy staff to manage it.
o If you launch a new product and anticipate a spike in traffic, you can
easily scale up temporarily and then go back down.
• Using web services (RESTful or SOAP) you can manage the AMI's by
creating them, destroying them, setting them to IP addresses, opening ports
on them, create new storage volumes from the elastic block store and attach
them to an AMI (like Dr. Wolosh did with /local)
Cloud Services
• Simple DB
o DB system on the cloud that does not use the relational model
• Amazon Simple Storage Service
o Web Service to store/retrieve large amounts of data.
• Amazon CloudFront
o Distribute data files from Amazon Simple Storage Service to
end users, by moving the data to the computer on amazon's
network closest to the end user and serving from there
• Amazon Simple Queue Service
o Message Oriented Middleware where processes both in and out
of the cloud can store and retrieve messages from the Queue
Other Services
There also seem to be hooks into amazon.com as well as some features
already implemented like shopping carts on the various pages which
are usable with an amazon web service ID. They aren't the main
services of EC2 and may count as other services, it's tough to say.....
The Rub
• Accessing the Amazon services requires an AWS ID. Basically
there is one AWS ID for the entire class and that has been used to
create our machines and give us storage space.
• With the AWS ID it would be possible to use the services like
Simple DB and also to stop/start AMI's, including those of other
teams.
• The advantage of Amazon web services is mostly for UCS where
they have simple management of computers through web services
and can scale up/down as they need to for different courses.
What we get
• Root access on a Linux box
o No restriction on ports below 1024
o Can install whatever is required
• a static ip address that can be used to connect to it
o in comparison to dynamic addresses at many people's home
connections
• UCS can open ports as needed
o specifically Dr. Wolosh mentioned that they will not open ports
on the AFS machines
• UCS can also add new space as needed
o It's as easy as using the web service to create more storage and
mount it
What do we get on AFS machines
• An account with memory limits in both disk space and RAM
o Lecture slides mention needing to request more space to Install
JBoss and Web Sphere not working at all
• A set machine behind a firewall that cannot be accessed outside of
the NJIT network except for certain exceptions
o It was mentioned that they will not open additional ports to the
outside world
o need to be on the vpn to use an arbitrary port
• A machine shared with others
o if two students run their project on the same port, only one will
be successful if both are on the same machine
• not the root
o Cannot do a lot of things and need to ask UCS
Sources on AWS
• Emails with Dr. Wolosh, he is the Amazon Web Services Guru at
UCS
• Amazon Developer Guide, in particular looking at the API's can get
a feel for what you can do.
• http://docs.amazonwebservices.com/AWSEC2/2009-0301/DeveloperGuide/
http://aws.amazon.com/ general guide to everything AWS
Overall Architecture
Chris Field
Overall Architecture View
Architecture Overview
Amazon AWS Architecture Overview
Amazon AWS Architecture
Amazon Web Services machine (174.129.241.232)
• JBOSS
o Store.war
 JSPs for front end
 various resources like images etc.
o Beans.jar
 cs633beans
 Java bean interfaces, implementations
 Communication class
 Posts forms to ListCart.jsp on web.njit.edu and extracts
results from xml messages
NJIT Architecture Overview
NJIT Architecture
NJIT Network
• web.njit.edu
o ListCart.jsp
 JSP that processes a web form and runs queries on Oracle
returning xml responses
• Prophet.njit.edu
o course
 Oracle DB
Database Design
Shruti Chandrashekar
Database Design
Fig: Database diagram showing the various tables with their attributes and relationships
Demo
Shruti & Lokesh
SQL Queries
• SELECT OID, CName, OrderDate from CustOrder co INNER
JOIN Customer c on co.CID = c.CID
• SELECT co.OID, OrderDate, CName, PName, Quantity, Price
* Quantity as Price
FROM OrderContents oc INNER JOIN custorder co on oc.oid =
co.OID INNER JOIN Customer c on c.CID = co.CID
INNER JOIN Product p on p.PID = oc.PID
ORDER BY co.OID
Query of CUSTORDERS/OrderContents after
Checkout
Oracle:
• SELECT p.PName, oc.Quantity, p.Price
FROM OrderContents oc INNER JOIN Product p on oc.PID = p.PID
WHERE oc.OID = xxx
Screen Shots
Demo of a Customer
Client/Server Interaction
Initial Query of CustOrder Table
Login Page
After log in with item from last time
Product List for Notebooks
Product Detail Pavilion
After adding to cart
Product List of Audio Category
View Cart
After removing camera and changing
quantity
After Purchase, note empty cart
Query of completed order
Query of completed order details
Problems Encountered
Setting up JBOSS
• JBOSS 5 just came out which is a significant departure from previous
versions. Most of the JBOSS material is from the book JBoss in Action at
http://www.manning.com/jamae/ there are older versions, so make sure you
get the one published January 2009.
• Even with the book a lot still isn't spelled out and requires guess work.
• In particular JBOSS has a bunch of configurations. But our project is in
JBOSS installation directory/server/default/deploy.
• To start JBOSS go into JBOSS installation/bin and run run.sh as ./run.sh -b
0.0.0.0. If you forget the -b 0.0.0.0 flag you will only be able to connect
locally.
How to Package App for JBOSS
• Shoppingcart.ear - Enterprise Archive File
o META-INF
 application.xml - application deployment descriptor. To get JBOSS
to redeploy java beans, need to modify this file (we used touch
application.xml) for this
o Beans.jar
 cs633beans - package for our beans
 .java and .class files for interfaces/implementations of beans and
DBCommunicator class
 redeploy.sh - shell script to touch Shoppingcart.ear/METAINF/application.xml
 classpath.sh - shell script to set classpath to compile EJBs
o Store.war - Web Archive File containing front end JSPs, graphics, static
html, etc.
How to Package App for JBOSS II
• We just created the directories in the deploy directory for each of
the archive files and just edited files directly in those directories.
• You can also package them up into an Enterprise Archive File
and move that into the deployment directory for the appropriate
server configuration.
Unable to compile ejb apps
• When trying to compile applications importing javax.ejb we got an error
saying that the package did not exist. The solution is to add the EJB jar to
the classpath. This is located in jboss installation directory /client/jbossjavaee.jar.
• In previous versions this was called jboss-j2ee.jar as in the link, so it
required an educated guess to determine jboss-javaee was probably the
same thing.
• Refer http://www.velocityreviews.com/forums/t135964-j2se-j2eeclasspath.html
How to set classpath
classpath.sh:
CLASSPATH=.:/local/softwares/jboss/jboss-5.0.1.GA/client/jbossjavaee.jar
export CLASSPATH
Prior to compiling execute in same directory as classpath.sh
. ./classpath.sh
Without the initial "." the variable change will not be reflected in the
current shell session
How to get jboss to redeploy project
touch application.xml where that is the application deployment
descriptor.
We created redeploy.sh:
touch ../META-INF/application.xml
after compiling
. ./classpath.sh
javac cs633beans/*.java
./redeploy.sh
Unable to load bean interface in JSP
Needed to put beans into a package, then after importing the package
we were able to successfully use the Java Bean interface. Just sticking
them into a java bean .jar file wasn't enough, they had to be in their
own package in order to be able to import them into the JSP file.
Unable to find bean implementations in JSP
Instead of using a local interface we switched to a remote interface and
it worked. This was an experiment after trying near everything
else. When declaring the interface you just put @Remote above the
definition in the Interface.
Developing web pages prior to EJBs
• Installed Apache Tomcat on our amazon web services server
o We can stop and restart tomcat as many times as we want
• Created plain java objects with the same code as the java bean
interface (minus the tags) and normal java objects to implement the
bean and return results in the same format of the bean.
• After creating the front end with the normal java objects, move
them to JBOSS and change the line: Interface i = (Interface) new
InterfaceBean() to be InitialContext ctx = new InitialContext();
Interface i = (Interface)
ctx.lookup("Shoppingcart/Interface/remote");
• Finally use i as a normal java object
PL/SQL Issues (various)
How to create an autonumber field in Oracle, needed for
ShoppingCartContents, OrderContents, and CustOrder. The answer is
called sequences.
CREATE SEQUENCE Order_seq
MINVALUE 1
START WITH 1
INCREMENT BY 1
NOCACHE
Usage: Order_seq.nextval in queries
http://www.techonthenet.com/oracle/sequences.php
PL/SQL Issues 2
Executing Multiple statements and declaring SQL variables:
DECLARE
variable1; variable2;
BEGIN
stmt1; stmt2;
END;
http://infolab.stanford.edu/~ullman/fcdb/oracle/or-plsql.html
dual table for executing select statements without a table
eg select Order_Seq.nextval into variable from dual
http://forums.asp.net/t/1158811.aspx
Using Java to post to web page and read
results
You use the URLConnection class to open an input and output
screen. The output screen writes the form parameters and the input
stream reads them.
http://www.java2s.com/Code/Java/NetworkProtocol/Postdatatohtmlform.htm
Lessons Learned
Andrew Corea
Enterprise Java Beans
EJBs are fairly easy to use compared to something like Corba. The
interface is a plain java object with a few annotations as is the
implementation.
To use an EJB it is just a matter of using the naming service to look up
the EJB and cast it to an object of type interface. There are no policy
files to edit like RMI and no compilation prior to normal compilation
which we used with both RMI and CORBA.
While building/using the beans is easier than CORBA/RMI, setting up
the server is significantly more advanced. There are a lot of nuances
(Packaging up the beans/website into java archives, installing and
configuring the server, etc.)
Client/Server Interaction Comparison
How to interact with clients using EJB
• Create InitialContext object
• Lookup object from InitialContext, no stubs/skeletons required.
How to interact with clients using CORBA
• Create ORB
• Lookup Object Reference from CORBA naming service
• Narrow naming context
• Use helper class with narrow naming context to get reference to the
object
How to interact with clients using RMI
• Lookup Naming Registry
• Lookup object from Registry
JSPs
http://www.jsptut.com
• Directives for how to import files
o Important for using beans
• Declarations for how to declare methods in a JSP
o Important for code organization
• Sessions and Form Processing as well
o For keeping/sending information between pages
Value of Unit Testing
• HTMLs that test the database jsp ListCart.jsp directly
• Dummy Objects for front end to be able to test presentation of DB
results prior to finishing beans
• Main Method in DBCommunicator class that tries some of the
operations and prints the xml messages and processed xml onto the
command line
END RESULT: Integration was a non-event. Just swap out object
instantiation of dummy object with naming context lookup for
bean. The procedure calls remain exactly the same. Also since DB
operations and communication links were already tested that all
worked as planned as well....
AWS
Lessons about AWS are in the section in the beginning. Nevertheless
AWS is also a big lessoned learned. So this is a pointer to the AWS
stuff at the beginning.
If you need to scale up for a temporary project AWS is the perfect
vehicle, pay only for what you need when you use it. Otherwise you'd
have to rent hardware, worry about power and cooling, worry about
disaster recovery, and then if it is only a temporary need figure out
what to do with the leftover hardware to recover some of your
investment. AWS is basically a data center that you don't need to
worry about.
Select Implementation Details
add_cart.jsp -- JSP calling bean sample
<%@ page import="cs633beans.*, java.util.*, java.lang.*, javax.naming.InitialContext" %>
<%
InitialContext ctx = new InitialContext();
ShoppingCart sc = (ShoppingCart) ctx.lookup("Shoppingcart/ShoppingCartBean/remote");
String PID = request.getParameter("PID");
String mySession = (String)session.getAttribute("CUSTOMERID");
sc.addItem(mySession, PID);
response.sendRedirect(request.getHeader("Referer"));
%>
Shopping Cart Bean Interface
ShoppingCart.java
package cs633beans;
import java.util.*;
import javax.ejb.Remote;
@Remote
public interface ShoppingCart {
public String addItem(String customerID, String productID) throws Exception;
public String removeItem(String customerID, String productID) throws Exception;
public String updateQuantity(String customerID, String productID, int quantity) throws
Exception;
List<Map<String,String>> showContents(String customerID) throws Exception;
public String checkOut(String customerID) throws Exception;
}
Future Enhancements
• Security
o Turn on SSL for entire website, or just for login and a credit card
page
• User Profile
o User Registration
o User Details (name, addresses, etc.)
o User Order History
• Store Features
o Shipping Price/Sales tax calculation
o Product registration page
o Search engine to search for products
o Link to paypal or something for processing credit cards
Changes for Use in the Real World
No company in their right mind would put the database server across the
internet from the web server.
• It is slow, each operation requires a call across the internet
o Even for small calls the internet has a high latency
o If you were transferring more than a few MB of data there would be an
even larger delay due to transfer time
• It is insecure, anyone can read the communication
o Encryption slows everything down and introduces overhead
• Java Beans have all sorts of facilities for interacting directly with the
database and making it much easier for the developers (Enterprise Beans
with Container Managed Persistence, etc.)
Definitely for use in the real world install the DB on the Amazon Web Services
box. Mostly this was an Academic exercise.
Ideas for future projects with AWS
1. Give each team 2 computers - one to set up/install DB on and
another to set up/install middleware on. Then they can do a 3 tier
system.
2. Make one team the database administrators for the other teams so
everyone connects to that AWS server for a database. Of course
database administrators must install/setup Oracle and provide
instructions on how to connect to Oracle via JDBC.
3. Give each team their own AWSID so that teams can start/stop
instances and more importantly use the Amazon Web Services built in
services like Simple DB, etc.
References I
JBOSS:
"JBoss in Action" by Javid Jamae and Peter Johnson
http://www.manning.com/jamae/
Java:
http://java.sun.com/tutorial
Api docs at http://java.sun.com/j2se
AWS :
http://aws.amazon.com/
http://centos.wikispaces.com
JSP:
www.jsptut.com
References:
http://infolab.stanford.edu/~ullman/fcdb/oracle/or-plsql.html - how to use PL/SQL
http://www.webreference.com/cgi-bin/perl/makerss.pl - for creating RSS
References II
Products links:
http://digitalcameras.bizrate.com/canon-eos-5d-with-24-105mm-lens-pid593642990/compareprices.html
http://www.imaging-resource.com/PRODS/SX110IS/SX110ISA.HTM
http://laptopcom.blogspot.com/2008_08_01_archive.html
http://www.notebooks.com/2009/04/22/hp-pavilion-dv3t-notebook-pricing-specs-and-details/
http://www.headphone.com/guide/by-headphone-type/sealed-type/
http://www.apple.com/ipodnano/
http://www.hometheatermag.com/buyersguides/speakers/
Logo:
http://www.aistudio.net/img/logo/newlogos/8_Ezshop24com_3_small.jpg
Thank you for your time
Questions?
Comments?