Infrastructure’s journey from on-premise to the Cloud

Notes of my efforts to expand my understanding of Implementing Microsoft Azure Infrastructure Solutions.

  • On-Premise Infrastructure – You manage your own systems and network on site. That include Domain Controller, File Servers, FTP Servers, Web and Database servers.
  • Data Centers Infrastructure – Dedicated space for housing infrastructure with High Bandwidth internet and redundant power sources. Data Centers also provides dust free environment, efficient cooling and air ventilation systems and high physical security.
  • Data Centers Managed Services Infrastructure – Data Centers manages the servers, provides LAN extension ( site – to – site) and all the benefits of Data Center as well as infrastructure administration.
  • Virtualization – Then came virtualization. That enabled to have multiple servers (VMs) run on the same server and share resources.
  • Data Centers Managed Services (with virtualized) Infrastructure – Applied virtualization with Data Center managed services added huge benefits for customers. Data centers can now create highly dense infrastructure. At this point, customers become Tenant.
  • Infrastructure as a Service – Finally the Self serving offering to the customer to provision their resources through web based or api based interface.

Cloud Characteristics are Self Service, Resources are pooled across multiple customers, Elasticity, Reliability and Utility modeled service

Categories of Cloud Services

  • SaaS – is a software license and delivery model in which software is licensed on a subscription basis and is centrally hosted. Web based email service, Sales Force, Adobe Creative Cloud and ESRI ArcGIS Online etc are example of Software as a Service.
  • PaaS – provides a platform allowing customers to develop, run and manage web applications without complexity of building and maintaining the infrastructure. Azure Cloud Services ( Web Role, Worker Role ) are example of Platform as a Service.
  • IaaS – provides virtualized computing resources over the internet. Azure Virtual Machine is an example of Infrastructure as a Service.

* based on cloud ranger Microsoft azure training.

Azure Accounts

Notes of my efforts to expand my understanding of Implementing Microsoft Azure Infrastructure Solutions.

To sign up with Azure, you can use either Microsoft Account ( [email protected], [email protected] etc) or Organization Account.

  • Azure Account – Is a mapping between Microsoft/Organization account to access the azure resources. Azure account is created at Azure Account Center. (account.windowsazure.com). You can have multiple Azure Subscriptions under one Azure account. It also determines the Azure Usage and assigns the Account Administrator.

A person who creates the Azure account becomes the Account Administrator and a Default Service Administrator.

  • Azure Subscriptions – Organize how cloud services are accessed. you need to have subscription in order to access the cloud services. Subscription controls how resource usage is reported, billed and paid. Under single Azure Account, you an have single or multiple subscriptions. Each subscription is billed and paid separately. Each subscription has an Unique ID.
  • Administrative Roles – Account Administrator – Every azure account can have only One account administrator. Account administrator can access the Account Center. He / She can create subscriptions, cancel subscriptions and change billing. Only Account Admin can add / remove Service Administrators.

Account Administrator does not have any access to service in that subscription. He / She can not use any resources on Azure.

Azure automatically assigns Account Administrator as default service administrator when a subscription is created.

  • Administrative Roles – Service Administrator – All subscriptions need a Service Administrator. One service administrator per subscription. This authorize access to the Azure Management Portal.
  • Administrative Roles – Co-Administrator – Can have upto 200 co-administrators. Co- Admins can not delete service Administrators. can not see the billing details on subscription. They can not change associations of subscriptions to Azure Directories.

* based on cloud ranger Microsoft azure training.

Azure PowerShell Basics

Notes of my efforts to expand my understanding of Implementing Microsoft Azure Infrastructure Solutions.

To start with Azure PowerShell, download Azure PowerShell modules from Download Azure PowerShell

There are 3 modules installed as part of Installation

  1. Azure ( Azure Service Management )
  2. Azure Resource Manager
  3. Azure Profile

Once Downloaded and Installed you can open PowerShell ISE and Azure module will automatically loaded

For any reason, if you don’t see Azure related modules loaded in ISE the path is following-

import-module "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Azure.psd1"
or
import-module -Name Azure

Directory: C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager
Directory: C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement
Directory: C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\Storage

There are two ways to Access the Azure Subscription through PowerShell

  • Using Management Certificate – This is more of a traditional approach. You download publishsettings file which contains information to connect to specific subscription.

Sign in to Azure Portal first, and then run following command in PowerShell

PS H:\> Get-AzurePublishSettingsFile

This will open a new browser window, and automatically downloads .publishsettings file for your Azure sing-in subscription. You can then use following command to import the file –

PS H:\> Get-AzureSubscription

To view the subscription. You can run various command like

PS H:\> Get-AzureVM
PS H:\> Get-AzureVMImage

To Remove the Subscription

PS H:\> Remove-AzureSubscription
cmdlet Remove-AzureSubscription at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
SubscriptionName: MaulikSoniWinAzureMSDNUltimate
WARNING: The default subscription is being removed. Use Select-AzureSubscription -Default <subscriptionName> to select a new default subscription.

Signing in to Azure with Microsoft / Organization Account – This is the preferred way to connect by Microsoft.

PS H:\> Add-AzureAccount

Id                                   Type Subscriptions       Tenants            
--                                   ---- -------------       -------            
ms_soni@                 User 3e015a41-4d41-49... {36e2465f-5d29-4...

This will open a Sign in dialog for Azure. Once signed in you will see the subscription info.

Azure Virtual Networks

Notes of my efforts to expand my understanding of Implementing Microsoft Azure Infrastructure Solutions.

What is Virtual Network (VNET) – Customer managed secure , isolated virtual networks. It’s network overlay that can be configured in Azure.

Azure VNET Attributes –

1. Services and VMs that are part of the same VNET can access each other
2. Subscription can have as many as100 VNETs. Default is 10.3. Each VNET can have as many Subnets
4. Virtual Networks are limited to single region
5. No IPv6 support
6. All services deployed within a VNET can access internet (by default)

Three possible solution you may possibly have for cloud services

  1. No VNET – Not have a VNET at all. No virtual networks because you don’t need. The VM is directly connected to internet.
  2. Cloud Only VNETs – is created when a VNET is created in Azure. Clouds and VMs are accessed through endpoints. When we create cloud only network, don’t have to consider on premise network addressing.No VPN devices required since we are not doing site-to-site networking.
  3. Hybrid Networks – Extension from on-premises to cloud.Is a connection of On-premise network with the Cloud VNET. Connecting from on-premises data center to cloud through a site-to-site tunnel. It requires a VPN device.

VNET Address space and Subnets – When we create VNET, specify topology to Azure how the network will be.

Private Address Spaces – is the range VMs and Services can use. Non-routable. Public network can not access private address space. Specified in CIDR notation ( Classless Inter-Domain Routing)

https://www.linkedin.com/redir/invalid-link-page?url=10%2e0%2e0%2e0 /8 : https://www.linkedin.com/redir/invalid-link-page?url=10%2e0%2e0%2e0 - https://www.linkedin.com/redir/invalid-link-page?url=10%2e255%2e255%2e255
https://www.linkedin.com/redir/invalid-link-page?url=172%2e16%2e0%2e0./12 : https://www.linkedin.com/redir/invalid-link-page?url=172%2e16%2e0%2e0 - https://www.linkedin.com/redir/invalid-link-page?url=172%2e31%2e255%2e255
https://www.linkedin.com/redir/invalid-link-page?url=192%2e168%2e0%2e0 /16 : https://www.linkedin.com/redir/invalid-link-page?url=192%2e168%2e0%2e0 - https://www.linkedin.com/redir/invalid-link-page?url=192%2e168%2e255%2e255

Subnets – breaks up the network for more manageable sections. All services can be accessed across subnets. Network security groups can be utilized to implement ACLs.

Subnet 1: https://www.linkedin.com/redir/invalid-link-page?url=192%2e168%2e1%2e0%2F24 - Frontend Subnet
Subnet 2: https://www.linkedin.com/redir/invalid-link-page?url=192%2e168%2e2%2e0%2F24   Backend Subnet

Closure Compiler – Postman Request

What is the Closure Compiler?

The Closure Compiler is a tool for making JavaScript download and run faster. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what’s left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls.

ref: https://developers.google.com/closure/compiler/

Clsoure RESTFul API end point – http://closure-compiler.appspot.com/compile

CURL request –

curl “http://closure-compiler.appspot.com/compile&#8221; -H “Origin: null” -H “Accept-Encoding: gzip, deflate” -H “Accept-Language: en-US,en;q=0.8,es;q=0.6” -H “Upgrade-Insecure-Requests: 1” -H “User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36” -H “Content-Type: application/x-www-form-urlencoded” -H “Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8” -H “Cache-Control: max-age=0”  -H “Connection: keep-alive” -H “DNT: 1” –data “js_code=++++function+hello”%”28name”%”29+”%”7B”%”0D”%”0A++++++”%”2F”%”2F+Greets+the+user”%”0D”%”0A++++++alert”%”28″%”27Hello”%”2C+”%”27+”%”2B+name”%”29″%”3B”%”0D”%”0A++++”%”7D”%”0D”%”0A++++hello”%”28″%”27New+user”%”27″%”29″%”3B”%”0D”%”0A++++&compilation_level=WHITESPACE_ONLY&output_format=text&output_info=compiled_code” –compressed

To import CURL to Postman -> select Import Raw Text and paste it.

postman_curl_closure

Spinner Control inside Fragmented View with Toast notification

package soni.maulik.booksbyauthor;
import android.content.Context;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_main, container, false);
//Populate the spinner in the fragment
Spinner spinner = (Spinner) rootView.findViewById(R.id.authorspinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(rootView.getContext(), R.array.authors,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id)
{
String selected = parentView.getItemAtPosition(position).toString();
Context context = parentView.getContext();
CharSequence text = selected;
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
TextView bk = (TextView) rootView.findViewById(R.id.booktext);
switch (position){
case 0:
bk.setText(getResources().getString(R.string.Allen));
break;
case 1:
bk.setText(getResources().getString(R.string.Thomas));
break;
case 2:
bk.setText(getResources().getString(R.string.Dan));
break;
case 3:
bk.setText(getResources().getString(R.string.Michael));
break;
case 4:
bk.setText(getResources().getString(R.string.Ravi));
break;
default:
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}
});
return rootView;
}
}
}

Multi-level grouping using Linq

Referenced from Here
I have a list of records with the following structure: (Simplified example!)

class Rate
{
    string Code;
    double InterestFrom;
    double InterestTo;
    double IncomeFrom;
    double IncomeTo;
    double Value;
}

I have a List defined. I need to convert this list to the following simplified structure

class RateList
{
   List<Code> code;
}
class Code
{
    string code;
    List<Interest> interest;
}
class Interest
{
    double InterestFrom;
    double InterestTo;
    List<Income> income;
}
class Income
{
    double IncomeFrom;
    double IncomeTo;
    double Value;
}

And I would like to do this with a single LINQ query. I can work out other solutions but the challenge is to do it within one LINQ statement. Basically, the top-level group is grouped by code. The next level by the values InterestFrom and InterestTo and the lowest level is a list of IncomeFrom, IncomeTo and Value.

Solution:

var rateList = new RateList
               {
                   code = (from r in rates
                           group r by r.Code into g
                           select new Code
                           {
                               code = g.Key,
                               interest = (from i in g
                                           group i by new {i.InterestFrom, i.InterestTo} into g2
                                           select new Interest
                                           {
                                               InterestFrom = g2.Key.InterestFrom,
                                               InterestTo = g2.Key.InterestTo,
                                               income = (from inc in g2
                                                         select new Income
                                                         {
                                                             IncomeFrom = inc.IncomeFrom,
                                                             IncomeTo = inc.IncomeTo,
                                                             Value = inc.Value
                                                         }).ToList()
                                           }).ToList()
                           }).ToList()
               };

ASP.NET MVC Web Api – IE 9 Shows download dialogue on HttpResponseMessage with content

If you are using Jquery File Upload / Kendo File Upload with ASP.NET web api, returning the content cause Download dialog in IE9.

To fix this issue, in your Web api controller use

public HttpResponseMessage ValidateFile(myModel myModel)
{
	var response = Request.CreateResponse(result==false? HttpStatusCode.NotAcceptable:HttpStatusCode.Accepted, result);
        response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
        return response;
}

Creating and Deploying SQL CLR Database Objects

Per MSDN , In addition to the Transact-SQL programming language, you can use .NET Framework languages to create database objects that retrieve and update data. Database objects that are written in managed code are called SQL Server Common Language Run (CLR) database objects.

I am going to take the same Phone Number validation example that MSDN has.
Open up Visual Studio 2012 and create new SQL Server Database Project.
1

Right Click the Project in solution explorer and select Add New Item.
Select SQL CLR C# and select SQLCLR C# User Defined Function. Name it ValidatePhone.cs.
2

Add the following code to validate the phone number using regex-

using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Text.RegularExpressions;

public partial class UserDefinedFunctions
{
    [SqlFunction(IsDeterministic = true, IsPrecise = true)]
    public static SqlBoolean validatePhone(SqlString phone)
    {
        string aNorthAmericanPhoneNumberPattern = @"^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$";
        if (!phone.IsNull)
        {
            Regex regex = new Regex(aNorthAmericanPhoneNumberPattern);
            return regex.IsMatch(phone.Value);
        }
        return true;
    }
}

Right Click the Project and Build the Solution.

Deployment

There are two ways you can deploy the CLR Object to sql server.
1) Right Click the Project in solution explorer and select Publish.At this point Visual Studio can directly publish this object to destination sql server. ( Notice the Generate Script and Publish buttons at the bottom)
2) Manually deploy assembly to SQL server.

3

Errors
error1

Since my destination sql server is sql server 2008 I need to make following change. Go to Project Properties and select Project Settings. The Target platform should be sql server 2008. ( or whatever version of sql server you are trying to deploy this solution to)
sol1

Permission Levels

1) SAFE : Only internal computation and local data access are allowed. SAFE is the most restrictive permission set. Code executed by an assembly with SAFE permissions cannot access external system resources such as files, the network, environment variables, or the registry.

2) EXTERNAL_ACCESS:EXTERNAL_ACCESS assemblies have the same permissions as SAFE assemblies, with the additional ability to access external system resources such as files, networks, environmental variables, and the registry.

3) UNSAFE: UNSAFE allows assemblies unrestricted access to resources, both within and outside SQL Server. Code executing from within an UNSAFE assembly can also call unmanaged code.

You can change the permission level as per your requirements from Project Properties Tab :
sol2

Manually Deploy Assembly to SQL Server

1) Open SQL Server Management Studio and create new Query.

2) Create the assembly in the server by adding the following TSQL Query

CREATE ASSEMBLY ValiatePhoneNumbers from 'c:\ValiatePhoneNumbers.dll' 
WITH PERMISSION_SET = SAFE;

3) he procedure, function, aggregate, user-defined type, or trigger must then be created in the instance of SQL Server. If the ValidatePhonenumbers assembly contains a method named validatePhone in the Procedures class, the following Transact-SQL can be added to the query to create a procedure called hello in SQL Server.

CREATE FUNCTION [dbo].[validatePhone]
(@phone NVARCHAR (4000))
RETURNS BIT
AS
 EXTERNAL NAME [ValiatePhoneNumbers].[UserDefinedFunctions].[validatePhone]

4) Calling the SQL CLR Object method

print dbo.validatePhone('614-777-4455')

NOTE
By default, CLR integration is turned off in SQL Server. To use CLR database objects, you must enable CLR integration. To do this, use the “clr enabled” option of the sp_configure stored procedure.

sp_configure 'clr enabled', 1;
GO
RECONFIGURE;
GO 

The TRUSTWORTHY database property is used to indicate whether the instance of SQL Server trusts the database and the contents within it. By default, this setting is OFF, but can be set to ON by using the ALTER DATABASE statement

ALTER DATABASE Test SET TRUSTWORTHY ON;