Wednesday, 5 September 2018

Microsoft Azure - Applications

Microsoft Azure - Applications


 

Windows Azure is usually misinterpreted as just a hosting solution, but there is a lot more that can be done using Windows Azure. It provides a platform to develop applications using a range of available technologies and programming languages. It offers to create and deploy applications using .net platform, which is Microsoft’s own application development technology. In addition to .net, there are many more technologies and languages supported. For example, Java, PHP, Ruby, Oracle, Linux, MySQL, Python.
Windows Azure applications are scaled by creating multiple instances of the application. The number of instances needed by the application is specified by the developer while hosting the applications. If traffic is increased or decreased on the website or web application it can be managed easily by logging in to Windows Azure management portal and specifying the instances. Load balancing can also be automated which would allow Azure to make the decision itself as when to assign more resources to application.
Web applications support .net, java, python, php and node.js. Tasks such as scaling and backups can be easily automated. A new feature called ‘webjobs’ is available, which is a kind of batch processing service. Webjobs can also be scaled and scheduled. The mobile application platforms supported are Xamarin iOS, Xamarin Android and IOS.
Azure platform is developed in such a way that developers need to concentrate on only the development part and need not worry about other technical stuff outside their domain. Thus most of the administrative work is done by Azure itself.
A marketplace is also set by Azure where its customers can buy applications and services. It is a platform where customers can search applications and deploy them in an easier way. Azure marketplace is available in 88 countries at present. An application purchased from the marketplace can be easily connected to the local development environment by the application developers. The pricing is done using 5 different models, which includes usage-based and monthly fee. Some of the applications are even free of charge.

Microsoft Azure - CDN

Caching is one of the ways for performance improvement. Windows Azure uses caching to increase the speed of cloud services. Content Delivery Network (CDN) puts stuff like blobs and other static content in a cache. The process involves placing the data at strategically chosen locations and caching it. As a result, it provides maximum bandwidth for its delivery to users. Let’s assume an application’s source is far away from the end user and many tours are taken over the internet to fetch data; the CDN offers a very competent solution to improve performance in this case. Additionally, it scales the instant high load in a very efficient manner.

Create a CDN

Step 1 − Login in to your Azure Management Portal.
Step 2 − Click on 'New' at bottom left corner.
Step 3 − Select ‘APP Services’ then ‘CDN’.
Step 4 − Click on ‘Quick Create’. The following screen will come up.
Create a CDN
You will see three fields in the pop up −
  • Subscription − There will be a list of subscriptions you have subscribed to and you can choose from one of them. In this demo, only one option was there in the subscription dropdown, which was ‘BizSpark’, the current subscription.
  • Origin Type − This dropdown will ask to select an origin type. The integrated service will have an option of Web Apps, Cloud Services, Storage and Media Services.
  • Origin URL − This will show the URLs based on the chosen origin type in the dropdown.
Step 5 − Choose one of the options from each dropdown as needed and click ‘Create’. CDN endpoint is created as show in the following image.
Create a CDN Step5

Create CDN for Custom Origin Links

In June 2015, CDN was updated with one more feature where users can specify a custom origin. Earlier only Azure services could be linked to CDN, but now any website can be linked to it using this service.
When we are create a CDN service, in the ‘Origin Type’ dropdown, there is an option ‘Custom Origin’ as shown in the following image, and then you can specify the link in the URL field.
Create CDN for Custom Origin Links

Manage CDN

Step 1 − Click on the Name of the CDN you want to manage in the list displayed in CDN services.
Step 2 − Click on ‘manage cdn’.
Manage CDN
Country filtering − You can allow/bock your website in specified countries. This is going to protect your data for better.
Step 3 − When you click on ‘manage cdn’ you will be taken to the following page in a new tab of your browser.
Step 4 − Click on ‘Country Filtering’ from menu items at the top of screen. Click on ‘Add Country Filter’ button as shown in the following image.
Manage CDN Step4
Step 5 − Specify the directory and select Allow/block.
Manage CDN Step5
Step 6 − Select the country in the next screen and you are done.
Manage CDN Step6
Compression − It allows files to be compressed. You can enable/disable compression. Also you can specify the file type.
Step 7 − Click on ‘Cache Setting’ and scroll down to the bottom of the page.
Step 8 − Select ‘Compression Enabled’ and click ‘Update’ button. By default, compression is disabled.
Manage CDN Step8
Analytics − You can see very useful figures in this section. For example, number of overall hits or in a specific geographic region. The report will also show how many times requests are served from CDN endpoints and how many of them are going back to the original server.
Step 9 − Click on ‘Analytics’ in menu items at the top of the page. You will see a list of all the reports in the left panel as shown in the following image.
Manage CDN Step9
Step 10 − Additionally, you can download the report as an excel file by clicking on the excel icon at the top right corner.

Map a Custom Domain Name

You might want to use a custom domain name instead of CDN endpoint that is autogenerated by Azure service. Windows Azure has provided a new feature that allows you to map a custom domain name to his application’s CDN endpoint. Let’s see how it is done in Azure Portal.
Step 1 − Click on ‘Manage Domain’ Button on the bottom horizontal menu.
Map CDN
Step 2 − Enter the custom URL in the text box and its done.
Map CDN

How to Manage Table using Azure Storage Explorer

Storing a table does not mean relational database here. Azure Storage can store just a table without any foreign keys or any other kind of relation. These tables are highly scalable and ideal for handling large amount of data. Tables can be stored and queried for large amount of data. The relational database can be stored using SQL Data Services, which is a separate service.
The three main parts of service are −
  • Tables
  • Entities
  • Properties
For example, if ‘Book’ is an entity, its properties will be Id, Title, Publisher, Author etc. Table will be created for a collection of entities. There can be 252 custom properties and 3 system properties. An entity will always have system properties which are PartitionKey, RowKey and Timestamp. Timestamp is system generated but you will have to specify the PartitionKey and RowKey while inserting data into the table. The example below will make it clearer. Table name and Property name is case sensitive which should always be considered while creating a table.

How to Manage Tables Using PowerShell

Step 1 − Download and install Windows PowerShell as discussed previously in the tutorial.
Step 2 − Right-click on ‘Windows PowerShell’, choose ‘Pin to Taskbar’ to pin it on the taskbar of your computer.
Step 3 − Choose ‘Run ISE as Administrator’.

Creating a Table

Step 1 − Copy the following commands and paste into the screen. Replace the highlighted text with your account.
Step 2 − Login into your account.
$StorageAccountName = "mystorageaccount" 
$StorageAccountKey = "mystoragekey" 
$Ctx = New-AzureStorageContext $StorageAccountName - StorageAccountKey 
$StorageAccountKey
Step 3 − Create a new table.
$tabName = "Mytablename" 
New-AzureStorageTable Name $tabName Context $Ctx 
The following image shows a table being created by the name of ‘book’.
Create Table
You can see that it has given the following end point as a result.
https://tutorialspoint.table.core.windows.net/Book
Similarly, you can retrieve, delete and insert data into the table using preset commands in PowerShell.

Retrieve Table

$tabName = "Book" 
Get-AzureStorageTable Name $tabName Context $Ctx

Delete Table

$tabName = "Book"
Remove-AzureStorageTable Name $tabName Context $Ctx

Insert rows into Table

function Add-Entity() { 
   [CmdletBinding()] 
 
   param( 
      $table, 
      [String]$partitionKey, 
      [String]$rowKey, 
      [String]$title, 
      [Int]$id, 
      [String]$publisher, 
      [String]$author 
   )  
   
   $entity = New-Object -TypeName Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity 
      -ArgumentList $partitionKey, $rowKey 
  
   $entity.Properties.Add("Title", $title) 
   $entity.Properties.Add("ID", $id) 
   $entity.Properties.Add("Publisher", $publisher) 
   $entity.Properties.Add("Author", $author) 
   
   
   $result = $table.CloudTable.Execute(
      [Microsoft.WindowsAzure.Storage.Table.TableOperation]
      ::Insert($entity)) 
}
  
$StorageAccountName = "tutorialspoint" 
$StorageAccountKey = Get-AzureStorageKey -StorageAccountName $StorageAccountName 
$Ctx = New-AzureStorageContext $StorageAccountName - StorageAccountKey 
   $StorageAccountKey.Primary  

$TableName = "Book"
  
$table = Get-AzureStorageTable Name $TableName -Context $Ctx -ErrorAction Ignore 
 
#Add multiple entities to a table. 
Add-Entity -Table $table -PartitionKey Partition1 -RowKey Row1 -Title .Net -Id 1
   -Publisher abc -Author abc 
Add-Entity -Table $table -PartitionKey Partition2 -RowKey Row2 -Title JAVA -Id 2 
   -Publisher abc -Author abc 
Add-Entity -Table $table -PartitionKey Partition3 -RowKey Row3 -Title PHP -Id 3
   -Publisher xyz -Author xyz 
Add-Entity -Table $table -PartitionKey Partition4 -RowKey Row4 -Title SQL -Id 4 
   -Publisher xyz -Author xyz

Retrieve Table Data

$StorageAccountName = "tutorialspoint" 
$StorageAccountKey = Get-AzureStorageKey - StorageAccountName $StorageAccountName 
$Ctx = New-AzureStorageContext  StorageAccountName $StorageAccountName -
   StorageAccountKey $StorageAccountKey.Primary; 

$TableName = "Book"
  
#Get a reference to a table. 
$table = Get-AzureStorageTable Name $TableName -Context $Ctx  

#Create a table query. 
$query = New-Object Microsoft.WindowsAzure.Storage.Table.TableQuery

#Define columns to select. 
$list = New-Object System.Collections.Generic.List[string] 
$list.Add("RowKey") 
$list.Add("ID") 
$list.Add("Title") 
$list.Add("Publisher") 
$list.Add("Author")
  
#Set query details. 
$query.FilterString = "ID gt 0" 
$query.SelectColumns = $list 
$query.TakeCount = 20
 
#Execute the query. 
$entities = $table.CloudTable.ExecuteQuery($query)

#Display entity properties with the table format. 

$entities  | Format-Table PartitionKey, RowKey, @{ Label = "Title"; 
Expression={$_.Properties["Title"].StringValue}}, @{ Label = "ID"; 
Expression={$_.Properties[“ID”].Int32Value}}, @{ Label = "Publisher"; 
Expression={$_.Properties[“Publisher”].StringValue}}, @{ Label = "Author"; 
Expression={$_.Properties[“Author”].StringValue}} -AutoSize 
The output will be as shown in the following image.
Retrive Table

Delete Rows from Table

$StorageAccountName = "tutorialspoint" 
 
$StorageAccountKey = Get-AzureStorageKey - StorageAccountName $StorageAccountName 
$Ctx = New-AzureStorageContext  StorageAccountName $StorageAccountName - 
   StorageAccountKey $StorageAccountKey.Primary  

#Retrieve the table. 
$TableName = "Book" 
$table = Get-AzureStorageTable -Name $TableName -Context $Ctx -ErrorAction 
Ignore 

#If the table exists, start deleting its entities. 
if ($table -ne $null) { 
   #Together the PartitionKey and RowKey uniquely identify every   
   #entity within a table.
 
   $tableResult = $table.CloudTable.Execute(
      [Microsoft.WindowsAzure.Storage.Table.TableOperation] 
      ::Retrieve(“Partition1”, "Row1")) 
  
   $entity = $tableResult.Result;
 
   if ($entity -ne $null) {
      $table.CloudTable.Execute(
         [Microsoft.WindowsAzure.Storage.Table.TableOperation] 
         ::Delete($entity)) 
   } 
}
The above script will delete the first row from the table, as you can see that we have specified Partition1 and Row1 in the script. After you are done with deleting the row, you can check the result by running the script for retrieving rows. There you will see that the first row is deleted.
While running these commands please ensure that you have replaced the accountname with your account name, accountkey with your account key.

How to Manage Table using Azure Storage Explorer

Step 1 − Login in to your Azure account and go to your storage account.
Step 2 − Click on the link ‘Storage explorer’ as shown in purple circle in the following image.
Storage Explorer
Step 3 − Choose ‘Azure Storage Explorer for Windows’ from the list. It is a free tool that you can download and install on your computer.
Step 4 − Run this program on your computer and click ‘Add Account’ button at the top.
Step 5 − Enter ‘Storage Account Name’ and ‘Storage account Key’ and click ‘Test Access. The buttons are encircled in following image.
Storage Account Name
Step 6 − If you already have any tables in storage you will see in the left panel under ‘Tables’. You can see the rows by clicking on them.

Create a Table

Step 1 − Click on ‘New’ and enter the table name as shown in the following image.
Create New Table

Insert Row into Table

Step 1 − Click on ‘New’.
Step 2 − Enter Field Name.
Step 3 − Select data type from dropdown and enter field value.
Select Data From Dropdown
Step 4 − To see the rows created click on the table name in the left panel.
Azure Storage Explorer is very basic and easy interface to manage tables. You can easily create, delete, upload, and download tables using this interface. This makes the tasks very easy for developers as compared to writing lengthy scripts in Windows PowerShell.