Skip to content

Commit

Permalink
Controller is able to send deploy package to agent. Closes Baud-UCS#32
Browse files Browse the repository at this point in the history
  • Loading branch information
gius committed Jun 25, 2015
1 parent 4d6ca22 commit c0dd771
Show file tree
Hide file tree
Showing 46 changed files with 790 additions and 49 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
<HintPath>..\packages\FluentAssertions.3.3.0\lib\net45\FluentAssertions.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NSubstitute, Version=1.8.2.0, Culture=neutral, PublicKeyToken=92dd2e9066daa5ca, processorArchitecture=MSIL">
<HintPath>..\packages\NSubstitute.1.8.2.0\lib\net45\NSubstitute.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -62,6 +66,7 @@
<ItemGroup>
<Compile Include="Agents\WebApiAgentAdapterDebugTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\AgentDeployServiceDebugTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BusinessLogic\BusinessLogic.csproj">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Baud.Deployment.BusinessLogic.Contracts;
using Baud.Deployment.BusinessLogic.Domain.Deployment.Contracts;
using Baud.Deployment.BusinessLogic.Domain.Deployment.Entities;
using Baud.Deployment.BusinessLogic.Providers;
using Baud.Deployment.BusinessLogic.Services;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;

namespace Baud.Deployment.BusinessLogic.Tests.Services
{
[TestClass]
public class AgentDeployServiceDebugTests
{
////[TestMethod]
public async Task _Debug_ProcessInstallationAsync_Success()
{
var uow = Substitute.For<IDeploymentUow>();
var packagesProvider = Substitute.For<IDeployPackagesProvider>();
packagesProvider.GetPackageBytes(null).ReturnsForAnyArgs(x => File.ReadAllBytes(@"C:\Temp\DEF\Baud.Deploy.HOS-RS-3.3.0.15118.4.nupkg"));

var service = new AgentDeployService(() => uow, new WebApiAgentAdapterProvider(), packagesProvider);

var installation = new Installation
{
DeployTarget = new DeployTarget
{
Site = new ServerSite
{
Key = "Test",
Server = new Server
{
AgentUrl = "http://localhost:9000/"
}
}
}
};
var result = await service.ProcessInstallationAsync(installation);

result.Should().Be(Baud.Deployment.BusinessLogic.Domain.Deployment.Enums.InstallationState.Success);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FluentAssertions" version="3.3.0" targetFramework="net451" />
<package id="NSubstitute" version="1.8.2.0" targetFramework="net451" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;

namespace Baud.Deployment.DeployLogic.Models
namespace Baud.Deployment.BusinessLogic.Agents.Models
{
public class Deployment
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;

namespace Baud.Deployment.DeployLogic.Models
namespace Baud.Deployment.BusinessLogic.Agents.Models
{
public class DeploymentLog
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;

namespace Baud.Deployment.DeployLogic.Models
namespace Baud.Deployment.BusinessLogic.Agents.Models
{
public enum DeploymentState
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;

namespace Baud.Deployment.DeployLogic.Models
namespace Baud.Deployment.BusinessLogic.Agents.Models
{
public enum LogSeverity
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public WebApiAgentAdapter(string baseUrl)
_baseUrl = baseUrl;
}

public async Task<DeployLogic.Models.Deployment> DeployPackageAsync(string siteID, byte[] package)
public async Task<Agents.Models.Deployment> DeployPackageAsync(string siteID, byte[] package)
{
var request = new RestRequest(Urls.Deploy, Method.POST);
request.AddUrlSegment(UrlSegments.Site, siteID);
request.AddFile(Parameters.Package, package, "package.nupkg");

var client = CreateClient();
var response = await client.ExecuteTaskAsync<DeployLogic.Models.Deployment>(request);
var response = await client.ExecuteTaskAsync<Agents.Models.Deployment>(request);

return response.Data;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@
<Compile Include="Agents\Models\LogSeverity.cs" />
<Compile Include="Agents\WebApiAgentAdapter.cs" />
<Compile Include="Contracts\IAgentAdapter.cs" />
<Compile Include="Contracts\IAgentAdapterProvider.cs" />
<Compile Include="Contracts\ICurrentUserProvider.cs" />
<Compile Include="Contracts\IDateTimeProvider.cs" />
<Compile Include="Contracts\IDeployPackagesProvider.cs" />
<Compile Include="Contracts\IDeployService.cs" />
<Compile Include="Domain\Deployment\Contracts\IDeploymentUow.cs" />
<Compile Include="Domain\Deployment\Contracts\IInstallationsRepository.cs" />
<Compile Include="Domain\Deployment\Contracts\IProjectsRepository.cs" />
Expand All @@ -75,6 +78,7 @@
<Compile Include="Domain\Deployment\Entities\ServerSite.cs" />
<Compile Include="Domain\Deployment\Enums\InstallationState.cs" />
<Compile Include="Domain\Deployment\Enums\LogSeverity.cs" />
<Compile Include="Domain\Deployment\Models\DeployPackageInfo.cs" />
<Compile Include="Domain\Deployment\Queries\InstallationQueries.cs" />
<Compile Include="Domain\EntityBase.cs" />
<Compile Include="Domain\IUow.cs" />
Expand All @@ -86,14 +90,18 @@
<Compile Include="Domain\Security\Entities\User.cs" />
<Compile Include="Domain\Security\Entities\UserPositionLink.cs" />
<Compile Include="Domain\Security\Queries\UserQueries.cs" />
<Compile Include="Providers\SimpleCurrentUserProvider.cs" />
<Compile Include="Providers\WebApiAgentAdapterProvider.cs" />
<Compile Include="QueryableExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\RealDateTimeProvider.cs" />
<Compile Include="Services\AgentDeployService.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Baud.Deployment.BusinessLogic.Contracts
{
public interface IAgentAdapter
{
Task<DeployLogic.Models.Deployment> DeployPackageAsync(string siteID, byte[] package);
Task<Agents.Models.Deployment> DeployPackageAsync(string siteID, byte[] package);

Task<IDictionary<string, string>> GetSharedParameters();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Baud.Deployment.BusinessLogic.Contracts
{
public interface IAgentAdapterProvider
{
IAgentAdapter CreateAgentAdapter(string agentUrl);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Baud.Deployment.BusinessLogic.Domain.Deployment.Models;

namespace Baud.Deployment.BusinessLogic.Contracts
{
public interface IDeployPackagesProvider
{
IQueryable<DeployPackageInfo> GetAvailablePackagesInfo();

IQueryable<KeyValuePair<string, string>> GetPackages();

IEnumerable<string> GetPackageVersions(string packageId);

string GetPackageFileFullPath(string packageId, string version);

byte[] GetPackageBytes(string packageFullPath);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Baud.Deployment.BusinessLogic.Domain.Deployment.Entities;
using Baud.Deployment.BusinessLogic.Domain.Deployment.Enums;

namespace Baud.Deployment.BusinessLogic.Contracts
{
public interface IDeployService
{
Task<InstallationState> ProcessInstallationAsync(Installation installation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@ namespace Baud.Deployment.BusinessLogic.Domain.Deployment.Contracts
public interface IInstallationsRepository
{
IQueryable<Installation> GetWaitingInstallations();

void MarkInstallationPending(int installationID);

void MarkInstallationSuccessfull(int installationID, Guid agentDeploymentID, DateTime deployed);

void MarkInstallationFailed(int installationID, Guid? agentDeploymentID, DateTime deployed);

void AddInstallationLog(int installationID, InstallationLog log);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ public class DeployTarget : EntityBase
public int ID { get; set; }
public int ApplicationID { get; set; }
public int EnvironmentID { get; set; }
public int ServerID { get; set; }
public int SiteID { get; set; }

public string Note { get; set; }
public string Url { get; set; }

public Environment Environment { get; set; }
public Application Application { get; set; }
public Server Server { get; set; }
public ServerSite Site { get; set; }

public List<Installation> Installations { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ public class Installation : EntityBase
[MaxLength(100)]
public string PackageVersion { get; set; }

[Required]
public string PackageFilePath { get; set; }

public DateTime Planned { get; set; }

public DateTime? Started { get; set; }
public DateTime? Deployed { get; set; }
public Guid? AgentDeploymentId { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class Server : EntityBase
[MaxLength(100)]
public string AgentUrl { get; set; }

public List<DeployTarget> DeployTargets { get; set; }
public List<ServerSite> Sites { get; set; }
public List<ServerParameter> Parameters { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class ServerSite : EntityBase

public Server Server { get; set; }

public List<DeployTarget> DeployTargets { get; set; }
public List<ServerParameter> Parameters { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Baud.Deployment.BusinessLogic.Domain.Deployment.Models
{
public class DeployPackageInfo
{
public string Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }

public IEnumerable<string> Versions { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@ public static IQueryable<Installation> OnlyPlannedBefore(this IQueryable<Install
{
return query.Where(x => x.Planned <= date);
}

public static IQueryable<Installation> FilterByID(this IQueryable<Installation> query, int installationID)
{
return query.Where(x => x.ID == installationID);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Baud.Deployment.BusinessLogic.Contracts;

namespace Baud.Deployment.BusinessLogic.Providers
{
public class SimpleCurrentUserProvider : ICurrentUserProvider
{
private readonly int _userID;

public SimpleCurrentUserProvider(int userID)
{
_userID = userID;
}

public int GetCurrentUserID()
{
return _userID;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Baud.Deployment.BusinessLogic.Agents;
using Baud.Deployment.BusinessLogic.Contracts;

namespace Baud.Deployment.BusinessLogic.Providers
{
public class WebApiAgentAdapterProvider : IAgentAdapterProvider
{
public IAgentAdapter CreateAgentAdapter(string agentUrl)
{
return new WebApiAgentAdapter(agentUrl);
}
}
}
Loading

0 comments on commit c0dd771

Please sign in to comment.