Skip to content

Commit

Permalink
adding the notion of automatically executing deployment & env. valida…
Browse files Browse the repository at this point in the history
…tion actions.

git-svn-id: https://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools/trunk@2040 079b0acf-d9fa-0310-9935-e5ade295c882
  • Loading branch information
ayenderahien committed Feb 18, 2009
1 parent 893fca4 commit 1a03139
Show file tree
Hide file tree
Showing 21 changed files with 239 additions and 92 deletions.
2 changes: 1 addition & 1 deletion Rhino.ServiceBus.Host/Actions/InstallAction.cs
Expand Up @@ -33,7 +33,7 @@ public void Execute(ExecutingOptions options)

var host = new RhinoServiceBusHost();
host.SetArguments(options.Assembly, options.ConfigFile);
host.CreateQueues();
host.InitialDeployment(installer.Account);
}
}
}
9 changes: 9 additions & 0 deletions Rhino.ServiceBus.Host/ProjectInstaller.cs
Expand Up @@ -4,6 +4,7 @@
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.ServiceProcess;


namespace Rhino.ServiceBus.Host
Expand All @@ -19,6 +20,14 @@ public string ServiceName
}
}

public ServiceAccount Account
{
get
{
return serviceProcessInstaller1.Account;
}
}

public ProjectInstaller()
{
InitializeComponent();
Expand Down
9 changes: 7 additions & 2 deletions Rhino.ServiceBus.Host/RhinoServiceBusHost.cs
@@ -1,4 +1,6 @@

using System;

namespace Rhino.ServiceBus.Host
{
using System.ServiceProcess;
Expand Down Expand Up @@ -38,10 +40,13 @@ public void DebugStart(string[] arguments)
OnStart(arguments);
}

public void CreateQueues()
public void InitialDeployment(ServiceAccount account)
{
var tmpHost = new RemoteAppDomainHost(asm, cfg);
tmpHost.CreateQueues();
var user = account.ToString();
if (account == ServiceAccount.User)
user = Environment.UserDomainName;
tmpHost.InitialDeployment(user);
tmpHost.Close();

}
Expand Down
45 changes: 45 additions & 0 deletions Rhino.ServiceBus/Actions/CreateLogQueueAction.cs
@@ -0,0 +1,45 @@
using System;
using System.Messaging;
using Rhino.ServiceBus.Internal;
using Rhino.ServiceBus.MessageModules;
using Rhino.ServiceBus.Msmq;

namespace Rhino.ServiceBus.Actions
{
public class CreateLogQueueAction : IDeploymentAction
{
private readonly MessageLoggingModule messageLoggingModule;
private readonly ITransport transport;

public CreateLogQueueAction(MessageLoggingModule messageLoggingModule, ITransport transport)
{
this.messageLoggingModule = messageLoggingModule;
this.transport = transport;
}

public void Execute(string user)
{
// will create the queues if they are not already there
messageLoggingModule.Init(transport);
var queuePath = MsmqUtil.GetQueuePath(new Endpoint
{
Uri = messageLoggingModule.LogQueue
}).QueuePath;

using (var queue = new MessageQueue(queuePath))
{
queue.SetPermissions(user,
MessageQueueAccessRights.DeleteMessage |
MessageQueueAccessRights.DeleteJournalMessage |
MessageQueueAccessRights.GenericRead |
MessageQueueAccessRights.GenericWrite |
MessageQueueAccessRights.GetQueuePermissions |
MessageQueueAccessRights.PeekMessage |
MessageQueueAccessRights.ReceiveJournalMessage |
MessageQueueAccessRights.ReceiveMessage |
MessageQueueAccessRights.WriteMessage,
AccessControlEntryType.Allow);
}
}
}
}
38 changes: 38 additions & 0 deletions Rhino.ServiceBus/Actions/CreateQueuesAction.cs
@@ -0,0 +1,38 @@
using System;
using System.Messaging;
using Rhino.ServiceBus.Msmq;

namespace Rhino.ServiceBus.Actions
{
public class CreateQueuesAction : IDeploymentAction
{
private readonly IQueueStrategy queueStrategy;
private readonly IServiceBus serviceBus;

public CreateQueuesAction(IQueueStrategy queueStrategy, IServiceBus serviceBus)
{
this.queueStrategy = queueStrategy;
this.serviceBus = serviceBus;
}

public void Execute(string user)
{
// will create the queues if they are not already there
var queues = queueStrategy.InitializeQueue(serviceBus.Endpoint);
foreach (var queue in queues)
{
queue.SetPermissions(user,
MessageQueueAccessRights.DeleteMessage |
MessageQueueAccessRights.DeleteJournalMessage |
MessageQueueAccessRights.GenericRead |
MessageQueueAccessRights.GenericWrite |
MessageQueueAccessRights.GetQueuePermissions |
MessageQueueAccessRights.PeekMessage |
MessageQueueAccessRights.ReceiveJournalMessage |
MessageQueueAccessRights.ReceiveMessage |
MessageQueueAccessRights.WriteMessage,
AccessControlEntryType.Allow);
}
}
}
}
2 changes: 1 addition & 1 deletion Rhino.ServiceBus/Actions/IDeploymentAction.cs
Expand Up @@ -2,6 +2,6 @@ namespace Rhino.ServiceBus.Actions
{
public interface IDeploymentAction
{
void Execute();
void Execute(string user);
}
}
@@ -1,6 +1,6 @@
namespace Rhino.ServiceBus.Actions
{
public interface IValidationAction
public interface IEnvironmentValidationAction
{
void Execute();
}
Expand Down
5 changes: 5 additions & 0 deletions Rhino.ServiceBus/Hosting/AbstractBootStrapper.cs
Expand Up @@ -2,6 +2,7 @@
using System.Reflection;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Rhino.ServiceBus.Actions;
using Rhino.ServiceBus.Impl;
using Rhino.ServiceBus.Internal;

Expand Down Expand Up @@ -30,6 +31,10 @@ public void InitializeContainer(IWindsorContainer windsorContainer)
protected virtual void ConfigureContainer()
{
container.Register(
AllTypes.Of<IDeploymentAction>()
.FromAssembly(Assembly),
AllTypes.Of<IEnvironmentValidationAction>()
.FromAssembly(Assembly),
AllTypes
.FromAssembly(Assembly)
.Where(type =>
Expand Down
22 changes: 11 additions & 11 deletions Rhino.ServiceBus/Hosting/DefaultHost.cs
Expand Up @@ -6,14 +6,15 @@
using Castle.Windsor.Configuration.Interpreters;
using log4net;
using log4net.Config;
using Rhino.ServiceBus.Actions;
using Rhino.ServiceBus.Impl;
using Rhino.ServiceBus.Internal;
using Rhino.ServiceBus.MessageModules;
using Rhino.ServiceBus.Msmq;

namespace Rhino.ServiceBus.Hosting
{
public class DefaultHost : MarshalByRefObject, IDisposable
public class DefaultHost : MarshalByRefObject, IApplicationHost
{
private readonly ILog logger = LogManager.GetLogger(typeof(DefaultHost));
private string assebmlyName;
Expand Down Expand Up @@ -137,20 +138,19 @@ public override object InitializeLifetimeService()
return null; //singleton
}

public void CreateQueues(string asmName)
public void InitialDeployment(string asmName, string user)
{
InitailizeBus(asmName);

var queueStrategy = container.Resolve<IQueueStrategy>();
// will create the queues if they are not already there
queueStrategy.InitializeQueue(serviceBus.Endpoint);
foreach (var action in container.ResolveAll<IDeploymentAction>())
{
action.Execute(user);
}

if(container.Kernel.HasComponent(typeof(MessageLoggingModule))==false)
return;
var transport = container.Resolve<ITransport>();
var loggingModule = container.Resolve<MessageLoggingModule>();
// will create the queues if they are not already there
loggingModule.Init(transport);
foreach (var action in container.ResolveAll<IEnvironmentValidationAction>())
{
action.Execute();
}
}
}
}
10 changes: 10 additions & 0 deletions Rhino.ServiceBus/Hosting/IApplicationHost.cs
@@ -0,0 +1,10 @@
using System;

namespace Rhino.ServiceBus.Hosting
{
public interface IApplicationHost : IDisposable
{
void Start(string assembly);
void InitialDeployment(string assembly, string user);
}
}
104 changes: 59 additions & 45 deletions Rhino.ServiceBus/Hosting/RemoteAppDomainHost.cs
Expand Up @@ -6,14 +6,14 @@

namespace Rhino.ServiceBus.Hosting
{
using System.Reflection;
using System.Text;
using System.Reflection;
using System.Text;

public class RemoteAppDomainHost
{
private readonly Type boosterType;
private readonly Type boosterType;
private readonly string assembly;
private string path;
private readonly string path;
private HostedService current;
private string configurationFile;

Expand All @@ -24,7 +24,7 @@ public RemoteAppDomainHost Configuration(string configFile)
}

public RemoteAppDomainHost(Type boosterType)
:this(boosterType.Assembly.Location, null)
: this(boosterType.Assembly.Location, null)
{
this.boosterType = boosterType;
}
Expand All @@ -40,19 +40,19 @@ public void Start()
{
HostedService service = CreateNewAppDomain();
current = service;
try
{
service.Start();
}
catch (ReflectionTypeLoadException e)
{
var sb = new StringBuilder();
foreach (var exception in e.LoaderExceptions)
{
sb.AppendLine(exception.ToString());
}
throw new TypeLoadException(sb.ToString(), e);
}
try
{
service.Start();
}
catch (ReflectionTypeLoadException e)
{
var sb = new StringBuilder();
foreach (var exception in e.LoaderExceptions)
{
sb.AppendLine(exception.ToString());
}
throw new TypeLoadException(sb.ToString(), e);
}
}

private HostedService CreateNewAppDomain()
Expand All @@ -69,27 +69,18 @@ private HostedService CreateNewAppDomain()
}

protected virtual HostedService CreateRemoteHost(AppDomain appDomain)
{
object instance = appDomain.CreateInstanceAndUnwrap("Rhino.ServiceBus",
"Rhino.ServiceBus.Hosting.DefaultHost");
var hoster = (DefaultHost) instance;

if (boosterType != null)
hoster.SetBootStrapperTypeName(boosterType.FullName);

return new HostedService
{
CreateQueues = ()=>hoster.CreateQueues(assembly),
Stop = ()=>
{
hoster.Dispose();
AppDomain.Unload(appDomain);
},
Start = () => hoster.Start(assembly)
};
}

private string ConfigurationFile
{
object instance = appDomain.CreateInstanceAndUnwrap("Rhino.ServiceBus",
"Rhino.ServiceBus.Hosting.DefaultHost");
var hoster = (DefaultHost)instance;

if (boosterType != null)
hoster.SetBootStrapperTypeName(boosterType.FullName);

return new HostedService(hoster, assembly, appDomain);
}

private string ConfigurationFile
{
get
{
Expand All @@ -110,19 +101,42 @@ public void Close()

#region Nested type: HostedService

protected class HostedService
protected class HostedService
{
public Action Start;
public Action Stop;
public Action CreateQueues;
private readonly IApplicationHost hoster;
private readonly string assembly;
private readonly AppDomain appDomain;

public HostedService(IApplicationHost hoster, string assembly, AppDomain appDomain)
{
this.hoster = hoster;
this.assembly = assembly;
this.appDomain = appDomain;
}

public void Stop()
{
hoster.Dispose();
AppDomain.Unload(appDomain);
}

public void Start()
{
hoster.Start(assembly);
}

public void InitialDeployment(string user)
{
hoster.InitialDeployment(assembly, user);
}
}

#endregion

public void CreateQueues()
public void InitialDeployment(string user)
{
HostedService service = CreateNewAppDomain();
service.CreateQueues();
service.InitialDeployment(user);
}
}
}

0 comments on commit 1a03139

Please sign in to comment.