From ea3fecd0987fe0d118f4b9bcf3fdb3d754f7296d Mon Sep 17 00:00:00 2001 From: David Duffett Date: Tue, 2 Aug 2011 16:13:16 +0100 Subject: [PATCH] NServiceBus.Host service deployment --- .../Dsl/NServiceBusHost/Extension.cs | 27 ++++++ .../NServiceBusHostConfigurator.cs | 88 +++++++++++++++++++ .../NServiceBusHost/NServiceBusHostOptions.cs | 25 ++++++ .../LocalNServiceBusHostTask.cs | 84 ++++++++++++++++++ .../RemoteNServiceBusHostTask.cs | 77 ++++++++++++++++ product/dropkick/dropkick.csproj | 5 ++ 6 files changed, 306 insertions(+) create mode 100644 product/dropkick/Configuration/Dsl/NServiceBusHost/Extension.cs create mode 100644 product/dropkick/Configuration/Dsl/NServiceBusHost/NServiceBusHostConfigurator.cs create mode 100644 product/dropkick/Configuration/Dsl/NServiceBusHost/NServiceBusHostOptions.cs create mode 100644 product/dropkick/Tasks/NServiceBusHost/LocalNServiceBusHostTask.cs create mode 100644 product/dropkick/Tasks/NServiceBusHost/RemoteNServiceBusHostTask.cs diff --git a/product/dropkick/Configuration/Dsl/NServiceBusHost/Extension.cs b/product/dropkick/Configuration/Dsl/NServiceBusHost/Extension.cs new file mode 100644 index 00000000..63b0914b --- /dev/null +++ b/product/dropkick/Configuration/Dsl/NServiceBusHost/Extension.cs @@ -0,0 +1,27 @@ +// Copyright 2007-2010 The Apache Software Foundation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. +namespace dropkick.Configuration.Dsl.NServiceBusHost +{ + using System; + using FileSystem; + + public static class Extension + { + public static void NServiceBusHost(this ProtoServer server, Action action) + { + var cfg = new NServiceBusHostConfigurator(new DotNetPath()); + action(cfg); + server.RegisterProtoTask(cfg); + } + } +} \ No newline at end of file diff --git a/product/dropkick/Configuration/Dsl/NServiceBusHost/NServiceBusHostConfigurator.cs b/product/dropkick/Configuration/Dsl/NServiceBusHost/NServiceBusHostConfigurator.cs new file mode 100644 index 00000000..1dfee9a0 --- /dev/null +++ b/product/dropkick/Configuration/Dsl/NServiceBusHost/NServiceBusHostConfigurator.cs @@ -0,0 +1,88 @@ +// Copyright 2007-2010 The Apache Software Foundation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. +namespace dropkick.Configuration.Dsl.NServiceBusHost +{ + using DeploymentModel; + using FileSystem; + using Tasks; + using Tasks.NServiceBusHost; + + public class NServiceBusHostConfigurator : + BaseProtoTask, + NServiceBusHostOptions + { + readonly Path _path; + string _serviceName; + string _displayName; + string _description; + string _instanceName; + string _location; + string _exeName; + string _password; + string _username; + + public NServiceBusHostConfigurator(Path path) + { + _path = path; + } + + public void ExeName(string name) + { + _exeName = name; + } + + public void Instance(string name) + { + _instanceName = name; + } + + public void LocatedAt(string location) + { + _location = location; + } + + public void PassCredentials(string username, string password) + { + _username = username; + _password = password; + } + + public void ServiceName(string name) + { + _serviceName = name; + } + + public void ServiceDisplayName(string name) + { + _displayName = name; + } + + public void ServiceDescription(string description) + { + _description = description; + } + + public override void RegisterRealTasks(PhysicalServer site) + { + var location = _path.GetPhysicalPath(site, _location, true); + if (site.IsLocal) + { + site.AddTask(new LocalNServiceBusHostTask(_exeName, location, _instanceName, _username, _password, _serviceName, _displayName, _description)); + } + else + { + site.AddTask(new RemoteNServiceBusHostTask(_exeName, location, _instanceName, site, _username, _password, _serviceName, _displayName, _description)); + } + } + } +} \ No newline at end of file diff --git a/product/dropkick/Configuration/Dsl/NServiceBusHost/NServiceBusHostOptions.cs b/product/dropkick/Configuration/Dsl/NServiceBusHost/NServiceBusHostOptions.cs new file mode 100644 index 00000000..c6f4a55a --- /dev/null +++ b/product/dropkick/Configuration/Dsl/NServiceBusHost/NServiceBusHostOptions.cs @@ -0,0 +1,25 @@ +// Copyright 2007-2010 The Apache Software Foundation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. +namespace dropkick.Configuration.Dsl.NServiceBusHost +{ + public interface NServiceBusHostOptions + { + void ExeName(string name); + void Instance(string name); + void LocatedAt(string location); + void PassCredentials(string username, string password); + void ServiceName(string name); + void ServiceDisplayName(string name); + void ServiceDescription(string description); + } +} \ No newline at end of file diff --git a/product/dropkick/Tasks/NServiceBusHost/LocalNServiceBusHostTask.cs b/product/dropkick/Tasks/NServiceBusHost/LocalNServiceBusHostTask.cs new file mode 100644 index 00000000..23f360d4 --- /dev/null +++ b/product/dropkick/Tasks/NServiceBusHost/LocalNServiceBusHostTask.cs @@ -0,0 +1,84 @@ +// Copyright 2007-2010 The Apache Software Foundation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. +namespace dropkick.Tasks.NServiceBusHost +{ + using CommandLine; + using DeploymentModel; + using FileSystem; + using Prompting; + + public class LocalNServiceBusHostTask : + BaseTask + { + private readonly LocalCommandLineTask _task; + private readonly PromptService _prompt = new ConsolePromptService(); + + public LocalNServiceBusHostTask(string exeName, string location, string instanceName, string username, string password, string serviceName, string displayName, string description) + { + string args = string.IsNullOrEmpty(instanceName) + ? "" + : " /instance:" + instanceName; + + if (username != null && password != null) + { + var user = username; + var pass = password; + if (username.ShouldPrompt()) + user = _prompt.Prompt("Win Service '{0}' UserName".FormatWith(exeName)); + if (shouldPromptForPassword(username, password)) + pass = _prompt.Prompt("Win Service '{0}' For User '{1}' Password".FormatWith(exeName, username)); + + args += " /username:{0}".FormatWith(user); + if (!string.IsNullOrEmpty(pass)) + args += " /password:{0}".FormatWith(pass); + } + + if (!string.IsNullOrEmpty(serviceName)) + args += " /serviceName:\"{0}\"".FormatWith(serviceName); + + if (!string.IsNullOrEmpty(displayName)) + args += " /displayName:\"{0}\"".FormatWith(displayName); + + if (!string.IsNullOrEmpty(description)) + args += " /description:\"{0}\"".FormatWith(description); + + _task = new LocalCommandLineTask(new DotNetPath(), exeName) + { + Args = "/install " + args, + ExecutableIsLocatedAt = location, + WorkingDirectory = location + }; + } + + public override string Name + { + get { return "[nservicebushost] local Installing"; } + } + + public override DeploymentResult VerifyCanRun() + { + return _task.VerifyCanRun(); + } + + public override DeploymentResult Execute() + { + Logging.Coarse("[nservicebushost] Installing a local NServiceBus.Host service."); + return _task.Execute(); + } + + private bool shouldPromptForPassword(string username, string password) + { + return !WindowsAuthentication.IsBuiltInUsername(username) && password.ShouldPrompt(); + } + } +} \ No newline at end of file diff --git a/product/dropkick/Tasks/NServiceBusHost/RemoteNServiceBusHostTask.cs b/product/dropkick/Tasks/NServiceBusHost/RemoteNServiceBusHostTask.cs new file mode 100644 index 00000000..0907453a --- /dev/null +++ b/product/dropkick/Tasks/NServiceBusHost/RemoteNServiceBusHostTask.cs @@ -0,0 +1,77 @@ +// Copyright 2007-2010 The Apache Software Foundation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. +namespace dropkick.Tasks.NServiceBusHost +{ + using CommandLine; + using DeploymentModel; + using Prompting; + + public class RemoteNServiceBusHostTask : + BaseTask + { + readonly RemoteCommandLineTask _task; + readonly PromptService _prompt = new ConsolePromptService(); + + public RemoteNServiceBusHostTask(string exeName, string location, string instanceName, PhysicalServer site, string username, string password, string serviceName, string displayName, string description) + { + string args = string.IsNullOrEmpty(instanceName) + ? "" + : " /instance:" + instanceName; + + if (username != null && password != null) + { + var user = username; + var pass = password; + if (username.ShouldPrompt()) + user = _prompt.Prompt("Win Service '{0}' UserName".FormatWith(exeName)); + if (password.ShouldPrompt()) + pass = _prompt.Prompt("Win Service '{0}' For User '{1}' Password".FormatWith(exeName, username)); + + args += " /username:{0} /password:{1}".FormatWith(user, pass); + } + + if (!string.IsNullOrEmpty(serviceName)) + args += " /serviceName:\"{0}\"".FormatWith(serviceName); + + if (!string.IsNullOrEmpty(displayName)) + args += " /displayName:\"{0}\"".FormatWith(displayName); + + if (!string.IsNullOrEmpty(description)) + args += " /description:\"{0}\"".FormatWith(description); + + _task = new RemoteCommandLineTask(exeName) + { + Args = "/install" + args, + ExecutableIsLocatedAt = location, + Machine = site.Name, + WorkingDirectory = location + }; + } + + public override string Name + { + get { return "[nservicebushost] remote Installing"; } + } + + public override DeploymentResult VerifyCanRun() + { + return _task.VerifyCanRun(); + } + + public override DeploymentResult Execute() + { + Logging.Coarse("[nservicebushost] Installing a remote NServiceBus.Host service"); + return _task.Execute(); + } + } +} \ No newline at end of file diff --git a/product/dropkick/dropkick.csproj b/product/dropkick/dropkick.csproj index 806498af..e5ef9f2a 100644 --- a/product/dropkick/dropkick.csproj +++ b/product/dropkick/dropkick.csproj @@ -102,6 +102,9 @@ + + + @@ -146,6 +149,8 @@ + +