Exemplo n.º 1
0
        public void Run(
            Project project,
            Package package,
            Deployment deployment,
            DeploymentProcess deploymentProcess)
        {
            try
            {
                // todo: extract part of it to another class
                var deploymentWorkingDir = _deploymentProcessSettings.WorkingDir
                                           .AddSegment(project.Id)
                                           .AddSegment("deploying-packages")
                                           .AddSegment($"{_clock.UtcNow.FileFriendlyFormat()}_{deployment.EnvironmentId}_package-{package.Id}");

                // todo: make asynchronous
                var processDirectory = _deploymentProcessDirectoryFactory.CreateFromZip(
                    deploymentProcessZip: deploymentProcess.File,
                    toDirectory: deploymentWorkingDir
                    );

                var processOutput = _deploymentProcessRunner.Run(
                    processDirectory.Path.ToString(),
                    deploymentProcessFile: processDirectory.OpenProcessDescriptionFile(),
                    variablesForEnvironment: package.GetVariablesForEnvironment(deployment.EnvironmentId)
                    );

                deployment.MarkFinished(processOutput);
            }
            catch (Exception)
            {
                deployment.MarkExecutionFailed();

                throw;
            }
        }
        public JsonResult ExecuteDeploy(string code, string node)
        {
            return(ExecuteFunctionRun(() =>
            {
                ActionResult result = new ActionResult();
                FunctionNodeType nodeType = FunctionNodeType.Function;
                if (string.IsNullOrEmpty(code) ||
                    !Enum.TryParse <FunctionNodeType>(node, out nodeType))
                {
                    result.Extend = new
                    {
                        State = false,
                        ErroMsg = "SysDeploymen.Msg0"
                    };
                    return Json(result.Extend, JsonRequestBehavior.AllowGet);
                }

                string loginName = this.Session["LoginName"].ToString();
                string password = this.Session["Password"].ToString();
                DeploymentProcess deploymentProcess = new DeploymentProcess(this, loginName, password);
                deploymentProcess.Connection();
                object obj = deploymentProcess.OneButtonDeployment(nodeType, code);
                deploymentProcess.Dispose();
                return Json(obj, JsonRequestBehavior.AllowGet);
            }));
        }
        private static SystemModel CreateProjectModel(string lifecycleRef, string projectGroupRef, params Variable[] variables)
        {
            var deploymentProcess = new DeploymentProcess(new DeploymentStep[0]);
            var project           = new Project(new ElementIdentifier("prj"), string.Empty, false, false, false, deploymentProcess, variables, new ElementReference[0], new ElementReference(lifecycleRef), new ElementReference(projectGroupRef), null, Enumerable.Empty <ProjectTrigger>(), TenantedDeploymentMode.TenantedOrUntenanted);

            return(new SystemModelBuilder().AddProject(project).Build());
        }
Exemplo n.º 4
0
 public static YamlDeploymentProcess FromModel(DeploymentProcess model)
 {
     return(new YamlDeploymentProcess
     {
         Steps = model.DeploymentSteps.Select(YamlDeploymentStep.FromModel).ToArray()
     });
 }
        public void MapEFToBOList()
        {
            var mapper = new DALDeploymentProcessMapper();
            DeploymentProcess entity = new DeploymentProcess();

            entity.SetProperties("A", true, "A", "A", "A", 1);

            List <BODeploymentProcess> response = mapper.MapEFToBO(new List <DeploymentProcess>()
            {
                entity
            });

            response.Count.Should().Be(1);
        }
Exemplo n.º 6
0
        public virtual BODeploymentProcess MapEFToBO(
            DeploymentProcess ef)
        {
            var bo = new BODeploymentProcess();

            bo.SetProperties(
                ef.Id,
                ef.IsFrozen,
                ef.JSON,
                ef.OwnerId,
                ef.RelatedDocumentIds,
                ef.Version);
            return(bo);
        }
Exemplo n.º 7
0
        public virtual DeploymentProcess MapBOToEF(
            BODeploymentProcess bo)
        {
            DeploymentProcess efDeploymentProcess = new DeploymentProcess();

            efDeploymentProcess.SetProperties(
                bo.Id,
                bo.IsFrozen,
                bo.JSON,
                bo.OwnerId,
                bo.RelatedDocumentIds,
                bo.Version);
            return(efDeploymentProcess);
        }
        public void MapEFToBO()
        {
            var mapper = new DALDeploymentProcessMapper();
            DeploymentProcess entity = new DeploymentProcess();

            entity.SetProperties("A", true, "A", "A", "A", 1);

            BODeploymentProcess response = mapper.MapEFToBO(entity);

            response.Id.Should().Be("A");
            response.IsFrozen.Should().Be(true);
            response.JSON.Should().Be("A");
            response.OwnerId.Should().Be("A");
            response.RelatedDocumentIds.Should().Be("A");
            response.Version.Should().Be(1);
        }
        public void MapBOToEF()
        {
            var mapper = new DALDeploymentProcessMapper();
            var bo     = new BODeploymentProcess();

            bo.SetProperties("A", true, "A", "A", "A", 1);

            DeploymentProcess response = mapper.MapBOToEF(bo);

            response.Id.Should().Be("A");
            response.IsFrozen.Should().Be(true);
            response.JSON.Should().Be("A");
            response.OwnerId.Should().Be("A");
            response.RelatedDocumentIds.Should().Be("A");
            response.Version.Should().Be(1);
        }
Exemplo n.º 10
0
 public Project ToModel()
 {
     return(new Project(
                ToModelName(),
                Description,
                IsDisabled,
                AutoCreateRelease,
                DefaultToSkipIfAlreadyInstalled,
                DeploymentProcess.ToModel(),
                Variables.EnsureNotNull().Select(v => v.ToModel()),
                IncludedLibraryVariableSetRefs.EnsureNotNull().Select(reference => new ElementReference(reference)),
                new ElementReference(LifecycleRef),
                new ElementReference(ProjectGroupRef),
                VersioningStrategy?.ToModel(),
                Triggers.EnsureNotNull().Select(t => t.ToModel())));
 }
Exemplo n.º 11
0
        public async void Get()
        {
            var mock   = new ServiceMockFacade <IDeploymentProcessRepository>();
            var record = new DeploymentProcess();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult(record));
            var service = new DeploymentProcessService(mock.LoggerMock.Object,
                                                       mock.RepositoryMock.Object,
                                                       mock.ModelValidatorMockFactory.DeploymentProcessModelValidatorMock.Object,
                                                       mock.BOLMapperMockFactory.BOLDeploymentProcessMapperMock,
                                                       mock.DALMapperMockFactory.DALDeploymentProcessMapperMock);

            ApiDeploymentProcessResponseModel response = await service.Get(default(string));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <string>()));
        }
        public void It_should_upload_and_download_tenant()
        {
            var tagset = new TagSet(new ElementIdentifier("ts1"), new List <string> {
                "t1", "t2"
            });
            var environment1 = new Environment(new ElementIdentifier("env1"), CreateItem <string>());

            var projectGroup       = new ProjectGroup(CreateItemWithRename <ElementIdentifier>(false), string.Empty);
            var libraryVariableSet = new LibraryVariableSet(CreateItemWithRename <ElementIdentifier>(false),
                                                            CreateItem <string>(), LibraryVariableSet.VariableSetContentType.Variables,
                                                            Enumerable.Empty <Variable>());
            var lifecycle = new Lifecycle(
                CreateItemWithRename <ElementIdentifier>(false),
                string.Empty,
                new RetentionPolicy(0, RetentionPolicy.RetentionUnit.Items),
                new RetentionPolicy(0, RetentionPolicy.RetentionUnit.Items),
                Enumerable.Empty <Phase>());

            var deploymentProcess = new DeploymentProcess(new List <DeploymentStep>
            {
                new DeploymentStep(CreateItem <string>(), CreateItem <DeploymentStep.StepCondition>(), CreateItem <bool>(),
                                   CreateItem <DeploymentStep.StepStartTrigger>(),
                                   CreateItem <IReadOnlyDictionary <string, PropertyValue> >(), new[]
                {
                    new DeploymentAction(CreateItem <string>(), CreateItem <string>(),
                                         CreateItem <IReadOnlyDictionary <string, PropertyValue> >(),
                                         new[] { new ElementReference("env1") }),
                })
            });
            var scope = new Dictionary <VariableScopeType, IEnumerable <ElementReference> >
            {
                { VariableScopeType.Environment, new[] { new ElementReference("env1") } },
                {
                    VariableScopeType.Action,
                    deploymentProcess.DeploymentSteps.SelectMany(s => s.Actions.Select(a => a.Name))
                    .Select(action => new ElementReference(action))
                    .ToArray()
                }
            };
            var variables = new[] { new Variable(CreateItem <string>(), CreateItem <bool>(), CreateItem <bool>(), CreateItem <string>(), scope, CreateItem <VariablePrompt>()) };

            var project1 = new Project(CreateItemWithRename <ElementIdentifier>(false), CreateItem <string>(),
                                       CreateItem <bool>(), CreateItem <bool>(), CreateItem <bool>(), deploymentProcess, variables,
                                       new[] { new ElementReference(libraryVariableSet.Identifier.Name) },
                                       new ElementReference(lifecycle.Identifier.Name), new ElementReference(projectGroup.Identifier.Name),
                                       CreateItem <VersioningStrategy>(), Enumerable.Empty <ProjectTrigger>(),
                                       TenantedDeploymentMode.TenantedOrUntenanted);

            var tenant = new Tenant(new ElementIdentifier("t1"),
                                    new[] { new ElementReference(tagset.Identifier.Name) },
                                    new Dictionary <string, IEnumerable <string> > {
                { project1.Identifier.Name, new[] { environment1.Identifier.Name } }
            });

            var expected = new SystemModelBuilder()
                           .AddProject(project1)
                           .AddTenant(tenant)
                           .AddProjectGroup(projectGroup)
                           .AddLifecycle(lifecycle)
                           .AddLibraryVariableSet(libraryVariableSet)
                           .AddEnvironment(environment1)
                           .Build();

            _uploader.UploadModel(expected).GetAwaiter();
            var actual = _downloader.DownloadModel().GetAwaiter().GetResult();

            actual.AssertDeepEqualsTo(expected);
        }
        public void It_should_upload_and_download_projects()
        {
            var environment1 = new Environment(new ElementIdentifier("env1"), CreateItem <string>());
            var environment2 = new Environment(new ElementIdentifier("env2"), CreateItem <string>());

            var projectGroup       = new ProjectGroup(CreateItemWithRename <ElementIdentifier>(false), string.Empty);
            var libraryVariableSet = new LibraryVariableSet(CreateItemWithRename <ElementIdentifier>(false),
                                                            CreateItem <string>(), LibraryVariableSet.VariableSetContentType.Variables,
                                                            Enumerable.Empty <Variable>());
            var lifecycle = new Lifecycle(
                CreateItemWithRename <ElementIdentifier>(false),
                string.Empty,
                new RetentionPolicy(0, RetentionPolicy.RetentionUnit.Items),
                new RetentionPolicy(0, RetentionPolicy.RetentionUnit.Items),
                Enumerable.Empty <Phase>());

            var deploymentProcess = new DeploymentProcess(new List <DeploymentStep>
            {
                new DeploymentStep(CreateItem <string>(), CreateItem <DeploymentStep.StepCondition>(), CreateItem <bool>(),
                                   CreateItem <DeploymentStep.StepStartTrigger>(),
                                   CreateItem <IReadOnlyDictionary <string, PropertyValue> >(), new[]
                {
                    new DeploymentAction(CreateItem <string>(), CreateItem <string>(),
                                         CreateItem <IReadOnlyDictionary <string, PropertyValue> >(),
                                         new[] { new ElementReference("env1") }),
                    new DeploymentAction(CreateItem <string>(), CreateItem <string>(),
                                         CreateItem <IReadOnlyDictionary <string, PropertyValue> >(),
                                         new[] { new ElementReference("env2") })
                }),
                new DeploymentStep(CreateItem <string>(), CreateItem <DeploymentStep.StepCondition>(), CreateItem <bool>(),
                                   CreateItem <DeploymentStep.StepStartTrigger>(),
                                   CreateItem <IReadOnlyDictionary <string, PropertyValue> >(), new[]
                {
                    new DeploymentAction(CreateItem <string>(), CreateItem <string>(),
                                         CreateItem <IReadOnlyDictionary <string, PropertyValue> >(),
                                         new[] { new ElementReference("env1") })
                })
            });
            var scope = new Dictionary <VariableScopeType, IEnumerable <ElementReference> >
            {
                { VariableScopeType.Environment, new[] { new ElementReference("env1"), new ElementReference("env2") } },
                { VariableScopeType.Machine, new[] { new ElementReference("m1"), new ElementReference("m2") } },
                { VariableScopeType.Role, new[] { new ElementReference("r1"), new ElementReference("r2") } },
                { VariableScopeType.Channel, new[] { new ElementReference("ch1"), new ElementReference("ch2") } },
                {
                    VariableScopeType.Action,
                    deploymentProcess.DeploymentSteps.SelectMany(s => s.Actions.Select(a => a.Name))
                    .Select(action => new ElementReference(action))
                    .ToArray()
                }
            };
            var variables = new[]
            {
                new Variable(CreateItem <string>(), CreateItem <bool>(), CreateItem <bool>(), CreateItem <string>(), scope,
                             CreateItem <VariablePrompt>()),
                new Variable(CreateItem <string>(), CreateItem <bool>(), CreateItem <bool>(), CreateItem <string>(), scope,
                             CreateItem <VariablePrompt>())
            };

            var project1 = new Project(CreateItemWithRename <ElementIdentifier>(false), CreateItem <string>(),
                                       CreateItem <bool>(), CreateItem <bool>(), CreateItem <bool>(), deploymentProcess, variables,
                                       new[] { new ElementReference(libraryVariableSet.Identifier.Name) },
                                       new ElementReference(lifecycle.Identifier.Name), new ElementReference(projectGroup.Identifier.Name),
                                       CreateItem <VersioningStrategy>(), Enumerable.Empty <ProjectTrigger>(),
                                       TenantedDeploymentMode.TenantedOrUntenanted);
            var project2 = new Project(CreateItemWithRename <ElementIdentifier>(false), CreateItem <string>(),
                                       CreateItem <bool>(), CreateItem <bool>(), CreateItem <bool>(), deploymentProcess, variables,
                                       new[] { new ElementReference(libraryVariableSet.Identifier.Name) },
                                       new ElementReference(lifecycle.Identifier.Name), new ElementReference(projectGroup.Identifier.Name),
                                       null, new[] { CreateProjectTrigger("m1", "env1"), CreateProjectTrigger("m2", "env2") },
                                       TenantedDeploymentMode.TenantedOrUntenanted);

            var expected = new SystemModelBuilder()
                           .AddProject(project1)
                           .AddProject(project2)
                           .AddProjectGroup(projectGroup)
                           .AddLifecycle(lifecycle)
                           .AddLibraryVariableSet(libraryVariableSet)
                           .AddEnvironment(environment1)
                           .AddEnvironment(environment2)
                           .Build();

            _repository.Machines.Create(new MachineResource {
                Name = "m1"
            });
            _repository.Machines.Create(new MachineResource {
                Name = "m2"
            });
            //_repository.FakeMachineRoles.Add("r1");
            //_repository.FakeMachineRoles.Add("r2");
            _repository.Channels.Create(new ChannelResource {
                Name = "ch1"
            });
            _repository.Channels.Create(new ChannelResource {
                Name = "ch2"
            });

            _uploader.UploadModel(expected).GetAwaiter();
            var actual = _downloader.DownloadModel().GetAwaiter().GetResult();

            actual.AssertDeepEqualsTo(expected);
        }
        public static DeploymentProcessResource UpdateWith(this DeploymentProcessResource resource, DeploymentProcess model, ProjectResource projectResource, IOctopusRepository repository)
        {
            resource.Steps.Clear();
            foreach (var step in model.DeploymentSteps.Select(s => new DeploymentStepResource().UpdateWith(s, projectResource, repository)))
            {
                resource.Steps.Add(step);
            }


            return(resource);
        }
Exemplo n.º 15
0
        public static async Task <DeploymentProcessResource> UpdateWith(this DeploymentProcessResource resource, DeploymentProcess model, IOctopusAsyncRepository repository)
        {
            resource.Steps.Clear();
            foreach (var step in model.DeploymentSteps.Select(s => new DeploymentStepResource().UpdateWith(s, repository)))
            {
                resource.Steps.Add(await step);
            }

            return(resource);
        }