public void GetDeploymentPlanForComponentAdjacencyGraph() { var componentDeploymentGraph = new ComponentDeploymentGraph(); //Add vertices var a = new ComponentDeploymentVertex("a", "a", new SemVer("1.0.0"), PlanAction.Skip, null); var b = new ComponentDeploymentVertex("b", "b", new SemVer("1.0.0"), PlanAction.Change, null); var c = new ComponentDeploymentVertex("c", "c", new SemVer("1.0.0"), PlanAction.Skip, null); var d = new ComponentDeploymentVertex("d", "d", new SemVer("1.0.0"), PlanAction.Change, null); var e = new ComponentDeploymentVertex("e", "e", new SemVer("1.0.0"), PlanAction.Skip, null); var f = new ComponentDeploymentVertex("f", "f", new SemVer("1.0.0"), PlanAction.Change, null); var g = new ComponentDeploymentVertex("g", "g", new SemVer("1.0.0"), PlanAction.Remove, null); var h = new ComponentDeploymentVertex("h", "h", new SemVer("1.0.0"), PlanAction.Change, null); var x = new ComponentDeploymentVertex("x", "x", new SemVer("1.0.0"), PlanAction.Skip, null); var y = new ComponentDeploymentVertex("y", "y", new SemVer("1.0.0"), PlanAction.Change, null); var z = new ComponentDeploymentVertex("z", "z", new SemVer("1.0.0"), PlanAction.Skip, null); componentDeploymentGraph.AddVertexRange(new ComponentDeploymentVertex[] { a, b, c, d, e, f, g, h, x, y, z }); //Create edges var b_a = new ComponentDeploymentEdge(b, a); var b_c = new ComponentDeploymentEdge(b, c); var c_b = new ComponentDeploymentEdge(c, b); var d_a = new ComponentDeploymentEdge(d, a); var e_d = new ComponentDeploymentEdge(e, d); var f_e = new ComponentDeploymentEdge(f, e); var g_d = new ComponentDeploymentEdge(g, d); var h_e = new ComponentDeploymentEdge(h, e); var h_d = new ComponentDeploymentEdge(h, d); var y_x = new ComponentDeploymentEdge(y, x); var z_y = new ComponentDeploymentEdge(z, y); componentDeploymentGraph.AddEdgeRange(new ComponentDeploymentEdge[] { b_a, b_c, c_b, d_a, e_d, f_e, g_d, h_e, h_d, y_x, z_y }); var deploymentScheduler = new DeploymentScheduler(); var environmentDeployment = deploymentScheduler.GetEnvironmentDeployment(componentDeploymentGraph); var products0 = environmentDeployment.ProductDeployments[0]; var products1 = environmentDeployment.ProductDeployments[1]; products0.DeploymentSteps.Count().Should().Be(ExpectedNumberOfDeploymentStepsForProductDeployment0); products0.DeploymentSteps.SelectMany(productDeploymentStep => productDeploymentStep.ComponentDeployments).Count().Should().Be(ExpectedNumberOfComponentDeploymentsForProductDeployment0); products1.DeploymentSteps.Count().Should().Be(ExpectedNumberOfDeploymentStepsForProductDeployment1); products1.DeploymentSteps.SelectMany(productDeploymentStep => productDeploymentStep.ComponentDeployments).Count().Should().Be(ExpectedNumberOfComponentDeploymentsForProductDeployment1); }
public string DeploymentSuccess(ComponentDeploymentVertex componentDeploymentVertex) { var name = GetName(componentDeploymentVertex); var deploymentUri = GetOctopusDeploymentUrl(componentDeploymentVertex); if (deploymentUri == null) { return(string.Format("Deployment succeeded for {0}", name)); } return(string.Format("Deployment succeeded for {0} - {1}", name, deploymentUri)); }
public string DeploymentProgress(ComponentDeploymentVertex componentDeploymentVertex, string processingMessage) { var name = GetName(componentDeploymentVertex); var deploymentUri = GetOctopusDeploymentUrl(componentDeploymentVertex); if (deploymentUri == null) { return(string.Format("Deploying {0}{1}{2}", name, Environment.NewLine, processingMessage)); } return(string.Format("Deploying {0} - {1}{2}{3}", name, deploymentUri, Environment.NewLine, processingMessage)); }
public string DeploymentFailed(ComponentDeploymentVertex componentDeploymentVertex, string errorMessage) { var name = GetName(componentDeploymentVertex); var deploymentUri = GetOctopusDeploymentUrl(componentDeploymentVertex); if (deploymentUri == null) { return(string.Format("Deployment failed for {0}{1}{2}", name, Environment.NewLine, errorMessage)); } return(string.Format("Deployment failed for {0} - {1}{2}{3}", name, deploymentUri, Environment.NewLine, errorMessage)); }
private string GetOctopusDeploymentUrl(ComponentDeploymentVertex componentDeploymentVertex) { if (componentDeploymentVertex == null || string.IsNullOrEmpty(componentDeploymentVertex.DeploymentId)) { return(null); } var deploymentUri = string.Format("{0}/app#/deployments/{1}", _url, componentDeploymentVertex.DeploymentId); return(deploymentUri); }
public ComponentVertexDeploymentResult Deploy(ComponentDeploymentVertex vertex, CancellationToken cancellationToken, ILogMessages logMessages, IProgress <ComponentVertexDeploymentProgress> progress) { if (!vertex.Exists || vertex.VariableAction == VariableAction.Leave) { return(new ComponentVertexDeploymentResult { Status = ComponentVertexDeploymentStatus.Success }); } var project = _repository.Projects.GetProjectByName(vertex.Name); var release = _repository.Projects.GetRelease(project.Id, vertex.Version); _repository.Releases.SnapshotVariables(release); return(new ComponentVertexDeploymentResult { Status = ComponentVertexDeploymentStatus.Success, Description = "Updated" }); }
/// <summary> /// Deploy component /// </summary> /// <param name="componentDeploymentVertex"></param> /// <param name="cancellationToken"></param> private ComponentVertexDeploymentResult DeployComponent(ComponentDeploymentVertex componentDeploymentVertex, CancellationToken cancellationToken) { try { _throttler.Wait(cancellationToken); try { if (cancellationToken.IsCancellationRequested) { return(new ComponentVertexDeploymentResult { Status = ComponentVertexDeploymentStatus.Cancelled, Description = _logMessages.DeploymentCancelled(componentDeploymentVertex) }); } //Start progress if (_progress != null) { var componentVertexDeploymentProgress = new ComponentVertexDeploymentProgress { Vertex = componentDeploymentVertex, Status = ComponentVertexDeploymentStatus.Started, MinimumValue = 0, MaximumValue = componentDeploymentVertex.DeploymentDuration.HasValue ? componentDeploymentVertex.DeploymentDuration.Value.Ticks : 0, Value = 0, Text = _logMessages.DeploymentStarted(componentDeploymentVertex) }; _progress.Report(componentVertexDeploymentProgress); } var result = new ComponentVertexDeploymentResult(); try { foreach (var deployer in _deployers) { result = deployer.Deploy(componentDeploymentVertex, cancellationToken, _logMessages, _progress); } } catch (Exception ex) { var stringBuilder = new StringBuilder(); WriteExceptionDetails(ex, stringBuilder, 1); result = new ComponentVertexDeploymentResult { Status = ComponentVertexDeploymentStatus.Failure, Description = _logMessages.DeploymentFailed(componentDeploymentVertex, stringBuilder.ToString()) }; } //Finish progress if (_progress != null) { var componentVertexDeploymentProgress = new ComponentVertexDeploymentProgress { Vertex = componentDeploymentVertex, Status = result.Status, MinimumValue = 0, MaximumValue = componentDeploymentVertex.DeploymentDuration.HasValue ? componentDeploymentVertex.DeploymentDuration.Value.Ticks : 0, Value = componentDeploymentVertex.DeploymentDuration.HasValue ? componentDeploymentVertex.DeploymentDuration.Value.Ticks : 0, Text = result.Description }; _progress.Report(componentVertexDeploymentProgress); } return(result); } finally { _throttler.Release(); } } catch (OperationCanceledException) { return(new ComponentVertexDeploymentResult { Status = ComponentVertexDeploymentStatus.Cancelled, Description = _logMessages.DeploymentCancelled(componentDeploymentVertex) }); } }
public string DeploymentStarted(ComponentDeploymentVertex componentDeploymentVertex) { var name = GetName(componentDeploymentVertex); return(string.Format("Deployment started for {0} - expected deployment duration {1}", name, componentDeploymentVertex.DeploymentDuration)); }
public string DeploymentSkipped(ComponentDeploymentVertex componentDeploymentVertex) { var name = GetName(componentDeploymentVertex); return(string.Format("Deployment skipped for {0}", name)); }
private string GetName(ComponentDeploymentVertex componentDeploymentVertex) { return(string.IsNullOrEmpty(componentDeploymentVertex.Name) ? componentDeploymentVertex.Id : componentDeploymentVertex.Name); }
public ComponentVertexDeploymentResult Deploy(ComponentDeploymentVertex componentDeploymentVertex, CancellationToken cancellationToken, ILogMessages logMessages, IProgress <ComponentVertexDeploymentProgress> progress) { if (!componentDeploymentVertex.Exists || componentDeploymentVertex.DeploymentAction == PlanAction.Skip) { return(new ComponentVertexDeploymentResult { Status = ComponentVertexDeploymentStatus.Success, Description = logMessages.DeploymentSkipped(componentDeploymentVertex) }); } if (componentDeploymentVertex.Version == null) { throw new Exception("Version for release is null"); } var environment = _repository.Environments.GetEnvironment(_environmentToDeployTo.Name); var project = _repository.Projects.GetProjectByName(componentDeploymentVertex.Name); var release = _repository.Projects.GetRelease(project.Id, componentDeploymentVertex.Version); var deployment = new DeploymentResource { ReleaseId = release.Id, EnvironmentId = environment.Id, Comments = _comments, ForcePackageDownload = _forcePackageDownload, ForcePackageRedeployment = _forcePackageRedeployment, }; var queuedDeployment = _repository.Deployments.Create(deployment); componentDeploymentVertex.DeploymentId = queuedDeployment.Id; var deploymentTask = _repository.Tasks.Get(queuedDeployment.TaskId); Action <TaskResource[]> interval = tasks => { foreach (var task in tasks) { if (cancellationToken.IsCancellationRequested) { _repository.Tasks.Cancel(task); } var duration = new TimeSpan(0); if (task.StartTime.HasValue) { var now = new DateTimeOffset(DateTime.UtcNow); duration = now.Subtract(task.StartTime.Value); } if (progress != null) { var componentVertexDeploymentProgress = new ComponentVertexDeploymentProgress { Vertex = componentDeploymentVertex, Status = ComponentVertexDeploymentStatus.InProgress, MinimumValue = 0, MaximumValue = componentDeploymentVertex.DeploymentDuration.HasValue ? componentDeploymentVertex.DeploymentDuration.Value.Ticks : 0, Value = duration.Ticks, Text = logMessages.DeploymentProgress(componentDeploymentVertex, task.Description) }; progress.Report(componentVertexDeploymentProgress); } } }; _repository.Tasks.WaitForCompletion(deploymentTask, _pollIntervalSeconds, _timeoutAfterMinutes, interval); deploymentTask = _repository.Tasks.Get(queuedDeployment.TaskId); var result = new ComponentVertexDeploymentResult(); switch (deploymentTask.State) { case TaskState.Success: result.Status = ComponentVertexDeploymentStatus.Success; result.Description = logMessages.DeploymentSuccess(componentDeploymentVertex); break; case TaskState.Canceled: case TaskState.Cancelling: result.Status = ComponentVertexDeploymentStatus.Cancelled; result.Description = logMessages.DeploymentCancelled(componentDeploymentVertex); break; case TaskState.Failed: case TaskState.TimedOut: result.Status = ComponentVertexDeploymentStatus.Failure; result.Description = logMessages.DeploymentFailed(componentDeploymentVertex, deploymentTask.ErrorMessage); break; default: result.Status = ComponentVertexDeploymentStatus.Failure; result.Description = logMessages.DeploymentFailed(componentDeploymentVertex, deploymentTask.ErrorMessage); break; } return(result); }