DCSIMG
February 2011 - Posts - Manu Cohen-Yashar's Blog

Manu Cohen-Yashar's Blog

February 2011 - Posts

VM Role is it Infrastructure As A Service?

Windows Azure was released as a platform a service (PAAS) to which you deploy applications. Its largest competitor Amazon EC2 (AWS) was released as an Infrastructure As A Service (IAAS) from which you get machines in the cloud.

AWS is a great success. The reason is because it is simple.
Customers feel safe because they work in a familiar environment – They work on a machine. The only difference is that this machine is not sitting in their local data canter.

There is no doubt that PAAS allows better use of the cloud in term of scalability and availability. It also releases the customer from many responsibilities, Yet it is new and new things takes time to get used to. This is why it is only natural that AWS has a larger market share than Azure.

Amazon understands that the future is probably with PAAS so it released a Java PAAS offer. On the other hand Microsoft understands that currently the market requires a good IAAS solution. It is about to release the VM Role (Currently in beta). With the VM role you get full control on the machine (VM) because you create the image.

Is VM Role really an IAAS solution?

Well Microsoft never said it is. They said that VM Role was maid to allow long configuration process of the environment in which your application should run. 
VM Role is not a true IAAS solution.
The main reason is because you cannot chose the OS.

In a true IAAS solution you can choose between a large verity of different environments (From various Linux environments to All kinds windows servers). You choose a template of starter configuration and of you go. You do not have to supply a VM Image.

I think that Microsoft should think positively of providing a true IAAS Solution along side with Windows Azure.

This is what the markets wants.

Manu  

VM Role Requires Server 2008 R2 SP1

I wanted to work with VM role. The first thing I did of course was to install Hyper-V to enable the creation of new virtual machines.

I created a new virtual machine but when I tried to start it (and install an OS) I got an error "Cannot Identify Virtual Machine …"

I investigated and found out that Hyper-V does not work without installing Windows Server 2008 R2 SP1 first. You can find it here.

Now it works and I can play with VM Role.

Hope this might help

Manu

Watch My Talk About Windows Azure

Two weeks ago I gave a talk introducing Windows Azure and cloud computing in Sela College. There were 30 participant who enjoyed a free Azure presentation.

The talk was given in Hebrew.

In this talk I explained basic concepts about cloud computing and described windows Azure.

I built a simple application and deployed it to the cloud using the new SilverLight portal.

You can watch the show here: Part1, Part2

Enjoy

Manu

State Management in Cloud Applications

Cloud applications are distributed applications by design. There are many instances of roles located on different VMs and everything is load balanced. In Windows Azure there is no sticky load balancing so you can never know which role instance will serve your request. Such an environment introduces the challenge of state management. This is not a new challenge we know it from Asp.Net applications. Now in windows azure we find it everywhere – In web roles and worker roles.

When you create a object and save data in its member you want to keep working with the same object instance because your data is there. In a distributed applications it is not possible because objects instances cannot be shared across VMs.

So all state (information traditionally placed in object members) must be moved to a shared location. Somewhere all instances will have access to the data.

Azure storage is independent of Azure roles so it can function as a common place holder for state. Some data fit great in blobs or tables but usually it is not convenient to save simple data in Azure storage. saving objects in blobs requires serialization, persisting data in tables requires adding partition key and row key to every object.

Well … There one more option. Azure AppFabric Cache.
Azure AppFabric Cache is a distributed cache independent of Azure roles where you can persist objects (the only requirement on the objects is that they should be DataContract serializable) 

It is simple. It is scalable and safe. 
I wrote a little State Manager that I use in my Azure applications. Instead of saving state in my business objects I export it to this state manager.

/// <summary>

/// Provides a State management infrastructure for distributed stateless services which needs to save state (i.e. data)

/// The State management infrastructure is independent and distributed which allows the services to remain stateless.

/// This State management infrastructure is implemented using Azure AppFabric Distributed Cache.

/// </summary>

public static class StateManager

{

  private static DataCacheFactory CacheFactory;

  private static Dictionary<string,DataCacheLockHandle> lockHandle;

 

  static StateManager()

  {

    CacheFactory = new DataCacheFactory();

    lockHandle = new Dictionary<string, DataCacheLockHandle>();

  }

 

  /// <summary>

  /// Get an object which was previously saved in the state manager

  /// </summary>

  /// <param name="stateID"></param>

  /// <param name="key"></param>

  /// <returns></returns>

  public static object GetState(string stateID, string key)

  {

    Contract.Requires(!string.IsNullOrEmpty(stateID));

    Contract.Requires(!string.IsNullOrEmpty(key));

 

    try

    {

      var cache = CacheFactory.GetDefaultCache();

      if (cache == null)

         throw new DataCacheException("Could not create a cache object");

 

       return cache.Get(stateID + key);

    }

    catch (DataCacheException ex)

    {

       if (ex.ErrorCode != 6) //Key referred to does not exist

          Logger.HandleException(ex);

 

        return null;

    }

    catch (Exception ex)

    {

       Logger.HandleException(ex);

       return null;

    }           

  }

 

 

/// <summary>

/// Get an object which was previously saved in the state manager yet lock it for lockDuration

/// </summary>

/// <param name="stateID"></param>

/// <param name="key"></param>

/// <param name="lockDuration"></param>

/// <returns></returns>

public static object GetStateAndLock(string stateID, string key, TimeSpan lockDuration)

{

   Contract.Requires(!string.IsNullOrEmpty(stateID));

   Contract.Requires(!string.IsNullOrEmpty(key));

 

   try

   {

     var cache = CacheFactory.GetDefaultCache();

     if (cache == null)

        throw new DataCacheException("Could not create a cache object");

 

        DataCacheLockHandle handle;

        var result = cache.GetAndLock(stateID + key,
                                      lockDuration, out handle);

                lockHandle[stateID + key] = handle;

                return result;

   }

   catch (DataCacheException ex)

   {

      if (ex.ErrorCode != 6) //Key referred to does not exist

         Logger.HandleException(ex);

 

       return null;

   }

   catch (Exception ex)

   {

       Logger.HandleException(ex);

       return null;

   }           

}

 

/// <summary>

/// Save an object in the state manager

/// </summary>

/// <param name="stateID"></param>

/// <param name="key"></param>

/// <param name="state"></param>

public static void PutState(string stateID, string key, object state)

{

   Contract.Requires(!string.IsNullOrEmpty(stateID));

   Contract.Requires(!string.IsNullOrEmpty(key));

 

   try

   {

     var cache = CacheFactory.GetDefaultCache();

     if (cache == null)

        throw new DataCacheException("Could not create a cache object");

 

     cache.Put(stateID+key, state);

   }

   catch (Exception ex)

   {

       Logger.HandleException(ex);

       return null;

   }           

}

 

 

public static void PutState(string stateID, string key, object state, TimeSpan invalidationTimeout)

{

   Contract.Requires(!string.IsNullOrEmpty(stateID));

   Contract.Requires(!string.IsNullOrEmpty(key));

 

   try

   {

     var cache = CacheFactory.GetDefaultCache();

 

     if (cache == null)

         throw new DataCacheException("Could not create a cache object");

 

      cache.Put(stateID + key, state, invalidationTimeout);

   }

   catch (Exception ex)

   {

       Logger.HandleException(ex);

       return null;

   }           

}

 

 

 /// <summary>

/// Save an object in the state manager and unlock it

/// </summary>

/// <param name="stateID"></param>

/// <param name="key"></param>

/// <param name="state"></param>

public static void PutStateAndUnlock(string stateID, string key, object state)

{

   Contract.Requires(!string.IsNullOrEmpty(stateID));

   Contract.Requires(!string.IsNullOrEmpty(key));

 

   try

   {

     var cache = CacheFactory.GetDefaultCache();

 

     if (cache == null)

         throw new DataCacheException("Could not create a cache object");


    
if (lockHandle.ContainsKey(stateID + key))

     {

       cache.PutAndUnlock(stateID + key, state, lockHandle[stateID + key]);

       lockHandle.Remove(stateID + key)

     }

      else

         cache.Put(stateID + key, state);                  

               

   }

   catch (Exception ex)

   {

       Logger.HandleException(ex);

       return null;

   }           

}

 

/// <summary>

/// Clear an object from the state manager

/// </summary>

/// <param name="stateID"></param>

/// <param name="key"></param>

public static void RemoveState(string stateID, string key)

{

   Contract.Requires(!string.IsNullOrEmpty(stateID));

   Contract.Requires(!string.IsNullOrEmpty(key));

 

   try

   {

     var cache = CacheFactory.GetDefaultCache();

 

     if (cache == null)

         throw new DataCacheException("Could not create a cache object");

 

      cache.Remove(stateID + key);

 

      if (lockHandle.ContainsKey(stateID + key))

         lockHandle.Remove(stateID + key);

    }

   catch (Exception ex)

   {

       Logger.HandleException(ex);

       return null;

   }           

}

}

Enjoy

Manu

How to add a custom icon to WF 4 custom activities (toolbox and designer)

Adding a custom toolbox icon to your custom activity is a simple task yet there are few rules to follow.

To add the custom Icon we use ToolboxBitmap Attribute. like so:

[
ToolboxBitmap(typeof(MyActivity),"myIcon.bmp")]
public sealed class MyActivity : NativeActivity

  1. The icon "myIcon.bmp" must be a bitmap file
  2. The icon must be 16X16 pixels
  3. The icon must be compiled as embedded resource in the current assembly

To display a custom icon in the designer you have to write the following xaml in the activity designer definition:

<sap:ActivityDesigner x:Class="MyActivityDesigner.ActivityDesigner1"

   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

   xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"

   xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation">

    <sap:ActivityDesigner.Icon>

        <DrawingBrush>

            <DrawingBrush.Drawing>

                <ImageDrawing>

                    <ImageDrawing.Rect>

                        <Rect Location="0,0" Size="16,16" ></Rect>

                    </ImageDrawing.Rect>

                    <ImageDrawing.ImageSource>

                       <BitmapImage
                       
UriSource="..\Resources\activityIcon.ico" >
                       </
BitmapImage
>

                    </ImageDrawing.ImageSource>

                </ImageDrawing>

            </DrawingBrush.Drawing>

        </DrawingBrush>

    </sap:ActivityDesigner.Icon>

enjoy

Manu

Windows Azure Reference List

I came across a very good list of references about windows azure

Portal (Product Home)

Windows Azure Platform <http://www.microsoft.com/windowsazure/>

Portal (Developers)

Windows Azure Developer Center <http://msdn.microsoft.com/en-us/windowsazure/default.aspx>

Portal (How-to Index)

Windows Azure Content Indexes <http://msdn.microsoft.com/en-us/library/gg465393.aspx>

Portal (Security & Performance)

Microsoft Global Foundation Services <http://www.globalfoundationservices.com/>

Portal (Benchmarking & Guideline)

Azurescope - Benchmarking and Guidance <http://azurescope.cloudapp.net/>

Portal (Interoperability)

Azure Interoperability <http://www.interoperabilitybridges.com/projects/tag/Azure.aspx>

ROI

Azure ROI Calculator <http://azureroi.cloudapp.net/>

SDK

Active Directory Federation Services 2.0 RTW <http://www.microsoft.com/downloads/en/details.aspx?FamilyID=118C3588-9070-426A-B655-6CEC0A92C10B>

SDK

Windows Identity Foundation <http://www.microsoft.com/downloads/en/details.aspx?FamilyID=EB9C345F-E830-40B8-A5FE-AE7A864C4D76>

SDK

Windows Identity Foundation SDK <http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c148b2df-c7af-46bb-9162-2c9422208504&displaylang=en>

SDK

Windows Azure SDK and Windows Azure Tools for Microsoft Visual Studio (November 2010) <http://www.microsoft.com/downloads/en/details.aspx?FamilyID=7a1089b6-4050-4307-86c4-9dadaa5ed018>

SDK

Windows Azure Platform Training Kit - January Update <http://www.microsoft.com/downloads/en/details.aspx?FamilyID=413E88F8-5966-4A83-B309-53B7B77EDF78>

SDK

Windows Azure AppFabric SDK V2.0 CTP – February Update <http://www.microsoft.com/downloads/en/details.aspx?FamilyID=D89640FC-C552-446E-AEAD-B1E0D940F31B&displaylang=en>

SDK

Windows Azure AppFabric SDK V1.0 - October Update <http://www.microsoft.com/downloads/en/details.aspx?FamilyID=39856a03-1490-4283-908f-c8bf0bfad8a5&displaylang=en>

White Papers

Windows Azure Platform white papers <http://www.microsoft.com/windowsazure/whitepapers/default.aspx>

Training

Windows Azure Training Kit <http://go.microsoft.com/fwlink/?LinkID=130354>

Training

Windows Azure Platform Training Course <http://msdn.microsoft.com/en-us/wazplatformtrainingcourse.aspx>

Training

Channel 9: Building Cloud Applications using the Windows Azure Platform <http://borntolearn.mslearn.net/btl/b/weblog/archive/2011/01/14/your-weekend-look-cloudy-free-windows-azure-training-just-released.aspx>

Training

Channel 9: Cloud Cover <http://channel9.msdn.com/Shows/Cloud+Cover>

Training

Windows Azure Boot Camp <http://www.azurebootcamp.com/>

Training

msdev.com Azure Platform Training Video <http://www.msdev.com/Directory/SearchResults.aspx?productId=12#0,1>

Training

Windows Azure Boot Camp <http://www.windowsazurebootcamp.com/>

Demo

Fabrikam Shipping <http://www.fabrikamshipping.com/>

Demo

Woodgrove Internet Banking <http://woodgrove.cloudapp.net/#/Home>

Code Samples

Codeplex Projects <http://www.codeplex.com/site/search?TagName=azure>

Code Samples

Code Gallery Projects <http://code.msdn.microsoft.com/Project/ProjectDirectory.aspx?TagName=azure>

Code Samples

Windows Azure Samples <http://msdn.microsoft.com/en-us/library/gg432966.aspx>

Forums & Blogs

Windows Azure Team Blog <http://blogs.msdn.com/b/windowsazure/>

Forums & Blogs

SQL Azure Team Blog <http://blogs.msdn.com/b/sqlazure/>

Forums & Blogs

Windows Azure AppFabric Team Blog <http://blogs.msdn.com/b/windowsazureappfabric/>

Forums & Blogs

Windows Azure Platform Forums <http://social.msdn.microsoft.com/Forums/en-US/category/windowsazureplatform>

Forums & Blogs

Jim Nakashima's blog - Cloudy in Seattle <http://blogs.msdn.com/b/jnak/>

Forums & Blogs

Ryan Dunn's blog - Extemporaneous Mumblings <http://dunnry.com/blog/>

Forums & Blogs

Steve Marx's blog - cloud development blog <http://blog.smarx.com/>

Enjoy

Manu

AppFabric Labs Was Upgraded

Azure AppFabric labs was upgraded. No more old portal style…

Now you can enjoy the new Silverlight portal look and feel.

On the way all the namespaces from the last version were deleted. I hope you are not damaged…

More improvements:

  • Ability to choose from a set of available cache sizes and provision a cache of the chosen size
  • Support for upgrading or downgrading between caches from the available sizes dynamically based on your requirements
  • Added client side tracing and client request tracking capabilities for improved diagnosis
  • Performance improvements

Go to : https://portal.appfabriclabs.com and start playing …

image

Manu

What is not supported in AppFabric Azure Cache

Named Cache:
In Windows Server AppFabric Caching Service it is possible to create named caches and provide different configuration characteristics to each cache. For example, one cache with rarely changing data could have a very long time-to-live configured for cached data while another cache containing more temporary data could have a much shorter time-to-live. Furthermore, it is possible to create regions on a single node in the cache cluster and associate searchable tags with cache entries. Neither of these features are implemented in Azure AppFabric Caching which supports only the default cache!

Cache Notifications:
The Windows Server AppFabric Caching Service supports cache notifications which cache clients can subscribe to and receive notification when various operations are performed on the cache and the items contained in it. This feature is not supported in Azure AppFabric Caching Service.

Clusters:
The Windows Server AppFabric Caching Service runs on a cluster of servers that present a unified cache to the client. This service requires IT support to manage and configure the servers. These clusters can be quite large – the documentation, for example, describes the cache management needs of a cluster in the range of 50 cache servers. This IT need disappears in Azure AppFabric Caching since Microsoft handles all service management.

Manu

Azure AppFabric Cache can't work together with Windows Appfabric

Azure appfabric distributed cache is very important for managing state in distributed applications. (I will talk about it in details in my next post) but it has a little unpleasant surprise.

It does not work side by side with Windows Server AppFabric !

If you previously installed Windows Server AppFabric, you must uninstall it before installing the AppFabric CTP SDK. These on-premise and cloud versions of AppFabric are not compatible at this time.

When both are installed Windows Azure Appfabric SDK will use Windows Server AppFabric Microsoft.ApplicationServer.Caching.xxx installed in the GAC instead of the original SDK assemblies.

The configuration will not be parsed correctly. The API will throw MethodNotFound exceptions… nothing works.

I was really unhappy to uninstall Windows Server AppFabric. I hope in the near future both will be able to leave in peace together on my machine.

Manu