Презентация slides 02SaaSArchitecture

Скачать презентацию  slides 02SaaSArchitecture Скачать презентацию slides 02SaaSArchitecture

slides_02saasarchitecture.ppt

  • Размер: 5 Mегабайта
  • Количество слайдов: 65

Описание презентации Презентация slides 02SaaSArchitecture по слайдам

CS 169 Software. Engineering Saa. SArchitecture Armando. Fox, David. Patterson, and Koushik. Sen Spring 2012 1CS 169 Software. Engineering Saa. SArchitecture Armando. Fox, David. Patterson, and Koushik. Sen Spring

Outlineand§ELLSsections From 100, 000 footviewto 500 footviewof. Saa. S • Clientserverarchitecture, HTTP, URIs, cookies(§ 2. 12.Outlineand§ELLSsections From 100, 000 footviewto 500 footviewof. Saa. S • Clientserverarchitecture, HTTP, URIs, cookies(§ 2. 12. 2) • HTML&CSS, XML&XPath(§ 2. 22. 3) • 3 tiersharednothingarchitecture, horizontalscaling(§ 2. 4) • modelviewcontrollerdesignpattern(§ 2. 5) – Models: Active. Record&CRUD(§ 2. 6) – Routes, controllers, and. REST(§ 2. 7) – Templateviews(§ 2. 8) • Fallacies&pitfalls, perspectives(§ 2. 92. 12) • Patterns, architecture, &perspective(§ 2. 10)

The. Webasa. Client. Server System; TCP/IPintro ELLS§ 2. 1– 2. 2 Armando. Fox 3© 2012 ArmandoThe. Webasa. Client. Server System; TCP/IPintro ELLS§ 2. 1– 2. 2 Armando. Fox 3© 2012 Armando Fox & David Patterson Licensed under Creative Commons Attribution-Non. Commercial-Share. Alike 3. 0 Unported License

Reminder • Thismaterialexpandson andgivesadditional perspectives/demosabout thematerialin ELLS • Weassumeyouwillwatch thescreencaststoo (screencast. saasbook. info) • It doesnotreplaceReminder • Thismaterialexpandson andgivesadditional perspectives/demosabout thematerialin ELLS • Weassumeyouwillwatch thescreencaststoo (screencast. saasbook. info) • It doesnotreplace reading thatmaterial 4 http: //saasbook. info

Webat 100, 000 feet • Thewebisac lient/server architecture • Itisfundamentally request/replyoriented Webbrowser Website Internet Webat 100, 000 feet • Thewebisac lient/server architecture • Itisfundamentally request/replyoriented Webbrowser Website Internet

6

Client. Servervs. Peerto. Peer • Highlevelarchitectureoftheoverallsystem – Soonwe’lltalkaboutarchitecture“inside”boxes • Client&servereach specialized fortheirtasks – Client: askquestionsonbehalfofusers –Client. Servervs. Peerto. Peer • Highlevelarchitectureoftheoverallsystem – Soonwe’lltalkaboutarchitecture“inside”boxes • Client&servereach specialized fortheirtasks – Client: askquestionsonbehalfofusers – Server: waitfor&respondtoquestions, servemanyclients • Design. Patternscapturecommonstructuralsolutionsto recurringproblems – Client. Serverisan architecturalpattern 7 C C S P P P

GET /bears/ Nutsandbolts: TCP/IPprotocols • IP(Internet. Protocol) address identifiesaphysicalnetwork interfacewithfour octets, e. g. 128. 32. 244.GET /bears/ Nutsandbolts: TCP/IPprotocols • IP(Internet. Protocol) address identifiesaphysicalnetwork interfacewithfour octets, e. g. 128. 32. 244. 172 – Specialaddress 127. 0. 0. 1 is“thiscomputer”, named localhost , evenifnotconnectedtothe. Internet! • TCP/IP(Transmission. Control. Protocol/Internet. Protocol) – IP: noguarantee, besteffortservicethatdelivers packets fromone. IP addresstoanother – TCP: make. IPreliablebydetecting“dropped”packets, dataarrivingoutof order, transmissionerrors, slownetworks, etc. , andrespondappropriately – TCP ports allowmultiple. TCPappsonsamecomputer • Vint. Cerf&Bob. Kahn: 2004 Turing. Awardfor Internetarchitecture&protocols, incl. TCP/IP GET /bears/ HTTP/0. 9 200 OK

Webat 100, 000 feet • Thewebisa client/server architecture • Itisfundamentally request/replyoriented • Domain. Name. System(DNS)isanotherkindof serverthatmapsWebat 100, 000 feet • Thewebisa client/server architecture • Itisfundamentally request/replyoriented • Domain. Name. System(DNS)isanotherkindof serverthatmaps names to IPaddresses Webbrowser Website DNSserver

Nowthatwe’retalking, whatdowesay? Hypertext. Transfer. Protocol • an ASCIIbasedrequest/replyprotocol fortransferring informationonthe. Web • HTTPrequest includes: – requestmethodNowthatwe’retalking, whatdowesay? Hypertext. Transfer. Protocol • an ASCIIbasedrequest/replyprotocol fortransferring informationonthe. Web • HTTPrequest includes: – requestmethod ( GET, POST , etc. ) – Uniform. Resource. Identifier(URI) – HTTPprotocolversionunderstoodbytheclient – headers— extrainforegardingtransferrequest • HTTPresponse fromserver – Protocolversion&Statuscode=> – Responseheaders – Responsebody HTTPstatuscodes: 2 xx— alliswell 3 xx— resourcemoved 4 xx— accessproblem 5 xx— servererror

HTTP  TCP  IP TCP  DNS All the above are correct. DNS  IPHTTP > TCP > IP TCP > DNS All the above are correct. DNS > IP ☐ ☐ 11 Assuming “>” means “relies on”, which statement is NOT correct:

Cookies • Observation: HTTPisstateless • Early. Web 1. 0 problem: howtoguideauser “through”aflowofpages? – use. IPaddresstoidentifyreturninguser? ✖Cookies • Observation: HTTPisstateless • Early. Web 1. 0 problem: howtoguideauser “through”aflowofpages? – use. IPaddresstoidentifyreturninguser? ✖ publiccomputers, userssharingsingle. IP – embedperuserjunkinto. URIquerystring? breakscaching • Quicklysupersededby cookies – Watch: screencast. saasbook. info

Usesofcookies •  Mostsitesquicklyrealizedthattheperuser statecouldbeusedforlotsofthings: – customization(“My. Yahoo”) – clicktracking/flowtracking – authentication (loggedinornot) – Whichofthesecouldbeimplementedonthe clientside?Usesofcookies • Mostsitesquicklyrealizedthattheperuser statecouldbeusedforlotsofthings: – customization(“My. Yahoo”) – clicktracking/flowtracking – authentication (loggedinornot) – Whichofthesecouldbeimplementedonthe clientside? Whichones shouldn’t beandwhy? • Agoldenrule: don’ttrusttheclient— cookies mustbetamperevident

Saa. S app; browser HTTP request; browser Saa. S app; HTTP response. Browser; Saa. S appSaa. S app; browser HTTP request; browser Saa. S app; HTTP response. Browser; Saa. S app ☐ ☐ 14 A ____ can create and modify cookies; the ____ is responsible for including the correct cookie with each request

HTML+CSS ELLS § 2. 3 Armando. Fox 15© 2012 Armando Fox & David Patterson Licensed underHTML+CSS ELLS § 2. 3 Armando. Fox 15© 2012 Armando Fox & David Patterson Licensed under Creative Commons Attribution-Non. Commercial-Share. Alike 3. 0 Unported License

16

CS 142 Lecture. Notes: HTMLSlide 17 Introduction This article is a review of the book DietaryCS 142 Lecture. Notes: HTMLSlide 17 Introduction This article is a review of the book Dietary Preferences of Penguins, by Alice Jones and Bill Smith. Jones and Smith’s controversial work makes three hard-to-swallow claims about penguins: First, that penguins actually prefer tropical foods such as bananas and pineapple to their traditional diet of fish Second, that tropical foods give penguins an odor that makes them unattractive to their traditional predators

CS 142 Lecture. Notes: HTMLSlide 18h 1 Introduction /h 1 p  This article is aCS 142 Lecture. Notes: HTMLSlide 18 Introduction

This article is a review of the book Dietary Preferences of Penguins , by Alice Jones and Bill Smith. Jones and Smith’s controversial work makes three hard-to-swallow claims about penguins:

  • First, that penguins actually prefer tropical foods such as bananas and pineapple to their traditional diet of fish
  • Second, that tropical foods give penguins an odor that makes them unattractive to their traditional predators

. . .

CS 142 Lecture. Notes: HTMLSlide 19h 1Introduction/h 1 p This article is a review of theCS 142 Lecture. Notes: HTMLSlide 19Introduction

This article is a review of the book Dietary Preferences of Penguins, by Alice Jones and Bill Smith. Jones and Smith’s controversial work makes three hard-to-swallow claims about penguins:

  • First, . . . Introduction This article is a review of the book Dietary Preferences of Penguins , by Alice Jones and Bill Smith. Jones and Smith’s controversial work makes two hard-to-swallow claims about penguins: ● First, that penguins actually prefer tropical foods such as bananas and pineapple to their traditional diet of fish ● Second, that tropical foods give penguins an odor that makes them unattractive to their traditional predators. . .

HTML~1. 0 • Descendantof. IBM’s. Generalized. Markup Language(1960’s)via. SGML(Standard Generalized. Markup. Language, 1986) • Document=Hierarchicalcollectionof elementsHTML~1. 0 • Descendantof. IBM’s. Generalized. Markup Language(1960’s)via. SGML(Standard Generalized. Markup. Language, 1986) • Document=Hierarchicalcollectionof elements – inline(headings, tables, lists. . . ) – embedded(images, Java. Scriptcode. . . ) – forms—allowusertosubmitsimpleinput(text, radio/checkbuttons, dropdownmenus. . . ) • Eachelementcanhave attributes (manyoptional) andsomeelementsalsohave content – ofparticularinterest: id and class attributes, for styling

Cascading. Style. Sheets • Idea: visualappearance ofpagedescribed inaseparatedocument( stylesheet ) – accessibility – branding/targeting – separatedesigners’&developers’concernsCascading. Style. Sheets • Idea: visualappearance ofpagedescribed inaseparatedocument( stylesheet ) – accessibility – branding/targeting – separatedesigners’&developers’concerns • Currentbestpractice: HTMLmarkupshould contain no visualstylinginformation

Howdoesitwork?  •  link rel=stylesheet href=http: //. . .  / (inside head element)sayswhatstylesheetgoeswiththis HTMLpageHowdoesitwork? • (inside element)sayswhatstylesheetgoeswiththis HTMLpage • HTML id & class attributesimportantin. CSS – id mustbe uniquewithinthispage – same class canbeattachedtomanyelements

Selectors identifyspecifictag(s)  div class=page. Frame id=page. Head  h 1 Welcome, span id=cust. NameArmando/span imgSelectors identifyspecifictag(s)

Welcome, Armando

• tagname: h 1 • classname: . page. Frame • element. ID: #page. Head • tagname&class: div. page. Frame • tagname&id: img#welcome (usuallyredundant) • descendantrelationship: div. cust. Name • Attributes inherit browserdefaultsunlessoverridden bothofthesematchtheouter div above. Don’tdothis!

p . a. a span All of thesespan. a ☐ ☐ 24 Which. CSSselectorwillselect only thep . a. a span All of thesespan. a ☐ ☐ 24 Which. CSSselectorwillselect only the word“bar”forstyling:

foo, bar

3 tiersharednothing architecture&scaling ELLS § 2. 4 Armando. Fox 25© 2012 Armando Fox & David Patterson3 tiersharednothing architecture&scaling ELLS § 2. 4 Armando. Fox 25© 2012 Armando Fox & David Patterson Licensed under Creative Commons Attribution-Non. Commercial-Share. Alike 3. 0 Unported License

26

Dynamiccontentgeneration • Inthe. Elder. Days, mostwebpageswere (collectionsof)plainoldfiles • Butmostinteresting. Web 1. 0/ecommerce sitesactually runaprogram togeneratethe “page”Dynamiccontentgeneration • Inthe. Elder. Days, mostwebpageswere (collectionsof)plainoldfiles • Butmostinteresting. Web 1. 0/ecommerce sitesactually runaprogram togeneratethe “page” • Originally: templateswithembeddedcode “snippets” • Eventually, codebecame“tailthatwagged thedog”andmovedoutofthe. Webserver

Sitesthatarereallyprograms (Saa. S) • Howdoyou: – “ map”URItocorrectprogram &function? – passarguments? – invokeprogramonserver? – handlepersistentstorage? –Sitesthatarereallyprograms (Saa. S) • Howdoyou: – “ map”URItocorrectprogram &function? – passarguments? – invokeprogramonserver? – handlepersistentstorage? – handlecookies? – handleerrors? – packageoutputbacktouser? • Frameworks supportthese commontasks presentation(Web server)yourapp Common. Gateway Interface(CGI)Filesystem ordatabase persistence logic(app) client(browser)

Developerenvironmentvs. mediumscaledeployment Webrick rack. SQLite adapter Rails libraryfile. sqlite 3 Develope r My. SQL thinrack. My.Developerenvironmentvs. mediumscaledeployment Webrick rack. SQLite adapter Rails libraryfile. sqlite 3 Develope r My. SQL thinrack. My. SQL adapter Rails library Apachew/mod_rails +cachingmode. Page cache Medium-scale deployment HTTPservers& staticassetcaches. Postgre. SQL Database cache “ Dynos” running apps Large-scale curated deployment, e. g. Heroku

“ Sharednothing” 30 “ Sharednothing”

Shardingvs. Replication • Partitiondataacross independent“shards”? +Scalesgreat – Badwhenoperationstouch1 table – Exampleuse: userprofile • Replicatealldataeverywhere? +Multitablequeriesfast –Shardingvs. Replication • Partitiondataacross independent“shards”? +Scalesgreat – Badwhenoperationstouch>1 table – Exampleuse: userprofile • Replicatealldataeverywhere? +Multitablequeriesfast – Hardtoscale: writesmust propagatetoallcopies=> temporary inconsistency indata values – Example: Facebookwall posts/“likes” 31 users. AJ users. KR users. SZApp server Allusers. App server

Summary: Web 1. 0 Saa. S • Browser requests webresource(URI)using. HTTP – HTTPisasimplerequestreplyprotocolthatrelieson. TCP/IP – In.Summary: Web 1. 0 Saa. S • Browser requests webresource(URI)using. HTTP – HTTPisasimplerequestreplyprotocolthatrelieson. TCP/IP – In. Saa. S, most. URI’scauseaprogramtoberun, ratherthanastaticfile tobefetched • HTML isusedtoencodecontent, CSS tostyleitvisually • Cookies allowservertotrackclient – Browserautomaticallypassescookietoserveroneachrequest – Servermaychangecookieoneachresponse – Typicalusage: cookieincludesa handle toserversideinformation – That’swhysomesitesdon’tworkifcookiesarecompletelydisabled • Frameworks makealltheseabstractionsconvenientfor programmerstouse, withoutsweatingthedetails • . . . andhelpmap. Saa. Sto 3 tier, sharednothingarchitecture

(a) Firefox (b) Apache web server (c) Postgre. SQL  (a) Microsoft Internet Information Server (b)(a) Firefox (b) Apache web server (c) Postgre. SQL (a) Microsoft Internet Information Server (b) Rack+Rails (c) Apache web server (a) Firefox (b) Microsoft Internet Information Server (c) My. SQL(a) Apache web server (b) Rack+Rails (c) Relational database☐ ☐ 33 Match the terms: (a) presentation tier, (b) logic tier, (c) persistence tier

Model. View. Controller ELLS § 2. 5 Armando. Fox 34© 2012 Armando Fox & David PattersonModel. View. Controller ELLS § 2. 5 Armando. Fox 34© 2012 Armando Fox & David Patterson Licensed under Creative Commons Attribution-Non. Commercial-Share. Alike 3. 0 Unported License

35

The. MVCDesign. Pattern • Goal: separateorganizationofdata(model)from. UI&presentation (view)byintroducing controller – mediatesuseractionsrequestingaccesstodata – presentsdatafor rendering bytheview •The. MVCDesign. Pattern • Goal: separateorganizationofdata(model)from. UI&presentation (view)byintroducing controller – mediatesuseractionsrequestingaccesstodata – presentsdatafor rendering bytheview • Webappsmayseem“obviously”MVCbydesign, butother alternativesarepossible. . . Controller • Useractions • Directivesfor renderingdata • Readdata • Updatedata • Dataprovidedto views throughcontroller Model. View

Eachentityhasamodel, controller, &setofviews 37 Moviegoers Controller Moviegoer Reviews Controller Review. Movies Controller Movie 4 D Eachentityhasamodel, controller, &setofviews 37 Moviegoers Controller Moviegoer Reviews Controller Review. Movies Controller Movie

Alternativesto. MVC 38 Railssupports. Saa. Sappsstructuredas. MVC, but otherarchitecturesmaybebetterfitforsomeapps. Page. Controller (Ruby. Sinatra) page A AAlternativesto. MVC 38 Railssupports. Saa. Sappsstructuredas. MVC, but otherarchitecturesmaybebetterfitforsomeapps. Page. Controller (Ruby. Sinatra) page A A page B page C B Cmodels Front. Controller (J 2 EEservlet) app models views Template. View (PHP) models views

All. MVCappshavebotha“client”part(e. g. Web browser)anda“cloud”part(e. g. Railsapponcloud). Model. View. Controllerisjustoneofseveral possiblewaystostructurea. Sapp. Peer-to-peer apps can beAll. MVCappshavebotha“client”part(e. g. Web browser)anda“cloud”part(e. g. Railsapponcloud). Model. View. Controllerisjustoneofseveral possiblewaystostructurea. Sapp. Peer-to-peer apps can be structured as Model-View-Controller. In. Saa. Sappsonthe. Web, controlleractions andviewcontentsaretransmittedusing. HTTP. ☐ ☐ 39 Whichstatementis NOT true aboutthe. Model. View. Controller (MVC)architecturalpattern:

Models, Databases, and Active. Record ELLS § 2. 6 Armando. Fox 40© 2012 Armando Fox &Models, Databases, and Active. Record ELLS § 2. 6 Armando. Fox 40© 2012 Armando Fox & David Patterson Licensed under Creative Commons Attribution-Non. Commercial-Share. Alike 3. 0 Unported License

41

In. Memoryvs. In. Storage objects • Howtorepresentpersistedobjectinstorage – Example: Movieand. Reviews • Basicoperationsonobject: CRUD(Create, Read, Update,In. Memoryvs. In. Storage objects • Howtorepresentpersistedobjectinstorage – Example: Movieand. Reviews • Basicoperationsonobject: CRUD(Create, Read, Update, Delete) • Active. Record: everymodelknowshowto CRUDitself, usingcommonmechanisms 42# m. name, m. rating, . . . ? marshal/serialize unmarshal/deserialize# m. name, m. rating, . . .

Rails. Models. Store. Datain Relational. Databases(RDBMS) • Eachtypeofmodelgetsitsowndatabase table – Allrowsintablehaveidenticalstructure – 1 rowintable==onemodelinstance – EachcolumnstoresvalueofanRails. Models. Store. Datain Relational. Databases(RDBMS) • Eachtypeofmodelgetsitsowndatabase table – Allrowsintablehaveidenticalstructure – 1 rowintable==onemodelinstance – Eachcolumnstoresvalueofan attribute ofthemodel – Eachrowhas uniquevaluefor primarykey (byconvention, in Railsthisisanintegerandiscalled id ) • Schema: Collectionofalltablesandtheirstructureid rating title release_date 2 G Gone. Withthe. Wind 19391215 11 PG Casablanca 19421126. . . 35 PG Star. Wars

Alternative: Data. Mapper • Data. Mapperassociatesseparate mapper witheach model – Idea: keepmapping independent ofparticulardatastore used=workswithmoretypesofdatabases –Alternative: Data. Mapper • Data. Mapperassociatesseparate mapper witheach model – Idea: keepmapping independent ofparticulardatastore used=>workswithmoretypesofdatabases – Usedby. Google. App. Engine – Con: can’texploit RDBMSfeaturesto simplifycomplex queries&relationships • We’llrevisitwhen talkingabout associations

Partofthe. Model’sjobistoconvertbetween inmemoryandstoredrepresentationsof objects. Although. Modeldataisdisplayedbythe. View, a Models’directinteractioniswith. Controllers. Although Data. Mapper doesn’t use relationalPartofthe. Model’sjobistoconvertbetween inmemoryandstoredrepresentationsof objects. Although. Modeldataisdisplayedbythe. View, a Models’directinteractioniswith. Controllers. Although Data. Mapper doesn’t use relational databases, it’s a valid way to implement a Model. The. CRUDactionsonlyapplytomodelsbackedby adatabasethatsupports. Active. Record. ☐ ☐ 45 Whichstatementis not trueaboutthe Modelin. Model. View. Controller:

Controllers, Routes, and RESTfulness ELLS § 2. 7 Armando. Fox 46© 2012 Armando Fox & DavidControllers, Routes, and RESTfulness ELLS § 2. 7 Armando. Fox 46© 2012 Armando Fox & David Patterson Licensed under Creative Commons Attribution-Non. Commercial-Share. Alike 3. 0 Unported License

47

Routes • In. MVC, eachinteractiontheusercandois handledbya controlleraction – Rubymethodthathandlesthatinteraction • A route maps HTTP method, URIRoutes • In. MVC, eachinteractiontheusercandois handledbya controlleraction – Rubymethodthathandlesthatinteraction • A route maps to controlleraction • 48 Route Action GET /movies/3 Showinfoaboutmoviewhose. ID=3 POST /movies Createnewmoviefromattachedformdata PUT /movies/5 Updatemovie. ID 5 fromattachedformdata DELETE /movies/5 Deletemoviewhose. ID=

Brief. Introto. Rails’Routing Subsystem • dispatchmethod, URItocorrectcontrolleraction • provides helpermethods thatgeneratea method, URIpairgivenacontrolleraction • parsesquery parametersBrief. Introto. Rails’Routing Subsystem • dispatchtocorrectcontrolleraction • provides helpermethods thatgeneratea pairgivenacontrolleraction • parsesquery parameters fromboth. URIandform submissionintoaconvenienthash • Builtinshortcutstogenerateall. CRUDroutes (thoughmostappswillalsohaveotherroutes) 49 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»} rakeroutes

GET /movies/3/edit HTTP/1. 0 • Matchesroute: GET /movies/: id/edit {: action=edit, : controller=movies} • Parsewildcardparameters: params[:GET /movies/3/edit HTTP/1. 0 • Matchesroute: GET /movies/: id/edit {: action=>»edit», : controller=>»movies»} • Parsewildcardparameters: params[: id] = «3» • Dispatchto edit methodin movies_controller. rb • Toincludea. URIingeneratedviewthatwillsubmittheform totheupdatecontrolleractionwith params[: id]==3, call helper: update_movie_path(3) # => PUT /movies/3 50 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»} rakeroutes

REST(Representational. State Transfer) • Idea: Selfcontained requestsspecifywhat resource tooperateonandwhattodotoit – Roy. Fielding’s. Ph. Dthesis, 2000 –REST(Representational. State Transfer) • Idea: Selfcontained requestsspecifywhat resource tooperateonandwhattodotoit – Roy. Fielding’s. Ph. Dthesis, 2000 – Wikipedia: “a posthocdescriptionofthe featuresthatmadethe. Websuccessful” • Aservice(inthe. SOAsense)whose operationsarelikethisisa. RESTfulservice • Ideally, RESTful. URIsnametheoperations • Let’sseean antiexample: http: //pastebin. com/ed. F 2 Nz.

Everyroutemusteventuallytriggeracontroller action. Onecommonsetof. RESTfulactionsisthe CRUDactionsonmodels. Theroutealwayscontainsoneormore parameters, suchas : id, toidentifytheresource A resource maybeexistingcontentorarequest tomodifysomething. ☐Everyroutemusteventuallytriggeracontroller action. Onecommonsetof. RESTfulactionsisthe CRUDactionsonmodels. Theroutealwayscontainsoneormore parameters, suchas : id, toidentifytheresource A resource maybeexistingcontentorarequest tomodifysomething. ☐ ☐ 52 Whichstatementis NOT trueregarding Rails. RESTfulroutesandthe resourcestowhichtheyrefer:

Template. Viewsand. Haml ELLS § 2. 8 Armando. Fox 53© 2012 Armando Fox & David PattersonTemplate. Viewsand. Haml ELLS § 2. 8 Armando. Fox 53© 2012 Armando Fox & David Patterson Licensed under Creative Commons Attribution-Non. Commercial-Share. Alike 3. 0 Unported License

54

Template. Viewpattern • Viewconsistsofmarkupwithselected interpolation tohappenatruntime – Usually, valuesofvariablesorresultof evaluatingshortbitsofcode • In. Elder. Days, this wasTemplate. Viewpattern • Viewconsistsofmarkupwithselected interpolation tohappenatruntime – Usually, valuesofvariablesorresultof evaluatingshortbitsofcode • In. Elder. Days, this was theapp(e. g. PHP) • Alternative: Transform. View 55 Haml Closure Renderer (Action. Vi ew) HTMLRJS (remote Java. Sc ript) erb Closure Movie Renderer (Action. Vi ew) XML JSO N

Hamlis. HTMLonadiet h 1. pagename All Movies table #movies  thead tr  th Movie TitleHamlis. HTMLonadiet %h 1. pagename All Movies %table #movies %thead %tr %th Movie Title %th Release Date %th More Info %tbody — @movies. each do |movie| %tr %td = movie. title %td= movie. release_date %td= link_to «More on #{movie. title}», | movie_path(movie) | = link_to ‘Add new movie’, new_movie_path

Don’tputcodeinyourviews • Syntactically, youcanputanycodeinview • But. MVCadvocatesthinviews&controllers – Hamlmakesdeliberatelyawkwardtoputinlots ofcode • Helpers (methodsthat“prettify”objectsfor includinginviews)havetheirownplacein Railsapp •Don’tputcodeinyourviews • Syntactically, youcanputanycodeinview • But. MVCadvocatesthinviews&controllers – Hamlmakesdeliberatelyawkwardtoputinlots ofcode • Helpers (methodsthat“prettify”objectsfor includinginviews)havetheirownplacein Railsapp • Alternativeto. Haml: html. erb(Embedded Ruby)templates, lookmorelike. PHP

Itwillworkwhendevelopingagainsta “toy”database, butnotinproduction Itwon’twork, because. Viewscan’t communicatedirectlywith. Models Behaviorvariesdependingontheapp. Itwillwork, butit’sbadformandviolates the. MVCguidelines☐ ☐ 58 WhathappensifyouembedcodeinItwillworkwhendevelopingagainsta “toy”database, butnotinproduction Itwon’twork, because. Viewscan’t communicatedirectlywith. Models Behaviorvariesdependingontheapp. Itwillwork, butit’sbadformandviolates the. MVCguidelines☐ ☐ 58 Whathappensifyouembedcodein your. Railsviewsthatdirectlyaccesses themodel?

Summary&Reflections: Saa. SArchitecture Armando. Fox 59© 2012 Armando Fox & David Patterson Licensed under Creative CommonsSummary&Reflections: Saa. SArchitecture Armando. Fox 59© 2012 Armando Fox & David Patterson Licensed under Creative Commons Attribution-Non. Commercial-Share. Alike 3. 0 Unported License

Thebigpicture(technologies) Controller View Model • URI’s, HTTP, TCP/IP stack • REST&RESTfulroutes • Databases&migrations • CRUD •Thebigpicture(technologies) Controller View Model • URI’s, HTTP, TCP/IP stack • REST&RESTfulroutes • Databases&migrations • CRUD • HTML&CSS • XML&XPath

c. 2008: “Railsdoesn’tscale” • Scalabilityisan architectural concern—notconfined tolanguageorframework • Thestatelesstiersof 3 tierarch doscale – Withcloudcomputing, justworryaboutconstantsc. 2008: “Railsdoesn’tscale” • Scalabilityisan architectural concern—notconfined tolanguageorframework • Thestatelesstiersof 3 tierarch doscale – Withcloudcomputing, justworryaboutconstants • Traditional relational databases donotscale • Varioussolutionscombiningrelationaland nonrelationalstorage(“No. SQL”) scalemuchbetter – Data. Mapperworkswellwithsomeofthem • Intelligentuseof caching (laterincourse)can greatlyimprovetheconstantfactors

Frameworks, Apps, Design patterns • Manydesignpatternssofar, moretocome • In 1995, itwasthewildwest: biggest. Web siteswereminicomputers, not 3Frameworks, Apps, Design patterns • Manydesignpatternssofar, moretocome • In 1995, itwasthewildwest: biggest. Web siteswereminicomputers, not 3 tier/cloud • Bestpractices(patterns)“extracted”from experienceandcapturedinframeworks • But. API’stranscendedit: 1969 protocols+ 1960 smarkuplanguage+1990 browser+ 1992 Webserverworksin

Architectureisabout Alternatives Patternwe’reusing Alternatives Client. Server Peerto. Peer Sharednothing(cloudcomputing) Symmetricmultiprocessor, shared globaladdressspace Model. View. Controller Pagecontroller,Architectureisabout Alternatives Patternwe’reusing Alternatives Client. Server Peerto. Peer Sharednothing(cloudcomputing) Symmetricmultiprocessor, shared globaladdressspace Model. View. Controller Pagecontroller, Frontcontroller, Templateview Active. Record Data. Mapper RESTful. URIs(allstateaffecting requestisexplicit) Same. URIdoesdifferentthings dependingoninternalstate 63 As you work on other Saa. S apps beyond this course, you should find yourself considering different architectural choices and questioning the choices being made.

Summary: Architecture&Rails • Modelviewcontrollerisawellknown architecturalpattern forstructuringapps • Railscodifies. Saa. Sappstructureas. MVC • Views are. Hamlw/embedded. Rubycode,Summary: Architecture&Rails • Modelviewcontrollerisawellknown architecturalpattern forstructuringapps • Railscodifies. Saa. Sappstructureas. MVC • Views are. Hamlw/embedded. Rubycode, transformedto. HTMLwhensenttobrowser • Models arestoredintablesofarelational database, accessedusing. Active. Record • Controllers tieviewsandmodelstogethervia routes andcodeincontrollermethods

Relationaldatabasesscalebetterthan “No. SQL”databases Theprogramminglanguageused(Ruby, Java, etc. )isn’tamainfactorinscalability Scalabilitycanbeimpededby any partof theappthatbecomesabottleneck. Sharednothingclustersscalebetterthan systemsbuiltfrommainframes☐ ☐ 65 Otherfactorsbeingequal,Relationaldatabasesscalebetterthan “No. SQL”databases Theprogramminglanguageused(Ruby, Java, etc. )isn’tamainfactorinscalability Scalabilitycanbeimpededby any partof theappthatbecomesabottleneck. Sharednothingclustersscalebetterthan systemsbuiltfrommainframes☐ ☐ 65 Otherfactorsbeingequal, which statementis NOT trueregarding. Saa. S scalability?




  • Мы удаляем страницу по первому запросу с достаточным набором данных, указывающих на ваше авторство. Мы также можем оставить страницу, явно указав ваше авторство (страницы полезны всем пользователям рунета и не несут цели нарушения авторских прав). Если такой вариант возможен, пожалуйста, укажите об этом.