Beispiel #1
0
        public RedeployDeploymentPlans GetRedeployDeploymentPlans(string environment, ComponentFilter componentFilter = null)
        {
            var environments = new[] { environment };

            var environmentIds = _repository.Environments
                                 .GetAll()
                                 .Where(x => environments.Contains(x.Name))
                                 .ToArray();

            var environmentReference = environmentIds.FirstOrDefault(x => x.Name == environment);

            if (environmentReference == null)
            {
                throw new Exception(string.Format("Unable to find environment - {0}", environment));
            }

            var dashboard = _repository.Dashboards.GetDynamicDashboard(null, environmentIds.Select(x => x.Id).ToArray());

            var redeployDeploymentPlans = new RedeployDeploymentPlans
            {
                EnvironmentId             = environmentReference.Id,
                EnvironmentDeploymentPlan = new EnvironmentDeploymentPlan(new List <ComponentDeploymentPlan>())
            };

            foreach (var dashboardProjectResource in dashboard.Projects)
            {
                if (GetProjectById(dashboardProjectResource.Id).IsDisabled)
                {
                    continue;
                }

                var projectName = dashboardProjectResource.Name;

                if (componentFilter != null && !componentFilter.Match(projectName))
                {
                    continue;
                }

                var projectId = dashboardProjectResource.Id;

                var componentFrom = GetComponentForEnvironment(dashboard, environmentReference.Id, projectId, componentFilter);
                var componentTo   = componentFrom;

                var deploymentPlan = GetEnvironmentDeploymentPlan(projectId, projectName, componentFrom, componentTo, true);

                //If the component is installed. Then re-install it
                if (componentFrom != null)
                {
                    deploymentPlan.Action = PlanAction.Change;
                }

                redeployDeploymentPlans.EnvironmentDeploymentPlan.DeploymentPlans.Add(deploymentPlan);
            }

            return(redeployDeploymentPlans);
        }
Beispiel #2
0
        public void ExcludeDoesNotMatchhWhenEmpty()
        {
            var componentFilter = new ComponentFilter()
            {
                Include     = false,
                Expressions = new List <string>()
            };

            var match = componentFilter.Match("not matched project name");

            Assert.True(match);
        }
Beispiel #3
0
        public BranchDeploymentPlans GetBranchDeploymentPlans(string environment, string branch, bool doNotUseDifferentialDeployment, ComponentFilter componentFilter = null)
        {
            var environments = new[] { environment };

            var environmentIds = _repository.Environments
                                 .GetAll()
                                 .Where(x => environments.Contains(x.Name))
                                 .ToArray();

            var environmentReference = environmentIds.FirstOrDefault(x => x.Name == environment);

            if (environmentReference == null)
            {
                throw new Exception(string.Format("Unable to find environment - {0}", environment));
            }

            var dashboard = _repository.Dashboards.GetDynamicDashboard(null, environmentIds.Select(x => x.Id).ToArray());

            var branchDeploymentPlan = new BranchDeploymentPlans
            {
                EnvironmentId             = environmentReference.Id,
                Branch                    = branch,
                EnvironmentDeploymentPlan = new EnvironmentDeploymentPlan(new List <ComponentDeploymentPlan>())
            };

            foreach (var dashboardProjectResource in dashboard.Projects)
            {
                if (GetProjectById(dashboardProjectResource.Id).IsDisabled)
                {
                    continue;
                }

                var projectName = dashboardProjectResource.Name;

                if (componentFilter != null && !componentFilter.Match(projectName))
                {
                    continue;
                }

                var projectId = dashboardProjectResource.Id;

                var componentFrom = GetComponentForBranch(dashboard, environmentReference.Id, projectId, branch, componentFilter);
                var componentTo   = GetComponentForEnvironment(dashboard, environmentReference.Id, projectId, componentFilter);

                var deploymentPlan = GetEnvironmentDeploymentPlan(projectId, projectName, componentFrom, componentTo, doNotUseDifferentialDeployment);

                branchDeploymentPlan.EnvironmentDeploymentPlan.DeploymentPlans.Add(deploymentPlan);
            }

            return(branchDeploymentPlan);
        }
Beispiel #4
0
        public void IncludeMatch()
        {
            var componentFilter = new ComponentFilter()
            {
                Include     = true,
                Expressions = new List <string>()
                {
                    "^project.*$"
                }
            };

            var match = componentFilter.Match("project name");

            Assert.True(match);
        }
Beispiel #5
0
        private static List <string> GetComponentDependancies(ComponentFilter componentFilter, VariableSetResource projectVariables,
                                                              string releaseId)
        {
            var componentDependanciesVariables = projectVariables.Variables
                                                 .Where(x => x.Name == ComponentDependanciesVariableName && !string.IsNullOrEmpty(x.Value)).ToList();

            try
            {
                return(componentDependanciesVariables
                       .SelectMany(x => JsonConvert.DeserializeObject <string[]>(x.Value))
                       .Where(x => componentFilter == null || componentFilter.Match(x))
                       .ToList());
            }
            catch
            {
                var releaseUri = string.Format("/app#/releases/{0}", releaseId);

                throw new Exception(string.Format("The variable {0} is not a valid json string array. Please update at {1}\r\nCurrent value:\r\n{2}",
                                                  componentDependanciesVariables, releaseUri, componentDependanciesVariables.First().Value));
            }
        }