Ruby on microsoft azure april 2014
-
Upload
brian-benz -
Category
Internet
-
view
585 -
download
1
description
Transcript of Ruby on microsoft azure april 2014
Ruby on Windows Azure
Brian Benz
Senior Technical Evangelist
Microsoft Open Technologies, Inc.
2 http://www.anglebrackets.org
Agenda
• Ruby on Windows Azure
• The Ruby SDK for Windows Azure
• Engine Yard
• DevOps - Chef and Puppet
• Ruby Support in Microsoft Open Source Tools
3 http://www.anglebrackets.org
Ruby, Rails, Ruby Gems
Ruby: 1990s
Object Oriented Scripting
Ruby on Rails – 2004, 2005
Framework for Ruby
Ruby Gems – 2007
Easy Installation and package management
Node npm, Python EasyInstall
Grails – Groovy (Java based) on Rails
Inspired by Ruby on Rails, but not Ruby
4 http://www.anglebrackets.org
Agenda
• Ruby on Windows Azure
The Ruby SDK for Windows Azure
• Engine Yard
• DevOps – Chef and Puppet
• Ruby Support in Microsoft Open Source Tools
5 http://www.anglebrackets.org
Get Ruby
6 http://www.anglebrackets.org
Ruby setup and Install
C:\ruby\rubygems-2.2.2>ruby setup.rb
RubyGems 2.2.2 installed
Installing ri documentation for rubygems-2.2.2
7 http://www.anglebrackets.org
Ruby Developer Center
8 http://www.anglebrackets.org
Tutorials, Articles and Updates
9 http://www.anglebrackets.org
Agenda
• Ruby on Windows Azure
The Ruby SDK for Windows Azure
• Engine Yard
• DevOps – Chef and Puppet
• Ruby Support in Microsoft Open Source Tools
10 http://www.anglebrackets.org
Ruby SDK – Windows, Mac, Linux, Gem
11 http://www.anglebrackets.org
Azure Installation using Ruby Gem
C:\ruby\rubygems-2.2.2>gem install azure
Fetching: json-1.8.1.gem (100%)
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
Successfully installed json-1.8.1
Fetching: systemu-2.6.4.gem (100%)
Successfully installed systemu-2.6.4
Fetching: macaddr-1.7.1.gem (100%)
Successfully installed macaddr-1.7.1
Fetching: uuid-2.3.7.gem (100%)
Successfully installed uuid-2.3.7
Fetching: azure-0.6.3.gem (100%)
Successfully installed azure-0.6.3
12 http://www.anglebrackets.org
Azure Installation - documentation
Installing ri documentation for azure-0.6.3
Installing ri documentation for json-1.8.1
Installing ri documentation for macaddr-1.7.1
Installing ri documentation for systemu-2.6.4
Installing ri documentation for uuid-2.3.7
5 gems installed
C:\ruby\rubygems-2.2.2>
13 http://www.anglebrackets.org
Reference, API Documentation
14 http://www.anglebrackets.org
VM Depot – Ruby Images
azure topic verb options
Command Line Syntax Overview
prompt>
accountaccount locationaccount affinity-groupvmvm diskvm endpointvm imageserviceservice certsiteconfig
downloadimportlistshowdeletestartrestartshutdowncapturecreateattachdetachbrowseset
usernamepassworddns-prefixvm-namelb-porttarget-image-namesource-pathdisk-image-namesize-in-gbthumbprintvalue-v-vv
Automation Support
Capabilities
• Fully Customize VM with Data Disks and Endpoint Configuration
• Automate Virtual Network Settings
17 http://www.anglebrackets.org
github.com/windowsazure/azure-sdk-for-ruby
Storage Blobs
create, list, and delete containers, work with container metadata and permissions, list blobs in containercreate block and page blobs (from a stream, a file, or a string), work with blob blocks and pages, delete blobswork with blob properties, metadata, leases, snapshot a blob
Tables create and delete tablescreate, query, insert, update, merge, and delete entities
Queues create, list, and delete queues, and work with queue metadatacreate, get, peek, update, delete messages
18 http://www.anglebrackets.org
github.com/windowsazure/azure-sdk-for-ruby
Service Bus
Queues
create, list and delete queues
send, receive, unlock and delete messages
Topics
create, list, and delete topics
send, receive, unlock and delete messages
create, list, and delete subscriptions
create, list, and delete rules
19 http://www.anglebrackets.org
Queue Storage
Stores large numbers of messages
Authenticated via HTTP or HTTPs
Up to 200TB
Tutorial: http://www.windowsazure.com/en-us/develop/ruby/how-to-guides/queue-service/
20 http://www.anglebrackets.org
Service Management REST API
Management Portal Tasks
Storage
Services
21 http://www.anglebrackets.org
Agenda
• Ruby on Windows Azure
The Ruby SDK for Windows Azure
• Engine Yard
• DevOps – Chef and Puppet
• Ruby Support in Microsoft Open Source Tools
22 http://www.anglebrackets.org
manage.windowsazure.com > New > Store
23 http://www.anglebrackets.org
• Engine Yard – What’s in the Box:
Ubuntu-based
Two Ruby application servers
One MySQL Server
Two load balancing servers
New AngularJS UI
Monthly Fee – currently $99 or $149 for premium support
Currently a $1 Trial for the first month
24 http://www.anglebrackets.org
Engine Yard Developer Center for Windows Azure
25 http://www.anglebrackets.org
Agenda
• Ruby on Windows Azure
The Ruby SDK for Windows Azure
• Engine Yard
• DevOps – Chef and Puppet
• Ruby Support in Microsoft Open Source Tools
26 http://www.anglebrackets.org
Chef on Windows Azure
Chef Community - community.opscode.com
15,000+ registered users
800 individual contributors
150 corporate contributors
500+ cookbooks
Support for on-Premise Windows and Windows Azure in the Cloud
27 http://www.anglebrackets.org
Chef on Windows Azure - Architecture
• Chef Server – Authentication
and Cookbooks
• Windows Azure –endorsed Linux packages
• New VM – loads workstation
• New workstation – loads client and recipes
28 http://www.anglebrackets.org
github.com/opscode/knife-azure
29 http://www.anglebrackets.org
Example Knife Command
Create Jenkins running on Ubuntu on an Azure VM knife azure server create
Creates a new Azure Server
--hosted-service-name JenkinsDemo1 Names the Server
--role-name DemoServer Names the Role
--run-list 'recipe[java],recipe[jenkins]‘ Retrieves a run-list, recipes, runs on Chef Client
30 http://www.anglebrackets.org
Puppet on Windows Azure
The power of Puppet = Community!
Demand for better windows integration and management
>1850 modules in the Forge alone
Strong Third Party Ecosystem
Vagrant
Test locally before you pay for cloud resources
Puphpet – from workstation to cloud
UI that helps generate a Vagrant file and Puppet manifests
31 http://www.anglebrackets.org
Puppet on Windows Azure -Architecture
Flavors Enterprise Puppet
OSS Puppet
Terminology Module
Manifest
Tools Facter
Dashboard
Forge
Geppetto
Cloudsmith
32 http://www.anglebrackets.org
forge.puppetlabs.com/msopentech/windowsazure
33 http://www.anglebrackets.org
Puppet on Windows Azure
The Windows Azure Puppet module
Virtual Machines – both Linux and Windows
Virtual Networks – create logically isolated sections of Azure and securely connect them to your on premise clients and servers
SQL Server – create and maintain your SQL database
34 http://www.anglebrackets.org
Puppet on Windows Azure
Manifest files
Collections of definitions, references and commands
Deploy VMs in a defined “desired state”.
bootstrap.pp – allows the creation of a new Puppet node
db.pp – create a new instance of SQL server
init.pp – defines a Windows Azure class that will allow easy deployment to the associated Windows Azure account
vm.pp – create a new virtual machine instance from a virtual machine image
vnet.pp – create a new virtual network
35 http://www.anglebrackets.org
Example Modules
Modules are just directories with files, arranged in a specific, predictable structure
Ala run list in Chef
site.pp
include ntp
include apache
include mysql
include mongodb
include build_essential
36 http://www.anglebrackets.org
Agenda
• Ruby on Windows Azure
The Ruby SDK for Windows Azure
• Engine Yard
• DevOps – Chef and Puppet
• Ruby Support in Microsoft Open Source Tools
37 http://www.anglebrackets.org
Ruby in Microsoft Open Source Tools
• Reactive Extensions – Ruby Library Asynchronous and event-based programming using:
Observable sequences
LINQ-style query operators
http://rxrb.codeplex.com/
Apache Qpid Proton AMQP libraries
Cross-platform AMQP messaging system
Message brokers written in C++ and Java
Clients for Ruby, also C++, Java, Perl, Python, Ruby, and .NET.
http://qpid.apache.org/releases/
38 http://www.anglebrackets.org
Summary
• Ruby on Windows Azure
The Ruby SDK for Windows Azure
• Engine Yard
• DevOps – Chef and Puppet
• Ruby Support in Microsoft Open Source Tools
39 http://www.anglebrackets.org
Storing Data
2 Examples:
Azure Storage
Table Storage
40 http://www.anglebrackets.org
Windows Azure Storage
Storage in the Cloud
Scalable, durable, and available
Anywhere at anytime access
Only pay for what the service uses
RESTful Web Services
Use from Windows Azure Compute
Use from anywhere on the internet
Applicationbuilding blocks
42 http://www.anglebrackets.org
Azure Data Management
43 http://www.anglebrackets.org
Storage Libraries in Many Languages
44 http://www.anglebrackets.org
Setting up Storage
• Configure Your Application to Access Storage• Download and use the Ruby azure package, which communicates with the storage REST
services.
• Use RubyGems to obtain the package
• Use a command-line interface such as PowerShell (Windows), Terminal (Mac), or Bash (Unix).
• Type "gem install azure" in the command window to install the gem and dependencies.
• Import the package
• Using your favorite text editor, add the following to the top of the Ruby file where you intend to use storage:
• require "azure"
45 http://www.anglebrackets.org
Storage Connection
• Setup a Windows Azure Storage Connection
• The azure module will read the environment variables AZURE_STORAGE_ACCOUNT and AZURE_STORAGE_ACCESS_KEY for information required to connect to your Windows Azure storage account.
• If these environment variables are not set, you must specify the account information before using Azure Storage Services with the following code:
Azure.config.storage_account_name = "<your azure storage account>"
Azure.config.storage_access_key = "<your azure storage access key>"
46 http://www.anglebrackets.org
Getting Storage Credentials
• To obtain the Account Name and Access Key values:
• Log into the Windows Azure Management Portal.
• Navigate to the storage account you want to use
• Click MANAGE KEYS at the bottom of the navigation pane.
• In the pop up dialog, you will see the storage account name, primary access key and secondary access key. For access key, you can either the primary one or the secondary one.
47 http://www.anglebrackets.org
Storing Data
2 Examples:
Azure Storage
Table Storage
48 http://www.anglebrackets.org
Azure Storage Concepts
49 http://www.anglebrackets.org
Create a Container
azure_blob_service = Azure::BlobService.new
begin
container =
azure_blob_service.create_container("test- container")
#Optional – Set Container to public read acess
azure_blob_service.set_container_acl('test-
container', "container")
rescue
puts $!
End
50 http://www.anglebrackets.org
Upload a Blob to a Container
content = File.open("test.png", "rb") { |file|
file.read }
blob =
azure_blob_service.create_block_blob(container.name,
"image-blob", content)
puts blob.name
51 http://www.anglebrackets.org
List the Blobs in a Container
containers =
azure_blob_service.list_containers()
containers.each do |container|
blobs =
azure_blob_service.list_blobs(container.name
)
blobs.each do |blob|
puts blob.name
end
end
52 http://www.anglebrackets.org
Download or Delete a Blob
#Download
blob, content =
azure_blob_service.get_blob(container.name,"
image-blob")
File.open("download.png","wb") {|f|
f.write(content)}
#Delete
azure_blob_service.delete_blob(container.nam
e, "image-blob")
53 http://www.anglebrackets.org
Storing Data
2 Examples:
Azure Storage
Table Storage
54 http://www.anglebrackets.org
Table Storage Concepts
55 http://www.anglebrackets.org
No Fixed Schema
56 http://www.anglebrackets.org
Create a Table
azure_table_service =
Azure::TableService.new
begin
azure_table_service.create_table("testtable
")
rescue
puts $!
end
57 http://www.anglebrackets.org
Add or Update an Entity
#Add
entity = { "content" => "test entity",
:PartitionKey => "test-partition-key",
:RowKey => "1" }
azure_table_service.insert_entity("testtabl
e", entity)
58 http://www.anglebrackets.org
Update an Entity
#update
entity = { "content" => "test entity with
updated content",
:PartitionKey => "test-partition-key",
:RowKey => "1" }
azure_table_service.update_entity("testtabl
e", entity)
59 http://www.anglebrackets.org
Process Groups of Entities
azure_table_service = Azure::TableService.new
batch =
Azure::Storage::Table::Batch.new("testtable",
"test-partition-key") do
insert "2", { "content" => "new content 2" }
insert "3", { "content" => "new content 3" }
end
results = azure_table_service.execute_batch(batch)
60 http://www.anglebrackets.org
Query Entities
#Single
result =
azure_table_service.get_entity("testtable", "test-
partition-key",
"1")
#Multiple
query = { :filter => "PartitionKey eq 'test-
partition-key'" }
result, token =
azure_table_service.query_entities("testtable",
query)
61 http://www.anglebrackets.org
Query a Subset of Entities
query = { :filter => "PartitionKey eq 'test-
partition-key'",
:select => ["content"] }
result, token =
azure_table_service.query_entities("testtable",
query)
62 http://www.anglebrackets.org
Deleting
#Entity
azure_table_service.delete_entity("testtable",
"test-partition-key", "1")
#Table
azure_table_service.delete_table("testtable")