CS169.1x Lecture 5: SaaS Architecture and Introduction to Rails " Fall 2012"



Similar documents
The Web as a Client-Server System; TCP/IP intro!

Outline. Lecture 18: Ruby on Rails MVC. Introduction to Rails

Ruby On Rails. CSCI 5449 Submitted by: Bhaskar Vaish

Evaluation. Chapter 1: An Overview Of Ruby Rails. Copy. 6) Static Pages Within a Rails Application

Web Development Frameworks

A Model of the Operation of The Model-View- Controller Pattern in a Rails-Based Web Server

Web-Based Hazus-MH. A Conceptual Approach. Mourad Bouhafs, AVP ATKINS Atlanta mourad.bouhafs@atkinsglobal.com

Ruby on Rails is a web application framework written in Ruby, a dynamically typed programming language The amazing productivity claims of Rails is

Cucumber: Finishing the Example. CSCI 5828: Foundations of Software Engineering Lecture 23 04/09/2012

Taxi Service Design Description

What s really under the hood? How I learned to stop worrying and love Magento

An Oracle White Paper June RESTful Web Services for the Oracle Database Cloud - Multitenant Edition

Portals and Hosted Files

DBX. SQL database extension for Splunk. Siegfried Puchbauer

White Paper Converting Lotus Notes Applications to the Cloud Using the CIMtrek converter Product

Deep in the CRUD LEVEL 1

Lecture 2. Internet: who talks with whom?

The Django web development framework for the Python-aware

Web Development. How the Web Works 3/3/2015. Clients / Server

Developers Integration Lab (DIL) System Architecture, Version 1.0

Building Dynamic Websites With the MVC Pattern. ACM UIUC, 2010

Deploying BIG-IP LTM with Microsoft Lync Server 2010 and 2013

Developing ASP.NET MVC 4 Web Applications Course 20486A; 5 Days, Instructor-led

The full setup includes the server itself, the server control panel, Firebird Database Server, and three sample applications with source code.

Web Application Development

Web Development. Owen Sacco. ICS2205/ICS2230 Web Intelligence

Information Systems Analysis and Design CSC John Mylopoulos. Software Architectures Information Systems Analysis and Design CSC340

Internet Engineering: Web Application Architecture. Ali Kamandi Sharif University of Technology Fall 2007

A Framework for Service-Oriented Extensions to Ruby on Rails

Literature Review Service Frameworks and Architectural Design Patterns in Web Development

Web Cloud Architecture

Rails Cookbook. Rob Orsini. O'REILLY 8 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo

EWD: Simplifying Web Application Architecture

ASP.NET MVC. in Action JEFFREY PALERMO JIMMY BOGARD BEN SCHEIRMAN MANNING. (74 w. long.) WITH MVCCONTRIB, N HIBERNATE, AND MORE.

Ruby on Rails. a high-productivity web application framework. blog.curthibbs.us/ Curt Hibbs <curt@hibbs.com>

Server-Side Scripting and Web Development. By Susan L. Miertschin

Why API? Using the REST API in an education environment. JAMF Software, LLC

Introduction to Django Web Framework

Standards, Tools and Web 2.0

A MORE FLEXIBLE MULTI-TENANT SOA FOR SAAS

Rails 4 Quickly. Bala Paranj.

Inside the Digital Commerce Engine. The architecture and deployment of the Elastic Path Digital Commerce Engine

Portals, Portlets & Liferay Platform

The Hadoop Eco System Shanghai Data Science Meetup

Web Frameworks. web development done right. Course of Web Technologies A.A. 2010/2011 Valerio Maggio, PhD Student Prof.

APACHE WEB SERVER. Andri Mirzal, PhD N

Web Applications: Overview and Architecture

Cloud Computing with Windows Azure using your Preferred Technology

Enabling REST Services with SAP PI. Michael Le Peter Ha

Glassfish, JAVA EE, Servlets, JSP, EJB

Continuous Integration

Ruby On Rails. James Reynolds

Brakeman and Jenkins: The Duo Detects Defects in Ruby on Rails Code

ios Cloud Development FOR Neal Goldstein WILEY John Wiley & Sons, Inc.

SwiftScale: Technical Approach Document

Developing ASP.NET MVC 4 Web Applications MOC 20486

Design Approaches of Web Application with Efficient Performance in JAVA

A collaborative platform for knowledge management

Advanced Tornado TWENTYONE Advanced Tornado Accessing MySQL from Python LAB

Onegini Token server / Web API Platform

September 2009 Cloud Storage for Cloud Computing

Course Name: Course in JSP Course Code: P5

Spark Job Server. Evan Chan and Kelvin Chu. Date

Building and Deploying Web Scale Social Networking Applications Using Ruby on Rails and Oracle. Kuassi Mensah Group Product Manager

CONTENT of this CHAPTER

How to test and debug an ASP.NET application

Large-Scale Web Applications

Red Hat Enterprise Portal Server: Architecture and Features

Drupal CMS for marketing sites

Evaluation Checklist Data Warehouse Automation

BeBanjo Infrastructure and Security Overview

S y s t e m A r c h i t e c t u r e

How To Build A Web App

Web Application Development and Frameworks

From Internet Data Centers to Data Centers in the Cloud

Concepts of Database Management Seventh Edition. Chapter 9 Database Management Approaches

OpenText Information Hub (ihub) 3.1 and 3.1.1

Web Development. Owen Sacco. ICS2205/ICS2230 Web Intelligence

Ernesto Ongaro BI Consultant February 19, The 5 Levels of Embedded BI

Introducing DocumentDB

Web application development landscape: technologies and models

McAfee Web Gateway Administration Intel Security Education Services Administration Course Training

Customer Bank Account Management System Technical Specification Document

User Guide FOR TOSHIBA STORAGE PLACE

SSL VPN Technology White Paper

Web Application Architectures

Pete Helgren Ruby On Rails on i

IBM Unica emessage Version 8 Release 6 February 13, User's Guide

Transcription:

CS169.1x Lecture 5: SaaS Architecture and Introduction to Rails " Fall 2012" 1"

Web at 100,000 feet" The web is a client/server architecture" It is fundamentally request/reply oriented" Web browser Internet Web site

3"

Now that we re talking, what do we say? Hypertext Transfer Protocol" an ASCII-based request/reply protocol for transferring information on the Web" HTTP request includes:" request method (GET, POST, etc.)" Uniform Resource Identifier (URI)" HTTP protocol version understood by the client" headers extra info regarding transfer request" HTTP response from server" Protocol version & Status code =>" Response headers" Response body" HTTP status codes: 2xx all is well 3xx resource moved 4xx access problem 5xx server error

Dynamic content generation" In the Elder Days, most web pages were (collections of) plain old files" But most interesting Web 1.0/e-commerce sites actually run a program to generate the page! Originally: templates with embedded code snippets " Eventually, code became tail that wagged the dog and moved out of the Web server"

Sites that are really programs (SaaS)" How do you:" map URI to correct program & function?" pass arguments?" invoke program on server?" handle persistent storage?" handle cookies?" handle errors?" package output back to user?" Frameworks support these common tasks! Filesystem or database persistence your app logic (app) Common Gateway Interface (CGI) presentation (Web server) client (browser)

Developer environment vs. medium-scale deployment" MySQL" file.sqlite3" SQLite adapter" Rails library" rack" Webrick" MySQL adapter" Rails library" MySQL adapter" Rails library" MySQL adapter" Rails library" rack" rack" rack" thin" thin" thin" Page cache" Developer PostgreSQL" Apache w/mod_rails + caching mode" Medium-scale deployment Database" cache" Dynos running apps HTTP servers & static asset caches" Large-scale curated deployment, e.g. Heroku

Match the terms: (a) presentation tier, (b) logic tier, (c) persistence tier (a) Apache web server (b) Rack+Rails (c) Relational database (a) Firefox (b) Apache web server (c) PostgreSQL (a) Microsoft Internet Information Server (b) Rack+Rails (c) Apache web server (a) Firefox (b) Microsoft Internet Information Server (c) MySQL 8"

9"

The MVC Design Pattern" Goal: separate organization of data (model) from UI & presentation (view) by introducing controller! mediates user actions requesting access to data" presents data for rendering by the view" Web apps may seem obviously MVC by design, but other alternatives are possible..." User actions" Directives for rendering data" Controller Read data" Update data" View" Model" Data provided to views through controller"

Each entity has a model, controller, & set of views" Movies Controller Movie" Moviegoers Controller Reviews Controller Moviegoer" Review" 11"

Alternatives to MVC" Page Controller" (Ruby Sinatra)" Front Controller" (J2EE servlet)" models" page A A" page B B" page C C" models" app Template View (PHP)" models" views" views" Rails supports SaaS apps structured as MVC, but other architectures may be better fit for some apps." 12"

Which statement is NOT true about the Model-View-Controller (MVC) architectural pattern: " In SaaS apps on the Web, controller actions and view contents are transmitted using HTTP." All MVC apps have both a client part (e.g. Web browser) and a cloud part (e.g. Rails app on cloud)." Model-View-Controller is just one of several possible ways to structure a SaaS app." Peer-to-peer apps can be structured as Model- View-Controller. 13"

14"

In-Memory vs. In-Storage #<Movie:0x1295580> m.name, m.rating,... #<Movie:0x32ffe416> m.name, m.rating,... objects" marshal/serialize" unmarshal/deserialize" How to represent persisted object in storage" Example: Movie and Reviews"?! Basic operations on object: CRUD (Create, Read, Update, Delete)" ActiveRecord: every model knows how to CRUD itself, using common mechanisms" 15"

Rails Models Store Data in Relational Databases (RDBMS) " Each type of model gets its own database table! All rows in table have identical structure " 1 row in table == one model instance" Each column stores value of an attribute of the model" Each row has unique value for primary key (by convention, in Rails this is an integer and is called id)" id! rating! title! release_date! 2" G" Gone With the Wind" 1939-12-15" 11" PG" Casablanca" 1942-11-26"..."..."..."..." 35" PG" Star Wars" 1977-05-25" Schema: Collection of all tables and their structure"

Alternative: DataMapper" Data Mapper associates separate mapper with each model" Idea: keep mapping independent of particular data store used => works with more types of databases" Used by Google AppEngine" Con: can t exploit RDBMS features to simplify complex queries & relationships" We ll revisit when talking about associations " 17"

Which statement is not true about the Model in Model-View-Controller: " The CRUD actions only apply to models backed by a database that supports ActiveRecord." Part of the Model s job is to convert between inmemory and stored representations of objects." Although Model data is displayed by the View, a Models direct interaction is with Controllers." Although DataMapper doesn t use relational databases, it s a valid way to implement a Model. 18"

Routes" In MVC, each interaction the user can do is handled by a controller action" Ruby method that handles that interaction " A route maps <HTTP method, URI> to controller action" " Route! Action! GET /movies/3 POST /movies PUT /movies/5 DELETE /movies/5 Show info about movie whose ID=3" Create new movie from attached form data" Update movie ID 5 from attached form data" Delete movie whose ID=5" 19"

Brief Intro to Rails Routing Subsystem" dispatch <method,uri> to correct controller action" provides helper methods that generate a <method,uri> pair given a controller action" parses query parameters from both URI and form submission into a convenient hash" Built-in shortcuts to generate all CRUD routes (though most apps will also have other routes)" rake routes! I GET /movies {:action=>"index", :controller=>"movies"} C POST /movies {:action=>"create", :controller=>"movies"} GET /movies/new {:action=>"new", :controller=>"movies"} GET /movies/:id/edit {:action=>"edit", :controller=>"movies"} R GET /movies/:id {:action=>"show", :controller=>"movies"} U PUT /movies/:id {:action=>"update", :controller=>"movies"} D DELETE /movies/:id {:action=>"destroy", :controller=>"movies"} 20"

GET /movies/3/edit HTTP/1.0" Matches route:" GET /movies/:id/edit {:action=>"edit", :controller=>"movies"}" Parse wildcard parameters: params[:id] = "3" Dispatch to edit method in movies_controller.rb To include a URI in generated view that will submit the form to the update controller action with params[:id]==3, call helper: update_movie_path(3) # => PUT /movies/3! rake routes! I GET /movies {:action=>"index", :controller=>"movies"} C POST /movies {:action=>"create", :controller=>"movies"} GET /movies/new {:action=>"new", :controller=>"movies"} GET /movies/:id/edit {:action=>"edit", :controller=>"movies"} R GET /movies/:id {:action=>"show", :controller=>"movies"} U PUT /movies/:id {:action=>"update", :controller=>"movies"} D DELETE /movies/:id {:action=>"destroy", :controller=>"movies"} 21"

REST (Representational State Transfer)" Idea: Self-contained requests specify what resource to operate on and what to do to it" Roy Fielding s PhD thesis, 2000" Wikipedia: a post hoc description of the features that made the Web successful! A service (in the SOA sense) whose operations are like this is a RESTful service" Ideally, RESTful URIs name the operations" Let s see an anti-example:" http://pastebin.com/edf2nzcf

Which statement is NOT true regarding Rails RESTful routes and the resources to which they refer: " A resource may be existing content or a request to modify something." Every route must eventually trigger a controller action. " One common set of RESTful actions is the CRUD actions on models. " The route always contains one or more parameters, such as :id, to identify the resource 23"

Rails as an MVC Framework Model, View, Controller Subclasses of ActiveRecord::Base, an object-relational mapping layer Subclasses of ActionView views/ *.html.haml Rails rendering models/*.rb controllers/ *.rb Rails routing Subclasses of ApplicationController tables Relational Database your app Persistence: mysql or sqlite3 Logic: your code & Rack appserver Presentation: WEBrick, Apache, etc. Client: Firefox

A trip through a Rails app 1. Routes (in routes.rb) map incoming URL s to controller actions and extract any optional parameters Route s wildcard parameters (eg :id), plus any stuff after? in URL, are put into params[] hash accessible in controller actions 2. Controller actions set instance variables, visible to views 1. Subdirs and filenames of views/ match controllers & action names Controller action eventually renders a view config/ routes.rb app/controllers/movies_controller.rb def show id = params[:id] @mv=movie.find(id) end app/views/movies/show.html.haml %li Rating: = @mv.rating GET /movies/:id {:action=>'show',:controller=>'movies'}

Why must every interaction with a SaaS app eventually cause something to be rendered? Because of convention over configuration Because HTTP is a request-reply protocol Because Model-View-Controller implies that every action renders its own View All of the above *