Multi-Tenancy on Azure

Topics: Administration, Troubleshooting
Mar 14, 2011 at 9:21 PM

I'm trying to set up a multi-tenant site on Azure and having a few problems. I already have a site running (not Orchard) at www.mysite.com. So, I set up a default instance of Orchard at orchard.mysite.com and added a tenant at www-new.mysite.com. 

(Setting up the second tenant proved a bit problematic as noted by others here: http://orchard.codeplex.com/discussions/244590 Like them, I had to reboot the web role in order to get the setup wizard to actually start; I got that same NullRef exception.)

Eventually I'll want to migrate my site from www-new to www; and so I tested renaming the host header in the Tenant settings and it throws:

Server Error in '/' Application.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 

Line 17:     <fieldset>
Line 18:         <legend>@T("Database Setup")</legend>
Line 19:         @if (Model.State.CurrentState != TenantState.State.Uninitialized) { 
Line 20:             <div class="warning message">@T("Warning: If you don't know what you're doing you *will* (likely) send this tenant into a downward spiral of irrecoverable disrepair. Have a nice day.")</div>
Line 21:         } else { 


Source File: e:\approot\_WASR_\0\Modules\Orchard.MultiTenancy\Views\Admin\Edit.cshtml    Line: 19 

 

Maybe I can Suspend the tenant and then modify it? Nope. Clicking Suspend throws:

Server Error in '/' Application.

File MySite/Settings.txt already exists

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentException: File MySite/Settings.txt already exists

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace: 

[ArgumentException: File IntelliCrop/Settings.txt already exists]
   Orchard.Azure.AzureFileSystem.CreateFile(String path) in c:\Projects\OrchardHg\src\Orchard.Azure\AzureFileSystem.cs:250
   Orchard.Azure.Environment.Configuration.AzureShellSettingsManager.Orchard.Environment.Configuration.IShellSettingsManager.SaveSettings(ShellSettings settings) in c:\Projects\OrchardHg\src\Orchard.Azure\Environment\Configuration\AzureShellSettingsManager.cs:38
   Orchard.MultiTenancy.Controllers.AdminController.Disable(String name) in c:\Projects\OrchardHg\src\Orchard.Web\Modules\Orchard.MultiTenancy\Controllers\AdminController.cs:136
   lambda_method(Closure , ControllerBase , Object[] ) +94

<snip>

I think I can fix this exception by allowing removing the throw. We'll see here in a few minutes. 

Mar 14, 2011 at 9:28 PM
Edited Mar 14, 2011 at 10:05 PM

Edited.

Mar 14, 2011 at 10:05 PM

Here's the code fix that solves both exceptions:

C:\Projects\OrchardHg\src\Orchard.Azure\Environment\Configuration\AzureShellSettingsManager.cs

void IShellSettingsManager.SaveSettings(ShellSettings settings) {
    var content = ComposeSettings(settings);
    var filePath = _fileSystem.Combine(settings.Name, SettingsFilename);
    
    Orchard.FileSystems.Media.IStorageFile file;
    if (_fileSystem.FileExists(filePath))
    {
        file = _fileSystem.GetFile(filePath);
    }
    else
    {
        file = _fileSystem.CreateFile(filePath);
    }

    using (var stream = file.OpenWrite()) {
        using (var writer = new StreamWriter(stream)) {
            writer.Write(content);
        }
    }

    _events.Saved(settings);
}

Coordinator
Mar 15, 2011 at 12:35 AM
Edited Mar 15, 2011 at 12:36 AM

Could you please submit this as a patch? (if you haven't already)

Mar 15, 2011 at 1:18 AM

I hadn't; my Hg repo has some business-specific stuff in it, so I attached the patch to this bug: http://orchard.codeplex.com/workitem/17215

Cheers.

Coordinator
Mar 15, 2011 at 1:21 AM

Thanks!