• Windows Azure Accelerators for Web Roles or How to Convert Azure into a dedicated hosting elastic automated solution

    Published by on July 13th, 2011 4:02 pm under Azure, Cloud Computing, Emerging Technology

    3 Comments

    Yesterday Nathan announced the release of the Windows Azure Accelerators for Web Roles. If you are using Windows Azure today, this can be a pain relief if you’ve got used to wait 15 minutes (or more) every time you deploy to Windows Azure (and hope nothing was wrong in the package to realize after then that you’ve lost 15 minutes of your life).

    Also, as the title says, and as Maarten says in his blog, if you have lots of small websites you don’t want to pay for 100 different web roles because that will be lots of money. Since Azure 1.4 you can use the Full IIS support but the experience is not optimal from the management perspective because it requires to redeploy each time you add a new website to the cscfg.

    In short, the best way I can describe this accelerator is:

    It transform your Windows Azure web roles into a dedicated elastic hosting solution with farm support and a very nice IIS web interface to manage the websites.

    I won’t go into much more details on the WHAT, since Nathan and Maarten already did a great job in their blogs. Instead I will focus on the HOW. We all love that things work, but when they don’t work you want to know where to touch. So, below you can find the blueprints of the engine.

     

    image

     

    image

    Below some key code snippets that shows how things work.

    The snippet below is the WebRole Entry Point Run method. We are spinning the Synchronization Service here that will block the execution. Since this is a web role, it will launch the IIS process as well and execute the code as usual. 

    public override void Run()
    {
        Trace.TraceInformation("WebRole.Run");
    
        // Initialize SyncService
        var localSitesPath = GetLocalResourcePathAndSetAccess("Sites");
        var localTempPath = GetLocalResourcePathAndSetAccess("TempSites");
        var directoriesToExclude = RoleEnvironment.GetConfigurationSettingValue("DirectoriesToExclude").Split(';');
        var syncInterval = int.Parse(RoleEnvironment.GetConfigurationSettingValue("SyncIntervalInSeconds"), CultureInfo.InvariantCulture);
    
        this.syncService = new SyncService(localSitesPath, localTempPath, directoriesToExclude, "DataConnectionstring");
        this.syncService.SyncForever(TimeSpan.FromSeconds(syncInterval));
    }
    

    Then the other important piece is the SyncForever method. What this method does is the following:

    • Update the IIS configuration using the IIS ServerManager API by reading from table storage
    • Synchronize the WebDeploy package from blob to local storage (point 4 in the diagram)
    • Deploy the sites using WebDeploy API, by taking the package from local storage
    • Creates and copies the WebDeploy package from IIS (if something changed)
    public void SyncForever(TimeSpan interval)
    {
        while (true)
        {
            Trace.TraceInformation("SyncService.Checking for synchronization");
    
            try
            {
                this.UpdateIISSitesFromTableStorage();
            }
            catch (Exception e)
            {
                Trace.TraceError("SyncService.UpdateIISSitesFromTableStorage{0}{1}", Environment.NewLine, e.TraceInformation());
            }
    
            try
            {
                this.SyncBlobToLocal();
            }
            catch (Exception e)
            {
                Trace.TraceError("SyncService.SyncBlobToLocal{0}{1}", Environment.NewLine, e.TraceInformation());
            }
    
            try
            {
                this.DeploySitesFromLocal();
            }
            catch (Exception e)
            {
                Trace.TraceError("SyncService.DeploySitesFromLocal{0}{1}", Environment.NewLine, e.TraceInformation());
            }
    
            try
            {
                this.PackageSitesToLocal();
            }
            catch (Exception e)
            {
                Trace.TraceError("SyncService.PackageSitesToLocal{0}{1}", Environment.NewLine, e.TraceInformation());
            }
    
            Trace.TraceInformation("SyncService.Synchronization completed");
    
            Thread.Sleep(interval);
        }
    }
    

    My advice: If you are using Windows Azure today don’t waste more time doing lengthy deployments Smile Download the Windows Azure Accelerators for Web Roles.

    Enjoy!

Tags