Beispiel #1
0
        public ProjectMetadata GetProjectMetadata(string projectName, string environmentName)
        {
            Guard.NotNullNorEmpty(projectName, "projectName");
            Guard.NotNullNorEmpty(environmentName, "environmentName");

            _log.DebugIfEnabled(() => string.Format("Getting project metadata. Project name: '{0}'. Environment name: '{1}'.", projectName, environmentName));

            ProjectInfo projectInfo =
                _projectInfoRepository.FindByName(projectName);

            if (projectInfo == null)
            {
                throw new ArgumentException(string.Format("Project named '{0}' doesn't exist.", projectName));
            }

            EnvironmentInfo environmentInfo =
                _environmentInfoRepository.FindByName(environmentName);

            if (environmentInfo == null)
            {
                throw new ArgumentException(string.Format("Environment named '{0}' doesn't exist.", environmentName));
            }

            if (projectInfo is DbProjectInfo)
            {
                return(GetDbProjectMetadata((DbProjectInfo)projectInfo, environmentInfo));
            }
            else
            {
                return(GetOrdinaryProjectMetadata(projectInfo, environmentInfo));
            }
        }
Beispiel #2
0
        protected EnvironmentInfo GetEnvironmentInfo()
        {
            EnvironmentInfo environmentInfo =
                _environmentInfoRepository.FindByName(
                    DeploymentInfo.TargetEnvironmentName);

            if (environmentInfo == null)
            {
                throw new DeploymentTaskException(string.Format("Environment named '{0}' doesn't exist.", DeploymentInfo.TargetEnvironmentName));
            }

            return(environmentInfo);
        }
        private IEnumerable <ProjectDeploymentData> CreateProjectEnvironmentDeployments(Guid uniqueClientId, EnvironmentDeployInfo environmentDeployInfo, IEnumerable <ProjectToDeploy> projects)
        {
            var projectDeployments         = new List <ProjectDeploymentData>();
            var priorityProjectDeplyoments = new List <ProjectDeploymentData>();

            EnvironmentInfo environmentInfo = _environmentInfoRepository.FindByName(environmentDeployInfo.TargetEnvironment);

            if (environmentInfo == null)
            {
                throw new FaultException <EnvironmentNotFoundFault>(new EnvironmentNotFoundFault {
                    EnvironmentName = environmentDeployInfo.TargetEnvironment
                });
            }

            foreach (var projectToDeploy in projects)
            {
                try
                {
                    ProjectInfo projectInfo = _projectInfoRepository.FindByName(projectToDeploy.ProjectName);

                    if (projectInfo == null)
                    {
                        throw new DeploymentTaskException(string.Format("Not found configuration for project: {0}", projectToDeploy.ProjectName));
                    }

                    ProjectConfigurationBuild lastSuccessfulBuild = GetLatestSuccessfulBuild(projectToDeploy.ProjectName, environmentDeployInfo.BuildConfigurationName);

                    if (lastSuccessfulBuild == null)
                    {
                        throw new DeploymentTaskException(string.Format("Successful build not found for project: {0} and configuration: {1}", projectToDeploy, environmentDeployInfo.BuildConfigurationName));
                    }

                    InputParams inputParams = BuildInputParams(projectInfo, environmentInfo);

                    var deploymentInfo = new Core.Domain.DeploymentInfo(projectToDeploy.DeploymentId, false, projectToDeploy.ProjectName, environmentDeployInfo.BuildConfigurationName, lastSuccessfulBuild.Id, environmentDeployInfo.TargetEnvironment, inputParams);

                    DeploymentTask deploymentTask;

                    // TODO LK: could replace below code with factory
                    if (projectInfo.Type == ProjectType.Db)
                    {
                        DeploymentTask dropDbProjectDeploymentTask = new DropDbProjectDeploymentTask(
                            ObjectFactory.Instance.CreateProjectInfoRepository(),
                            ObjectFactory.Instance.CreateEnvironmentInfoRepository(),
                            ObjectFactory.Instance.CreateDbManagerFactory());

                        priorityProjectDeplyoments.Add(new ProjectDeploymentData(deploymentInfo, projectInfo, dropDbProjectDeploymentTask));

                        deploymentTask =
                            new DeployDbProjectDeploymentTask(
                                ObjectFactory.Instance.CreateProjectInfoRepository(),
                                ObjectFactory.Instance.CreateEnvironmentInfoRepository(),
                                ObjectFactory.Instance.CreateArtifactsRepository(),
                                ObjectFactory.Instance.CreateDbScriptRunnerFactory(),
                                ObjectFactory.Instance.CreateDbVersionProvider(),
                                ObjectFactory.Instance.CreateFileAdapter(),
                                ObjectFactory.Instance.CreateZipFileAdapter(),
                                ObjectFactory.Instance.CreateScriptsToRunWebSelectorForEnvironmentDeploy(),
                                ObjectFactory.Instance.CreateMsSqlDatabasePublisher(),
                                ObjectFactory.Instance.CreateDbManagerFactory(),
                                ObjectFactory.Instance.CreateUserNameNormalizer(),
                                ObjectFactory.Instance.CreateDirectoryAdapter());
                    }
                    else if (projectInfo.Type == ProjectType.NtService)
                    {
                        deploymentTask = new DeployNtServiceDeploymentTask(
                            ObjectFactory.Instance.CreateProjectInfoRepository(),
                            ObjectFactory.Instance.CreateEnvironmentInfoRepository(),
                            ObjectFactory.Instance.CreateArtifactsRepository(),
                            ObjectFactory.Instance.CreateNtServiceManager(),
                            ObjectFactory.Instance.CreatePasswordCollector(),
                            ObjectFactory.Instance.CreateFailoverClusterManager(),
                            ObjectFactory.Instance.CreateDirectoryAdapter(),
                            ObjectFactory.Instance.CreateFileAdapter(),
                            ObjectFactory.Instance.CreateZipFileAdapter())
                        {
                            UseLocalSystemUser = true
                        };
                    }
                    else
                    {
                        deploymentTask = projectInfo.CreateDeploymentTask(ObjectFactory.Instance);
                    }

                    projectDeployments.Add(new ProjectDeploymentData(deploymentInfo, projectInfo, deploymentTask));
                }
                catch (Exception e)
                {
                    LogMessage(uniqueClientId, DiagnosticMessageType.Error, e.Message);
                }
            }

            priorityProjectDeplyoments.AddRange(projectDeployments);

            return(priorityProjectDeplyoments);
        }