Пример #1
0
        public void Discover_SingleAgentNotAvailable_ThrowsException()
        {
            // arrange
            var agentUri          = new Uri("net.tcp://someuri:53714/");
            var connectionManager = new AgentConnectionManager();

            // act
            IDeploymentAgent agent = connectionManager.Discover(agentUri);
        }
Пример #2
0
 private IExceptionInfo GetLastExceptionSafe(IDeploymentAgent deploymentAgent)
 {
     try
     {
         return(deploymentAgent.GetLastException());
     }
     catch
     {
         return(null);
     }
 }
        public void GetService_AgentIsAlive_ReturnsDeploymentService()
        {
            // arrange
            var connectionManager  = new AgentConnectionManager();
            IDeploymentAgent agent = connectionManager.Discover(new Uri(AgentConfiguration.AgentUrl));

            // act
            var target = agent.GetService <IDeploymentService>();

            // assert
            Assert.That(target, Is.Not.Null);
        }
Пример #4
0
        public void Discover_SingleAgent_ReturnsAgent()
        {
            // arrange
            var agentUri          = new Uri(AgentConfiguration.AgentUrl);
            var connectionManager = new AgentConnectionManager();

            // act
            IDeploymentAgent agent = connectionManager.Discover(agentUri);

            // assert
            Assert.That(agent.IsAlive(), Is.True);
            Assert.That(agent.Uri, Is.EqualTo(agentUri));
            Assert.That(agent.MachineName, Is.EqualTo(Environment.MachineName));
            Assert.That(agent.Version, Is.EqualTo(typeof(Program).Assembly.GetName().Version));
        }
Пример #5
0
        public void Discover_AllAgents_ReturnsListWithAgent()
        {
            // arrange
            var connectionManager = new AgentConnectionManager();

            // act
            IEnumerable <IDeploymentAgent> discoveredAgents = connectionManager.Discover();

            // assert
            IDeploymentAgent agent = discoveredAgents.FirstOrDefault();

            Assert.That(agent, Is.Not.Null);
            Assert.That(agent.IsAlive(), Is.True);
            Assert.That(agent.Uri, Is.EqualTo(new Uri(AgentConfiguration.AgentUrl)));
            Assert.That(agent.MachineName, Is.EqualTo(Environment.MachineName));
            Assert.That(agent.Version, Is.EqualTo(typeof(Program).Assembly.GetName().Version));
        }
        public void Deploy_SimpleWorkflow_ExecutesWorkflow()
        {
            // arrange
            string expectedFileName = Path.Combine("SimpleWorkflowTest", "TestFile.txt");
            string template         = this.LoadTemplate("OpenDeploymentManager.Agent.IntegrationTests.Workflows.SimpleWorkflow.xaml");

            var connectionManager  = new AgentConnectionManager();
            IDeploymentAgent agent = connectionManager.Discover(new Uri(AgentConfiguration.AgentUrl));
            var target             = agent.GetService <IDeploymentService>();

            // act
            var arguments = new[] { new KeyValue <object> {
                                        Key = "FileName", Value = expectedFileName
                                    } };

            target.Deploy(Guid.NewGuid(), Guid.NewGuid(), template, arguments, new KeyValue <string> [0]);

            // assert
            Assert.That(File.Exists(expectedFileName), Is.True);
        }
Пример #7
0
        public void Deploy(int publicationId, Action <int> machineDeploymentStarted, Action <int, bool> machineDeploymentComplete)
        {
            AspNetDeployEntities entities = new AspNetDeployEntities();

            Publication publication = entities.Publication
                                      .Include("Package.BundleVersion.Properties")
                                      .Include("Package.BundleVersion.ProjectVersions")
                                      .Include("Package.BundleVersion.ProjectVersions.SourceControlVersion")
                                      .Include("Package.BundleVersion.DeploymentSteps.Properties")
                                      .Include("Package.BundleVersion.DeploymentSteps.MachineRoles")
                                      .Include("Environment.Properties")
                                      .Include("Environment.Machines.MachineRoles")
                                      .First(p => p.Id == publicationId);

            IList <Machine> affectedMachines = this.GetAffectedMachines(publication);
            IDictionary <Machine, IDeploymentAgent>   agents = this.CreateDeploymentAgents(affectedMachines, publication.Package);
            IDictionary <Machine, MachinePublication> machinePublications = this.CreateMachinePublications(affectedMachines, publication, entities);

            if (!this.ValidateDeploymentAgents(agents))
            {
                return;
            }

            string bundlePackagePath = pathServices.GetBundlePackagePath(publication.Package.BundleVersionId, publication.Package.Id);

            if (!this.ValidatePackage(bundlePackagePath))
            {
                return;
            }

            this.ChangePublicationResult(publication, PublicationState.InProgress, entities);

            foreach (MachinePublication machinePublication in machinePublications.Values)
            {
                this.ChangeMachinePublication(machinePublication, MachinePublicationState.Queued, entities);
            }

            foreach (KeyValuePair <Machine, IDeploymentAgent> pair in agents)
            {
                Machine          machine         = pair.Key;
                IDeploymentAgent deploymentAgent = pair.Value;

                MachinePublication machinePublication = machinePublications[machine];

                if (!deploymentAgent.IsReady())
                {
                    this.RecordException(entities, null, new AspNetDeployException("Deployment agent not ready"));
                    this.ChangePublicationResult(publication, PublicationState.Error, entities);
                    return;
                }

                machineDeploymentStarted(machine.Id);

                try
                {
                    deploymentAgent.BeginPublication(publication.Id);
                    deploymentAgent.ResetPackage();

                    this.ChangeMachinePublication(machinePublication, MachinePublicationState.Uploading, entities);
                    deploymentAgent.UploadPackage(bundlePackagePath);

                    this.ChangeMachinePublication(machinePublication, MachinePublicationState.Configuring, entities);

                    IList <DeploymentStep> machineDeploymentSteps = this.GetMachineDeploymentSteps(publication.Package, machine);

                    foreach (DeploymentStep deploymentStep in machineDeploymentSteps)
                    {
                        if (deploymentStep.Type == DeploymentStepType.RunVsTests)
                        {
                            this.LogMachinePublicationStep(machinePublication, deploymentStep, entities, MachinePublicationLogEvent.DeploymentStepConfiguringComplete);
                            continue;
                        }

                        try
                        {
                            this.LogMachinePublicationStep(machinePublication, deploymentStep, entities, MachinePublicationLogEvent.DeploymentStepConfiguring);
                            deploymentAgent.ProcessDeploymentStep(deploymentStep);
                            this.LogMachinePublicationStep(machinePublication, deploymentStep, entities, MachinePublicationLogEvent.DeploymentStepConfiguringComplete);
                        }
                        catch (Exception e)
                        {
                            this.RecordException(entities, null, e);
                            this.LogMachinePublicationStep(machinePublication, deploymentStep, entities, MachinePublicationLogEvent.DeploymentStepConfiguringError, this.GetLastExceptionSafe(deploymentAgent));
                            throw;
                        }
                    }

                    this.ChangeMachinePublication(machinePublication, MachinePublicationState.Running, entities);

                    for (var i = 0; i < machineDeploymentSteps.Count; i++)
                    {
                        DeploymentStep deploymentStep = machineDeploymentSteps[i];

                        if (deploymentStep.Type == DeploymentStepType.RunVsTests)
                        {
                            this.LogMachinePublicationStep(machinePublication, deploymentStep, entities, MachinePublicationLogEvent.DeploymentStepExecuting);

                            IVariableProcessor variableProcessor = this.variableProcessorFactory.Create(publication.Package.BundleVersionId, machine.Id);
                            ProjectVersion     projectVersion    = publication.Package.BundleVersion.ProjectVersions.First(pv => pv.Id == deploymentStep.GetIntProperty("ProjectId"));

                            IProjectTestRunner projectTestRunner = this.projectTestRunnerFactory.Create(projectVersion.ProjectType, variableProcessor);

                            IList <TestResult> testResults = projectTestRunner.Run(projectVersion);

                            if (testResults.All(t => t.IsPass))
                            {
                                this.LogMachinePublicationStep(machinePublication, deploymentStep, entities, MachinePublicationLogEvent.DeploymentStepExecutingComplete);
                            }
                            else
                            {
                                this.LogMachinePublicationStep(
                                    machinePublication,
                                    deploymentStep,
                                    entities,
                                    MachinePublicationLogEvent.DeploymentStepExecutingError,
                                    new ExceptionInfo()
                                {
                                    Message       = string.Join(", ", testResults.Where(t => !t.IsPass).Select(t => t.TestClassName + "." + t.TestName)),
                                    ExceptionData = testResults
                                                    .Where(t => !t.IsPass)
                                                    .Select((t, index) => new ExceptionDataInfo()
                                    {
                                        Name       = index + ". " + t.TestClassName + "." + t.TestName,
                                        Value      = t.Message,
                                        IsProperty = true
                                    })
                                                    .Cast <IExceptionDataInfo>()
                                                    .ToList()
                                });
                            }

                            continue;
                        }

                        try
                        {
                            this.LogMachinePublicationStep(machinePublication, deploymentStep, entities, MachinePublicationLogEvent.DeploymentStepExecuting);

                            if (deploymentAgent.ExecuteNextOperation())
                            {
                                this.LogMachinePublicationStep(machinePublication, deploymentStep, entities, MachinePublicationLogEvent.DeploymentStepExecutingComplete);
                            }
                            else
                            {
                                throw new AspNetDeployException("Error executing deploymentStep");
                            }
                        }
                        catch (Exception e)
                        {
                            e.Data.Add("Deployment step id", deploymentStep.Id);
                            e.Data.Add("Deployment ttep index", i + 1);
                            e.Data.Add("Machine name", machine.Name);

                            this.RecordException(entities, null, e);

                            this.LogMachinePublicationStep(
                                machinePublication,
                                deploymentStep,
                                entities,
                                MachinePublicationLogEvent.DeploymentStepExecutingError,
                                this.GetLastExceptionSafe(deploymentAgent));

                            throw;
                        }
                    }

                    deploymentAgent.Complete();
                }
                catch (Exception e)
                {
                    e.Data.Add("Publication.Id", publication.Id);
                    e.Data.Add("Publication.Package.Id", publication.Package.Id);

                    /*deploymentAgent.Rollback();*/
                    machineDeploymentComplete(machine.Id, false);
                    this.ChangeMachinePublication(machinePublication, MachinePublicationState.Error, entities);
                    this.ChangePublicationResult(publication, PublicationState.Error, entities);
                    this.RecordException(entities, null, e);

                    return;
                }

                this.ChangeMachinePublication(machinePublication, MachinePublicationState.Complete, entities);
                machineDeploymentComplete(machine.Id, true);
            }

            this.ChangePublicationResult(publication, PublicationState.Complete, entities);
        }