Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 8 Software as a Service (SaaS )

Similar presentations


Presentation on theme: "Lecture 8 Software as a Service (SaaS )"— Presentation transcript:

1 Lecture 8 Software as a Service (SaaS )
CSCE 740 Software Engineering Lecture 8 Software as a Service (SaaS ) Topics SaaS Readings: SaaS book Ch 2 February

2 Ruby; Rails; Cucumber; Capybara; Rspec; : Next Time: x
Last Time Chapter 16 Software Reuse New SaaS edX/169 site: Courseware: Lectures for each week; HW Discussion: Blog for each week Wiki: YouTube videos Tutorials and Resources; Syllabus: textbook & VM; Progress SaaS Software Ruby; Rails; Cucumber; Capybara; Rspec; : Next Time: x

3 CS 169.1 Lecture Schedule EdX

4 HW 2 – Rails – Rotten Potatoes
git clone git://github.com/saasbook/hw2_rottenpotatoes.git bundle install --without production rake db:migrate rake db:seed rails server Create a free Heroku.com ( account Name rottenpotatoes will be taken already heroku run rake db:migrate heroku run rake db:seed

5 Software as a Service SaaS
client-server three-tier architecture Design Patterns Model View Controller Model deals with app’s resources:e.g. users, movies,… Controllers map broweser actions to application code SaaS book – Chapter 2

6 Ruby with Rails Rails uses Active Record pattern for models
because it maps well to relational databases For views Rails uses the Template View pattern For Controllers Rails follows the Represntational State transfer (REST) principle each controller action describes a single self-contained operation on one of the application’s resources Modern SaaS frameworks such as rails capture developer experience by supporting SaaS design patterns SaaS book – Chapter 2

7 Rails Rails is a web application development framework in Ruby The Rails philosophy includes several guiding principles: DRY – “Don’t Repeat Yourself” – suggests that writing the same code over and over again is a bad thing. Convention Over Configuration – means that Rails makes assumptions about what you want to do and how you’re going to do it, rather than requiring you to specify every little thing through endless configuration files. REST (Representational State Transfer) is the best pattern for web applications

8 2.1 100,000 Feet: Client-Server Architecture
to Appendix A and get this book’s “bookware” running on your own computer or in the cloud. Screencast shows how to deploy and login to your Virtual Machine and try an interaction with the simple educational app RottenPotatoes, SaaS book – Chapter 2

9 SaaS book – Chapter 2

10 Design Patterns “design pattern—
a reusable structure, behavior, strategy, or technique that captures a proven solution to a collection of similar problems by separating the things that change from those that stay the same” Examples: client-server model-view-controller Design Patterns book – GoF (Gang Of Four) SaaS book – Chapter 2

11 SaaS Summary “SaaS Web apps are examples of the client-server architectural pattern, client sending requests to the server on the user’s behalf, and the server software is specialized for handling large volumes of such requests. Because Web apps use open standards that anyone can implement royalty-free, the Web browser has become the “universal client.” An alternative to client-server is peer-to-peer, in which all entities act as both clients and servers. While arguably more flexible, this architecture makes it difficult to specialize the software to do either job really well” SaaS book – Chapter 2

12 2.2 50,000 Feet: Communication—HTTP and URIs
Network protocol – “set of communication rules on which agents participating in a network agree” HTTP – TCP/IP – IP address – Domain Name System (DNS) protocol on top of TCP/IP hostname to IP address mapping  ???.??? local host SaaS book – Chapter 2

13 Port Numbers Port numbers from 1 to to distinguish servers at the same IP address. 80 webserver 22 ssh 443 https The IANA. The Internet Assigned Numbers Authority assigns official default port numbers for various protocols and manages the top-level or “root” zone of DNS. . SaaS book – Chapter 2

14 URIs versus URLs A Uniform Resource Identifier (URI) names a resource available on the Internet. The interpretation of the resource name varies from application to application. SaaS book – Chapter 2

15 HTTP cookies HTTP cookies associate a particular user’s browser with information held at the server corresponding to that user’s session it is the browser’s responsibility, not HTTP’s or the SaaS app’s, to make sure the right cookies are included with each HTTP request. Stateless protocols therefore simplify server design at the expense of application design, but happily, successful frameworks such as Rails shield you from much of this complexity. SaaS book – Chapter 2

16 2.3 10,000 Feet: Representation—HTML and CSS
Screencast 2.3.1: HTML Introduction Screencast 2.3.2: Inspecting the ID and Class attributes CSS uses selector notations Screencast 2.3.3: Introduction to CSS SaaS book – Chapter 2

17 The MVC Architecture “Model–View–Controller (MVC) is an architecture that separates the representation of information from the user's interaction with it” Models – represent the data Views – the User Interface Controllers – the “glue” between models and views

18 The Components of Rails
Action Pack Action Controller - manages the controllers in Rails apps Action Dispatch - handles routing of web requests Action View - manages the view in Rails apps Action Mailer - a framework for building services Active Model - interface between the Action Pack gem services and Object Relationship Mapping gems such as Active Record Active Record - base for the models in a Rails Apps Active Resource - framework for connection between business objects and web services Active Support Railties

19 Representational State Transfer (REST)
Roy Fielding’s doctoral thesis, Architectural Styles and the Design of Network-based Software Architectures “REST in terms of Rails boils down to two main principles: Using resource identifiers such as URLs to represent resources. Transferring representations of the state of that resource between system components”

20 Creating a New Rails Project
# gem install rails $ rails –version $ rails new blog $ rails new –h Usage: rails new APP_PATH [options] … $ cd blog

21 Rails Application Directory
File/Folder Purpose app/ Contains the controllers, models, views and assets for your appl config/ Configure your application’s runtime rules, routes, database, and config.ru Rack configuration for Rack based servers used to start the appl db/ Contains your current database schema, and db migrations. doc/ In-depth documentation for your application. Gemfile Gemfile.lock These files allow you to specify what gem dependencies are needed for your Rails application. lib/ Extended modules for your application. log/ Application log files. public/ Contains the static files and compiled assets.

22 Rails Application Directory (continued)
README.rdoc This is a brief instruction manual for your application. You should edit this file to tell others what your application does, how to set it up, and so on. script/ Contains the rails script that starts your app and can contain other scripts you use to deploy or run your application. test/ Unit tests, fixtures, and other test apparatus. These are covered in Testing Rails Applications tmp/ Temporary files vendor/ A place for all third-party code. In a typical Rails application, this includes Ruby Gems, the Rails source code (if you optionally install it into your project) and plugins containing additional prepackaged functionality. Rakefile This file locates and loads tasks that can be run from the command line. The task definitions are defined throughout the components of Rails. Rather than changing Rakefile, you should add your own tasks by adding files to the lib/tasks directory of your application.

23 Rails Application Directory: app
This is your application, it contains: assets - images javascripts stylesheets controllers - application_controller.rb movies_controller.rb helpers application_helper.rb movies_helper.rb mailers models - movie.rb Views – layouts: application.html.haml movies: edit.html.haml index.html.haml new.html.haml show.html.haml

24 HAML – a lightweight Markup Language
“used to describe the XHTML of any web document without the use of traditional inline coding” “Haml functions as a replacement for inline page templating systems such as PHP, RHTML, and ASP”

25 YAML YAML (rhymes with camel) is a human-readable data serialization format YAML is a recursive acronym for "YAML Ain't Markup Language” emphacizing data-orientation over document mark-up --- receipt: Oz-Ware Purchase Invoice date: customer: given: Dorothy family: Gale items: - part_no: A4786 descrip: Water Bucket (Filled) price: 1.47 quantity: 4 - part_no: E1628 descrip: High Heeled "Ruby" Slippers size: 8 price: quantity: 1

26 Configuring a Database
Environments Development Test - automated tests Production config/database.yml development:   adapter: sqlite3   database: db/development.sqlite3   pool: 5   timeout: 5000

27 Creating the Database rake db:create // Rake is a general-purpose command-runner rake –T rake about # List versions of all Rails frameworks and the env... rake assets:clean # Remove compiled assets rake assets:precompile # Compile all the assets named in config.assets.pre... rake cucumber # cucumber rake task not available (cucumber not in... rake db:create # Create the database from config/database.yml for ... rake db:drop # Drops the database for the current Rails.env (use... rake db:fixtures:load # Load fixtures into the current environment's data... rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE... rake db:migrate:status # Display status of migrations

28 Starting up the Web Server
$rails server //starts instance of the WEBrick web server Set browser to “Welcome Aboard page”

29 rails generate rails generate controller home index rails generate
Usage: rails generate GENERATOR [args] [options] General options: -h, [--help] # Print generator's options and usage -p, [--pretend] # Run but do not make any changes -f, [--force] # Overwrite files that already exist

30 Setting the Application Home Page
Edit in text editor <h1>Hello, Rails!</h1> $ rm public/index.html Open the file config/routes.rb Blog::Application.routes.draw do   #...   # You can have the root of your site routed with "root"   # just remember to delete public/index.html.   root :to => "home#index" The root :to => "home#index" tells Rails to map the root action to the home controller’s index action.

31 Getting Up and Running Quickly with Scaffolding
Creating a Resource $ rails generate scaffold Post name:str title:str content:text File Purpose db/migrate/ _create_posts.rb Migration to create the posts table in db app/models/post.rb The Post model test/unit/post_test.rb Unit testing harness for the posts model test/fixtures/posts.yml Sample posts for use in testing config/routes.rb Edited to include routing info for posts app/controllers/posts_controller.rb The Posts controller app/views/posts/index.html.erb A view to display an index of all posts app/views/posts/edit.html.erb A view to edit an existing post app/views/posts/show.html.erb A view to display a single post

32 What’s Next? The Ruby on Rails guides The Ruby on Rails Tutorial The Ruby on Rails mailing list The #rubyonrails channel on irc.freenode.net

33 Rails Summary – from Saasbook
Rails defines three environments—development, production and test—each with its own copy of the database. A migration is a script describing a specific set of changes to the database. As apps evolve and add features, migrations are added Changing a database using a migration takes three steps: create the migration, apply the migration to development database, and after testing apply the migration to production database. The rails generate migration generator fills in the boilerplate for a new migration, and the ActiveRecord::Migration class contains helpful methods for defining it. rake db:migrate applies only those migrations not already applied to the development database. The method for applying migrations to a production database depends on the deployment environment. Patterson, David; Fox, Armando ( ). Engineering Long-Lasting Software: An Agile Approach Using SaaS and Cloud Computing, Beta Edition

34 Active Record Summary Active Record uses convention over configuration to infer database table names from the names of model classes, and to infer the names and types of the columns (attributes) associated with a given kind of model. Basic Active Record support focuses on the CRUD actions: create, read, update, delete. Model instances can be Created either by calling new followed by save or by calling create, which combines the two. Every model instance saved in the database receives an ID number unique within its table called the primary key, … Patterson, David; Fox, Armando ( ). Engineering Long-Lasting Software: An Agile Approach Using SaaS and Cloud Computing, Beta Edition

35 Summary: Haml Haml allows you to intersperse HTML tags with Ruby code for your views. The result of evaluating Ruby code can either be discarded or interpolated into the HTML page. For conciseness, Haml relies on indentation to reveal HTML element nesting. Convention over configuration is used to determine the file names for controllers and views corresponding to a given model. If the RESTful route helpers are used, as in resources :movies, convention over configuration also maps RESTful action names to controller action (method) names.

36 HAML summary continued
Rails provides various helper methods that take advantage of the RESTful route URIs, including link_to for generating HTML links whose URIs refer to RESTful Patterson, David; Fox, Armando ( ). Engineering Long-Lasting Software: An Agile Approach Using SaaS and Cloud Computing, Beta

37 Heroku - Cloud Heroku is a cloud platform as a service (PaaS) supporting several programming languages. Heroku, one of the first cloud platforms, has been in development since June 2007 when it supported Ruby

38 https://toolbelt.heroku.com/
Heroku Toolbelt What is it? Heroku client - CLI tool for creating and managing Heroku apps Foreman - an easy option for running your apps locally Git - revision control and pushing to Heroku Runs on your machine $ heroku login Enter your Heroku credentials. Password: Could not find an existing public key. Would you like to generate one? [Yn] Generating new SSH public key. Uploading ssh public key /Users/adam/.ssh/id_rsa.pub

39 Heroku Toolbelt continued
You're now ready to create your first Heroku app: $ cd ~/myapp $ heroku create Creating stark-fog done, stack is cedar | Git remote heroku added Technical details The install script will add our repository and key to your apt sources and then have apt install the heroku and foreman packages from it. The heroku command line client will be installed into /usr/local/heroku and /usr/local/heroku/bin will be added to your PATH.

40 Heroku API

41 References – Cucumber and Rspec
Code Download hwcuc-code.tgz Copyrights apply to this source code. You may use the source code in your own projects, however the source code may not be used to create training material, courses, books, articles, and the like. We make no guarantees that this source code is fit for any purpose.

42 Behavior Driven Design in Cucumber
Describe behaviour in plain text Write a step definition in Ruby Run and watch it fail Write code to make the step pass Run again and see the step pass Repeat 2-5 until green like a cuke Repeat 1-6 until the money runs out

43 Cucumber Ex.: 1 Describe Behavior
Create feature and Scenarios

44 Cucumber Ex: 2 Write step definition

45 Cucumber Ex.: 3 Run/watch it fail
Given When Then

46 Rails Tutorial for Devise with RSpec and Cucumber
by Daniel Kehoe Last updated 1 September 2012 Ruby on Rails tutorial showing how to create a Rails 3.2 application using Devise with RSpec and Cucumber. Devise gives you ready-made authentication and user management. RSpec is a popular alternative to the Test::Unit testing framework. Cucumber is used for Behaviour Driven Development. Here’s what you can do: learn as-you-go by following the steps in this tutorial to build a starter app clone the example code from the GitHub repo for a ready-to-use starter app generate a customized starter app with the Rails Composer tool

47 Cucumber Ex.: 4 Write code to pass

48 Cucumber Ex.: 5 Run again

49 Cucumber Ex.: 6 Repeat 2-5 green

50 HW 3 : Behavior-Driven Design
Setup git clone git commit git tag hw3-part1b git diff hw3-part1b git push origin --tags Create a declarative scenario step for adding movies Happy paths for filtering movies Happy paths for sorting movies by title and by release date HW 3 Submission - features directory only tar czf features.tar.gz features/


Download ppt "Lecture 8 Software as a Service (SaaS )"

Similar presentations


Ads by Google