private static InputParams BuildInputParams(ProjectInfo projectInfo, EnvironmentInfo environmentInfo)
        {
            switch (projectInfo.Type)
            {
            case ProjectType.WebApp:
                // deploy to all web server machines
                return(new WebAppInputParams(environmentInfo.WebServerMachineNames));

            case ProjectType.Db:
                return(new DbInputParams());

            case ProjectType.NtService:
                return(new NtServiceInputParams());

            case ProjectType.SchedulerApp:
                return(new SsdtInputParams());

            case ProjectType.TerminalApp:
                return(new SsdtInputParams());

            case ProjectType.WebService:
                return(new SsdtInputParams());

            case ProjectType.Extension:
                return(new ExtensionInputParams());

            case ProjectType.PowerShellScript:
                return(new PowerShellInputParams());

            default:
                throw new DeploymentTaskException(string.Format("Project type: {0} is not supported in environment deployment.", projectInfo.Type));
            }
        }
        public void GetWebServerNetworkPath_WhenAbsoluteLocalPathIsCorrect_ReturnCorrectPath()
        {
            var envInfo =
            new EnvironmentInfo(
              _EnvironmentName,
              true,
              _ConfigurationTemplateName,
              _AppServerMachine,
              _FailoverClusterMachineName,
              _WebMachineNames,
              _TerminalMachineName,
              _SchedulerServerTasksMachineNames,
              _SchedulerServerBinariesMachineNames,
              _NtServicesBaseDirPath,
              _WebAppsBaseDirPath,
              _SchedulerAppsBaseDirPath,
              _TerminalAppsBaseDirPath,
              false,
              TestData.EnvironmentUsers,
              TestData.AppPoolInfos,
              TestData.DatabaseServers,
              TestData.ProjectToFailoverClusterGroupMappings,
              TestData.WebAppProjectConfigurationOverrides,
              TestData.DbProjectConfigurationOverrides,
              _TerminalAppsShortcutFolder,
              _ArtifactsDeploymentDirPath,
              _DomainName,
              TestData.CustomEnvMachines);

              Assert.AreEqual(
            "\\\\" + _WebMachineNames[0] + "\\c$\\",
            envInfo.GetWebServerNetworkPath(_WebMachineNames[0], "c:\\"));
        }
        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 override IEnumerable<string> GetTargetFolders(IObjectFactory objectFactory, EnvironmentInfo environmentInfo)
        {
            Guard.NotNull(objectFactory, "objectFactory");
              Guard.NotNull(environmentInfo, "environmentInfo");

              return
            environmentInfo.TerminalAppsBaseDirPath
              .Select(machineName => environmentInfo.GetSchedulerServerNetworkPath(machineName.ToString(), ""))
              .ToList();
        }
        public ExtractArtifactsDeploymentStep(EnvironmentInfo environmentInfo, ProjectInfo projectInfo, string projectConfigurationName, string projectConfigurationBuildId, string artifactsFilePath, string targetArtifactsDirPath)
        {
            if (environmentInfo == null)
              {
            throw new ArgumentNullException("environmentInfo");
              }

              if (projectInfo == null)
              {
            throw new ArgumentNullException("projectInfo");
              }

              if (string.IsNullOrEmpty(projectConfigurationName))
              {
            throw new ArgumentException("Argument can't be null nor empty.", "projectConfigurationName");
              }

              if (string.IsNullOrEmpty(projectConfigurationBuildId))
              {
            throw new ArgumentException("Argument can't be null nor empty.", "projectConfigurationBuildId");
              }

              if (string.IsNullOrEmpty(artifactsFilePath))
              {
            throw new ArgumentException("Argument can't be null nor empty.", "artifactsFilePath");
              }

              if (string.IsNullOrEmpty(targetArtifactsDirPath))
              {
            throw new ArgumentException("Argument can't be null nor empty.", "targetArtifactsDirPath");
              }

              _environmentInfo = environmentInfo;
              _projectInfo = projectInfo;
              _projectConfigurationName = projectConfigurationName;
              _projectConfigurationBuildId = projectConfigurationBuildId;
              _artifactsFilePath = artifactsFilePath;
              _targetArtifactsDirPath = targetArtifactsDirPath;

              string archiveParentPath = string.Empty;

              if (_projectInfo.ArtifactsAreEnvironmentSpecific)
              {
            archiveParentPath = string.Format("{0}/", _environmentInfo.ConfigurationTemplateName);
              }

              // eg. when artifacts are enviroment specific: Service/dev2/
              _archiveSubPath =
            !string.IsNullOrEmpty(_projectInfo.ArtifactsRepositoryDirName)
              ? string.Format("{0}{1}/", archiveParentPath, _projectInfo.ArtifactsRepositoryDirName)
              : archiveParentPath;
        }
        public override IEnumerable<string> GetTargetFolders(EnvironmentInfo environmentInfo)
        {
            if (environmentInfo == null)
              {
            throw new ArgumentNullException("environmentInfo");
              }

              return
            new List<string>
              {
            environmentInfo.GetTerminalServerNetworkPath(
              Path.Combine(environmentInfo.TerminalAppsBaseDirPath, TerminalAppDirName))
              };
        }
        public string GetDefaultPackageDirPath(string environmentName, string projectName)
        {
            EnvironmentInfo environmentInfo = _environmentInfoRepository.FindByName(environmentName);

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

            if (string.IsNullOrEmpty(environmentInfo.ManualDeploymentPackageDirPath))
            {
                return(null);
            }

            return(_dirPathParamsResolver.ResolveParams(environmentInfo.ManualDeploymentPackageDirPath, projectName));
        }
        public override IEnumerable<string> GetTargetFolders(IObjectFactory objectFactory, EnvironmentInfo environmentInfo)
        {
            Guard.NotNull(objectFactory, "objectFactory");
              Guard.NotNull(environmentInfo, "environmentInfo");

              WebAppProjectConfiguration configuration =
            environmentInfo.GetWebAppProjectConfiguration(Name);

              return
            environmentInfo
              .WebServerMachineNames
              .Select(
            wsmn =>
            environmentInfo.GetWebServerNetworkPath(
              wsmn,
              Path.Combine(environmentInfo.WebAppsBaseDirPath, configuration.WebAppDirName)))
              .ToList();
        }
        public static string CollectPasssword(IPasswordCollector passwordCollector, EnvironmentInfo environmentInfo, string machineName, string userId, out EnvironmentUser environmentUser)
        {
            if (passwordCollector == null)
              {
            throw new ArgumentNullException("passwordCollector");
              }

              if (environmentInfo == null)
              {
            throw new ArgumentNullException("environmentInfo");
              }

              if (string.IsNullOrEmpty(machineName))
              {
            throw new ArgumentException("Argument can't be null nor empty.", "machineName");
              }

              if (string.IsNullOrEmpty(userId))
              {
            throw new ArgumentException("Argument can't be null nor empty.", "userId");
              }

              environmentUser = environmentInfo.GetEnvironmentUserByName(userId);

              if (environmentUser == null)
              {
            throw new InvalidOperationException(string.Format("There's no environment user with id '{0}' defined in environment named '{1}'.", userId, environmentInfo.Name));
              }

              string environmentUserPassword =
            passwordCollector.CollectPasswordForUser(
              environmentInfo.Name,
              machineName,
              environmentUser.UserName);

              if (string.IsNullOrEmpty(environmentUserPassword))
              {
            throw new InvalidOperationException(string.Format("Couldn't obtain password for user named '{0}' for environment named '{1}'.", environmentUser.UserName, environmentInfo.Name));
              }

              return environmentUserPassword;
        }
        public List <string> GetWebMachineNames(string environmentName)
        {
            if (string.IsNullOrEmpty(environmentName))
            {
                throw new ArgumentException("Environment name can't be null or empty", "environmentName");
            }

            EnvironmentInfo environmentInfo = _environmentInfoRepository.FindByName(environmentName);

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

            return(environmentInfo.WebServerMachineNames.ToList());
        }
        public IEnumerable<string> GetTargetUrls(EnvironmentInfo environmentInfo)
        {
            if (environmentInfo == null)
              {
            throw new ArgumentNullException("environmentInfo");
              }

              WebAppProjectConfiguration webAppProjectConfiguration =
            environmentInfo.GetWebAppProjectConfiguration(Name);

              // TODO IMM HI: what about https vs http?
              return
            environmentInfo.WebServerMachineNames
              .Select(
            wsmn =>
            string.Format(
              "http://{0}/{1}",
              wsmn,
              webAppProjectConfiguration.WebAppName))
              .ToList();
        }
        public List <string> GetWebAppProjectTargetUrls(string projectName, string environmentName)
        {
            if (string.IsNullOrEmpty(projectName))
            {
                throw new ArgumentException("Argument can't be null nor empty.", "projectName");
            }

            if (string.IsNullOrEmpty(environmentName))
            {
                throw new ArgumentException("Argument can't be null nor empty.", "environmentName");
            }

            WebAppProjectInfo webAppProjectInfo =
                _projectInfoRepository.FindByName(projectName) as WebAppProjectInfo;

            if (webAppProjectInfo == null)
            {
                throw new FaultException <ProjectNotFoundFault>(new ProjectNotFoundFault {
                    ProjectName = projectName
                });
            }

            EnvironmentInfo environmentInfo =
                _environmentInfoRepository.FindByName(environmentName);

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

            List <string> targetUrls =
                webAppProjectInfo.GetTargetUrls(environmentInfo)
                .ToList();

            return(targetUrls);
        }
        public List <string> GetProjectTargetFolders(string projectName, string environmentName)
        {
            if (string.IsNullOrEmpty(projectName))
            {
                throw new ArgumentException("Argument can't be null nor empty.", "projectName");
            }

            if (string.IsNullOrEmpty(environmentName))
            {
                throw new ArgumentException("Argument can't be null nor empty.", "environmentName");
            }

            ProjectInfo projectInfo =
                _projectInfoRepository.FindByName(projectName);

            if (projectInfo == null)
            {
                throw new FaultException <ProjectNotFoundFault>(new ProjectNotFoundFault {
                    ProjectName = projectName
                });
            }

            EnvironmentInfo environmentInfo =
                _environmentInfoRepository.FindByName(environmentName);

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

            List <string> targetFolders =
                projectInfo.GetTargetFolders(ObjectFactory.Instance, environmentInfo)
                .ToList();

            return(targetFolders);
        }
        public void GetWebServerNetworkPath_WhenAbsoluteLocalPathIsCorrect_ReturnCorrectPath()
        {
            var envInfo =
            new EnvironmentInfo(
              _EnvironmentName,
              _ConfigurationTemplateName,
              _AppServerMachine,
              _FailoverClusterMachineName,
              _WebMachineNames,
              _TerminalMachineName,
              _DatabaseMachineName,
              _NtServicesBaseDirPath,
              _WebAppsBaseDirPath,
              _SchedulerAppsBaseDirPath,
              _TerminalAppsBaseDirPath,
              false,
              _EnvironmentUsers,
              _ProjectToFailoverClusterGroupMappings);

              Assert.AreEqual(
            "\\\\" + _WebMachineNames[0] + "\\c$\\",
            envInfo.GetWebServerNetworkPath(_WebMachineNames[0], "c:\\"));
        }
Exemple #15
0
        private static InputParams BuildInputParams(ProjectInfo projectInfo, EnvironmentInfo environmentInfo)
        {
            switch (projectInfo.Type)
              {
            case ProjectType.WebApp:
              // deploy to all web server machines
              return new WebAppInputParams(environmentInfo.WebServerMachineNames);

            case ProjectType.Db:
              return new DbInputParams();

            case ProjectType.NtService:
              return new NtServiceInputParams();

            case ProjectType.SchedulerApp:
              return new SsdtInputParams();

            case ProjectType.TerminalApp:
              return new SsdtInputParams();

            case ProjectType.WebService:
              return new SsdtInputParams();

            case ProjectType.Extension:
              return new ExtensionInputParams();

            case ProjectType.PowerShellScript:
              return new PowerShellInputParams();

            default:
              throw new DeploymentTaskException(string.Format("Project type: {0} is not supported in environment deployment.", projectInfo.Type));
              }
        }
Exemple #16
0
 public abstract IEnumerable<string> GetTargetFolders(EnvironmentInfo environmentInfo);
        public void Test_GetTargetFolders_RunsProperly_WhenAllIsWell()
        {
            string machine = Environment.MachineName;
              const string baseDirPath = "c:\\basedir";

              var envInfo =
            new EnvironmentInfo(
              "name",
              true,
              "templates",
              machine,
              "failover",
              new[] { "webmachine" },
              "terminalmachine",
              new[] { "schedulerServerTasksMachineName1", "schedulerServerTasksMachineName2", },
              new[] { "schedulerServerBinariesMachineName1", "schedulerServerBinariesMachineName2", },
              baseDirPath,
              "webbasedir",
              "c:\\scheduler",
              "terminal",
              false,
              TestData.EnvironmentUsers,
              TestData.AppPoolInfos,
              TestData.DatabaseServers,
              TestData.ProjectToFailoverClusterGroupMappings,
              TestData.WebAppProjectConfigurationOverrides,
              TestData.DbProjectConfigurationOverrides,
              "terminalAppsShortcutFolder",
              "artifactsDeploymentDirPath",
              "domain-name",
              TestData.CustomEnvMachines);

              var projectInfo =
            new NtServiceProjectInfo(
              _ProjectName,
              _ArtifactsRepositoryName,
              _AllowedEnvironmentNames,
              _ArtifactsRepositoryDirName,
              _ArtifactsAreNotEnvironmentSpecific,
              _NtServiceName,
              _NtServiceDirName,
              _NtServiceDisplayName,
              _NtServiceExeName,
              _NtServiceUserId,
              "");

              var targetFolders = projectInfo.GetTargetFolders(_objectFactoryFake.Object, envInfo).ToList();

              Assert.IsNotNull(targetFolders);
              Assert.AreEqual(1, targetFolders.Count);
              Assert.AreEqual("\\\\" + machine + "\\c$\\basedir\\" + _NtServiceDirName, targetFolders[0]);
        }
        public void SetUp()
        {
            _projectInfoRepositoryFake = new Mock<IProjectInfoRepository>();
              _environmentInfoRepositoryFake = new Mock<IEnvironmentInfoRepository>();
              _artifactsRepositoryFake = new Mock<IArtifactsRepository>();
              _taskSchedulerFake = new Mock<ITaskScheduler>();
              _passwordCollectorFake = new Mock<IPasswordCollector>();
              _directoryAdapterFake = new Mock<IDirectoryAdapter>();
              _fileAdapterFake = new Mock<IFileAdapter>();
              _zipFileAdapterFake = new Mock<IZipFileAdapter>();

              _projectInfo = ProjectInfoGenerator.GetSchedulerAppProjectInfo();

              SchedulerAppTask schedulerAppTask1 = _projectInfo.SchedulerAppTasks.First();
              SchedulerAppTask schedulerAppTask2 = _projectInfo.SchedulerAppTasks.Second();

              _environmentInfo =
            DeploymentDataGenerator.GetEnvironmentInfo(
              new[]
              {
            new EnvironmentUser(schedulerAppTask1.UserId, "user_name_1"),
            new EnvironmentUser(schedulerAppTask2.UserId, "user_name_2"),
              });

              _projectInfoRepositoryFake.Setup(pir => pir.FindByName(It.IsAny<string>()))
            .Returns(_projectInfo);

              string exeAbsolutePath1 =
            Path.Combine(
              _environmentInfo.SchedulerAppsBaseDirPath,
              _projectInfo.SchedulerAppDirName,
              schedulerAppTask1.ExecutableName);

              var scheduledTaskRepetition1 =
            new ScheduledTaskRepetition(
              schedulerAppTask1.Repetition.Interval,
              schedulerAppTask1.Repetition.Duration,
              schedulerAppTask1.Repetition.StopAtDurationEnd);

              ScheduledTaskDetails taskDetails1 =
            GetTaskDetails(schedulerAppTask1, exeAbsolutePath1, true, false, scheduledTaskRepetition1);

              ScheduledTaskDetails taskDetailsDisabled1 =
            GetTaskDetails(schedulerAppTask1, exeAbsolutePath1, false, false, scheduledTaskRepetition1);

              int timesCalled11 = 0;

              _taskSchedulerFake
            .Setup(x => x.GetScheduledTaskDetails(_environmentInfo.SchedulerServerTasksMachineNames.First(), schedulerAppTask1.Name))
            .Returns(() =>
            {
              timesCalled11++;

              if (timesCalled11 == 1)
              {
            return taskDetails1;
              }

              if (timesCalled11 == 2)
              {
            return taskDetailsDisabled1;
              }

              throw new Exception("Unexpected number of calls!");
            });

              int timesCalled21 = 0;

              _taskSchedulerFake
            .Setup(x => x.GetScheduledTaskDetails(_environmentInfo.SchedulerServerTasksMachineNames.Second(), schedulerAppTask1.Name))
            .Returns(() =>
            {
              timesCalled21++;

              if (timesCalled21 == 1)
              {
            return taskDetails1;
              }

              if (timesCalled21 == 2)
              {
            return taskDetailsDisabled1;
              }

              throw new Exception("Unexpected number of calls!");
            });

              string exeAbsolutePath2 =
            Path.Combine(
              _environmentInfo.SchedulerAppsBaseDirPath,
              _projectInfo.SchedulerAppDirName,
              schedulerAppTask2.ExecutableName);

              var scheduledTaskRepetition2 =
            new ScheduledTaskRepetition(
              schedulerAppTask2.Repetition.Interval,
              schedulerAppTask2.Repetition.Duration,
              schedulerAppTask2.Repetition.StopAtDurationEnd);

              ScheduledTaskDetails taskDetails2 =
            GetTaskDetails(schedulerAppTask2, exeAbsolutePath2, true, false, scheduledTaskRepetition2);

              ScheduledTaskDetails taskDetailsDisabled2 =
            GetTaskDetails(schedulerAppTask2, exeAbsolutePath2, false, false, scheduledTaskRepetition2);

              int timesCalled12 = 0;

              _taskSchedulerFake
            .Setup(x => x.GetScheduledTaskDetails(_environmentInfo.SchedulerServerTasksMachineNames.First(), schedulerAppTask2.Name))
            .Returns(() =>
            {
              timesCalled12++;

              if (timesCalled12 == 1)
              {
            return taskDetails2;
              }

              if (timesCalled12 == 2)
              {
            return taskDetailsDisabled2;
              }

              throw new Exception("Unexpected number of calls!");
            });

              int timesCalled22 = 0;

              _taskSchedulerFake
            .Setup(x => x.GetScheduledTaskDetails(_environmentInfo.SchedulerServerTasksMachineNames.Second(), schedulerAppTask2.Name))
            .Returns(() =>
            {
              timesCalled22++;

              if (timesCalled22 == 1)
              {
            return taskDetails2;
              }

              if (timesCalled22 == 2)
              {
            return taskDetailsDisabled2;
              }

              throw new Exception("Unexpected number of calls!");
            });

              _environmentInfoRepositoryFake
            .Setup(x => x.FindByName(It.IsAny<string>()))
            .Returns(_environmentInfo);

              _directoryAdapterFake
            .Setup(x => x.Exists(It.IsAny<string>()))
            .Returns(true);

              _deployTask =
            new DeploySchedulerAppDeploymentTask(
              _projectInfoRepositoryFake.Object,
              _environmentInfoRepositoryFake.Object,
              _artifactsRepositoryFake.Object,
              _taskSchedulerFake.Object,
              _passwordCollectorFake.Object,
              _directoryAdapterFake.Object,
              _fileAdapterFake.Object,
              _zipFileAdapterFake.Object);

              _deployTask.Initialize(DeploymentInfoGenerator.GetSchedulerAppDeploymentInfo());
        }
        public void Test_GetTargetFolders_RunsProperly_WhenAllIsWell()
        {
            string machine = Environment.MachineName;
              const string baseDirPath = "c:\\basedir";

              var envInfo =
            new EnvironmentInfo(
              "name",
              "templates",
              machine,
              "failover",
              new[] { "webmachine" },
              "terminalmachine",
              "databasemachine",
              baseDirPath,
              "webbasedir",
              "c:\\scheduler",
              "terminal",
              false,
              _EnvironmentUsers,
              _ProjectToFailoverClusterGroupMappings);

              var projectInfo =
            new NtServiceProjectInfo(
              _ProjectName,
              _ArtifactsRepositoryName,
              _ArtifactsRepositoryDirName,
              _ArtifactsAreNotEnvironmentSpecific,
              _NtServiceName,
              _NtServiceDirName,
              _NtServiceDisplayName,
              _NtServiceExeName,
              _NtServiceUserId);

              var targetFolders = projectInfo.GetTargetFolders(envInfo).ToList();

              Assert.IsNotNull(targetFolders);
              Assert.AreEqual(1, targetFolders.Count);
              Assert.AreEqual("\\\\" + machine + "\\c$\\basedir\\" + _NtServiceDirName, targetFolders[0]);
        }
        private bool HasSettingsChanged(ScheduledTaskDetails taskDetails, SchedulerAppTask schedulerAppTask, EnvironmentInfo environmentInfo)
        {
            if (taskDetails == null)
              {
            return false;
              }

              string taskExecutablePath = GetTaskExecutablePath(schedulerAppTask, environmentInfo);

              return !(taskDetails.Name == schedulerAppTask.Name
              && taskDetails.ScheduledHour == schedulerAppTask.ScheduledHour
              && taskDetails.ScheduledMinute == schedulerAppTask.ScheduledMinute
              && taskDetails.ExecutionTimeLimitInMinutes == schedulerAppTask.ExecutionTimeLimitInMinutes
              && taskDetails.Repetition.Interval == schedulerAppTask.Repetition.Interval
              && taskDetails.Repetition.Duration == schedulerAppTask.Repetition.Duration
              && taskDetails.Repetition.StopAtDurationEnd == schedulerAppTask.Repetition.StopAtDurationEnd
              && taskDetails.ExeAbsolutePath == taskExecutablePath);
        }
        public void Test_GetTargetFolders_RunsProperly_WhenAllIsWell()
        {
            string machine = Environment.MachineName;

              var envInfo =
            new EnvironmentInfo(
              "name",
              "templates",
              machine,
              "failover",
              new[] { "webmachine" },
              "terminalmachine",
              "databasemachine",
              "C:\\basedir",
              "C:\\basedir",
              "c:\\scheduler",
              "terminal",
              false,
              _EnvironmentUsers,
              _ProjectToFailoverClusterGroupMappings);

              var projectInfo =
            new WebAppProjectInfo(
              Name,
              ArtifactsRepositoryName,
              ArtifactsRepositoryDirName,
              false,
              IisSiteName,
              WebAppName,
              WebAppDirName,
              AppPoolInfo);

              Assert.IsNotNullOrEmpty(projectInfo.GetTargetFolders(envInfo).FirstOrDefault());
        }
        public override IEnumerable <string> GetTargetFolders(IObjectFactory objectFactory, EnvironmentInfo environmentInfo)
        {
            Guard.NotNull(objectFactory, "objectFactory");
            Guard.NotNull(environmentInfo, "environmentInfo");

            return
                (environmentInfo.TerminalAppsBaseDirPath
                 .Select(machineName => environmentInfo.GetSchedulerServerNetworkPath(machineName.ToString(), ""))
                 .ToList());
        }
        public void Test_GetTargetFolde_RunsProperly_WhenAllIsWell()
        {
            string machine = Environment.MachineName;
              const string baseDirPath = "c:\\basedir";

              var envInfo =
            new EnvironmentInfo(
              "name",
              true,
              "templates",
              "appservermachine",
              "failover",
              new[] { "webmachine" },
              "terminalmachine",
              new[] { machine },
              new[] { machine },
              baseDirPath,
              "webbasedir",
              "c:\\scheduler",
              "terminal",
              false,
              TestData.EnvironmentUsers,
              TestData.AppPoolInfos,
              TestData.DatabaseServers,
              TestData.ProjectToFailoverClusterGroupMappings,
              TestData.WebAppProjectConfigurationOverrides,
              TestData.DbProjectConfigurationOverrides,
              "terminalAppsShortcutFolder",
              "artifactsDeploymentDirPath",
              "domain-name",
              TestData.CustomEnvMachines);

              var schedulerAppProjectInfo =
            new SchedulerAppProjectInfo(
              _ProjectName,
              _ArtifactsRepositoryName,
              _AllowedEnvironmentNames,
              _ArtifactsRepositoryDirName,
              _ArtifactsAreNotEnvirionmentSpecific,
              _SchedulerAppDirName,
              _SchedulerAppExeName,
              new List<SchedulerAppTask>
              {
            new SchedulerAppTask(
              _SchedulerAppName,
              _SchedulerAppName,
              _SchedulerAppUserId,
              _ScheduledHour,
              _ScheduledMinute,
              _ExecutionTimeLimitInMinutes,
              _Repetition)
              });

              List<string> targetFolders =
            schedulerAppProjectInfo.GetTargetFolders(_objectFactoryFake.Object, envInfo)
              .ToList();

              Assert.IsNotNull(targetFolders);
              Assert.AreEqual(1, targetFolders.Count);
              Assert.AreEqual("\\\\" + machine + "\\c$\\scheduler\\" + _SchedulerAppDirName, targetFolders[0]);
        }
        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);
        }
        public override IEnumerable<string> GetTargetFolders(IObjectFactory objectFactory, EnvironmentInfo environmentInfo)
        {
            Guard.NotNull(objectFactory, "objectFactory");
              Guard.NotNull(environmentInfo, "environmentInfo");

              if (environmentInfo.EnableFailoverClusteringForNtServices)
              {
            IFailoverClusterManager failoverClusterManager =
              objectFactory.CreateFailoverClusterManager();

            string clusterGroupName =
              environmentInfo.GetFailoverClusterGroupNameForProject(Name);

            IEnumerable<string> possibleNodeNames =
              failoverClusterManager.GetPossibleNodeNames(
            environmentInfo.FailoverClusterMachineName,
            clusterGroupName);

            return
              possibleNodeNames
            .Select(node => EnvironmentInfo.GetNetworkPath(node, Path.Combine(environmentInfo.NtServicesBaseDirPath, NtServiceDirName)))
            .ToList();
              }
              else
              {
            return
              new List<string>
              {
            environmentInfo.GetAppServerNetworkPath(
              Path.Combine(environmentInfo.NtServicesBaseDirPath, NtServiceDirName))
              };
              }
        }
        private void DoPrepareDeploymentToStandardEnvironment(EnvironmentInfo environmentInfo, Lazy<string> artifactsBinariesDirPathProvider)
        {
            Func<CollectedCredentials> collectCredentialsFunc =
            () =>
            {
              if (UseLocalSystemUser)
              {
            return new CollectedCredentials(LocalSystemUserName);
              }

              EnvironmentUser environmentUser =
            environmentInfo.GetEnvironmentUser(_projectInfo.NtServiceUserId);

              string environmentUserPassword =
            PasswordCollectorHelper.CollectPasssword(
              _passwordCollector,
              DeploymentInfo.DeploymentId,
              environmentInfo,
              environmentInfo.AppServerMachineName,
              environmentUser,
              OnDiagnosticMessagePosted);

              return
            new CollectedCredentials(
              environmentUser.UserName,
              environmentUserPassword);
            };

              DoPrepareCommonDeploymentSteps(
            _projectInfo.NtServiceName,
            environmentInfo.AppServerMachineName,
            environmentInfo.NtServicesBaseDirPath,
            environmentInfo.GetAppServerNetworkPath,
            artifactsBinariesDirPathProvider,
            collectCredentialsFunc,
            true);
        }
        private void DoPrepareDeploymentToClusteredEnvironment(EnvironmentInfo environmentInfo, Lazy<string> artifactsBinariesDirPathProvider)
        {
            string clusterGroupName = environmentInfo.GetFailoverClusterGroupNameForProject(DeploymentInfo.ProjectName);

              if (string.IsNullOrEmpty(clusterGroupName))
              {
            throw new InvalidOperationException(string.Format("There is no cluster group defined for project '{0}' in environment '{1}'.", DeploymentInfo.ProjectName, environmentInfo.Name));
              }

              string failoverClusterMachineName = environmentInfo.FailoverClusterMachineName;

              if (string.IsNullOrEmpty(failoverClusterMachineName))
              {
            throw new InvalidOperationException(string.Format("Environment '{0}' has no failover cluster machine name defined.", environmentInfo.Name));
              }

              string currentNodeName =
            _failoverClusterManager.GetCurrentNodeName(failoverClusterMachineName, clusterGroupName);

              if (string.IsNullOrEmpty(currentNodeName))
              {
            throw new InvalidOperationException(string.Format("Cluster group '{0}' has no current node in a cluster '{1}' in environment '{2}'.", clusterGroupName, environmentInfo.FailoverClusterMachineName, environmentInfo.Name));
              }

              PostDiagnosticMessage(string.Format("Current node: '{0}'.", currentNodeName), DiagnosticMessageType.Trace);

              List<string> possibleNodeNames =
            _failoverClusterManager.GetPossibleNodeNames(failoverClusterMachineName, clusterGroupName)
              .ToList();

              PostDiagnosticMessage(string.Format("Possible nodes: {0}.", string.Join(", ", possibleNodeNames.Select(n => string.Format("'{0}'", n)))), DiagnosticMessageType.Trace);

              if (possibleNodeNames.Count < 2)
              {
            throw new InvalidOperationException(string.Format("There is only one possible node for cluster group '{0}' in a cluster '{1}' in environment '{2}'.", clusterGroupName, environmentInfo.FailoverClusterMachineName, environmentInfo.Name));
              }

              // update nt service on all machines other than current owner node
              CollectedCredentials cachedCollectedCredentials = null;

              Func<string, Func<CollectedCredentials>> collectCredentialsFunc =
            machineName =>
            () =>
            {
              // ReSharper disable AccessToModifiedClosure
              if (cachedCollectedCredentials != null)
              {
            return cachedCollectedCredentials;
              }
              // ReSharper restore AccessToModifiedClosure

              if (UseLocalSystemUser)
              {
            cachedCollectedCredentials = new CollectedCredentials(LocalSystemUserName);
              }
              else
              {
            EnvironmentUser environmentUser =
              environmentInfo.GetEnvironmentUser(_projectInfo.NtServiceUserId);

            string environmentUserPassword =
              PasswordCollectorHelper.CollectPasssword(
                _passwordCollector,
                DeploymentInfo.DeploymentId,
                environmentInfo,
                machineName,
                environmentUser,
                OnDiagnosticMessagePosted);

            cachedCollectedCredentials =
              new CollectedCredentials(
                environmentUser.UserName,
                environmentUserPassword);
              }

              return cachedCollectedCredentials;
            };

              foreach (string possibleNodeName in possibleNodeNames)
              {
            string machineName = possibleNodeName;

            if (string.Equals(machineName, currentNodeName, StringComparison.OrdinalIgnoreCase))
            {
              continue;
            }

            DoPrepareCommonDeploymentSteps(
              _projectInfo.NtServiceName,
              machineName,
              environmentInfo.NtServicesBaseDirPath,
              absoluteLocalPath => EnvironmentInfo.GetNetworkPath(machineName, absoluteLocalPath),
              artifactsBinariesDirPathProvider,
              collectCredentialsFunc(machineName),
              false);
              }

              // move cluster group to another node
              string targetNodeName =
            possibleNodeNames.FirstOrDefault(nodeName => nodeName != currentNodeName);

              PostDiagnosticMessage(string.Format("Target node: '{0}'.", targetNodeName), DiagnosticMessageType.Trace);

              if (string.IsNullOrEmpty(targetNodeName))
              {
            throw new InvalidOperationException(string.Format("There is no node in cluster '{0}' that we can move cluster group '{1}' to.", failoverClusterMachineName, clusterGroupName));
              }

              AddSubTask(
            new MoveClusterGroupToAnotherNodeDeploymentStep(
              _failoverClusterManager,
              failoverClusterMachineName,
              clusterGroupName,
              targetNodeName));

              // update nt service on the machine that was the previous owner node
              string previousMachineName = currentNodeName;

              DoPrepareCommonDeploymentSteps(
            _projectInfo.NtServiceName,
            previousMachineName,
            environmentInfo.NtServicesBaseDirPath,
            absoluteLocalPath => EnvironmentInfo.GetNetworkPath(previousMachineName, absoluteLocalPath),
            artifactsBinariesDirPathProvider,
            collectCredentialsFunc(previousMachineName),
            false);
        }
Exemple #28
0
 public override IEnumerable<string> GetTargetFolders(IObjectFactory objectFactory, EnvironmentInfo environmentInfo)
 {
     throw new NotSupportedException();
 }
 public override IEnumerable <string> GetTargetFolders(IObjectFactory objectFactory, EnvironmentInfo environmentInfo)
 {
     throw new NotSupportedException();
 }
        public void Test_GetAppServerNetworkPath_Throws_When_path_startswithbackslashes()
        {
            var envInfo = new EnvironmentInfo(
            _EnvironmentName,
            true,
            _ConfigurationTemplateName,
            _AppServerMachine,
            _FailoverClusterMachineName,
            _WebMachineNames,
            _TerminalMachineName,
            _SchedulerServerTasksMachineNames,
            _SchedulerServerBinariesMachineNames,
            _NtServicesBaseDirPath,
            _WebAppsBaseDirPath,
            _SchedulerAppsBaseDirPath,
            _TerminalAppsBaseDirPath,
            false,
            TestData.EnvironmentUsers,
            TestData.AppPoolInfos,
            TestData.DatabaseServers,
            TestData.ProjectToFailoverClusterGroupMappings,
            TestData.WebAppProjectConfigurationOverrides,
            TestData.DbProjectConfigurationOverrides,
            _TerminalAppsShortcutFolder,
            _ArtifactsDeploymentDirPath,
            _DomainName,
            TestData.CustomEnvMachines);

              Assert.Throws<ArgumentException>(
            () => envInfo.GetAppServerNetworkPath(@"\\kasjdkasdj"));
        }
        public override IEnumerable<string> GetTargetFolders(EnvironmentInfo environmentInfo)
        {
            if (environmentInfo == null)
              {
            throw new ArgumentNullException("environmentInfo");
              }

              // TODO IMM HI: this might be wrong (due to msdeploy)!
              return
            environmentInfo
              .WebServerMachineNames
              .Select(
            wsmn =>
            environmentInfo.GetWebServerNetworkPath(
              wsmn,
              Path.Combine(environmentInfo.WebAppsBaseDirPath, WebAppDirName)))
              .ToList();
        }
 public abstract IEnumerable <string> GetTargetFolders(IObjectFactory objectFactory, EnvironmentInfo environmentInfo);
        private string GetTaskExecutablePath(SchedulerAppTask schedulerAppTask, EnvironmentInfo environmentInfo)
        {
            string targetDirPath = GetTargetDirPath(environmentInfo);

              return Path.Combine(targetDirPath, schedulerAppTask.ExecutableName);
        }
        public void Test_GetTargetUrls_RunsProperly_WhenAllIsWell()
        {
            string machine = Environment.MachineName;
              const string baseDirPath = "c:\\basedir";

              var envInfo =
            new EnvironmentInfo(
              "name",
              "templates",
              machine,
              "failover",
              new[] { "webmachine" },
              "terminalmachine",
              "databasemachine",
              baseDirPath,
              "webbasedir",
              "c:\\scheduler",
              "terminal",
              false,
              _EnvironmentUsers,
              _ProjectToFailoverClusterGroupMappings);

              var projectInfo =
            new WebAppProjectInfo(
              Name,
              ArtifactsRepositoryName,
              ArtifactsRepositoryDirName,
              ArtifactsAreNotEnvironmentSpecific,
              IisSiteName,
              WebAppName,
              WebAppDirName,
              AppPoolInfo);

              List<string> targetUrls =
            projectInfo.GetTargetUrls(envInfo)
              .ToList();

              Assert.IsNotNull(targetUrls);
              Assert.AreEqual(1, targetUrls.Count);
              Assert.AreEqual("http://webmachine/" + WebAppName, targetUrls[0]);
        }
        private void AddTaskConfigurationSteps(EnvironmentInfo environmentInfo, string schedulerServerTasksMachineName, SchedulerAppTask schedulerAppTask, ScheduledTaskDetails taskDetails = null)
        {
            bool hasSettingsChanged = HasSettingsChanged(taskDetails, schedulerAppTask, environmentInfo);
              bool taskExists = taskDetails != null;

              EnvironmentUser environmentUser =
            environmentInfo.GetEnvironmentUserById(schedulerAppTask.UserId);

              string environmentUserPassword = null;

              if (!taskExists || hasSettingsChanged)
              {
            // collect password if not already collected
            if (!_collectedPasswordsByUserName.TryGetValue(environmentUser.UserName, out environmentUserPassword))
            {
              environmentUserPassword =
            PasswordCollectorHelper.CollectPasssword(
              _passwordCollector,
              DeploymentInfo.DeploymentId,
              environmentInfo,
              schedulerServerTasksMachineName,
              environmentUser,
              OnDiagnosticMessagePosted);

              _collectedPasswordsByUserName.Add(environmentUser.UserName, environmentUserPassword);
            }
              }

              string taskExecutablePath =
            GetTaskExecutablePath(schedulerAppTask, environmentInfo);

              if (!taskExists)
              {
            // create a step for scheduling a new app
            AddSubTask(
              new CreateSchedulerTaskDeploymentStep(
            schedulerServerTasksMachineName,
            schedulerAppTask.Name,
            taskExecutablePath,
            environmentUser.UserName,
            environmentUserPassword,
            schedulerAppTask.ScheduledHour,
            schedulerAppTask.ScheduledMinute,
            schedulerAppTask.ExecutionTimeLimitInMinutes,
            schedulerAppTask.Repetition,
            _taskScheduler));
              }
              else if (hasSettingsChanged)
              {
            // create a step for updating an existing scheduler app
            AddSubTask(
              new UpdateSchedulerTaskDeploymentStep(
            schedulerServerTasksMachineName,
            schedulerAppTask.Name,
            taskExecutablePath,
            environmentUser.UserName,
            environmentUserPassword,
            schedulerAppTask.ScheduledHour,
            schedulerAppTask.ScheduledMinute,
            schedulerAppTask.ExecutionTimeLimitInMinutes,
            schedulerAppTask.Repetition,
            _taskScheduler));
              }
        }
        public void Test_InstallNtServiceDeploymentStepServiceDirPathDoesntExist()
        {
            const string serviceName = "serviceName";
              const string serviceDir = "serviceDir";
              const string artifactsRepo = "artifactsRepo";
              const string projectName = "projectName";
              const string buildID = "id";
              const string envName = "envName";
              const string baseDirPath = "c:\\basedir";

              string machine = Environment.MachineName;

              var ntServiceProjectInfo =
            new NtServiceProjectInfo(
              "name",
              artifactsRepo,
              "artifactsRepoDir",
              false,
              serviceName,
              serviceDir,
              "serviceDisplayed",
              "exeName",
              "Sample.User");

              var envInfo =
            new EnvironmentInfo(
              "name",
              "templates",
              machine,
              "failover",
              new[] { "webmachine" },
              "terminalmachine",
              "databasemachine",
              baseDirPath,
              "webbasedir",
              "scheduler",
              "terminal",
              false,
              _EnvironmentUsers,
              _ProjectToFailoverClusterGroupMappings);

              _environmentInfoRepository
            .Setup(e => e.GetByName(envName))
            .Returns(envInfo);

              _passwordCollector
            .Setup(pc => pc.CollectPasswordForUser(envInfo.Name, envInfo.AppServerMachineName, envInfo.GetEnvironmentUserByName(ntServiceProjectInfo.NtServiceUserId).UserName))
            .Returns("some password");

              _ntServiceManager
            .Setup(n => n.DoesServiceExist(machine, serviceName))
            .Returns(false);

              _artifactsRepository
            .Setup(a => a.GetArtifacts(artifactsRepo,projectName, buildID, It.IsAny<string>()));

              var deployNTService =
            new DeployNtServiceDeploymentTask(
              _environmentInfoRepository.Object,
              _artifactsRepository.Object,
              _ntServiceManager.Object,
              _passwordCollector.Object,
              _failoverClusterManager.Object,
              ntServiceProjectInfo,
              projectName,
              buildID,
              envName);

              Assert.Throws<DeploymentTaskException>(deployNTService.PrepareAndExecute);
        }
 private string GetTargetDirPath(EnvironmentInfo environmentInfo)
 {
     return Path.Combine(environmentInfo.SchedulerAppsBaseDirPath, _projectInfo.SchedulerAppDirName);
 }
        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);
        }
        private Lazy<string> AddStepsToObtainBinaries(EnvironmentInfo environmentInfo)
        {
            // create a step for downloading the artifacts
              var downloadArtifactsDeploymentStep =
            new DownloadArtifactsDeploymentStep(
              _projectInfo,
              DeploymentInfo,
              GetTempDirPath(),
              _artifactsRepository);

              AddSubTask(downloadArtifactsDeploymentStep);

              // create a step for extracting the artifacts
              var extractArtifactsDeploymentStep =
            new ExtractArtifactsDeploymentStep(
              _projectInfo,
              environmentInfo,
              DeploymentInfo,
              downloadArtifactsDeploymentStep.ArtifactsFilePath,
              GetTempDirPath(),
              _fileAdapter,
              _zipFileAdapter);

              AddSubTask(extractArtifactsDeploymentStep);

              if (_projectInfo.ArtifactsAreEnvironmentSpecific)
              {
            var binariesConfiguratorStep =
              new ConfigureBinariesStep(
            environmentInfo.ConfigurationTemplateName,
            GetTempDirPath());

            AddSubTask(binariesConfiguratorStep);
              }

              return new Lazy<string>(() => extractArtifactsDeploymentStep.BinariesDirPath);
        }