Java on Windows Azure Cloud           Service            黃忠成
Windows Azure OverviewCloud Service  Web Role  Worker RoleVirtual MachinesWeb SitesVirtual NetworkMobile ServiceMedia Serv...
VM and Cloud ServiceVirtual Machines  IaaS  Load Balancing by Setting (from Portal)  Scale out need more actions  OS is ma...
Java On Windows Azure
環境的準備.NET Framework 2.0/3.5JDKWindows Azure SDK 1.8EclipseEclipse Plug-InsTomcat
Installing.NET Framework 2.0/3.5Installing JDK 7Installing Eclipse 3.7Install Windows Azure SDK  http://go.microsoft.com/f...
Install Eclipse Plug-Ins
讓我們開始吧
Creating Dynamic Web Project
Add index.jspDemo and Run
Add Windows Azure Deployment          Project
Include JDK and Tomcat
Add Deployment WAR files
Session, Cache, and Remote          Debugger稍後我們會深入討論這個畫面中的設定
整個專案樹會變成這樣
Run In Emulator
現在在哪?我們的Web Project會編譯並打包為.WAR當按下Run In Windows Azure Emulator後,會將.WAR及Cloud Service相關設定打包成.csdef,cscfg及.cspkg,並啟動本地端的Wind...
Enable Remote Debugger
Add Breakpoint and Run Emulator
Starting Debug
最終結果
Publish to Cloud Service
Publish To Cloud Service
Publish To Cloud Service
Publish To Cloud Service
Waiting for Publish
Testing in Cloud Service
開發流程                     使用本地端的        建立Windows      撰寫你的Web                     Tomcat來測試   Azure Deployment       Appli...
About Remote DebuggerYou can debug in local and cloud serviceAfter package is deployment, you can create debugconfiguratio...
Remote Connect
Welcome your Worker Role
管理你的Cloud ServiceRemote Connect
SWAP to Production slot
SCALE
Change Remote Desktop Password
Access Database
Creating MySQL(ClearDB)http://www.cleardb.com/
Get Connection Information
Testing Connecting
Add MySQL JDBC Driver
Using code
Creating SQL Azure Database
Connecting with SQL Management             Studio
Connecting with CodeAdd SQL Server JDBC Driver
Get Connection String
Connecting with code
存取Storage Services
建立Storage Services Account
Add Azure Client Library to Project
Use Table Storage Service
Add useTable.jspImport Azure Client Library in .jspPrepare connection string
About Connection String
Creating Entity ClassEntity class must Inherit from TableServiceEntityAdd Properties
About Partition key and row key Table use Partition key and row key as Primary Key Partition Key will help data partition ...
Creating Table and Add Entity
RunDemo
Is Done???Download Azure Storage Explorer  http://azurestorageexplorer.codeplex.com/
Testing
Make thing easy….Creating StorageClient Helper classesCreating TableHelper classes
Demo and TryingDemo
Using Blob Storage Service
Blob StorageBlob Storage can store large data itemBlob Storage is durability and scalableBlob Architecture             Acc...
Blob TypesBlock Blob   Block Blob 最大支援至200GB   Block Blob 可以分區塊上傳,每個Block最大為4MB,直到呼叫Put Block List前,所上   傳的區塊都不會成為檔案的一部份,因...
Creating Upload HandlerDemo
Create Blobs.jspDemo
Using Queue Service
Creating Queue.jspDemo
Using Storage EmulatorWindows Azure SDK provides Storage ServiceEmulator
Testing our Application with Storage             Emulator
Storage Emulator NotesIt’s Emulator, do not provides full function !!We recommend you testing in real Cloud StorageService
Enable CDN for Storage Service
Why use CDNCDN will deliver storage content to worldwide CDNServersUser access same CDN endpoint will redirect to nearCDN ...
Enable CDN on Storage Services Back to Previous Portal
Enable CDN on Storage Services
Enable CDN on Storage Services CDN will take 60 minutes to activate
Changing URL of Resource link Just change url from blob storage endpoint to CDN endpoint Like   http://res1026.blob.core.w...
Using CDN notesAccess static pictures/resources/javascriptsWhen storage is changed, CDN may need 72-hours torefresh status...
Enable Caching
Introducing Windows Azure Caching  Provides general Caching Services  Provides two Cache Services    Role-base Caching    ...
About Co-located and Dedicated Co-Located Caching   Use same Role memory to caching data   You should not use large memory...
PreparingDownload spymemcached.jar(2.8.1)  http://code.google.com/p/spymemcached/downloads/lis  tAdd .JAR to Project
Configure a Co-Located Caching
Testing in EmulatorDemo
Configure a Dedicated Caching Add memcache_default Endpoint
Configure a Dedicated Caching Import Caching Folder as Components
Configure a Dedicated Caching Import Caching Shim Folder as Components
Configure a Dedicated Caching Add MemcacheShimInstaller.exe as Component
Configure a Dedicated Caching Add web.config in WorkerRole1approot
Configure a Dedicated Caching Creating New Worker Role
Configure a Dedicate CachingEnable Co-located Caching in DedicateCache Role
Test in Emulator
Caching Setting
About Sessions and Multiple        Instances
Default SessionsCloud Services will use Round-Robin to accomplishload balanceIn 2 Instances  the user first enter the page...
Enable Sticky Session
Modify Instance Count
Add session operations in index.jsp
Test in CloudDemo
Manually Upload Package
Build Cloud Deployment Package
Upload Cloud Deployment Package         To Cloud Service Create Cloud Service
Add Remote Connect Certification
Upload Cloud Deployment Package         To Cloud Service Upload Package
Optimized Deploy
Include JDK and tomcat will increase      deployment package size
Create JDK Package Not only JRE, full JDK Required.
Create Tomcat Package
Upload JDK and Tomcat to cloud
Creating Empty Deployment Project
Export WAR
Add BlobDownloader.exe and .cfg,  StorageClient.dll to app root
Modify BlobDownloader.exe.cfg Change storage account and access key
Modify startup.cmd
Test in EmulatorDemo
The Deployment Package Size
Understanding startup.cmdStartup.cmd like autoexec.bat, executing in VM start-upYou can do everything in here  Download so...
Understanding run.cmdWhen startup.cmd is end, run.cmd will be executingIn samples, here will use  utilwhileproc.cmd java.e...
The Deploy Processing  VM        Deploy                      Run startup.cmdStarting   packages                       Run ...
So….Anything can be done in command line will also canbe done in Worker RoleSo  You can use Play Framework  You can use ot...
Caching Service as Session
Sticky Session的問題當握有Session的VM/Role出現問題導致當機時, 該機器上的Session將完全消失 也就是說這種Session處理方式是不具容錯性的使用Caching Service來儲存Session的優點 Ses...
怎麼做?建立Dedicated Caching下載Tomcat Session Manager http://code.google.com/p/memcached-session-manager/在Web Application專案中加入sp...
建立context.xml
引入Tomcat Session Manager至   Deployment Project 修改Startup.cmd
TestingDemo
Move Non-Web Application to      Cloud Service
轉移Desktop Application至Cloud         Service
怎麼做?建立Windows Azure Deployment Project輸出.JAR至Windows Azure Deployment Project的approot目錄下開啟必要的port(如果需要的話)
修改startup.cmd
Web <-> Background Agent
一個較為複雜的分散式架構                                 位於機器A的服務           接收需求, 並分配需求User        到後端的Services          Service A    ...
怎麼做?建立Service建立Web Application建立Deployment Project建立另一個Worker Role
怎麼做?輸出Service的.JAR至ServerRole的approot目錄下修改ServerRole的startup.cmd添加必要的port(internal)
怎麼做?Web Application如何連接到Service??
TestingDemo
Without EclipseUse Other IDE
PrepareInstall Ant  http://ant.apache.org/Download Azure Start Kit for Java  https://github.com/MSOpenTech/WindowsAzureToo...
Creating .WAR (NetBeans 7)
Extract Start Kit for Java
Copy .WARCopy .war from dist folder (NetBeans 7)
Include JDK and Tomcat Zip files
Copy Sample startup.cmdDelete approotstartup.cmd, rename startupApacheTomcat7.txt tostartup.cmd
Modify startup.cmdMake sure all name is correct
BuildUse Ant to build project  In deploy project folder    ant -buildfile package.xml
Test in EmulatorExecutionDeployProjectEmulatorToolsRunInEmulator.cmd
Prepare for Cloud PackageModify package.xml in DeployProject root
Change packageTypeant -buildfile package.xml
Upload Package to CloudCreating Cloud ServiceUpload Sample Certification  The password is Password1
Upload Package to Cloud
Optimized againWar Hot Deploy
Understanding run.cmdWhat’s whileproc.cmd ?Writing own wardetecting.exeChanging startup.cmdChanging run.cmdDeploy and test...
ResourcesDevelop Center  http://www.windowsazure.com/en-us/develop/java/Azure Caching  http://msdn.microsoft.com/en-  us/l...
Sampleshttp://www.code6421.com/BlogPics/JavaAzureTrainingDemo.zipNotes  JDK and Tomcat is not included
Upcoming SlideShare
Loading in...5
×

Java and windows azure cloud service

601

Published on

Java on Windows Azure Cloud Service

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
601
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Java and windows azure cloud service

  1. 1. Java on Windows Azure Cloud Service 黃忠成
  2. 2. Windows Azure OverviewCloud Service Web Role Worker RoleVirtual MachinesWeb SitesVirtual NetworkMobile ServiceMedia Service
  3. 3. VM and Cloud ServiceVirtual Machines IaaS Load Balancing by Setting (from Portal) Scale out need more actions OS is maintain by your self Provides Management APICloud Service PaaS Load Balancing by Auto Scale out is simple and automation OS, and software included will patching auto, you don’t need maintain Provides Management API
  4. 4. Java On Windows Azure
  5. 5. 環境的準備.NET Framework 2.0/3.5JDKWindows Azure SDK 1.8EclipseEclipse Plug-InsTomcat
  6. 6. Installing.NET Framework 2.0/3.5Installing JDK 7Installing Eclipse 3.7Install Windows Azure SDK http://go.microsoft.com/fwlink/?LinkID=252838&clcid=0 x409Install Tomcat 7
  7. 7. Install Eclipse Plug-Ins
  8. 8. 讓我們開始吧
  9. 9. Creating Dynamic Web Project
  10. 10. Add index.jspDemo and Run
  11. 11. Add Windows Azure Deployment Project
  12. 12. Include JDK and Tomcat
  13. 13. Add Deployment WAR files
  14. 14. Session, Cache, and Remote Debugger稍後我們會深入討論這個畫面中的設定
  15. 15. 整個專案樹會變成這樣
  16. 16. Run In Emulator
  17. 17. 現在在哪?我們的Web Project會編譯並打包為.WAR當按下Run In Windows Azure Emulator後,會將.WAR及Cloud Service相關設定打包成.csdef,cscfg及.cspkg,並啟動本地端的Windows Azure Computer Emulator來執行.這是一個本地端的Cloud Service 模擬器.
  18. 18. Enable Remote Debugger
  19. 19. Add Breakpoint and Run Emulator
  20. 20. Starting Debug
  21. 21. 最終結果
  22. 22. Publish to Cloud Service
  23. 23. Publish To Cloud Service
  24. 24. Publish To Cloud Service
  25. 25. Publish To Cloud Service
  26. 26. Waiting for Publish
  27. 27. Testing in Cloud Service
  28. 28. 開發流程 使用本地端的 建立Windows 撰寫你的Web Tomcat來測試 Azure Deployment Application 及除錯 Project Import WAR(從你 在模擬器上測試及 的Web Application 除錯 Project)Remote Debugger 佈署至雲端
  29. 29. About Remote DebuggerYou can debug in local and cloud serviceAfter package is deployment, you can create debugconfiguration and starting debug
  30. 30. Remote Connect
  31. 31. Welcome your Worker Role
  32. 32. 管理你的Cloud ServiceRemote Connect
  33. 33. SWAP to Production slot
  34. 34. SCALE
  35. 35. Change Remote Desktop Password
  36. 36. Access Database
  37. 37. Creating MySQL(ClearDB)http://www.cleardb.com/
  38. 38. Get Connection Information
  39. 39. Testing Connecting
  40. 40. Add MySQL JDBC Driver
  41. 41. Using code
  42. 42. Creating SQL Azure Database
  43. 43. Connecting with SQL Management Studio
  44. 44. Connecting with CodeAdd SQL Server JDBC Driver
  45. 45. Get Connection String
  46. 46. Connecting with code
  47. 47. 存取Storage Services
  48. 48. 建立Storage Services Account
  49. 49. Add Azure Client Library to Project
  50. 50. Use Table Storage Service
  51. 51. Add useTable.jspImport Azure Client Library in .jspPrepare connection string
  52. 52. About Connection String
  53. 53. Creating Entity ClassEntity class must Inherit from TableServiceEntityAdd Properties
  54. 54. About Partition key and row key Table use Partition key and row key as Primary Key Partition Key will help data partition Appropriate use of Partition key will increase performance for accessing Table Storage
  55. 55. Creating Table and Add Entity
  56. 56. RunDemo
  57. 57. Is Done???Download Azure Storage Explorer http://azurestorageexplorer.codeplex.com/
  58. 58. Testing
  59. 59. Make thing easy….Creating StorageClient Helper classesCreating TableHelper classes
  60. 60. Demo and TryingDemo
  61. 61. Using Blob Storage Service
  62. 62. Blob StorageBlob Storage can store large data itemBlob Storage is durability and scalableBlob Architecture Account Container Blob IMG001.JPG pictures IMG002.JPG sally movies MOV1.AVI
  63. 63. Blob TypesBlock Blob Block Blob 最大支援至200GB Block Blob 可以分區塊上傳,每個Block最大為4MB,直到呼叫Put Block List前,所上 傳的區塊都不會成為檔案的一部份,因此沒有人可以存取未呼叫Pub Block List前 的區塊資料 當上傳檔案小於64MB時,可選擇直接上傳而不分區塊 Block Blob 通常用於儲存影片等須完整後才能提供下載的檔案Page Blob 最佳化亂數存取型,常用於儲存即時性資料,沒有檔案完整性的確認機制 Page Blob於建立時即需指定大小,之後可分區塊寫入(每個區塊大小必須符合512 Byte的倍數, 最大為1TB, 與Block Blob不同,一經上傳完成,該區塊即成為檔案的一 部份,所有人皆可取用 Page Blob 最大支援至1TB Page Blob 通常用於Client Application,例如Silverlight,WPF or WinForm
  64. 64. Creating Upload HandlerDemo
  65. 65. Create Blobs.jspDemo
  66. 66. Using Queue Service
  67. 67. Creating Queue.jspDemo
  68. 68. Using Storage EmulatorWindows Azure SDK provides Storage ServiceEmulator
  69. 69. Testing our Application with Storage Emulator
  70. 70. Storage Emulator NotesIt’s Emulator, do not provides full function !!We recommend you testing in real Cloud StorageService
  71. 71. Enable CDN for Storage Service
  72. 72. Why use CDNCDN will deliver storage content to worldwide CDNServersUser access same CDN endpoint will redirect to nearCDN ServerI.e.: User in East US will connect to East US CDN Server User in East Asia will connect to East Asia CDN Server
  73. 73. Enable CDN on Storage Services Back to Previous Portal
  74. 74. Enable CDN on Storage Services
  75. 75. Enable CDN on Storage Services CDN will take 60 minutes to activate
  76. 76. Changing URL of Resource link Just change url from blob storage endpoint to CDN endpoint Like http://res1026.blob.core.windows.net/imagecontainer/N FpcWQ3H1THKOEHyGrjQGA.jpg To http://az412373.vo.msecnd.net/imagecontainer/NFpcWQ 3H1THKOEHyGrjQGA.jpg
  77. 77. Using CDN notesAccess static pictures/resources/javascriptsWhen storage is changed, CDN may need 72-hours torefresh statusFor real-time resources, use storage service insteadCDNCDN will provides purged API in feature.
  78. 78. Enable Caching
  79. 79. Introducing Windows Azure Caching Provides general Caching Services Provides two Cache Services Role-base Caching Shared Caching support memcache protocol Node.js PHP Java
  80. 80. About Co-located and Dedicated Co-Located Caching Use same Role memory to caching data You should not use large memory for caching Dedicated Use another Role memory to caching data In general , we will use all memory for caching
  81. 81. PreparingDownload spymemcached.jar(2.8.1) http://code.google.com/p/spymemcached/downloads/lis tAdd .JAR to Project
  82. 82. Configure a Co-Located Caching
  83. 83. Testing in EmulatorDemo
  84. 84. Configure a Dedicated Caching Add memcache_default Endpoint
  85. 85. Configure a Dedicated Caching Import Caching Folder as Components
  86. 86. Configure a Dedicated Caching Import Caching Shim Folder as Components
  87. 87. Configure a Dedicated Caching Add MemcacheShimInstaller.exe as Component
  88. 88. Configure a Dedicated Caching Add web.config in WorkerRole1approot
  89. 89. Configure a Dedicated Caching Creating New Worker Role
  90. 90. Configure a Dedicate CachingEnable Co-located Caching in DedicateCache Role
  91. 91. Test in Emulator
  92. 92. Caching Setting
  93. 93. About Sessions and Multiple Instances
  94. 94. Default SessionsCloud Services will use Round-Robin to accomplishload balanceIn 2 Instances the user first enter the page will direct to Instance A We save some data in session Then user click some button then will direct to instance B Session will not exists in Instance B (lost session)
  95. 95. Enable Sticky Session
  96. 96. Modify Instance Count
  97. 97. Add session operations in index.jsp
  98. 98. Test in CloudDemo
  99. 99. Manually Upload Package
  100. 100. Build Cloud Deployment Package
  101. 101. Upload Cloud Deployment Package To Cloud Service Create Cloud Service
  102. 102. Add Remote Connect Certification
  103. 103. Upload Cloud Deployment Package To Cloud Service Upload Package
  104. 104. Optimized Deploy
  105. 105. Include JDK and tomcat will increase deployment package size
  106. 106. Create JDK Package Not only JRE, full JDK Required.
  107. 107. Create Tomcat Package
  108. 108. Upload JDK and Tomcat to cloud
  109. 109. Creating Empty Deployment Project
  110. 110. Export WAR
  111. 111. Add BlobDownloader.exe and .cfg, StorageClient.dll to app root
  112. 112. Modify BlobDownloader.exe.cfg Change storage account and access key
  113. 113. Modify startup.cmd
  114. 114. Test in EmulatorDemo
  115. 115. The Deployment Package Size
  116. 116. Understanding startup.cmdStartup.cmd like autoexec.bat, executing in VM start-upYou can do everything in here Download something Executing any executable file Set Environment VariablesJust remember This startup.cmd must end, so if you need execution tomcat(startup.bat), you need use cmd /c to creating another command line window
  117. 117. Understanding run.cmdWhen startup.cmd is end, run.cmd will be executingIn samples, here will use utilwhileproc.cmd java.exe This command will keep detecting java is running or not If java.exe is not in running status(not in process explorer) Fabric Controller will mark this VM is down Switch to another VM
  118. 118. The Deploy Processing VM Deploy Run startup.cmdStarting packages Run run.cmd
  119. 119. So….Anything can be done in command line will also canbe done in Worker RoleSo You can use Play Framework You can use other Web Server, like apache or Jboss you can use Apache Lucene as Search Engine
  120. 120. Caching Service as Session
  121. 121. Sticky Session的問題當握有Session的VM/Role出現問題導致當機時, 該機器上的Session將完全消失 也就是說這種Session處理方式是不具容錯性的使用Caching Service來儲存Session的優點 Session儲存於外部機器 儲存Session的機器本身也是一個Cloud Service,所以具 備容錯及Replication能力
  122. 122. 怎麼做?建立Dedicated Caching下載Tomcat Session Manager http://code.google.com/p/memcached-session-manager/在Web Application專案中加入spymemcached.jar的引用
  123. 123. 建立context.xml
  124. 124. 引入Tomcat Session Manager至 Deployment Project 修改Startup.cmd
  125. 125. TestingDemo
  126. 126. Move Non-Web Application to Cloud Service
  127. 127. 轉移Desktop Application至Cloud Service
  128. 128. 怎麼做?建立Windows Azure Deployment Project輸出.JAR至Windows Azure Deployment Project的approot目錄下開啟必要的port(如果需要的話)
  129. 129. 修改startup.cmd
  130. 130. Web <-> Background Agent
  131. 131. 一個較為複雜的分散式架構 位於機器A的服務 接收需求, 並分配需求User 到後端的Services Service A Web Application 位於機器B的服務 Service B 在這種架構下, Service A及B屬於內部 網路, 使用者無法直接連到
  132. 132. 怎麼做?建立Service建立Web Application建立Deployment Project建立另一個Worker Role
  133. 133. 怎麼做?輸出Service的.JAR至ServerRole的approot目錄下修改ServerRole的startup.cmd添加必要的port(internal)
  134. 134. 怎麼做?Web Application如何連接到Service??
  135. 135. TestingDemo
  136. 136. Without EclipseUse Other IDE
  137. 137. PrepareInstall Ant http://ant.apache.org/Download Azure Start Kit for Java https://github.com/MSOpenTech/WindowsAzureToolkitF orEclipseWithJavaMake sure Antbin and java environment variables isset.
  138. 138. Creating .WAR (NetBeans 7)
  139. 139. Extract Start Kit for Java
  140. 140. Copy .WARCopy .war from dist folder (NetBeans 7)
  141. 141. Include JDK and Tomcat Zip files
  142. 142. Copy Sample startup.cmdDelete approotstartup.cmd, rename startupApacheTomcat7.txt tostartup.cmd
  143. 143. Modify startup.cmdMake sure all name is correct
  144. 144. BuildUse Ant to build project In deploy project folder ant -buildfile package.xml
  145. 145. Test in EmulatorExecutionDeployProjectEmulatorToolsRunInEmulator.cmd
  146. 146. Prepare for Cloud PackageModify package.xml in DeployProject root
  147. 147. Change packageTypeant -buildfile package.xml
  148. 148. Upload Package to CloudCreating Cloud ServiceUpload Sample Certification The password is Password1
  149. 149. Upload Package to Cloud
  150. 150. Optimized againWar Hot Deploy
  151. 151. Understanding run.cmdWhat’s whileproc.cmd ?Writing own wardetecting.exeChanging startup.cmdChanging run.cmdDeploy and testingTry hot deploy
  152. 152. ResourcesDevelop Center http://www.windowsazure.com/en-us/develop/java/Azure Caching http://msdn.microsoft.com/en- us/library/windowsazure/gg278356.aspxMy Blog http://www.dotblogs.com.tw/code6421/
  153. 153. Sampleshttp://www.code6421.com/BlogPics/JavaAzureTrainingDemo.zipNotes JDK and Tomcat is not included

×