Ruby on microsoft azure april 2014

63
Ruby on Windows Azure Brian Benz Senior Technical Evangelist Microsoft Open Technologies, Inc.

description

This was presented at DevIntersection 2014. In this session we covered tips and tricks for getting the most out of Ruby in the cloud using several tools provided by Microsoft and Azure, including the Ruby SDK and developer center. Topics included best practices for security, performance, and reliability when accessing structured, unstructured, and NoSQL data.

Transcript of Ruby on microsoft azure april 2014

Page 1: Ruby on microsoft azure   april 2014

Ruby on Windows Azure

Brian Benz

Senior Technical Evangelist

Microsoft Open Technologies, Inc.

Page 2: Ruby on microsoft azure   april 2014

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

Page 3: Ruby on microsoft azure   april 2014

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

Page 4: Ruby on microsoft azure   april 2014

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

Page 5: Ruby on microsoft azure   april 2014

5 http://www.anglebrackets.org

Get Ruby

Page 6: Ruby on microsoft azure   april 2014

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

Page 7: Ruby on microsoft azure   april 2014

7 http://www.anglebrackets.org

Ruby Developer Center

Page 8: Ruby on microsoft azure   april 2014

8 http://www.anglebrackets.org

Tutorials, Articles and Updates

Page 9: Ruby on microsoft azure   april 2014

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

Page 10: Ruby on microsoft azure   april 2014

10 http://www.anglebrackets.org

Ruby SDK – Windows, Mac, Linux, Gem

Page 11: Ruby on microsoft azure   april 2014

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

Page 12: Ruby on microsoft azure   april 2014

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>

Page 13: Ruby on microsoft azure   april 2014

13 http://www.anglebrackets.org

Reference, API Documentation

Page 14: Ruby on microsoft azure   april 2014

14 http://www.anglebrackets.org

VM Depot – Ruby Images

Page 15: Ruby on microsoft azure   april 2014

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

Page 16: Ruby on microsoft azure   april 2014

Automation Support

Capabilities

• Fully Customize VM with Data Disks and Endpoint Configuration

• Automate Virtual Network Settings

Page 17: Ruby on microsoft azure   april 2014

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

Page 18: Ruby on microsoft azure   april 2014

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

Page 19: Ruby on microsoft azure   april 2014

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/

Page 20: Ruby on microsoft azure   april 2014

20 http://www.anglebrackets.org

Service Management REST API

Management Portal Tasks

Storage

Services

Page 21: Ruby on microsoft azure   april 2014

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

Page 22: Ruby on microsoft azure   april 2014

22 http://www.anglebrackets.org

manage.windowsazure.com > New > Store

Page 23: Ruby on microsoft azure   april 2014

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

Page 24: Ruby on microsoft azure   april 2014

24 http://www.anglebrackets.org

Engine Yard Developer Center for Windows Azure

Page 25: Ruby on microsoft azure   april 2014

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

Page 26: Ruby on microsoft azure   april 2014

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

Page 27: Ruby on microsoft azure   april 2014

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

Page 28: Ruby on microsoft azure   april 2014

28 http://www.anglebrackets.org

github.com/opscode/knife-azure

Page 29: Ruby on microsoft azure   april 2014

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

Page 30: Ruby on microsoft azure   april 2014

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

Page 31: Ruby on microsoft azure   april 2014

31 http://www.anglebrackets.org

Puppet on Windows Azure -Architecture

Flavors Enterprise Puppet

OSS Puppet

Terminology Module

Manifest

Tools Facter

Dashboard

Forge

Geppetto

Cloudsmith

Page 32: Ruby on microsoft azure   april 2014

32 http://www.anglebrackets.org

forge.puppetlabs.com/msopentech/windowsazure

Page 33: Ruby on microsoft azure   april 2014

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

Page 34: Ruby on microsoft azure   april 2014

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

Page 35: Ruby on microsoft azure   april 2014

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

Page 36: Ruby on microsoft azure   april 2014

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

Page 37: Ruby on microsoft azure   april 2014

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/

Page 38: Ruby on microsoft azure   april 2014

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

Page 39: Ruby on microsoft azure   april 2014

39 http://www.anglebrackets.org

Storing Data

2 Examples:

Azure Storage

Table Storage

Page 40: Ruby on microsoft azure   april 2014

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

Page 41: Ruby on microsoft azure   april 2014

Applicationbuilding blocks

Page 42: Ruby on microsoft azure   april 2014

42 http://www.anglebrackets.org

Azure Data Management

Page 43: Ruby on microsoft azure   april 2014

43 http://www.anglebrackets.org

Storage Libraries in Many Languages

Page 44: Ruby on microsoft azure   april 2014

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"

Page 45: Ruby on microsoft azure   april 2014

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>"

Page 46: Ruby on microsoft azure   april 2014

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.

Page 47: Ruby on microsoft azure   april 2014

47 http://www.anglebrackets.org

Storing Data

2 Examples:

Azure Storage

Table Storage

Page 48: Ruby on microsoft azure   april 2014

48 http://www.anglebrackets.org

Azure Storage Concepts

Page 49: Ruby on microsoft azure   april 2014

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

Page 50: Ruby on microsoft azure   april 2014

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

Page 51: Ruby on microsoft azure   april 2014

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

Page 52: Ruby on microsoft azure   april 2014

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")

Page 53: Ruby on microsoft azure   april 2014

53 http://www.anglebrackets.org

Storing Data

2 Examples:

Azure Storage

Table Storage

Page 54: Ruby on microsoft azure   april 2014

54 http://www.anglebrackets.org

Table Storage Concepts

Page 55: Ruby on microsoft azure   april 2014

55 http://www.anglebrackets.org

No Fixed Schema

Page 56: Ruby on microsoft azure   april 2014

56 http://www.anglebrackets.org

Create a Table

azure_table_service =

Azure::TableService.new

begin

azure_table_service.create_table("testtable

")

rescue

puts $!

end

Page 57: Ruby on microsoft azure   april 2014

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)

Page 58: Ruby on microsoft azure   april 2014

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)

Page 59: Ruby on microsoft azure   april 2014

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)

Page 60: Ruby on microsoft azure   april 2014

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)

Page 61: Ruby on microsoft azure   april 2014

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)

Page 62: Ruby on microsoft azure   april 2014

62 http://www.anglebrackets.org

Deleting

#Entity

azure_table_service.delete_entity("testtable",

"test-partition-key", "1")

#Table

azure_table_service.delete_table("testtable")

Page 63: Ruby on microsoft azure   april 2014