Скачать презентацию CSCE 740 Software Engineering Lecture 8 Software as Скачать презентацию CSCE 740 Software Engineering Lecture 8 Software as

2fb4c73a22bd04bbfba8d197471a32d3.ppt

  • Количество слайдов: 51

CSCE 740 Software Engineering Lecture 8 Software as a Service (Saa. S ) Topics CSCE 740 Software Engineering Lecture 8 Software as a Service (Saa. S ) Topics • Saa. S Readings: Saa. S book Ch 2 February 17 2014

Last Time § Chapter 16 Software Reuse New Saa. S § ed. X/169 site: Last Time § Chapter 16 Software Reuse New Saa. S § ed. X/169 site: § Courseware: Lectures for each week; HW Discussion: Blog for each week Wiki: You. Tube videos § Tutorials and Resources; Syllabus: textbook & VM; Progress § § § http: //vimeo. com/saasbook/videos Saa. S Software § Ruby; Rails; Cucumber; Capybara; Rspec; : Next Time: § x – 2– CSCE 740 Spring 2014

CS 169. 1 Lecture Schedule Ed. X – 3– CSCE 740 Spring 2014 CS 169. 1 Lecture Schedule Ed. X – 3– CSCE 740 Spring 2014

HW 2 – Rails – Rotten Potatoes 1. git clone git: //github. com/saasbook/hw 2_rottenpotatoes. HW 2 – Rails – Rotten Potatoes 1. git clone git: //github. com/saasbook/hw 2_rottenpotatoes. git 2. bundle install --without production 3. rake db: migrate 4. rake db: seed 5. rails server 6. Create a free Heroku. com (http: //www. heroku. com) account • Name rottenpotatoes will be taken already 7. heroku run rake db: migrate 8. heroku run rake db: seed – 4– CSCE 740 Spring 2014

Software as a Service Saa. S client-server three-tier architecture Design Patterns Model View Controller Software as a Service Saa. S 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 – 5– Saa. S book – Chapter 2 CSCE 740 Spring 2014

Ruby with Rails uses Active Record pattern for models § because it maps well Ruby with 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 selfcontained operation on one of the application’s resources § Modern Saa. S frameworks such as rails capture developer experience by supporting Saa. S design patterns – 6– Saa. S book – Chapter 2 CSCE 740 Spring 2014

Rails is a web application development framework in Ruby The Rails philosophy includes several 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 – 7– http: //guides. rubyonrails. org/getting_started. html CSCE 740 Spring 2014

2. 1 100, 000 Feet: Client-Server Architecture to Appendix A and get this book’s 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 2. 1. 1 - shows how to deploy and login to your Virtual Machine and try an interaction with the simple educational app Rotten. Potatoes, – 8– Saa. S book – Chapter 2 CSCE 740 Spring 2014

– 9– Saa. S book – Chapter 2 CSCE 740 Spring 2014 – 9– Saa. S book – Chapter 2 CSCE 740 Spring 2014

Design Patterns “design pattern— § a reusable structure, behavior, strategy, or technique § that 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 – Go. F (Gang Of Four) – 10 – Saa. S book – Chapter 2 CSCE 740 Spring 2014

Saa. S Summary § “Saa. S Web apps are examples of the client-server architectural Saa. S Summary § “Saa. S 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” – 11 – Saa. S book – Chapter 2 CSCE 740 Spring 2014

2. 2 50, 000 Feet: Communication— HTTP and URIs § Network protocol – “set 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 – 129. 252. 11. 170 § Domain Name System (DNS) protocol on top of TCP/IP § hostname to IP address mapping § www. cse. sc. edu 129. 252. ? ? ? § local host – 12 – Saa. S book – Chapter 2 CSCE 740 Spring 2014

Port Numbers Port numbers from 1 to 65535 to distinguish servers at the same Port Numbers Port numbers from 1 to 65535 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. . – 13 – Saa. S book – Chapter 2 CSCE 740 Spring 2014

URIs versus URLs A Uniform Resource Identifier (URI) names a resource available on the 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. – 14 – Saa. S book – Chapter 2 CSCE 740 Spring 2014

HTTP cookies associate a particular user’s browser with information held at the server corresponding 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 Saa. S 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. – 15 – Saa. S book – Chapter 2 CSCE 740 Spring 2014

2. 3 10, 000 Feet: Representation— HTML and CSS Screencast 2. 3. 1: HTML 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 – 16 – Saa. S book – Chapter 2 CSCE 740 Spring 2014

The MVC Architecture “Model–View–Controller (MVC) is an architecture that separates the representation of information 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 – 17 – http: //en. wikipedia. org/wiki/Model-view-controller CSCE 740 Spring 2014

The Components of Rails Action Pack n Action Controller - manages the controllers in The Components of Rails Action Pack n Action Controller - manages the controllers in Rails apps n Action Dispatch - handles routing of web requests Action View - manages the view in Rails apps n Action Mailer - a framework for building e-mail services Active Model - interface between the Action Pack gem services and Object Relationship Mapping gems such as Active Record - base for the models in a Rails Apps Active Resource - framework for connection between business objects and web services Active Support Railtiesttp: //guides. rubyonrails. org/getting_started. html h – 18 – CSCE 740 Spring 2014

Representational State Transfer (REST) Roy Fielding’s doctoral thesis, Architectural Styles and the Design of 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: 1. Using resource identifiers such as URLs to represent resources. 2. Transferring representations of the state of that resource between system components” – 19 – http: //guides. rubyonrails. org/getting_started. html CSCE 740 Spring 2014

Creating a New Rails Project # gem install rails $ rails –version $ rails Creating a New Rails Project # gem install rails $ rails –version $ rails new blog $ rails new –h Usage: rails new APP_PATH [options] … $ cd blog – 20 – http: //guides. rubyonrails. org/getting_started. html CSCE 740 Spring 2014

Rails Application Directory File/Folder Purpose app/ Contains the controllers, models, views and assets for 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. 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. – 21 – http: //guides. rubyonrails. org/getting_started. html CSCE 740 Spring 2014

Rails Application Directory (continued) README. rdoc This is a brief instruction manual for your 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. – 22 – http: //guides. rubyonrails. org/getting_started. html CSCE 740 Spring 2014

Rails Application Directory: app This is your application, it contains: assets - images javascripts 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 – • • – 23 – layouts: application. html. haml movies: edit. html. haml index. html. haml new. html. haml show. html. haml CSCE 740 Spring 2014

HAML – a lightweight Markup Language “used to describe the XHTML of any web 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” – 24 – http: //en. wikipedia. org/wiki/Haml CSCE 740 Spring 2014

YAML (rhymes with camel) is a human-readable data serialization format YAML is a recursive 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: 2007 -08 -06 customer: given: Dorothy family: Gale items: - part_no: A 4786 descrip: Water Bucket (Filled) price: 1. 47 quantity: 4 - part_no: E 1628 descrip: High Heeled "Ruby" Slippers size: 8 price: 100. 27 http: //www. yaml. org/start. html quantity: 1 – 25 – http: //en. wikipedia. org/wiki/YAML CSCE 740 Spring 2014

Configuring a Database Environments • Development • Test - automated tests • Production config/database. Configuring a Database Environments • Development • Test - automated tests • Production config/database. yml n n n – 26 – development: adapter: sqlite 3 database: db/development. sqlite 3 pool: 5 timeout: 5000 http: //guides. rubyonrails. org/getting_started. html CSCE 740 Spring 2014

Creating the Database rake db: create // Rake is a general-purpose command-runner rake –T 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 … – 27 – http: //guides. rubyonrails. org/getting_started. html CSCE 740 Spring 2014

Starting up the Web Server $rails server //starts instance of the WEBrick web server Starting up the Web Server $rails server //starts instance of the WEBrick web server Set browser to http: //localhost: 3000 “Welcome Aboard page” – 28 – http: //guides. rubyonrails. org/getting_started. html CSCE 740 Spring 2014

rails generate controller home index rails generate • Usage: rails generate GENERATOR [args] [options] 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 … • • – 29 – CSCE 740 Spring 2014

Setting the Application Home Page Edit in text editor <h 1>Hello, Rails!</h 1> $ Setting the Application Home Page Edit in text editor Hello, Rails! $ rm public/index. html Open the file config/routes. rb n n n 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. – 30 – http: //guides. rubyonrails. org/getting_started. html CSCE 740 Spring 2014

Getting Up and Running Quickly with Scaffolding Creating a Resource $ rails generate scaffold Getting Up and Running Quickly with Scaffolding Creating a Resource $ rails generate scaffold Post name: str title: str content: text File Purpose db/migrate/20100207214_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 … – 31 – http: //guides. rubyonrails. org/getting_started. html CSCE 740 Spring 2014

What’s Next? The Ruby on Rails guides The Ruby on Rails Tutorial The Ruby 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 – 32 – http: //guides. rubyonrails. org/getting_started. html CSCE 740 Spring 2014

Rails Summary – from Saasbook • Rails defines three environments—development, production and test—each with 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 Active. Record: : 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 (2012 -07 -11). Engineering Long. Lasting Software: An Agile Approach Using Saa. S and Cloud – 33 – Computing, Beta Edition CSCE 740 Spring 2014

Active Record Summary • Active Record uses convention over configuration to infer database table 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 (2012 -07 -11). Engineering Long -Lasting Software: An Agile Approach Using Saa. S and Cloud Computing, Beta Edition – 34 – CSCE 740 Spring 2014

Summary: Haml • Haml allows you to intersperse HTML tags with Ruby code for 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. – 35 – CSCE 740 Spring 2014

HAML summary continued • Rails provides various helper methods that take advantage of the 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 (2012 -07 -11). Engineering Long-Lasting Software: An Agile Approach Using Saa. S and Cloud Computing, Beta – 36 – CSCE 740 Spring 2014

Heroku - Cloud Heroku is a cloud platform as a service (Paa. S) supporting Heroku - Cloud Heroku is a cloud platform as a service (Paa. S) supporting several programming languages. Heroku, one of the first cloud platforms, has been in development since June 2007 when it supported Ruby – 37 – http: //en. wikipedia. org/wiki/Heroku CSCE 740 Spring 2014

Heroku Toolbelt What is it? Heroku client - CLI tool for creating and managing 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. Email: [email protected] com 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 – 38 – https: //toolbelt. heroku. com/ CSCE 740 Spring 2014

Heroku Toolbelt continued You're now ready to create your first Heroku app: $ cd Heroku Toolbelt continued You're now ready to create your first Heroku app: $ cd ~/myapp $ heroku create Creating stark-fog-398. . . done, stack is cedar http: //stark-fog-398. herokuapp. com/ | [email protected] com: stark-fog-398. git 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 – 39 – added to your PATH. CSCE 740 Spring 2014

Heroku API https: //api-docs. heroku. com/ – 40 – CSCE 740 Spring 2014 Heroku API https: //api-docs. heroku. com/ – 40 – CSCE 740 Spring 2014

References – Cucumber and Rspec • http: //pragprog. com/book/hwcuc/the-cucumber-book • Code • Download hwcuc-code. References – Cucumber and Rspec • http: //pragprog. com/book/hwcuc/the-cucumber-book • 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. • http: //cukes. info/ • http: //pragprog. com/book/achbd/the-rspec-book • Code • http: //www. slideshare. net – 41 – CSCE 740 Spring 2014

Behavior Driven Design in Cucumber 1. Describe behaviour in plain text 2. Write a Behavior Driven Design in Cucumber 1. Describe behaviour in plain text 2. Write a step definition in Ruby 3. Run and watch it fail 4. Write code to make the step pass 5. Run again and see the step pass 6. Repeat 2 -5 until green like a cuke 7. Repeat 1 -6 until the money runs out – 42 – http: //cukes. info/ CSCE 740 Spring 2014

Cucumber Ex. : 1 Describe Behavior Create feature and Scenarios – 43 – http: Cucumber Ex. : 1 Describe Behavior Create feature and Scenarios – 43 – http: //cukes. info/ CSCE 740 Spring 2014

Cucumber Ex: 2 Write step definition – 44 – http: //cukes. info/ CSCE 740 Cucumber Ex: 2 Write step definition – 44 – http: //cukes. info/ CSCE 740 Spring 2014

Cucumber Ex. : 3 Run/watch it fail Given When Then – 45 – http: Cucumber Ex. : 3 Run/watch it fail Given When Then – 45 – http: //cukes. info/ CSCE 740 Spring 2014

Rails Tutorial for Devise with RSpec and Cucumber by Daniel Kehoe Last updated 1 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 Git. Hub repo for a ready-to-use starter app generate a customized starter app with the Rails Composer tool – 46 – CSCE 740 Spring 2014 http: //railsapps. github. com/tutorial-rails-devise-rspec-cucumber. html

Cucumber Ex. : 4 Write code to pass – 47 – http: //cukes. info/ Cucumber Ex. : 4 Write code to pass – 47 – http: //cukes. info/ CSCE 740 Spring 2014

Cucumber Ex. : 5 Run again – 48 – http: //cukes. info/ CSCE 740 Cucumber Ex. : 5 Run again – 48 – http: //cukes. info/ CSCE 740 Spring 2014

Cucumber Ex. : 6 Repeat 2 -5 green – 49 – http: //cukes. info/ Cucumber Ex. : 6 Repeat 2 -5 green – 49 – http: //cukes. info/ CSCE 740 Spring 2014

HW 3 : Behavior-Driven Design 1. Setup b. git clone git@github. com: Your. Git. HW 3 : Behavior-Driven Design 1. Setup b. git clone [email protected] com: Your. Git. Hub. Account/hw 3_rottenpotatoes. git commit c. git tag hw 3 -part 1 b d. git diff hw 3 -part 1 b git push origin --tags a. e. 2. Create a declarative scenario step for adding movies 3. Happy paths for filtering movies 4. Happy paths for sorting movies by title and by release date 5. HW 3 Submission - features directory only a. – 50 – tar czf features. tar. gz features/ CSCE 740 Spring 2014

– 51 – CSCE 740 Spring 2014 – 51 – CSCE 740 Spring 2014