Azure 236504 – winter 2015/16. What Is Cloud Computing? Imagine if tap water didn’t exist. Every...

Preview:

Citation preview

Azure236504 – winter 2015/16

What Is Cloud Computing?

Imagine if tap water didn’t exist. Every household would need to dig a well. Doing so would be a pain. Wells are expensive to build, and expensive to maintain. You wouldn’t be able get a large quantity of water quickly if you needed it—at least not without upgrading your pump.

Source: Programming Windows Azure (Sriram Krisbnan)

What Is Cloud Computing?

And if you no longer needed the well, there would be no store to return it to, and no way to recoup your capital investment. If you vacated the house, or the proper plumbing were installed in your house, you would have invested in a well you don’t need.

Source: Programming Windows Azure (Sriram Krisbnan)

Some History

At the beginning, programmers typed in code using punch cards or tape, and submitted the cards or tape to a machine that executed jobs synchronously, one after another. This was massively inefficient, since the computer was subjected to a lot of idle time.

Source: Programming Windows Azure (Sriram Krisbnan)

Time-Sharing Systems

Cloud computing has its origins in the 1960s, as the time-sharing systems appeared.

Time sharing took advantage of the time theprocessor spent waiting for I/O, and allocated these slices of time to other users.

Source: Programming Windows Azure (Sriram Krisbnan)

Mainframe Computing

These are computers used primarily by corporate and governmental organizations for critical applications, bulk data processing such as census, industry and consumer statistics, enterprise resource planning and transaction processing.

Source: Programming Windows Azure (Sriram Krisbnan)

Grid Computing VS Cloud ComputingThe term grid computing originated in the 1990s, and referred to making computers accessible in a manner similar to a power grid.

Grid computing is about users making few, but very large, requests Only a few of these allocations can be serviced at any given time, and others must be queuedCloud computing, on theother hand, is about lots of small allocation requests, with allocations happening in real time. Source: Programming Windows Azure (Sriram

Krisbnan)

Why Cloud?

• “Unlimited resources”

• Scale on demand

• #clients

• #services

• Out of the box infrastructure

• Redundant (geographical)

• Compatibility with different clients

• Less deployment management

History of Azure

•The idea: A new kind of software, that you don’t install from CD (2005)

•A trip to Hotmail led to the name idea “Pink Poodle” (2006)

•The chosen name was “Red Dog”

Source: Programming Windows Azure (Sriram Krisbnan)

History of Azure•The funding team worked in a startup-like fashion, they did things that weren’t normally done at Microsoft.

•Such as turning a nearby building into a small data center, and stealing power from the buildings around it

•Red Dog, now renamed Windows Azure, was officially unveiled on October 27, 2008. Source: Programming Windows Azure (Sriram

Krisbnan)

Why Azure?

• Integrated into Visual Studio

• Many services in one place

• Mobile service

• Has API for both tables and custom APIs

• General computing- because Arduino computational resources are limited

• Connects to both Windows Phone and Arduino

• Course requirement

The Azure portal

• Azure control panel: https://manage.windowsazure.com

• Each of you will connect his Microsoft account to his Azure pass.

• Only one pass per account allowed!

• You need Visual Studio 2013 or newer. You can get it from MSDNAA: https://csms.cs.technion.ac.il:4423/

Mobile Service Software Stack

App Service

ControllerControllerProxy

JSON / XMLJSON / XML

HTTPHTTP

Client Cloud

To Visual Studio!

• Preparing the solution

• You will need:

• Azure Mobile Service

To Visual Studio!

• Preparing the solution

• You will need:

• A Client Project

• We will use WPF

• In order to supportWindows Phoneyou will needUniversal App

Adding the Azure Libraries

• Managed by NuGet

Adding the Azure Libraries

• Search for “Azure”

• Add:“Windows AzureMobile Services”and:“Windows AzureStorage”

Visual Studio Project Structure

Solution (*.sln)

Project – Client App Project – Cloud Service

class MyController : ApiController {...

}

class TodoItemController : TableController<TodoItem> {...

}

App Service

CtrlrCtrlrProxy

JSON / XMLJSO / XML

HTTPHTTP

Visual Studio Project Structure

Solution (*.sln)

Project – Client AppProject – Cloud

Service

public static MoblieServiceClient MobileService Defined in framework

class MyProxy { public static async Task<Result> DoWork(Request r) { return await App.MobileService.InvokeApiAsync<Result>(... r ...); }}

App Service

CtrlrCtrlrProxy

JSON / XMLJSON / XML

HTTPHTTP

Async

• The Async keyword makes it easy to write multi-threaded non-blocking calls

public async Task<int> ExampleMethodAsync(){ // . . . .}

string contents = await contentsTask;task<int> result = f(42);int x = await result;

JSON

• JavaScript Object Notation

• A lightweight data-interchange format

• “Self-describing“, easy to parse in code, human-readable

{"employees":[    {"firstName":"John", "lastName":"Doe"},    {"firstName":"Anna", "lastName":"Smith"},    {"firstName":"Peter", "lastName":"Jones"}]}

App Service

CtrlrCtrlrProxy

JSON / XMLJSON / XML

HTTPHTTP

Naming Requirements

• In service project:

class MyController : ApiController // must end with “Controller”

public MyReturnType GetMyMethod(MyParamType p)// must start with Get/Post for HTTP Get/Post methods

Naming Requirements

• In client project:

return await App.MobileService.InvokeApiAsync<MyReturnType , MyParamType>(“mycontroller/mymethod",

MyParamType p HttpMethod.Get, new Dictionary<string, string>() ...);

// mycontroller – name of controller in lowercase without// “controller”// mymethod – name of method in lowercase without “Get/Post”// MyParamType, MyReturnType - parameter & return types// HttpMethod.Get must match method in controller// new Dictionary<string, string>() ... – additional url// parameters

Other Constants

• In client project:

• In class App:public static MobileServiceClient MobileService = new MobileServiceClient("http://myService.azure-mobile.net/", “ApplicationKey");

Other Constants

• Find application keyhere:

Blob Storage

Blob Storage private static readonly string blobStoreConnectionString = "DefaultEndpointsProtocol=https;AccountName=basastorage;AccountKey=" + "MyKey";

private async void StoreBlob(byte[] blobData){ CloudStorageAccount storageAccount = CloudStorageAccount.Parse(blobStoreConnectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("mycontainer"); container.CreateIfNotExists(); CloudBlockBlob blockBlob = container.GetBlockBlobReference("myBlob"); await blockBlob.UploadFromByteArrayAsync(blobData, 0, blobData.Count()); }

Get storage account objectfrom connection string

Blob Storage private static readonly string blobStoreConnectionString = "DefaultEndpointsProtocol=https;AccountName=basastorage;AccountKey=" + "MyKey";

private async void StoreBlob(byte[] blobData){ CloudStorageAccount storageAccount = CloudStorageAccount.Parse(blobStoreConnectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("mycontainer"); container.CreateIfNotExists(); CloudBlockBlob blockBlob = container.GetBlockBlobReference("myBlob"); await blockBlob.UploadFromByteArrayAsync(blobData, 0, blobData.Count()); }

Get the blob storage clientfor the current storage account

Blob Storage private static readonly string blobStoreConnectionString = "DefaultEndpointsProtocol=https;AccountName=basastorage;AccountKey=" + "MyKey";

private async void StoreBlob(byte[] blobData){ CloudStorageAccount storageAccount = CloudStorageAccount.Parse(blobStoreConnectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("mycontainer"); container.CreateIfNotExists(); CloudBlockBlob blockBlob = container.GetBlockBlobReference("myBlob"); await blockBlob.UploadFromByteArrayAsync(blobData, 0, blobData.Count()); }

Get the container reference. This is the handle for the container.

Blob Storage private static readonly string blobStoreConnectionString = "DefaultEndpointsProtocol=https;AccountName=basastorage;AccountKey=" + "MyKey";

private async void StoreBlob(byte[] blobData){ CloudStorageAccount storageAccount = CloudStorageAccount.Parse(blobStoreConnectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("mycontainer"); container.CreateIfNotExists(); CloudBlockBlob blockBlob = container.GetBlockBlobReference("myBlob"); await blockBlob.UploadFromByteArrayAsync(blobData, 0, blobData.Count()); }

This one is self-explanatory :)

Blob Storage private static readonly string blobStoreConnectionString = "DefaultEndpointsProtocol=https;AccountName=basastorage;AccountKey=" + "MyKey";

private async void StoreBlob(byte[] blobData){ CloudStorageAccount storageAccount = CloudStorageAccount.Parse(blobStoreConnectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("mycontainer"); container.CreateIfNotExists(); CloudBlockBlob blockBlob = container.GetBlockBlobReference("myBlob"); await blockBlob.UploadFromByteArrayAsync(blobData, 0, blobData.Count()); }

Get the blob reference. This is handle for the blob.

Blob Storage private static readonly string blobStoreConnectionString = "DefaultEndpointsProtocol=https;AccountName=basastorage;AccountKey=" + "MyKey";

private async void StoreBlob(byte[] blobData){ CloudStorageAccount storageAccount = CloudStorageAccount.Parse(blobStoreConnectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("mycontainer"); container.CreateIfNotExists(); CloudBlockBlob blockBlob = container.GetBlockBlobReference("myBlob"); await blockBlob.UploadFromByteArrayAsync(blobData, 0, blobData.Count()); }

Upload the byte array!

Blob Storage private static readonly string blobStoreConnectionString = "DefaultEndpointsProtocol=https;AccountName=basastorage;AccountKey=" + "MyKey";

private async void StoreBlob(byte[] blobData){ CloudStorageAccount storageAccount = CloudStorageAccount.Parse(blobStoreConnectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("mycontainer"); container.CreateIfNotExists(); CloudBlockBlob blockBlob = container.GetBlockBlobReference("myBlob"); await blockBlob.UploadFromByteArrayAsync(blobData, 0, blobData.Count()); }

Upload the byte array!

Blob Storage private static readonly string blobStoreConnectionString = "DefaultEndpointsProtocol=https;AccountName=basastorage;AccountKey=" + "MyKey";

private async void StoreBlob(byte[] blobData){ CloudStorageAccount storageAccount = CloudStorageAccount.Parse(blobStoreConnectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("mycontainer"); container.CreateIfNotExists(); CloudBlockBlob blockBlob = container.GetBlockBlobReference("myBlob"); await blockBlob.UploadFromByteArrayAsync(blobData, 0, blobData.Count()); }

Also has methods for string, stream and file

Publishing• Don’t forget to publish your service!!!

Publishing• You will need the Master key from the Manage Keys window

Appendix: ESP-8266

•A cheap and relatively simple to use WiFi module

•Under 5$ in eBay

•Basic tutorial in course website

•For advanced users: fully programmable SoC (system-on-chip)

Appendix: ESP-8266• Comes with various baud rates. (Begin guessing with 115200)

• You can see the current baud rate using "AT+CIOBAUD?". (A very stupid command. why?)

• Setting a new baud rate: "AT+CIOBAUD=115200".

• Don’t use the Arduino to convert baud rates (i.e. 115200 to 9600)

• Uses strictly 3.3V. DO NOT CONNECT TO 5V!!!

• Current has some peaks, according to the Internet, the current might jump up to 1A (!!!), this is why we use a capacitor.

• TX/RX logic is also 3.3V. Works fine with Arduino Uno/Mega

Appendix: ESP-8266

~470μF

Recommended