Sunday, August 29, 2010

Umbraco CMS - complete install on Windows Azure (the Microsoft cloud)

We use the Umbraco CMS a lot at work - it's widely regarded as one of (if not the) best CMSs out there in the .NET world. We've also done quite a bit of R&D work on Microsoft Azure cloud offering and this blog post shares a bit of that knowledge (all of the other guides out there appear to focus on getting the Umbraco database running on SQL Azure, but not how to get the Umbraco server-side application itself up and running on Azure). The cool thing is that Umbraco comes up quite nicely on Azure, with only config changes needed (no code changes).

So, first let's review the toolset / platforms I used:

* Umbraco 4.5.2, built for .NET 3.5
* Latest Windows Azure Guest OS (1.5 - Release 201006-01)
* Visual Studio 2010 Professional
* SQL Express 2008 Management Studio
* .NET 3.5 sp1


Step one is simply to get Umbraco running happily in VS 2010 as a regular ASP.NET project. The steps to achieve this are well documented here. Test your work by firing up Umbraco locally, accessing the admin console and generating a bit of content (XSLTs / Macros / Documents etc.) before progressing further. (The key to working efficiently with Azure is to always have a working case to fall back on, instead of wondering what bit of your project is not cloud-friendly).

Then use these steps to make your Umbraco project "Azure-aware" . Again, test your installation by deploying to the Azure Dev Compute and Storage Fabric on your local machine and testing that Umbraco works as it should before going to production. The Azure Dev environment is by no means perfect (see below) or a true synonym for Azure Production, but it's a good check nonetheless.

Now we need to use the SQL Azure Migration Wizard tool to migrate the Umbraco SQL Express database. I used v3.3.6 (which worked fine with SQL Express contrary to some of the comments on the site) to convert the Umbraco database to its SQL Azure equivalent - the only thing the migration tool has to change is add a clustered index on one of the tables (dbo.umbracoUserLogins) as follows - everything else migrates over to SQL Azure easily:



CREATE CLUSTERED INDEX [ci_azure_fixup_dbo_umbracoUserLogins] ON [dbo].[umbracoUserLogins]
(
[userID]
)WITH (IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF)
GO

Then create a new database in SQL Azure and re-play the script generated by AzureMW into it to create the db schema and standing data that Umbraco expects. To connect to it, you'll replace a line like this in the Umbraco web.config:

<add key="umbracoDbDSN" value="server=.\SQLExpress;database=umbraco452;user id=xxx;password=xxx" />


with a line like this:

<add key="umbracoDbDSN" value="server=tcp:<<youraccountname>>.database.windows.net;database=umbraco;user id=<<youruser>>@<<youraccount>>;password=<<yourpassword>>" />

So we now have the Umbraco database running in SQL Azure, and the Umbraco codebase itself wrapped using an Azure WebRole and deployed to Azure as a package. If we do this using the Visual Studio tool set, we get:

19:27:18 - Preparing...
19:27:19 - Connecting...
19:27:19 - Uploading...
19:29:48 - Creating...
19:31:12 - Starting...
19:31:52 - Initializing...
19:31:52 - Instance 0 of role umbraco452_net35 is initializing
19:38:35 - Instance 0 of role umbraco452_net35 is busy
19:40:15 - Instance 0 of role umbraco452_net35 is ready
19:40:16 - Complete.

Note the total time taken - Azure is deploying a new VM image for you when it does this, it's not just deploying a web app to IIS, so the time taken is always ~ 13 minutes, give or take. I wish it was quicker..



Final comments

If you deploy and it takes longer than ~13 minutes, then double check the common Azure gotchas. In my experience they are:

1. Missing assemblies in production - so your project runs fine on the Dev Fabric and just hangs in Production on deploy - for Umbraco you need to make sure that Copy Local is set to true for cms.dll, businesslogic.dll and of course umbraco.dll so that they get packaged up.

2. Forgetting to change the default value of DiagnosticsConnectionString in ServiceConfiguration.cscfg (by default it wants to persist to local storage which is inaccessible in production - you'll need to use an Azure storage service and update the connection string to match, e.g. your ServiceConfiguration.cscfg should look something like this:

<?xml version="1.0"?>
<ServiceConfiguration serviceName="UmbracoCloudService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
<Role name="umbraco452_net35">
<Instances count="1" />
<ConfigurationSettings>
<Setting name="DiagnosticsConnectionString" value="DefaultEndpointsProtocol=https;AccountName=travelinkce;AccountKey=youraccountkey/>
</ConfigurationSettings>
</Role>
</ServiceConfiguration>


You also need to run Umbraco in full-trust mode, otherwise you will get a security exception when Umbraco tries to read files that are not inside its own "local store" as defined by the .NET CAS (Code Access Security) sub system running on the production Azure VM. In other words, you need the enableNativeCodeExecution property set to true in your ServiceDefinition.csdef like so:

<?xml version="1.0" encoding="utf-8"?>

<ServiceDefinition name="UmbracoCloudService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WebRole name="umbraco452_net35" enableNativeCodeExecution="true">
    <InputEndpoints>
      <InputEndpoint name="HttpIn" protocol="http" port="80" />
    </InputEndpoints>
    <ConfigurationSettings>
      <Setting name="DiagnosticsConnectionString" />
    </ConfigurationSettings>
  </WebRole>
</ServiceDefinition>



The Azure development tools (Fabric etc.) are quite immature in my opinion - very slow to start up (circa one minute) and simply crash when you've done something wrong rather than give a meaningful error message and then exit (for example, when trying to access a local SQL Server Express database (which is wrong - fair enough), the loadbalancer simply crashed with a System.Net.Sockets.SocketException{"An existing connection was forcibly closed by the remote host"}. I have the same criticism of the Azure production system - do a search to see how many people spin their wheels waiting for their roles to deploy with no feedback as to what is going / has gone wrong. Azure badly needs more dev-friendly logging output.

I couldn't get the .NET 4.0 build of Umbraco to work (and it should, .NET 4.0 is now supported on Azure). The problem appears to lie in missing sections in the machine.config file on my Azure machine that I haven't had the time or inclination to dig into yet.

You'll also find that the following directories do not get packaged up into your Azure deployment package by default: xslt, css, scripts, masterpages. To get around this quickly, I just put an empty file in each directory to force their inclusion in the build. If these directories are missing, you will be unable to create content in Umbraco.


Exercises for the reader

* Convert the default InProc session state used by Umbraco to SQLServer mode (otherwise you will have a problem once you scale out beyond one instance on Azure). Starting point is this article - http://blogs.msdn.com/b/sqlazure/archive/2010/08/04/10046103.aspx, but google for errata to the script - the original script supplied does not work out of the box.

* Use an Azure XDrive or similar to store content in one place and cluster Umbraco.

Wednesday, August 18, 2010

Using Ninject as your Dependency Injection container in ASP.NET MVC 3

MVC 3 Preview 1 has been available for a few weeks now from Microsoft, with Preview 2 scheduled for release sometime next month.

As a web development framework, MVC 3 is pretty cool - simple to set up and start using, with a terse, clean syntax courtesy of the new Razor view engine. Coupled with Entity Framework 4 (supporting both code-first generation of database schemas and wrapping existing database schemas), MVC 3 + EF 4 has the makings of a very good web development stack.

If you're interested in using Ninject as the Dependency Injection (DI) container in MVC 3, then you'll find the code below interesting - I couldn't find this anywhere else on the web so ended up writing it. It's the required implementation of the System.Web.Mvc.IMvcServiceLocator that gets instantiated and used in the Application_Start method in Global.asax.cs.

Using DI with MVC 3 makes a lot of sense - we use it to decouple concrete implementations from the interface that we code against so that we can quickly swap in alternate implementations, e.g. a quick, self-contained in-memory database for unit testing using Moq or similar.

This link from Brad Wilson shows how to set up Microsoft Unity as the dependency injection container and this presentation from Phil Haack gives a fleeting, tantalising glimpse of how the Ninject equivalent might look but there's nowhere to get the complete code you need to get it working!

So I put the two together in order to use Ninject as my DI container. Here's the code (with zero comments as per my normal coding standard):

using System.Web.Mvc;
using System;
using System.Collections.Generic;
using Ninject;

namespace AdminApp.Models
{

public class NinjectMvcServiceLocator : IMvcServiceLocator
{
public IKernel Kernel { get; private set; }

public NinjectMvcServiceLocator(IKernel kernel)
{
Kernel = kernel;
}

public object GetService(Type serviceType)
{
try
{
return Kernel.Get(serviceType);
}
catch (Ninject.ActivationException e)
{
throw new System.Web.Mvc.ActivationException("PAK", e);
}
}


public IEnumerable<tservice> GetAllInstances<tservice>()
{
try
{
return Kernel.GetAll<tservice>();
}
catch (Ninject.ActivationException e)
{
throw new System.Web.Mvc.ActivationException("PAK", e);
}
}

public IEnumerable<object> GetAllInstances(Type serviceType)
{
try
{
return Kernel.GetAll(serviceType);
}
catch (Ninject.ActivationException e)
{
throw new System.Web.Mvc.ActivationException("PAK", e);
}
}

public TService GetInstance<tservice>()
{
try
{
return Kernel.Get<tservice>();
}
catch (Ninject.ActivationException e)
{
throw new System.Web.Mvc.ActivationException("PAK", e);
}
}

public TService GetInstance<tservice>(string key)
{
try
{
return Kernel.Get<tservice>(key);
}
catch (Ninject.ActivationException e)
{
throw new System.Web.Mvc.ActivationException("PAK", e);
}
}

public object GetInstance(Type serviceType)
{
try
{
return Kernel.Get(serviceType);
}
catch (Ninject.ActivationException e)
{
throw new System.Web.Mvc.ActivationException("PAK", e);
}
}

public object GetInstance(Type serviceType, string key)
{
try
{
return Kernel.Get(serviceType, key);
}
catch (Ninject.ActivationException e)
{
throw new System.Web.Mvc.ActivationException("PAK", e);
}
}


public void Release(object instance)
{
try
{
Kernel.Release(instance);
}
catch (Ninject.ActivationException e)
{
throw new System.Web.Mvc.ActivationException("PAK", e);
}
}



}
}





And here's how to instantiate and use it in Global.asax.cs:

var kernel = new StandardKernel(new NinjectRegistrationModule());
var locator = new NinjectMvcServiceLocator(kernel);
MvcServiceLocator.SetCurrent(locator);


Finally, here's a sample NinjectRegistrationModule which maps the implementation I want onto the generic interface that my code consumes:

using Ninject.Modules;
using AdminApp.Controllers;

namespace AdminApp
{
class NinjectRegistrationModule : NinjectModule
{
public override void Load()
{
Bind<ISpecialRepository>().To<DbSpecialRepository>().InRequestScope();
}
}
}

Friday, July 23, 2010

Effect of the SCEA study guide on the exam

The SCEA study guide book - especially chapter nine - is already having an effect on the exam. And that effect is interesting, mostly positive but with some negatives as well.

In general, it is fair to say that the overall standard of submissions has improved, and a lot of submissions clearly contain cues from chapter nine of the book - naming conventions, diagram layout, adoption of the server A and B spec approach for the deployment diagram - it's all there in a lot of submissions.

The book has made some of the submissions more anodyne / bland / standardized, which in turn makes me a little sentimental for the past. There's nothing like trying to traverse a crazy class diagram late at night for keeping your brain sharp!

In my opinion, a small but not insignificant percentage of candidates (a bit less than 10%) actually end up submitting a **worse** assignment under the influence of the book, and for a very interesting reason. If you buy the book and read it and aren't an architect, then you will have an incomplete understanding of the concepts covered within it. By extension, when you apply the book material to your submission, there is a very good chance that you will make mistakes that are pretty glaring. So the book will make your submission worse, not better.

As a corollary, if you buy the book and really get the material, your application of that new-found material on top of your already substantial knowledge and skills will result in a strong submission.

In summary then, the book is not a magic book.

The interesting medium / long-term question is whether or not the exam should always have a pass rate of X% and a fail rate of Y% or if it is acceptable to have X approach 100% as a result of the book (that's not happening but clearly it could).

Saturday, March 27, 2010

Book - feedback so far

The book has just gone back to the printers for a second run. Apparently the first print run (a few thousand I think?) was chewed up by Amazon and direct pre-orders. It's fantastic for that many people to have the book and I really hope it helps you in preparing for the exam.

So, the feedback so far: the reviews on Amazon (both .com and .co.uk) are for the old book, not the new one. Amazon just copied the reviews across (the last one was written two years before the new book published).

So all I've got to go on are comments that I've received directly. Broadly speaking, reviewers fall into two camps:

1. Those who like the ~200 page guide / map to a much larger body of research material (happy);

2. Those who want / expect to find all of the revision material in one book (not so happy).

Our goal was always to write a book that did not replicate the reams of material that exist for the JEE platform. We simply saw no point in doing that. Instead, we wanted to write a book that the candidate could use to:

1. Construct a revision schedule for Part One;

2. Understand how to approach Part Two - constructing your own solution for a given business problem using the JEE platform;

3. Prepare the candidate for Part Three - defending your Part Two submission and explaining how you solution satisfies various NFRs (non-functional requirements).

Broadly speaking, I think we've hit the goals we set. There is an errata list that will be sent to the publisher for the second print and will be published here as well for the purchasers of the first run.

Tuesday, January 26, 2010

SCEA book publication and shipment dates



The book has gone to the printers! It comes off the press on Monday February 1st and gets to Pearson's warehouse on February 4th. From there it usually takes a week to get to Amazon (in the US). Here's the Amazon US and Amazon UK links. It's also available for the Kindle.

People who placed pre-orders for hard copy editions will receive their shipment first - shipped direct from Pearson's warehouse next week.

As far as the online edition goes, the Rough Cut disappears after the final update (which matches the printed book) and it then becomes part of the regular Safari Library and is accessible to all subscribers.

If these dates change, I'll put out another update. It will be fantastic to see the book finally out there!

Sunday, November 29, 2009

Book - chapter nine available for download

I've put a PDF copy of chapter nine up on www.box.net for download here. Chapter nine is two things - a seminal chapter in terms of the exam content it covers (Parts II and III of the SCEA exam) and also one that Safari Rough Cuts (SRC) keep missing out on in updating it. The version of the book on SRC is a lot older than this version. I'll keep this download link live until SRC is updated with the latest version. Enjoy.

Thursday, November 26, 2009

Google Go overview for JEE and .NET architects / developers

A few days ago, Google released a pre-release / early look copy of a new programming language and platform - Google Go - for general consumption and feedback. After working with Go for a couple of days, I took my notes and thoughts on how it compares to the Java (J2EE / JEE) and .NET platforms - specifically as far as enterprise computing goes - and wrote them up into this article. All feedback appreciated.

From the Conclusion: "Go has the potential to completely supplant both C and C++ in the systems programming space and that is clearly it's first goal, but it also has the potential to do much more than that - to reach into the enterprise computing / web+application tier as well. It would be short-sighted in this day and age to design a platform that was restricted to low-level systems programming only, when most companies invest far more time and effort in building applications that are used by consumers to communicate, collaborate, transact ecommerce and more. In this author's opinion, Go has the legs to go further".

Another book update (aka where is it..)

The book is still moving through pre-production at Pearson. I'm sure a good number of you will be wondering what kind of impetus can be administered to push it along and I feel the same way myself!

It looks like the book content got caught up in a major upgrade to Safari Rough Cuts that is just about sorted now. A new version has just published, but I know that it does not have the latest chapter nine content that I wrote last month. Chapter nine is a key chapter in the book, focusing as it does on the JustBuildIt scenario that I outlined at JavaOne 2009 and solves it completely. This chapter maps onto Parts II and III of the exam, where candidates download a business scenario of equal complexity and have to propose and defend a solution to it.

I'm waiting to see when this chapter will show up on Rough Cuts. If it's only a few days away, I'll write another post advising that it's there. But if the delay is going to be as long as the previous delay (essentially four - six weeks to get some content updated), then I'll publish chapter nine as a PDF file on www.box.net, like the other sample chapter and the JavaOne 2008 and 2009 slides. Again, apologies for the delay - I'm pushing as hard as I can.

Thursday, October 22, 2009

Addressing book comments on previous post

I just wanted to address some of the comments posted against the previous post in a standalone post (posting my comments against previous comments inline isn't a great way for people to see replies).

A new version of the book was pushed to Rough Cuts late last week and there is another one waiting to go as well. As I understand it from Pearson, Safari are in the middle of a software upgrade at the mo, hence the tardiness in pushing updated content onto Rough Cuts.

Once, the next version of the book makes it onto Rough Cuts, I'll be happy that it represents the content for most of the chapters that you'll see in the published book, i.e. go ahead and use it to revise. The one exception is chapter nine, where I consider the content in that chapter to be the bare minimum you need to provide in part two of the exam to pass. We'll be beefing up the UML diagrams and associated English text in that chapter. So the content in chapter nine is correct, but not yet sufficient, for part two.

Thursday, October 15, 2009

SCEA study guide - progress update

We're pretty much finished with the book edits now. One chapter still looks light and that content will be finished this weekend. But we've underestimated the time the publication process takes at Pearson. Greg tells me that we're looking at late December / early January for the book to be physically on the bookshelves.

Apologies for setting expectations of mid-October in my blog posts - I didn't realise the time the publication process takes. To mitigate this publication delay, we'll be getting the Rough Cuts content updated with the latest version as soon as possible.

Saturday, September 12, 2009

Addressing Rough Cuts feedback received

Since the book draft has been released on Safari Rough Cuts, I've received feedback on it, both as blog comments and also directly through the Rough Cuts feedback mechanism.

Focusing on the areas of improvement that people have commented on:

1. The final version of the book is significantly longer than the rough cuts version, but it is no weighty tome either. The whole point of the book is to focus on the material that we believe is directly relevant to the JEE Architect exam, as opposed to the JEE platform itself;

2. The next version of the book contains chapter six (JEE security) which is missing from the current Rough Cuts version - that was a trade-off that we took - to get the book on Rough Cuts in order to get reader feedback, without chapter six; and

3. The next version of the book contains a completed chapter nine - a fully-worked Part Two and Three solution to an assignment (the JustBuildIt business problem) of similar complexity to the exam assignments.

Thanks for all the feedback so far - it helps us to make the book better. Unfortunately, time does not permit me to respond to feedback left anonymously, but rest assured that your comments have been read. Finally, we're still shooting for the October date to production.

Sunday, August 30, 2009

Book update

Well, the book edits continue apace, and most of the artwork has been sent to the Pearson graphics team to be transformed from the raw, blocky diagrams that we have created into beautiful images for the book.

We're basically left with chapter six and nine edits now. There's a bank holiday tomorrow so I'm planning on using that to get my work done and then send it to the editors for review. We're almost there!

Humphrey

Wednesday, July 01, 2009

SCEA study guide now on Rough Cuts

Well, the book draft has finally made it onto Rough Cuts here. All feedback is truly appreciated and we'll be looking to get a more rounded / completed version up as soon as possible.

Sunday, June 21, 2009

Sample SCEA book chapter for download - web tier

In anticipation of the full book going up on Rough Cuts any day now, I wanted to share one of the chapters to get early feedback on it. The chapter I'm sharing is the third chapter focusing on the web tier portion of the exam and is still in draft status, but with the exception of the graphics needed, is more complete than not. All feedback appreciated. Link to chapter.

Friday, June 19, 2009

SCEA study guide book update

Just a short update on the book for all of the comments asking for an update. I put the content on the Pearson FTP server for peer review and editing the Saturday before JavaOne. Unfortunately it's taking longer than expected to get it pushed through that review process - I'm asking pretty regularly and I'll keep asking on your behalf. As soon as it goes up on Rough Cuts I'll let you guys know.. thanks for the continued interest in the book!

Thursday, June 11, 2009

Slides from JavaOne BOF on the SCEA exam

I've posted the slides for my BOF talk at JavaOne - enjoy! (including the obvious typo on slide 16).

Sample assignment for the SCEA exam - part two

So, as a follow-up to part one of this little series, below is the exact list of deliverables that you are required to develop for part two of the exam.

It is your task to create an architecture and design for the System under Discussion (SuD) with the given business domain model, information provided above and requirements in the use cases. The architecture must be built using the JEE platform. All deliverables will be accepted as HTML only and each diagram must be UML compliant.

1.Create a class diagram for the SuD. Public method names referenced in other UML diagrams (e.g. sequence diagrams) should be provided.

2.Create a Component diagram for the SuD showing the components used in the system and their interaction. Examples of components are EJBs, Servlets, JSPs, major POJOs (Plain Old Java Objects) and important Managers / Controllers / Design Pattern implementations.

3.Create a Deployment diagram that describes the proposed physical layout of the major tiers of the SuD.

4.Create either a Sequence or Collaboration diagram for each use case provided.

In addition to these UML deliverables, the exam requires you to:

1.List the top three risks and identify a mitigation strategy for each risk.

2.List any assumptions made during the process of coming up with the architecture and design.

Your architecture and design will be graded on how well it supports the requirements detailed in this document and on the clarity of all information provided in both textual and diagrammatic form.

Tuesday, June 09, 2009

Sample assignment for the SCEA exam - part one

Following up on last week's BOF at JavaOne, I promised to put the slides online as well as the expanded version of a sample scenario for part two of the exam. The slides are coming later, and here is the expanded version of the JustBuildIt scenario. As per the talk, the goal here is to expand on this scenario over time and create a fully-worked solution from it. In subsequent posts, I'll be posting the domain model, deliverables and use case diagrams so that you can see the full complexity of a scenario that I believe is of the same complexity as an actual scenario in the architect's exam today.

Enjoy!


You are the architect for JustBuildIt Corporation, an international, vertically-integrated construction company with significant operations in the US and Canada, Europe and the Pacific Rim. JustBuildIt operates its own forests, quarries and steel foundries to supply its own building sites with wood, concrete and steel. This end to end style of operation has helped JustBuildIt to keep its costs of raw material down in an era of soaring commodity prices. The management team has recently concluded a business-wide review from leaves to roots of the entire company and one fact is apparent – JustBuildIt pays a lot of money moving raw materials to construction sites, even when there are materials just as suitable nearby.

JustBuildIt has decided to build a building commodities exchange to allow it and some of its competitors to pool excess capacity in a co-opetition model. In the future, raw materials for a construction site will be sourced through the exchange, rather than exclusively from JustBuildIt inventory.

Based on the management’s report and also interviews with key senior staff, you know the following:

• JustBuildIt have recently invested in an inventory and order management system which tracks capacity of their production facilities and also individual orders coming in from construction sites around the world. This system is accessed via a JMS Queue;

• JustBuildIt have decided to expose the interface to their exchange as a web services API;

• In order to counter accusations of unfairness, JustBuildIt has agreed with all participants that 95% of all transactions to and from the exchange will execute in 5 seconds or less, with the remaining 5% executing in 10 seconds or less;

• The system has an uptime requirement during core working hours (GMT -8 to GMT +8) of 99.99%; and

• The actual placement of orders into the exchange is a manual process – JustBuildIt site foremen place orders daily based on individual construction site requirements.

Sunday, April 26, 2009

Short book update

Just a quick update on the book. As with all things literary, this book has taken on a life of its own, and Mark and I missed our self-set date of end Feb to have the book with Pearsons for final review and publishing. But the good news is that we're close to having a draft copy up on Safari - i.e. we're shooting to have the book up on Safari in the next two weeks. I'll post the link as soon as I have it.

Saturday, March 07, 2009

Presenting at JavaOne 2009 - SCEA Take Two!

Sun have accepted my BOF proposal for JavaOne 2009, so it's time to start looking for flights to SFO again and making sure that the hotel I'm staying at isn't right in the middle of the Tenderloin..

My proposal this year built on the material covered in last year's BOF, and I'll also take time to dig deeper into Part Two of the exam (where a lot of people come a cropper) and work through exactly what the examiners are / aren't looking for and why.

If you're going to JavaOne in this crunch year, looking forward to seeing you at the BOF!