예제 #1
0
        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);
            }
        }
예제 #2
0
        private readonly ITeamCityClient _teamCityClient; // TODO IMM HI: abstract away?

        #endregion Fields

        #region Constructors

        public AgentService(
            IDeploymentPipeline deploymentPipeline,
            IProjectInfoRepository projectInfoRepository,
            IEnvironmentInfoRepository environmentInfoRepository,
            ITeamCityClient teamCityClient,
            IDeploymentRequestRepository deploymentRequestRepository,
            IDiagnosticMessagesLogger diagnosticMessagesLogger,
            IProjectMetadataExplorer projectMetadataExplorer,
            IDirPathParamsResolver dirPathParamsResolver)
        {
            Guard.NotNull(deploymentPipeline, "deploymentPipeline");
              Guard.NotNull(projectInfoRepository, "projectInfoRepository");
              Guard.NotNull(environmentInfoRepository, "environmentInfoRepository");
              Guard.NotNull(teamCityClient, "teamCityClient");
              Guard.NotNull(deploymentRequestRepository, "deploymentRequestRepository");
              Guard.NotNull(diagnosticMessagesLogger, "diagnosticMessagesLogger");
              Guard.NotNull(dirPathParamsResolver, "dirPathParamsResolver");

              _projectInfoRepository = projectInfoRepository;
              _environmentInfoRepository = environmentInfoRepository;
              _teamCityClient = teamCityClient;
              _deploymentPipeline = deploymentPipeline;
              _deploymentRequestRepository = deploymentRequestRepository;
              _diagnosticMessagesLogger = diagnosticMessagesLogger;
              _projectMetadataExplorer = projectMetadataExplorer;
              _dirPathParamsResolver = dirPathParamsResolver;
        }
예제 #3
0
        private readonly ITeamCityClient _teamCityClient; // TODO IMM HI: abstract away?

        #endregion Fields

        #region Constructors

        public AgentService(IDeploymentPipeline deploymentPipeline, IProjectInfoRepository projectInfoRepository, IEnvironmentInfoRepository environmentInfoRepository, ITeamCityClient teamCityClient, IDeploymentRequestRepository deploymentRequestRepository, IDiagnosticMessagesLogger diagnosticMessagesLogger)
        {
            if (deploymentPipeline == null)
              {
            throw new ArgumentNullException("deploymentPipeline");
              }

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

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

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

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

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

              _projectInfoRepository = projectInfoRepository;
              _environmentInfoRepository = environmentInfoRepository;
              _teamCityClient = teamCityClient;
              _deploymentPipeline = deploymentPipeline;
              _deploymentRequestRepository = deploymentRequestRepository;
              _diagnosticMessagesLogger = diagnosticMessagesLogger;
        }
예제 #4
0
        public AgentService(
            IDeploymentPipeline deploymentPipeline,
            IProjectInfoRepository projectInfoRepository,
            IEnvironmentInfoRepository environmentInfoRepository,
            ITeamCityRestClient teamCityClient,
            IDeploymentRequestRepository deploymentRequestRepository,
            IDiagnosticMessagesLogger diagnosticMessagesLogger,
            IProjectMetadataExplorer projectMetadataExplorer,
            IDirPathParamsResolver dirPathParamsResolver,
            IApplicationConfiguration applicationConfiguration,
            IEnvironmentDeployInfoRepository environmentDeployInfoRepository,
            IEnvDeploymentPipeline envDeploymentPipeline)
        {
            Guard.NotNull(deploymentPipeline, "deploymentPipeline");
            Guard.NotNull(projectInfoRepository, "projectInfoRepository");
            Guard.NotNull(environmentInfoRepository, "environmentInfoRepository");
            Guard.NotNull(teamCityClient, "teamCityClient");
            Guard.NotNull(deploymentRequestRepository, "deploymentRequestRepository");
            Guard.NotNull(diagnosticMessagesLogger, "diagnosticMessagesLogger");
            Guard.NotNull(dirPathParamsResolver, "dirPathParamsResolver");
            Guard.NotNull(applicationConfiguration, "applicationConfiguration");
            Guard.NotNull(environmentDeployInfoRepository, "environmentDeployInfoRepository");
            Guard.NotNull(envDeploymentPipeline, "envDeploymentPipeline");

            _projectInfoRepository           = projectInfoRepository;
            _environmentInfoRepository       = environmentInfoRepository;
            _teamCityClient                  = teamCityClient;
            _deploymentPipeline              = deploymentPipeline;
            _deploymentRequestRepository     = deploymentRequestRepository;
            _diagnosticMessagesLogger        = diagnosticMessagesLogger;
            _projectMetadataExplorer         = projectMetadataExplorer;
            _dirPathParamsResolver           = dirPathParamsResolver;
            _applicationConfiguration        = applicationConfiguration;
            _environmentDeployInfoRepository = environmentDeployInfoRepository;
            _envDeploymentPipeline           = envDeploymentPipeline;
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        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);
            }
        }