Website Snapshot with Composite Windows Azure Web Role

This is a follow up on doing plugins for the Composit Windows Azure Web Role. I created a snapshot pluging providing functionlity to create snapshots and restore them again of the websites.

Motivation for this was that whenever I am working on some Composite C1 Package and need to test it, I used to install a new website with the Web Platform Installer and try out the package. Then to make things easier I created a copy of the site after it was configured, such I always could just copy the folder locally and start that site with WebMatrix. 

Sometime down the path, I found my self using more time on creating a site for testing then I wanted to and now I have a solution thats even easier for me.

SnapShot Plugin

As shown in my post Empowered by the Composite Windows Azure Web Role I showed how easy one could create a plugin for the Web Role running the websites. This is what I am using in this example also.

The endpoints for the plugin is as follows and implementation can be found at https://gist.github.com/s093294/8595109.

    [RoutePrefix("api/snapshots")]
    public class SnapShotController : ApiController
    {
        public readonly IStore store;
        public readonly WebsiteSettingsController websitesettings;
        
        [HttpGet]
        [Route("{websitename}")]
        public IHttpActionResult GetSnapShots(string websitename)

        [HttpPut]
        [Route("{websitename}/{snapshotname}")]
        public async Task<IHttpActionResult> ApplySnapShot(string websitename, string snapshotname)

        [HttpPost]
        [Route("")]
        public IHttpActionResult CreateSnapShot(string websitename)

        
    }

The plugin is using OWIN to host the endpoints on a port specified in the Web Role Configuration:

        public Task InitializePluginAsync()
        {
            var endpoint = RoleEnvironment.
                CurrentRoleInstance.InstanceEndpoints["SnapShotServiceEndpoint"];
            string baseUri = string.Format("{0}://{1}",
                endpoint.Protocol, endpoint.IPEndpoint);
            Trace.TraceInformation(baseUri);

            IUnityContainer container = CompositeWebRole.DependencyResolver.Container;

            _app = WebApp.Start(new StartOptions(url: baseUri), 
                (appbuilder) => new Startup().Configuration(appbuilder,
                    new UnityDependencyResolver(container)));
            
            return Task.FromResult<object>(null);
        }

That is all that is needed to do such a extension to the Composite Windows Azure Web Role. This means I can now work on some azure cloud service for testing and when I am done I can reset it with a call like this : http://{deploymentname}.cloudapp.net:{configuration_port}/api/snapshots/{website_name}/{snapshot}

It also means I could have Azure Job Schedular request that endpoint every 8 hours and use it as a demo site for things and have it automatic reset.

I will create a blog post with a video showing this in action when at my recording machine.



comments powered by Disqus