微軟實戰課程日:玩轉雲端 技術與架構
DESCRIPTION
TRANSCRIPT
Microsoft Inconfidential
2013/5/4 10:00-16:00
張榮發基金會國際會議中心 10Fs
微軟實戰課程日獨立專家,實用解答
Microsoft Inconfidential
小朱Windows Azure MVPMCSD: Web Applications
玩轉雲端:技術與架構Flying on Cloud: Design and Architect your
Cloud Applications on Windows Azure Platform
Microsoft Inconfidential
本課程的內容全都是非機密。您可以盡情的在網誌,論壇,網站與社群媒體中分享本課程的內容。
您可以盡情的在課程進行間拍照或是錄影。
Microsoft Confidential
Microsoft Inconfidential
• MVP awarded since 2004 (SQL Server, ASP.NET, Software Architecture, Azure)
• 台灣 Windows Azure Platform 種子講師。• 微軟 MSDN 資深講師與文章作譯者。• 奇豐資訊技術研發經理暨顧問。• 台灣首批 MCSD: Web Application 認證專家。• 著有 3+2 本書。• 國立中山大學資訊管理系碩士在職專班修業中。
小朱 ( 朱明中 )About me
Microsoft Inconfidential
• Windows Azure 平台技術概覽• 服務導向架構 (Service Oriented Architecture)
• 設計與架構雲端服務• 服務掛載: Web API 與自我服務 (Self-hosting Service)
• Playing: 具社群單一簽入能力的 Web API Service
Flying on the Cloud: Design and Architect for Cloud AppsAgenda
Microsoft Inconfidential
Quick view of Windows Azure Platform Technologies
Windows Azure Platform
平台技術概觀
雲端的演進給 IT 帶來的挑戰
有哪些安全與保證?
我如何整合我現有的 IT投資?
如何部署我的異質且複雜的 IT 建設?
整合性 異質性 安全性
On-premises and Cloud
Broad and flexible
Secure and reliable為企業的需要所設計
delivers.
本地端 AND 雲端 可信賴開放,寬度
與彈性
當地貨幣
全球資料中心
全球 CDN
全球支援
Microsoft Global Foundation Services 24 x 7 x 365 支援超過 10 億 客戶, ,2,000 萬 企業, 76 個市場 worldwide
整合在基礎建設,安全性,產品開發與全球營運的產業經驗總計 280 年
₩ ¥
€ руб
$
$£
$
Rp
TL
chf
krkr
$R$
$
當地支援團隊
data
servicestableHDInsight
blob storage
SQL database
app
services
media
hpcintegratio
n analytics
caching identityservice
bus
web sitesmobile
services
cloud services
infrastructure
servicescdn
virtual machines
virtual network vpn
traffic manager
Apps
virtual network
tablecloud services
caching identitydata
servicestableHDInsight
blob storage
SQL database
app
services
media
hpcintegratio
n analytics
caching identityservice
bus
web sitesmobile
services
cloud services
infrastructure
servicescdn
virtual machines
virtual network vpn
traffic manager
virtual network
data
servicestableHDInsight
blob storage
SQL database
app
services
media
hpcintegratio
n analytics
caching identityservice
bus
web sitesmobile
services
cloud services
infrastructure
servicescdn
virtual machines
virtual network vpn
traffic manager
Azure 資料中心,您的資料中心。
vpn
virtual network
virtual machine
s
vpn
Microsoft Inconfidential
Service Oriented Architecture in Cloud
服務導向架構
Microsoft Inconfidential
• SOA 是一種架構模型,由網站服務技術等標準化元件組成,目的是建構一個具彈性、可重複使用的整合性介面。
– 分散式架構 (distributed) 。– 關係鬆散的界面 (loosely coupled) 。– 依據開放的標準 (Open standard) 。– 以流程角度出發 (process centric) 。
• 雲端是實現 SOA 應用程式的最佳載具。– 運算能力。– 儲存能力。– 資料交換能力。
服務導向架構
Microsoft Inconfidential
服務導向架構的組成
Microsoft Inconfidential
• Application Front-end ( 應用程式前端 )
– Web Application GUI
– Service Surface (API)
• Service ( 服務應用程式 )
– Runtime Engine
– Business Logics
• Service Repository ( 資料儲存庫 )
– Data Store and Buffer
• Service Bus ( 服務匯流排 )
– Data and Message Exchange
服務導向架構
Microsoft Inconfidential
Designing and Architecting your Cloud Service
設計與架構雲端服務
Microsoft Inconfidential
• 能運用雲端的運算資源做有效率的調控。On-demand, Utility Computing, Pay as you go.
• 能充份運用雲端近乎無限的資源。Storage, Computes, network bandwidths, support services.
• 能在雲端供應商的承諾下,提供至少同等的高可用度。Windows Azure Computes: 99.95%
Your Service Application: 至少 99.9% 。
• 運用適當的架構方式,提供多用戶相同的軟體服務。Multitenant Service (Software as a Service)
雲端服務的主要構成要件
Microsoft Inconfidential
• 服務水準 (Service Level) = 客戶的斷線忍受力。服務可以撐多久?
Microsoft Inconfidential
• 軟體的角度:– 單一使用者:單機板軟體。– 多使用者:伺服器或服務軟體。
• 平台的角度:– 租戶 (tenant) :平台上使用軟體的使用者或組織。– 單租戶 (single-tenant)
– 多租戶 (multi-tenant)
服務可以給多少使用者用?
Microsoft Inconfidential
架構思考Data Service
資料服務端
Application Service應用程式服務端
Presentation Service展現層端
• 充份運用海量級資料儲存的能力 (低成本高容量 ) 。
• 支援分散式資料運算。• 支援層次間資料交換的需求。• 與本地端做資料交換。
• 應用程式的核心,包含運算與商業邏輯。• 指揮資料服務以儲存與提供運算或處理所需資料。
• 處理來自展現層端的服務需求。• 必須具備高度可用性。
• 直接面對使用者的介面。• 具使用者親和度與設備親和度。• 支援不同層次的設備。• 支援不同層次的用戶端程式。
開發雲端服務Data Service資料服務端
Application Service應用程式服務端
Presentation Service展現層端 IIS
Web Role
Worker Role
Worker Role
Worker Role
Microsoft Inconfidential
• 高可用度很重要,穩定度則更重要。• 雲端上各服務是分開在不同的虛擬機器內。
– Socket 是有可能斷線的。– 服務資源是有可能中斷的。
• 重試機制 (Retry Policy)
– Storage: Retry Policy
– SQL Database: Transient Failure Retry Policy
服務穩定嗎?
Microsoft Inconfidential
ASP.NET Web API and Self-host Service 服務掛載: Web API 與自我掛載服務
(Self-hosting Service)
Microsoft Inconfidential
• 由 WCF REST API 演化而成。• 基於 ASP.NET MVC Programming Model 。• 適合 RESTful API 服務開發。• Web Role vs. Worker Role
– Web Role 還要多加 IIS ,消耗的資源會多一些。– Worker Role 沒有 IIS ,可用資源多一些。
• Web API 支援自我掛載 (self-hosting) 。
ASP.NET Web API
Microsoft Inconfidential
• 掛載 Web API 於 Worker Role 的注意事項– 使用 HttpSelfHostConfiguration 對 Web API 進行設定。– 使用 HttpSelfHostServer 啟動 HTTP Listening 。
• Server.OpenAsync().Wait()
• Server.CloseAsync().Wait()
– 在 Worker Role 部署時一定要設定 Worker Role 取得管理員核准模式。
• <Runtime executionContext=“elevated” />
• 定義在服務定義檔內。
• 若沒有設定, Worker Role 會進入死亡迴圈內。
Hosting Web API on Worker Role
Microsoft Inconfidential
DEMO
掛載簡單的 Web API 服務於 Worker Role
Microsoft Inconfidential
Playing Case
具社群單一簽入能力的 SSO API Service
Microsoft Inconfidential
Service Workflow
Microsoft Inconfidential
Architecture
Social Network Identity Provider
Tenant Database(Table Storage)
Tenant User Tokens(Table Storage)
Web Application
Client
SSO Server(API)
Microsoft Inconfidential
• Tenant Registration
– /tenant/ (GET, POST ,PUT, DELETE)
– /tenant/registerIdentityProvider (POST)
• SSO Interface
– /sso/login (GET)
– /sso/requestToken (GET)
– /sso/getToken (GET)
– /sso/renewToken (GET)
REST interface
Microsoft Inconfidential
• Table Storage
– tenants Table
– identityProviders Table (for tenant’s identity provider registration)
– logs Table (logging for API invocations)
• PII (Personal Information Identification)
– Forward from Social Identity Provider
– Just store access token only (or don’t store)
– Forward to given redirect target
• Data Exchange
– JSON-based data exchange.
Storage
Microsoft Inconfidential
switch (idp){ case "Facebook": redirectUrl = string.Format( "https://www.facebook.com/dialog/oauth?client_id={0}&redirect_uri={1}&state={2}", "facebook_app_id", "http://sso.studyazure.com/sso/requestToken", "FACEBOOK"); break;
case "Google": redirectUrl = string.Format("https://accounts.google.com/o/oauth2/auth?" + "scope=[SCOPE_GOOGLE]&state={2}&redirect_uri={1}&" + "response_type=code&client_id={0}&approval_prompt=force", "google_app_id", "http://sso.studyazure.com/sso/requestToken", "GOOGLE"); break;
case "MicrosoftAccount": redirectUrl = string.Format( "https://login.live.com/oauth20_authorize.srf?" + "client_id={0}&scope=wl.basic&response_type=token&state={2}&redirect_uri={1}", "ms_account_app_id", "http://sso.studyazure.com/sso/requestToken", "MSACCOUNT"); break;
default: return this.Request.CreateResponse(HttpStatusCode.BadRequest);}
Login Implementation
Microsoft Inconfidential
Access Token Implementation
if (State == "FACEBOOK"){ response = client.GetAsync(string.Format( "https://graph.facebook.com/oauth/access_token?" + "client_id={0}&redirect_uri={1}&client_secret={2}&code={3}", "[facebook_app_id]", "http://sso.studyazure.com/sso/requestToken", "[facebook_app_secret]", Code)).Result;
NameValueCollection responseDataItems = HttpUtility.ParseQueryString(response.Content.ReadAsStringAsync().Result);
return this.Request.CreateResponse<string>(HttpStatusCode.OK, JsonConvert.SerializeObject(new { access_token = responseDataItems["access_token"] }), "application/json");}else if (State == "GOOGLE"){ // ...}else if (State == "MSACCOUNT"){ // ...}
Microsoft Inconfidential
• 服務與資料存取邏輯分開
• Design Patterns
– Repository Pattern
– Factory Pattern
– Dependency Injection (IoC Pattern)
• Hosting on ASP.NET Web API Self-host Service
Service Design
Microsoft Inconfidential
• 使用 Worker Role 掛載服務,省下 IIS 的資源。• 使用 2 個以上的執行個體,獲取 99.95% 的可用性。
– 高可用度要求:可用度不可以比雲端供應商低。– 選用超小型的執行個體,每小時 NT$0.6206 元 (每月每個約 470
元 ) 。
• 將資料儲存在 Table storage ,成本較低。– 每 GB NT$2.9477 元。– SQL Database 每 GB 要 NT$309.97 元。
• 多租戶架構。• 此服務每月營運成本約 NT$1,500 元。
Service Considerations
Microsoft Inconfidential
DEMO
SSO Server
Microsoft Inconfidential
• Windows Azure Platform 是一個成熟的公有雲服務。• SOA 架構適合於雲端環境建置。• 架構思維在服務應用程式設計上十分重要。• 透過 ASP.NET Web API Self-hosting 配合 Worker Role 讓服
務可用資源最大化。• 設計服務要想的並不少,就連一個簡單的 SSO API Service ,遇到了 Multitenant 也會讓事情變複雜。
結語Conclusion
Microsoft Inconfidential
• Free Trial:http://www.windowsazure.com/en-us/pricing/free-trial/?WT.mc_id=WWE001_1032548834
• MSDN Subscription Offer:https://www.windowsazure.com/en-us/pricing/member-offers/msdn-benefits/?WT.mc_id=WWE001_1032548834
• BizSpark Offer: https://www.windowsazure.com/en-us/pricing/member-offers/bizspark-benefits/?WT.mc_id=WWE001_1032548834
• MPN Offer: https://www.windowsazure.com/en-us/offers/ms-azr-0002p/?WT.mc_id=WWE001_1032548834
Windows Azure 試用與評估資源
Microsoft Inconfidential
推薦下列書籍給想要開發 Web 應用程式的朋友:Recommended Readings for Web Application Development
網頁用戶端應用程式開發(HTML5, JS, CSS3)
伺服器端應用程式開發(ASP.NET)
雲端應用程式開發 (Windows Azure)
41
提醒
上滿 4堂課 交回問卷問卷禮
+抽獎
Microsoft Inconfidential
第二屆 V-Day虛擬化戰士英雄會2013 年 5月 8日
facebook.com/regionbbsfacebook.com/studyazure
dotblogs.com.tw/regionbbs
© 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.