Skip to content

Commit

Permalink
Merge pull request chucknorris#1 from davidduffett/master
Browse files Browse the repository at this point in the history
NServiceBus.Host deployment
  • Loading branch information
laazyj committed Aug 2, 2011
2 parents 0ae1889 + ea3fecd commit 96fc085
Show file tree
Hide file tree
Showing 6 changed files with 306 additions and 0 deletions.
27 changes: 27 additions & 0 deletions product/dropkick/Configuration/Dsl/NServiceBusHost/Extension.cs
Original file line number Diff line number Diff line change
@@ -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<NServiceBusHostOptions> action)
{
var cfg = new NServiceBusHostConfigurator(new DotNetPath());
action(cfg);
server.RegisterProtoTask(cfg);
}
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
84 changes: 84 additions & 0 deletions product/dropkick/Tasks/NServiceBusHost/LocalNServiceBusHostTask.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
5 changes: 5 additions & 0 deletions product/dropkick/dropkick.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
<Compile Include="Configuration\Dsl\MsSrss\ProtoSsrsTask.cs" />
<Compile Include="Configuration\Dsl\MsSrss\ReportOptions.cs" />
<Compile Include="Configuration\Dsl\NetworkShare\ExistingShareOptions.cs" />
<Compile Include="Configuration\Dsl\NServiceBusHost\Extension.cs" />
<Compile Include="Configuration\Dsl\NServiceBusHost\NServiceBusHostConfigurator.cs" />
<Compile Include="Configuration\Dsl\NServiceBusHost\NServiceBusHostOptions.cs" />
<Compile Include="Configuration\Dsl\Registry\Extension.cs" />
<Compile Include="Configuration\Dsl\Registry\ProtoCreateRegistryKeyTask.cs" />
<Compile Include="Configuration\Dsl\Registry\RegistryExtension.cs" />
Expand Down Expand Up @@ -146,6 +149,8 @@
<Compile Include="Tasks\Msmq\CreateRemoteMsmqQueueTask.cs" />
<Compile Include="Tasks\Msmq\RemoteExtension.cs" />
<Compile Include="Tasks\MsSsrs\PublishSsrsTask.cs" />
<Compile Include="Tasks\NServiceBusHost\LocalNServiceBusHostTask.cs" />
<Compile Include="Tasks\NServiceBusHost\RemoteNServiceBusHostTask.cs" />
<Compile Include="Tasks\Registry\BaseRegistryTask.cs" />
<Compile Include="Tasks\Registry\CreateRegistryKeyTask.cs" />
<Compile Include="Tasks\Registry\CreateRegistryValueTask.cs" />
Expand Down

0 comments on commit 96fc085

Please sign in to comment.