public ExtractArtifactsDeploymentStep( ProjectInfo projectInfo, EnvironmentInfo environmentInfo, DeploymentInfo deploymentInfo, string artifactsFilePath, string targetArtifactsDirPath, IFileAdapter fileAdapter, IDirectoryAdapter directoryAdapter, IZipFileAdapter zipFileAdapter) { Guard.NotNull(projectInfo, "projectInfo"); Guard.NotNull(environmentInfo, "environmentInfo"); Guard.NotNull(deploymentInfo, "deploymentInfo"); Guard.NotNullNorEmpty(artifactsFilePath, "artifactsFilePath"); Guard.NotNullNorEmpty(targetArtifactsDirPath, "targetArtifactsDirPath"); Guard.NotNull(fileAdapter, "fileAdapter"); Guard.NotNull(directoryAdapter, "directoryAdapter"); Guard.NotNull(zipFileAdapter, "zipFileAdapter"); _projectInfo = projectInfo; _environmentInfo = environmentInfo; _deploymentInfo = deploymentInfo; _artifactsFilePath = artifactsFilePath; _targetArtifactsDirPath = targetArtifactsDirPath; _fileAdapter = fileAdapter; _directoryAdapter = directoryAdapter; _zipFileAdapter = zipFileAdapter; }
public GatherDbScriptsToRunDeploymentStep( string dbName, Lazy<string> scriptsDirectoryPathProvider, string databaseServerMachineName, string environmentName, DeploymentInfo deploymentInfo, IDbVersionProvider dbVersionProvider, IScriptsToRunSelector scriptsToRunSelector) { Guard.NotNullNorEmpty(dbName, "dbName"); Guard.NotNull(scriptsDirectoryPathProvider, "scriptsDirectoryPathProvider"); Guard.NotNullNorEmpty(databaseServerMachineName, "databaseServerMachineName"); Guard.NotNullNorEmpty(environmentName, "environmentName"); Guard.NotNull(deploymentInfo, "deploymentInfo"); Guard.NotNull(dbVersionProvider, "dbVersionProvider"); Guard.NotNull(scriptsToRunSelector, "scriptsToRunWebSelector"); _dbName = dbName; _scriptsDirectoryPathProvider = scriptsDirectoryPathProvider; _sqlServerName = databaseServerMachineName; _environmentName = environmentName; _deploymentInfo = deploymentInfo; _dbVersionProvider = dbVersionProvider; _scriptsToRunSelector = scriptsToRunSelector; _scriptsToRun = Enumerable.Empty<DbScriptToRun>(); }
public DeployUberDeployerAgentUsingConsoleAppDeploymentStep(DeploymentInfo deploymentInfo, IDirectoryAdapter directoryAdapter) { Guard.NotNull(deploymentInfo, "deploymentInfo"); Guard.NotNull(directoryAdapter, "directoryAdapter"); _deploymentInfo = deploymentInfo; _directoryAdapter = directoryAdapter; }
public void OnDeploymentTaskStarting(DeploymentInfo deploymentInfo, DeploymentTask deploymentTask, DeploymentContext deploymentContext) { if (deploymentInfo.TargetEnvironmentName == ProductionEnvironmentName && deploymentInfo.ProjectConfigurationName != ProductionProjectConfigurationName) { throw new InvalidOperationException(string.Format( "Can't deploy project ('{0}') with non-production configuration ('{1}') to the production environment!", deploymentInfo.ProjectName, deploymentInfo.ProjectConfigurationName)); } }
public DownloadArtifactsDeploymentStep(ProjectInfo projectInfo, DeploymentInfo deploymentInfo, string targetDirPath, IArtifactsRepository artifactsRepository) { Guard.NotNull(projectInfo, "projectInfo"); Guard.NotNull(deploymentInfo, "deploymentInfo"); Guard.NotNullNorEmpty(targetDirPath, "targetDirPath"); Guard.NotNull(artifactsRepository, "artifactsRepository"); _projectInfo = projectInfo; _deploymentInfo = deploymentInfo; _targetDirPath = targetDirPath; _artifactsRepository = artifactsRepository; _artifactsFilePath = Path.Combine(_targetDirPath, "artifacts.zip"); }
public void OnDeploymentTaskStarting_WhenEnvironmentIsProductionAndConfigurationIsNot_ThrowsInvalidOperationException() { DeploymentInfo deploymentInfo = new DeploymentInfo( Guid.NewGuid(), false, "project_name", "branch", "project_configuration_build_id", EnforceTargetEnvironmentConstraintsModule.ProductionEnvironmentName, new TerminalAppInputParams()); Assert.Throws<InvalidOperationException>( () => _enforceTargetEnvironmentConstraintsModule.OnDeploymentTaskStarting(deploymentInfo, _deploymentTask, _deploymentContext)); }
public void Prepare_should_throw_exception_when_web_machines_are_invalid(List<string> webMachines) { // Arrange var webInputParams = new WebAppInputParams(webMachines); DeploymentInfo deploymentInfo = new DeploymentInfo( Guid.NewGuid(), false, "projectName", "projectConfigurationName", "projectConfigurationBuildId", "targetEnvironmentName", webInputParams); _deployWebAppDeploymentTask.Initialize(deploymentInfo); // Act assert Assert.Throws<DeploymentTaskException>(() => _deployWebAppDeploymentTask.Prepare()); }
public void OnDeploymentTaskFinished(DeploymentInfo deploymentInfo, DeploymentTask deploymentTask, DeploymentContext deploymentContext) { if (deploymentInfo.IsSimulation || deploymentTask is CreateManualDeploymentPackageDeploymentTask) { return; } var deploymentRequest = new DeploymentRequest { RequesterIdentity = deploymentContext.RequesterIdentity, DateStarted = deploymentContext.DateStarted, DateFinished = deploymentContext.DateFinished, ProjectName = deploymentInfo.ProjectName, ProjectConfigurationName = deploymentInfo.ProjectConfigurationName, ProjectConfigurationBuildId = deploymentInfo.ProjectConfigurationBuildId, TargetEnvironmentName = deploymentInfo.TargetEnvironmentName, FinishedSuccessfully = deploymentContext.FinishedSuccessfully, }; _deploymentRequestRepository.AddDeploymentRequest(deploymentRequest); }
public void StartDeployment(DeploymentInfo deploymentInfo, DeploymentTask deploymentTask, DeploymentContext deploymentContext) { Guard.NotNull(deploymentInfo, "deploymentInfo"); Guard.NotNull(deploymentTask, "deploymentTask"); Guard.NotNull(deploymentContext, "deploymentContext"); PostDiagnosticMessage(string.Format("Starting{0} '{1}'.", (deploymentInfo.IsSimulation ? " (simulation)" : ""), deploymentTask.GetType().Name), DiagnosticMessageType.Info); deploymentContext.DateStarted = DateTime.UtcNow; deploymentTask.DiagnosticMessagePosted += OnDeploymentTaskDiagnosticMessagePosted; bool finishedSuccessfully = false; OnDeploymentTaskStarting(deploymentInfo, deploymentTask, deploymentContext); try { deploymentTask.Initialize(deploymentInfo); deploymentTask.PrepareAndExecute(); finishedSuccessfully = true; PostDiagnosticMessage(string.Format("Finished{0} '{1}' (\"{2}\").", (deploymentInfo.IsSimulation ? " (simulation)" : ""), deploymentTask.GetType().Name, deploymentTask.Description), DiagnosticMessageType.Info); PostDiagnosticMessage("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -", DiagnosticMessageType.Info); } finally { deploymentContext.DateFinished = DateTime.UtcNow; deploymentContext.FinishedSuccessfully = finishedSuccessfully; // TODO IMM HI: catch exceptions; pass them upstream using some mechanisms like DeploymentTask.DiagnosticMessagePosted event OnDeploymentTaskFinished(deploymentInfo, deploymentTask, deploymentContext); deploymentTask.DiagnosticMessagePosted -= OnDeploymentTaskDiagnosticMessagePosted; } }
public void SetUp() { _environmentInfo = DeploymentDataGenerator.GetEnvironmentInfo(); _deploymentInfo = DeploymentInfoGenerator.GetDbDeploymentInfo(); _projectInfo = ProjectInfoGenerator.GetTerminalAppProjectInfo(); _fileAdapterFake = new Mock<IFileAdapter>(MockBehavior.Loose); _directoryAdapterFake = new Mock<IDirectoryAdapter>(MockBehavior.Loose); _zipFileAdapterFake = new Mock<IZipFileAdapter>(MockBehavior.Loose); _deploymentStep = new ExtractArtifactsDeploymentStep( _projectInfo, _environmentInfo, _deploymentInfo, _ArtifactsFilePath, _TargetArtifactsDirPath, _fileAdapterFake.Object, _directoryAdapterFake.Object, _zipFileAdapterFake.Object); }
public void OnDeploymentTaskStarting(DeploymentInfo deploymentInfo, DeploymentTask deploymentTask, DeploymentContext deploymentContext) { // do nothing }
private List<ProjectDeployment> BuildDefaultProjectDeployments(IEnumerable<ProjectInfo> dependentProjectsToDeploy, string defaultTeamCityProjectConfiguration) { var projectDeployments = new List<ProjectDeployment>(); foreach (var projectInfo in dependentProjectsToDeploy) { IEnumerable<TeamCityBuildType> teamCityBuildTypes = _temCityRestClient.GetBuildTypes(projectInfo.ArtifactsRepositoryName); TeamCityBuildType defaultBuildType = teamCityBuildTypes.FirstOrDefault(x => x.Name == defaultTeamCityProjectConfiguration); if (defaultBuildType == null) { throw new DeploymentTaskException(string.Format("TeamCity configuration: [{0}] does not exist for project: [{1}]", defaultTeamCityProjectConfiguration, projectInfo.Name)); } TeamCityBuild lastSuccessfulBuild = _temCityRestClient.GetLastSuccessfulBuild(defaultBuildType.Id); if (lastSuccessfulBuild == null) { throw new DeploymentTaskException(string.Format("Cannot obtain last successful build for project [{0}], configuration: [{1}], team city build type id: [{2}]", projectInfo.Name, defaultTeamCityProjectConfiguration, defaultBuildType.Id)); } var deploymentInfo = new DeploymentInfo(_deploymentId, false, projectInfo.Name, defaultTeamCityProjectConfiguration, lastSuccessfulBuild.Id, _targetEnvironment, projectInfo.CreateEmptyInputParams()); projectDeployments.Add( new ProjectDeployment { ProjectInfo = projectInfo, DeploymentInfo = deploymentInfo, TeamCityBuild = lastSuccessfulBuild, }); } return projectDeployments; }
protected override void ExecuteTask() { try { IProjectInfoRepository projectInfoRepository = ObjectFactory.Instance.CreateProjectInfoRepository(); ProjectInfo projectInfo = projectInfoRepository.FindByName(ProjectName); DeploymentTask deploymentTask = projectInfo.CreateDeploymentTask(ObjectFactory.Instance); IDeploymentPipeline deploymentPipeline = ObjectFactory.Instance.CreateDeploymentPipeline(); deploymentPipeline.DiagnosticMessagePosted += (eventSender, tmpArgs) => Log(Level.Info, tmpArgs.Message); var deploymentContext = new DeploymentContext(RequesterIdentity); Guid deploymentId = Guid.NewGuid(); var deploymentInfo = new DeploymentInfo( deploymentId, IsSimulation, ProjectName, ConfigurationName, BuildId, Environment, projectInfo.CreateEmptyInputParams()); deploymentPipeline.StartDeployment(deploymentInfo, deploymentTask, deploymentContext); } catch (Exception exc) { Log(Level.Error, "Error: " + exc); } }
private void OnDeploymentTaskStarting(DeploymentInfo deploymentInfo, DeploymentTask deploymentTask, DeploymentContext deploymentContext) { foreach (IDeploymentPipelineModule deploymentPipelineModule in _modules) { deploymentPipelineModule.OnDeploymentTaskStarting(deploymentInfo, deploymentTask, deploymentContext); } }
public override int Run(string[] args) { if (args.Length != 3 && args.Length != 4) { DisplayCommandUsage(); return 1; } IProjectInfoRepository projectInfoRepository = ObjectFactory.Instance.CreateProjectInfoRepository(); string projectName = args[0]; string projectConfigurationName = args[1]; string targetEnvironmentName = args[2]; bool isSimulation = (args.Length >= 4 ? string.Equals(args[3], "simulate", StringComparison.OrdinalIgnoreCase) : false); ProjectInfo projectInfo = projectInfoRepository.FindByName(projectName); if (projectInfo == null) { OutputWriter.WriteLine("Project named '{0}' doesn't exist.", projectName); return 1; } ITeamCityClient teamCityClient = ObjectFactory.Instance.CreateTeamCityClient(); Project project = teamCityClient.GetProjectByName(projectInfo.ArtifactsRepositoryName); ProjectDetails projectDetails = teamCityClient.GetProjectDetails(project); ProjectConfiguration projectConfiguration = projectDetails.ConfigurationsList .Configurations .SingleOrDefault(pc => pc.Name == projectConfigurationName); if (projectConfiguration == null) { OutputWriter.WriteLine( "Project configuration named '{0}' doesn't exist for project '{1}'.", projectConfigurationName, projectName); return 0; } ProjectConfigurationDetails projectConfigurationDetails = teamCityClient.GetProjectConfigurationDetails(projectConfiguration); ProjectConfigurationBuild projectConfigurationBuild = teamCityClient.GetProjectConfigurationBuilds(projectConfigurationDetails, 0, 1) .Builds .FirstOrDefault(); if (projectConfigurationBuild == null) { throw new InvalidOperationException( string.Format( "Project configuration '{0}' of project '{1}' doesn't have any builds yet.", projectConfigurationName, projectName)); } if (projectConfigurationBuild.Status != BuildStatus.Success) { throw new InvalidOperationException( string.Format( "Couldn't deploy latest build of project configuration '{0}' of project '{1}' because it was not successfull.", projectConfigurationName, projectName)); } string projectConfigurationBuildId = projectConfigurationBuild.Id; try { DeploymentTask deploymentTask = projectInfo.CreateDeploymentTask(ObjectFactory.Instance); Guid deploymentId = Guid.NewGuid(); var deploymentInfo = new DeploymentInfo( deploymentId, isSimulation, projectName, projectConfigurationName, projectConfigurationBuildId, targetEnvironmentName, projectInfo.CreateEmptyInputParams()); IDeploymentPipeline deploymentPipeline = ObjectFactory.Instance.CreateDeploymentPipeline(); deploymentPipeline.DiagnosticMessagePosted += (eventSender, tmpArgs) => LogMessage(tmpArgs.Message, tmpArgs.MessageType); var deploymentContext = new DeploymentContext(RequesterIdentity); deploymentPipeline.StartDeployment(deploymentInfo, deploymentTask, deploymentContext, false); return 0; } catch (Exception exc) { LogMessage("Error: " + exc, DiagnosticMessageType.Error); return 1; } }
public ProjectDeploymentData(DeploymentInfo deploymentInfo, ProjectInfo projectInfo, DeploymentTask deploymentTask) { DeploymentTask = deploymentTask; DeploymentInfo = deploymentInfo; ProjectInfo = projectInfo; }
public override int Run(string[] args) { if (args.Length != 4 && args.Length != 5) { DisplayCommandUsage(); return 1; } IProjectInfoRepository projectInfoRepository = ObjectFactory.Instance.CreateProjectInfoRepository(); string projectName = args[0]; string projectConfigurationName = args[1]; string projectConfigurationBuildId = args[2]; string targetEnvironmentName = args[3]; bool isSimulation = (args.Length >= 5 ? string.Equals(args[4], "simulate", StringComparison.OrdinalIgnoreCase) : false); ProjectInfo projectInfo = projectInfoRepository.FindByName(projectName); if (projectInfo == null) { OutputWriter.WriteLine("Project named '{0}' doesn't exist.", projectName); return 1; } Guid deploymentId = Guid.NewGuid(); var deploymentInfo = new DeploymentInfo( deploymentId, isSimulation, projectName, projectConfigurationName, projectConfigurationBuildId, targetEnvironmentName, projectInfo.CreateEmptyInputParams()); try { DeploymentTask deploymentTask = projectInfo.CreateDeploymentTask(ObjectFactory.Instance); IDeploymentPipeline deploymentPipeline = ObjectFactory.Instance.CreateDeploymentPipeline(); deploymentPipeline.DiagnosticMessagePosted += (sender, tmpArgs) => LogMessage(tmpArgs.Message, tmpArgs.MessageType); var deploymentContext = new DeploymentContext(RequesterIdentity); deploymentPipeline.StartDeployment(deploymentInfo, deploymentTask, deploymentContext, false); return 0; } catch (Exception exc) { LogMessage("Error: " + exc, DiagnosticMessageType.Error); return 1; } }
public void OnDeploymentTaskFinished(DeploymentInfo deploymentInfo, DeploymentTask deploymentTask, DeploymentContext deploymentContext) { // do nothing }
public ProjectDeploymentData(DeploymentInfo deploymentInfo, ProjectInfo projectInfo, DeploymentTask deploymentTask) { DeploymentTask = deploymentTask; DeploymentInfo = deploymentInfo; ProjectInfo = projectInfo; }