Exemple #1
0
        protected override async Task ExecuteQuery(CancellationToken cancellationToken, params string[] args)
        {
            var server      = this.ServerManager.GetServer(this.Address);
            var projectData = await server.GetProjectStatus(cancellationToken, this.Project, 5);

            log.Trace("Retrieved status for cruise control project {project}: {@projectData}", this.Project, projectData);
            var status = this.CreateStatus(projectData);

            log.Trace("Converted status for cruise control project {project}: {@status}", this.Project, status);
            this.CurrentStatus = status;

            if (status.Duration.TotalSeconds > 0)
            {
                this.cachedDuration = status.Duration;
            }

            if (this.PreviousCheckStatus != null)
            {
                if (status.State != ObservationState.Running)
                {
                    if (status.State != this.PreviousCheckStatus.State || this.PreviousCheckStatus.BuildNumber != status.BuildNumber)
                    {
                        log.Debug("Shoud take snapshot, build not running. {@status}, {@PreviousCheckStatus}", status, this.PreviousCheckStatus);
                        log.Debug("Changing estimated duration {proj}", new { ProjectName = this.Project, PrevEstimatedDurtion = this.estimatedDuration, NewEstimatedDuration = this.cachedDuration });
                        this.estimatedDuration            = this.cachedDuration;
                        this.PreviousCheckStatus          = status;
                        this.PreviousCheckStatus.Duration = this.cachedDuration;
                        this.AddOrUpdateSnapshot(this.PreviousCheckStatus);
                    }
                }
                else
                {
                    if (this.PreviousCheckStatus.BuildNumber < status.BuildNumber)
                    {
                        log.Debug("Shoud take snapshot, build running. {@status}, {@PreviousCheckStatus}", status, this.PreviousCheckStatus);
                        this.PreviousCheckStatus.State = CcStatusToObservationStatus(projectData);
                        log.Debug("Changing estimated duration {proj}", new { ProjectName = this.Project, PrevEstimatedDurtion = this.estimatedDuration, NewEstimatedDuration = this.cachedDuration });
                        this.estimatedDuration            = this.cachedDuration;
                        this.PreviousCheckStatus.Duration = this.cachedDuration;
                        this.AddOrUpdateSnapshot(this.PreviousCheckStatus);
                    }
                }
            }
            else
            {
                log.Debug("Initialize previous check status: {@status}", status);
                this.PreviousCheckStatus = status;
                if (!this.PreviousCheckStatus.Building)
                {
                    this.AddSnapshot(this.PreviousCheckStatus);
                }
            }
        }
        private static Status CreateStatus(CruiseControlBuild build)
        {
            var result = new CruiseControlStatus();

            result.Building    = false;
            result.BuildNumber = build.BuildNumber;
            result.Details     = build.BuildLabel;
            result.Url         = build.Url;
            result.Label       = build.BuildLabel;
            result.Time        = build.BuildTime;
            result.State       = CcStatusToObservationStatus(build.Status);
            result.Name        = build.Name;
            return(result);
        }
Exemple #3
0
        /// <summary>
        /// Adds or updates snapshot based on <paramref name="status"/>. Update is done when build with the same number is already present.
        /// </summary>
        /// <param name="status">Status which should be added/updated.</param>
        private void AddOrUpdateSnapshot(CruiseControlStatus status)
        {
            var existingStatusIndex = this.Snapshots.IndexOf(this.Snapshots.FirstOrDefault(snap => (snap.Status as CruiseControlStatus)?.BuildNumber == status.BuildNumber));

            if (existingStatusIndex >= 0)
            {
                log.Debug("Changes exist for build cruise control project {proj}", new { ProjectName = this.Project, Build = status.BuildNumber });
                this.Snapshots.RemoveAt(existingStatusIndex);
                this.Snapshots.Insert(existingStatusIndex, new Snapshot(status));
            }
            else
            {
                this.AddSnapshot(status);
            }
        }
        private CruiseControlStatus CreateStatus(CruiseControlJob job)
        {
            var result = new CruiseControlStatus();

            result.Name     = job.Name;
            result.Details  = job.Description;
            result.Building = job.Activity == ActivityConstants.Building;
            result.Pending  = job.Activity == ActivityConstants.Pending;
            result.CheckingModifications = job.Activity == ActivityConstants.CheckingModifications;
            if (int.TryParse(job.LastBuildLabel, out var buildNr))
            {
                result.BuildNumber = buildNr;
            }

            result.Url = job.WebUrl;
            SetCulprits(job, result);

            result.NextBuildTime = job.NextBuildTime;
            result.LastBuildTime = job.LastBuildTime;

            if (result.Building)
            {
                result.State = ObservationState.Running;
            }
            else
            {
                result.State = CcStatusToObservationStatus(job);
            }

            if (result.Building)
            {
                result.Duration = DateTime.Now - job.NextBuildTime;
                result.Time     = job.NextBuildTime.ToUniversalTime();
            }
            else
            {
                result.Time = DateTime.UtcNow;
            }

            result.EstimatedDuration = this.estimatedDuration;

            return(result);
        }
        private static void SetCulprits(CruiseControlJob job, CruiseControlStatus result)
        {
            var breakers = job.MessageList.MessagesSafe.Where(msg => msg.Kind == MessageKind.Breakers);

            foreach (var breakersLine in breakers)
            {
                foreach (var breaker in breakersLine.Text.Split(',').Select(brk => brk.Trim()).Where(brk => !string.IsNullOrEmpty(brk)))
                {
                    if (result.Culprits.Any(brk => brk.Name == breaker))
                    {
                        continue;
                    }

                    var culprit = new CruiseControlUser {
                        Name = breaker
                    };
                    result.Culprits.Add(culprit);
                }
            }
        }