Skip to content

Commit

Permalink
Added entities for deployment. #30 #28
Browse files Browse the repository at this point in the history
Renaming: Deployment -> Installation
  • Loading branch information
gius committed Jun 11, 2015
1 parent 5e4f1ee commit 9b8b3af
Show file tree
Hide file tree
Showing 34 changed files with 517 additions and 125 deletions.
6 changes: 3 additions & 3 deletions src/Agent/DeployAgent/DeployAgent/Api/DeployController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public DeployController(IDeployService deployService)
}

[Route("api/deploy/{site}")]
public async Task<Baud.Deployment.DeployLogic.Models.Deployment> Post(string site)
public async Task<Baud.Deployment.DeployLogic.Models.Installation> Post(string site)
{
if (!Request.Content.IsMimeMultipartContent())
{
Expand All @@ -43,9 +43,9 @@ public DeployController(IDeployService deployService)
var streamProvider = new MemoryDataStreamProvider(packageStream);
await Request.Content.ReadAsMultipartAsync(streamProvider);

var deploymentID = Guid.NewGuid();
var installationID = Guid.NewGuid();

return _deployService.DeployPackage(site, deploymentID, packageStream);
return _deployService.DeployPackage(site, installationID, packageStream);
}
}
}
Expand Down
36 changes: 18 additions & 18 deletions src/Agent/DeployAgent/DeployLogic.Tests/BiggySitesServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ public void GetSiteParameters_Throws_WhenSiteNotPresent()
}

[TestMethod]
public void CreateDeployment_CreatesSite_IfNotExist()
public void CreateInstallation_CreatesSite_IfNotExist()
{
var service = CreateCleanService();
var serviceHelper = (IBiggySitesServiceTesting)service;

var sitesBeforeDeployment = serviceHelper.ListSites().ToList();
Assert.AreEqual(sitesBeforeDeployment.Count, 0);
var sitesBeforeInstallation = serviceHelper.ListSites().ToList();
Assert.AreEqual(sitesBeforeInstallation.Count, 0);

service.CreateDeployment("TestSite", new Models.PackageInfo(), new Guid());
service.CreateInstallation("TestSite", new Models.PackageInfo(), new Guid());

var sitesAfterDeployment = serviceHelper.ListSites().ToList();
sitesAfterDeployment.Should().ContainSingle("TestSite");
var sitesAfterInstallation = serviceHelper.ListSites().ToList();
sitesAfterInstallation.Should().ContainSingle("TestSite");
}

[TestMethod]
public void CreateDeployment_Throws_IfDeploymentIDAlreadyExistis_InAnotherSite()
public void CreateInstallation_Throws_IfInstallationIDAlreadyExistis_InAnotherSite()
{
var service = CreateCleanService();
var serviceHelper = (IBiggySitesServiceTesting)service;
Expand All @@ -51,9 +51,9 @@ public void CreateDeployment_Throws_IfDeploymentIDAlreadyExistis_InAnotherSite()
{
ID = "AnotherPackage",
Version = "1.0",
Deployments = new List<Models.Deployment>
Installations = new List<Models.Installation>
{
new Models.Deployment
new Models.Installation
{
ID = new Guid(ConflictingGuid)
}
Expand All @@ -63,13 +63,13 @@ public void CreateDeployment_Throws_IfDeploymentIDAlreadyExistis_InAnotherSite()
};
serviceHelper.AddSite(existingSite);

Action action = () => service.CreateDeployment("TestSite", new Models.PackageInfo { ID = "TestPackage", Version = "1.0" }, new Guid(ConflictingGuid));
Action action = () => service.CreateInstallation("TestSite", new Models.PackageInfo { ID = "TestPackage", Version = "1.0" }, new Guid(ConflictingGuid));

action.ShouldThrow<InvalidOperationException>();
}

[TestMethod]
public void CreateDeployment_Throws_IfDeploymentIDAlreadyExistis_InAnotherPackage()
public void CreateInstallation_Throws_IfInstallationIDAlreadyExistis_InAnotherPackage()
{
var service = CreateCleanService();
var serviceHelper = (IBiggySitesServiceTesting)service;
Expand All @@ -83,9 +83,9 @@ public void CreateDeployment_Throws_IfDeploymentIDAlreadyExistis_InAnotherPackag
{
ID = "AnotherPackage",
Version = "1.0",
Deployments = new List<Models.Deployment>
Installations = new List<Models.Installation>
{
new Models.Deployment
new Models.Installation
{
ID = new Guid(ConflictingGuid)
}
Expand All @@ -95,13 +95,13 @@ public void CreateDeployment_Throws_IfDeploymentIDAlreadyExistis_InAnotherPackag
};
serviceHelper.AddSite(existingSite);

Action action = () => service.CreateDeployment("TestSite", new Models.PackageInfo { ID = "TestPackage", Version = "1.0" }, new Guid(ConflictingGuid));
Action action = () => service.CreateInstallation("TestSite", new Models.PackageInfo { ID = "TestPackage", Version = "1.0" }, new Guid(ConflictingGuid));

action.ShouldThrow<InvalidOperationException>();
}

[TestMethod]
public void CreateDeployment_Throws_IfDeploymentIDAlreadyExistis_InTheSamePackage()
public void CreateInstallation_Throws_IfInstallationIDAlreadyExistis_InTheSamePackage()
{
var service = CreateCleanService();
var serviceHelper = (IBiggySitesServiceTesting)service;
Expand All @@ -115,9 +115,9 @@ public void CreateDeployment_Throws_IfDeploymentIDAlreadyExistis_InTheSamePackag
{
ID = "TestPackage",
Version = "1.0",
Deployments = new List<Models.Deployment>
Installations = new List<Models.Installation>
{
new Models.Deployment
new Models.Installation
{
ID = new Guid(ConflictingGuid)
}
Expand All @@ -127,7 +127,7 @@ public void CreateDeployment_Throws_IfDeploymentIDAlreadyExistis_InTheSamePackag
};
serviceHelper.AddSite(existingSite);

Action action = () => service.CreateDeployment("TestSite", new Models.PackageInfo { ID = "TestPackage", Version = "1.0" }, new Guid(ConflictingGuid));
Action action = () => service.CreateInstallation("TestSite", new Models.PackageInfo { ID = "TestPackage", Version = "1.0" }, new Guid(ConflictingGuid));

action.ShouldThrow<InvalidOperationException>();
}
Expand Down
38 changes: 19 additions & 19 deletions src/Agent/DeployAgent/DeployLogic/BiggySitesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,55 +60,55 @@ public void RemoveSiteParameter(string siteID, string key)
_sites.Update(site);
}

public Models.Deployment CreateDeployment(string siteID, Models.PackageInfo packageInfo, Guid deploymentID)
public Models.Installation CreateInstallation(string siteID, Models.PackageInfo packageInfo, Guid installationID)
{
CheckUniqueDeploymentID(deploymentID);
CheckUniqueInstallationID(installationID);
var site = GetOrCreateSite(siteID);
var package = GetOrCreatePackage(site, packageInfo);

var deployment = new Models.Deployment
var installation = new Models.Installation
{
ID = deploymentID,
ID = installationID,
SiteID = site.ID,
PackageID = package.ID,
Date = DateTime.Now,
State = Models.DeploymentState.Pending
State = Models.InstallationState.Pending
};
package.Deployments.Add(deployment);
package.Installations.Add(installation);
_sites.Update(site);

return deployment;
return installation;
}

public void LogDeploymentProgress(string siteID, string packageID, Guid deploymentID, Models.DeploymentState state, int logLevel, Models.LogSeverity severity, string text)
public void LogInstallationProgress(string siteID, string packageID, Guid installationID, Models.InstallationState state, int logLevel, Models.LogSeverity severity, string text)
{
var site = _sites.First(x => x.ID == siteID);
var package = site.InstalledPackages.First(x => x.ID == packageID);
var deployment = package.Deployments.First(x => x.ID == deploymentID);
var installation = package.Installations.First(x => x.ID == installationID);

deployment.State = state;
installation.State = state;

var log = new Models.DeploymentLog
var log = new Models.InstallationLog
{
Level = logLevel,
Timestamp = DateTime.Now,
Severity = severity,
Text = text
};
deployment.Logs.Add(log);
installation.Logs.Add(log);

_sites.Update(site);
}

private void CheckUniqueDeploymentID(Guid deploymentID)
private void CheckUniqueInstallationID(Guid installationID)
{
var existingDeployments = from s in _sites
from p in s.InstalledPackages
from d in p.Deployments
select d.ID;
if (existingDeployments.Contains(deploymentID))
var existinginstallations = from s in _sites
from p in s.InstalledPackages
from d in p.Installations
select d.ID;
if (existinginstallations.Contains(installationID))
{
throw new InvalidOperationException(string.Format("There is already a deployment with ID '{0}'", deploymentID));
throw new InvalidOperationException(string.Format("There is already an installation with ID '{0}'", installationID));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ namespace Baud.Deployment.DeployLogic.Contracts
{
public interface IDeployService
{
Models.Deployment DeployPackage(string siteID, Guid deploymentID, System.IO.Stream packageStream);
Models.Installation DeployPackage(string siteID, Guid installationID, System.IO.Stream packageStream);
}
}
4 changes: 2 additions & 2 deletions src/Agent/DeployAgent/DeployLogic/Contracts/ISitesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ namespace Baud.Deployment.DeployLogic.Contracts
{
public interface ISitesService
{
Models.Deployment CreateDeployment(string siteID, Models.PackageInfo packageInfo, Guid deploymentID);
Models.Installation CreateInstallation(string siteID, Models.PackageInfo packageInfo, Guid installationID);

IReadOnlyDictionary<string, string> GetSiteParameters(string siteID);

void SetSiteParameter(string siteID, string key, string value);

void RemoveSiteParameter(string siteID, string key);

void LogDeploymentProgress(string siteID, string packageID, Guid deploymentID, Models.DeploymentState state, int logLevel, Models.LogSeverity severity, string text);
void LogInstallationProgress(string siteID, string packageID, Guid installationID, Models.InstallationState state, int logLevel, Models.LogSeverity severity, string text);
}
}
6 changes: 3 additions & 3 deletions src/Agent/DeployAgent/DeployLogic/DeployLogic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@
<Compile Include="Contracts\ISharedSettingsService.cs" />
<Compile Include="Contracts\ISitesService.cs" />
<Compile Include="DeployScriptException.cs" />
<Compile Include="Models\Deployment.cs" />
<Compile Include="Models\DeploymentLog.cs" />
<Compile Include="Models\DeploymentState.cs" />
<Compile Include="Models\Installation.cs" />
<Compile Include="Models\InstallationLog.cs" />
<Compile Include="Models\InstallationState.cs" />
<Compile Include="Models\LogSeverity.cs" />
<Compile Include="Models\Package.cs" />
<Compile Include="Models\PackageInfo.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@

namespace Baud.Deployment.DeployLogic.Models
{
public class Deployment
public class Installation
{
public Guid ID { get; set; }
public string SiteID { get; set; }
public string PackageID { get; set; }
public DateTime Date { get; set; }

public DeploymentState State { get; set; }
public InstallationState State { get; set; }

public IList<DeploymentLog> Logs { get; set; }
public IList<InstallationLog> Logs { get; set; }

public Deployment()
public Installation()
{
Logs = new List<DeploymentLog>();
Logs = new List<InstallationLog>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Baud.Deployment.DeployLogic.Models
{
public class DeploymentLog
public class InstallationLog
{
public DateTime Timestamp { get; set; }
public int Level { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Baud.Deployment.DeployLogic.Models
{
public enum DeploymentState
public enum InstallationState
{
Pending,
Failure,
Expand Down
4 changes: 2 additions & 2 deletions src/Agent/DeployAgent/DeployLogic/Models/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace Baud.Deployment.DeployLogic.Models
{
public class Package : PackageInfo
{
public IList<Deployment> Deployments { get; set; }
public IList<Installation> Installations { get; set; }

public Package()
{
Deployments = new List<Deployment>();
Installations = new List<Installation>();
}
}
}
Loading

0 comments on commit 9b8b3af

Please sign in to comment.