// GET: Deployments/RunExecute //[FrameworkAuthorization] public ActionResult RunExecute(string name, string stepAction, int stepId) { if (name == null) { ViewBag.Message = "Invalid name. Nothing to display."; //return View(); Redirect, because RunExecute View does not exist return(RedirectToAction("Execute")); } //ToDo: Check if deployment is verified but allow to execute after additional confirmation using (var service = DomainLocator.GetRepositoryService()) { //Get deployment and its steps. var converter = new Converter(); var deploymentBO = service.Object.ReadDeployment(name); var runDeployment = new RunDeployment { Deployment = converter.Convert(deploymentBO) }; var deploymentSteps = service.Object.ReadDeploymentSteps(name); switch (stepAction) { case "startdeployment": //Set steps' status to init and ... foreach (var deploymentStep in deploymentSteps) { deploymentStep.StepState = BO.DeploymentStepState.Init; service.Object.CreateDeploymentStep(name, deploymentStep); runDeployment.DeploymentSteps.Add(converter.Convert(deploymentStep)); //... the first step's to active only if the list is not empty runDeployment.DeploymentSteps[0].StepState = DeploymentStepState.Active; } //Set deployment's status to active when deployment starts... deploymentBO.Status = BO.DeploymentStatus.Active; service.Object.CreateDeployment(deploymentBO); runDeployment.Deployment.Status = DeploymentStatus.Active; break; //... and change the status of a steps with stepId and matching stepAction case "complete": deploymentSteps.Single(s => s.Id == stepId).StepState = BO.DeploymentStepState.Successful; service.Object.CreateDeploymentStep(name, deploymentSteps.Single(s => s.Id == stepId)); break; case "skip": deploymentSteps.Single(s => s.Id == stepId).StepState = BO.DeploymentStepState.Skipped; service.Object.CreateDeploymentStep(name, deploymentSteps.Single(s => s.Id == stepId)); break; case "failed": deploymentSteps.Single(s => s.Id == stepId).StepState = BO.DeploymentStepState.Failed; service.Object.CreateDeploymentStep(name, deploymentSteps.Single(s => s.Id == stepId)); break; } } return(RedirectToAction("Execute", new { name })); }
// GET: Deployments/Execute //[FrameworkAuthorization] public ActionResult Execute(string name) { if (name == null) { ViewBag.Message = "Invalid name. Nothing to display."; return(View()); } var runDeployment = new RunDeployment(); using (var service = DomainLocator.GetRepositoryService()) { var deploymentBO = service.Object.ReadDeployment(name); var converter = new Converter(); runDeployment.Deployment = converter.Convert(deploymentBO); if (runDeployment.Deployment.Status == DeploymentStatus.Active) { var deploymentSteps = service.Object.ReadDeploymentSteps(name); var steps = deploymentSteps as BO.IDeploymentStep[] ?? deploymentSteps.ToArray(); if (steps.Any()) { if (steps.Last().StepState != Domain.Shared.DeploymentStepState.Init && steps.Last().StepState != Domain.Shared.DeploymentStepState.Active) { runDeployment.Deployment.Status = DeploymentStatus.Failed; foreach (var deploymentStep in steps) { if (deploymentStep.StepState != Domain.Shared.DeploymentStepState.Failed) { runDeployment.Deployment.Status = DeploymentStatus.Successful; } } service.Object.CreateDeployment(converter.Convert(runDeployment.Deployment)); return(RedirectToAction("Index")); } foreach (var deploymentStep in steps) { runDeployment.DeploymentSteps.Add(converter.Convert(deploymentStep)); } } else { runDeployment.DeploymentSteps.Add( new DeploymentStep() { Id = 1, Description = "No steps available", StepState = DeploymentStepState.Active } ); } } } return(View(runDeployment)); }
public DeployPackageHandler( SheepItDbContext dbContext, DeploymentFactory deploymentFactory, RunDeployment runDeployment) { _dbContext = dbContext; _deploymentFactory = deploymentFactory; _runDeployment = runDeployment; }