Ejemplo n.º 1
0
        public WCFSatelliteDeploymentAgent(IVariableProcessor variableProcessor, string endpoint, string login, string password, TimeSpan?openTimeoutSpan = null, TimeSpan?waitTimeout = null)
        {
            this.variableProcessor = variableProcessor;

            WSHttpBinding binding = new WSHttpBinding(SecurityMode.TransportWithMessageCredential);

            binding.MaxBufferPoolSize           = 1024 * 1024 * 10;
            binding.MaxReceivedMessageSize      = 1024 * 1024 * 10;
            binding.ReaderQuotas.MaxArrayLength = 1024 * 1024 * 10;

            binding.OpenTimeout    = openTimeoutSpan ?? new TimeSpan(0, 10, 0);
            binding.CloseTimeout   = openTimeoutSpan ?? new TimeSpan(0, 10, 0);
            binding.SendTimeout    = waitTimeout ?? new TimeSpan(3, 0, 0);
            binding.ReceiveTimeout = waitTimeout ?? new TimeSpan(3, 0, 0);

            binding.BypassProxyOnLocal = false;
            binding.UseDefaultWebProxy = true;

            binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;

            this.deploymentClient = new DeploymentServiceClient(binding, new EndpointAddress(new Uri(endpoint + "/DeploymentService")));
            this.deploymentClient.ClientCredentials.UserName.UserName = login;
            this.deploymentClient.ClientCredentials.UserName.Password = password;

            this.monitoringClient = new MonitoringServiceClient(binding, new EndpointAddress(new Uri(endpoint + "/MonitoringService")));
            this.monitoringClient.ClientCredentials.UserName.UserName = login;
            this.monitoringClient.ClientCredentials.UserName.Password = password;

            this.informationClient = new InformationServiceClient(binding, new EndpointAddress(new Uri(endpoint + "/InformationService")));
            this.informationClient.ClientCredentials.UserName.UserName = login;
            this.informationClient.ClientCredentials.UserName.Password = password;
        }
        public IProjectTestRunner Create(ProjectType projectType, IVariableProcessor variableProcessor)
        {
            if (projectType.HasFlag(ProjectType.Test))
            {
                return(new VisualStudioTestRunner(variableProcessor, this.pathServices));
            }

            throw new AspNetDeployException("Project type is not supported: " + projectType);
        }
Ejemplo n.º 3
0
        private Task <ActionExecuteResult> ExecuteAction(string action, string actionSetting, ArgumentProvider argument)
        {
            IVariableProcessor comparer = null;

            if (string.Equals(action, CompareProcessor.Method, StringComparison.CurrentCultureIgnoreCase))
            {
                comparer = new CompareProcessor();
            }
            else if (string.Equals(action, CompareNumberProcessor.Method, StringComparison.CurrentCultureIgnoreCase))
            {
                comparer = new CompareNumberProcessor();
            }

            if (comparer == null)
            {
                throw new ArgumentOutOfRangeException(nameof(action), $"Only {CompareProcessor.Method} and {CompareNumberProcessor.Method} are supported for now.");
            }
            return(comparer.Execute(actionSetting, argument));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of Service
 /// </summary>
 /// <param name="actorService">The Microsoft.ServiceFabric.Actors.Runtime.ActorService that will host this actor instance.</param>
 /// <param name="actorId">The Microsoft.ServiceFabric.Actors.ActorId for this actor instance.</param>
 public ExtractVariablesActor(ActorService actorService, ActorId actorId)
     : base(actorService, actorId)
 {
     this.Processor = new VariableProcessor();
 }
Ejemplo n.º 5
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);
        }
 public VisualStudioTestRunner(IVariableProcessor variableProcessor, IPathServices pathServices)
 {
     this.variableProcessor = variableProcessor;
     this.pathServices      = pathServices;
 }
Ejemplo n.º 7
0
        public IDeploymentAgent Create(Machine machine, BundleVersion bundleVersion)
        {
            IVariableProcessor variableProcessor = this.variableProcessorFactory.Create(bundleVersion.Id, machine.Id);

            return(new WCFSatelliteDeploymentAgent(variableProcessor, machine.URL, machine.Login, machine.Password));
        }