예제 #1
0
        public MeasurementTimeByType Calculate(MeasurementType type, ReleaseWindow releaseWindow, IEnumerable<Metric> metrics)
        {
            if (releaseWindow == null)
                throw new ArgumentNullException("releaseWindow");

            switch (type)
            {
                case MeasurementType.OverallTime:
                    return CalculateOverallTime(releaseWindow);

                case MeasurementType.DownTime:
                    return CalculateTimeBetweenMetrics(releaseWindow, metrics, type, MetricType.SiteDown, MetricType.SiteUp);

                case MeasurementType.DeployTime:
                    return CalculateTimeBetweenMetrics(releaseWindow, metrics, type, MetricType.StartDeploy, MetricType.FinishDeploy);

                case MeasurementType.PreDownTime:
                    return CalculatePreDownTime(releaseWindow, metrics);

                case MeasurementType.PostDownTime:
                    return CalculatePostDownTime(releaseWindow, metrics);

                case MeasurementType.RunTime:
                    return CalculateTimeBetweenMetrics(releaseWindow, metrics, type, MetricType.StartRun, MetricType.FinishRun);
                default: return null;
            }
        }
 private bool CheckIfAllowedToClose(Guid userId, IEnumerable<SignOff> signOffs, ReleaseWindow releaseWindow)
 {
     return BusinessRuleEngine.Execute<bool>(userId,
         BusinessRuleConstants.Release.AllowCloseAfterSignOffRule.ExternalId,
         new Dictionary<string, object>
         {
             { BusinessRuleConstants.Release.AllowCloseAfterSignOffRule.Parameters.ElementAt(0).Name, signOffs },
             { BusinessRuleConstants.Release.AllowCloseAfterSignOffRule.Parameters.ElementAt(1).Name, releaseWindow }
         });
 }
예제 #3
0
        public Measurement Calculate(ReleaseWindow releaseWindow, IEnumerable<Metric> metrics, params MeasurementType[] types)
        {
            if (types.IsNullOrEmpty() || releaseWindow == null)
                return null;

            return new Measurement
            {
                ReleaseWindow = releaseWindow,
                Metrics = types.Select(x => Calculate(x, releaseWindow, metrics))
            };
        }
        public ReleaseWindow FindOverlappedWindow(ReleaseWindow releaseWindow)
        {
            if (ReleaseWindowHelper.IsMaintenance(releaseWindow))
                return null;

            IList<Product> products;

            using (var gateway = ProductGatewayFactory())
            {
                products = gateway.GetProducts(releaseWindow.Products).ToList();

                if (products.IsNullOrEmpty())
                    throw new ProductShouldBeAssignedException(releaseWindow.ExternalId);

                if (products.Count != releaseWindow.Products.Count())
                    throw new ProductNotFoundException(releaseWindow.Products.Where(x => products.All(p => p.Description != x)));

                if (products.All(x => x.ReleaseTrack == ReleaseTrack.Automated))
                    return null;
            }

            using (var gateway = ReleaseWindowGatewayFactory())
            {
                foreach (var product in products.Where(x => x.ReleaseTrack != ReleaseTrack.Automated))
                {
                    var conflictingRelease = gateway.FindFirstOverlappedRelease(
                        product.Description,
                        releaseWindow.StartTime,
                        releaseWindow.EndTime,
                        releaseWindow.ExternalId);

                    if (conflictingRelease == null)
                        Logger.DebugFormat("There are no booked releases for product={2} and time period={0} - {1}",
                            releaseWindow.StartTime,
                            releaseWindow.EndTime,
                            product.Description);
                    else
                    {
                        Logger.DebugFormat(
                            "Conflicting release with Id={3} found for product={2} and time period={0} - {1}",
                            releaseWindow.StartTime,
                            releaseWindow.EndTime,
                            product.Description,
                            conflictingRelease.ExternalId);

                        return conflictingRelease;
                    }
                }

                return null;
            }
        }
예제 #5
0
        private static MeasurementTimeByType CalculateOverallTime(ReleaseWindow releaseWindow)
        {
            if (!releaseWindow.SignedOff.HasValue)
            {
                Log.WarnFormat("Release is not signed off. ReleaseId={0}", releaseWindow.ExternalId);
                return null;
            }

            var startTime = releaseWindow.StartTime;
            var signedOffTime = releaseWindow.SignedOff;

            return new MeasurementTimeByType
                {
                    Type = MeasurementType.OverallTime,
                    Value = ConvertToMinutes((signedOffTime.Value - startTime).TotalMinutes)
                };
        }
예제 #6
0
        private static MeasurementTimeByType CalculatePostDownTime(ReleaseWindow releaseWindow, IEnumerable<Metric> metrics)
        {
            var siteUpTime = GetMetricTime(MetricType.SiteUp, metrics);
            if (!siteUpTime.HasValue)
            {
                Log.WarnFormat("Some metrics are absent. ReleaseId={0}, Metrics={1}", releaseWindow.ExternalId, new[] { MetricType.SiteUp }.FormatElements());
                return null;
            }
            if (!releaseWindow.SignedOff.HasValue)
            {
                Log.WarnFormat("Release is not signed off. ReleaseId={0}", releaseWindow.ExternalId);
                return null;
            }

            if (releaseWindow.SignedOff.Value < siteUpTime.Value)
                throw new ArgumentException("release start down time less then release start time");

            return new MeasurementTimeByType
                {
                    Type = MeasurementType.PostDownTime,
                    Value = ConvertToMinutes((releaseWindow.SignedOff.Value - siteUpTime.Value).TotalMinutes)
                };
        }
 private static string FormatMessage(ReleaseWindow duplicatedRelease)
 {
     return string.Format("There is already a release booked with ExternalId={0}. ReleaseWindow: {1}",  duplicatedRelease.ExternalId, duplicatedRelease);
 }
 public DuplicatedReleaseException(ReleaseWindow duplicatedRelease, Exception innerException)
     : base(FormatMessage(duplicatedRelease), innerException)
 {
 }
 public DuplicatedReleaseException(ReleaseWindow duplicatedRelease)
     : base(FormatMessage(duplicatedRelease))
 {
 }
예제 #10
0
 public bool IsMaintenance(ReleaseWindow releaseWindow)
 {
     var releaseType = EnumDescriptionHelper.GetEnumDescription<ReleaseType, ReleaseTypeDescription>(releaseWindow.ReleaseType);
     return releaseType.IsMaintenance;
 }
예제 #11
0
        private static MeasurementTimeByType CalculateTimeBetweenMetrics(ReleaseWindow releaseWindow, IEnumerable<Metric> metrics,
            MeasurementType measurementType, MetricType startMetricType, MetricType finishMetricType)
        {
            var metricDict = GetMetricTimes(new[] { startMetricType, finishMetricType }, metrics);
            if (metricDict == null)
            {
                Log.WarnFormat("Some metrics are absent. ReleaseId={0}, Metrics={1}", releaseWindow.ExternalId, new[] { startMetricType, finishMetricType }.FormatElements());
                return null;
            }

            var startMetricTime = metricDict[startMetricType];
            var finishMetricTime = metricDict[finishMetricType];

            if (finishMetricTime < startMetricTime)
                throw new ArgumentException(string.Format("{1} time less then {0} time", startMetricType, finishMetricType));

            return new MeasurementTimeByType
            {
                Type = measurementType,
                Value = ConvertToMinutes(
                    finishMetricTime.Subtract(startMetricTime).TotalMinutes
                )
            };
        }
 private static string FormatMessage(ReleaseWindow releaseWindow)
 {
     return string.Format("Release is not signed off. ReleaseWindow: {0}", releaseWindow);
 }
 public ReleaseNotSignedOffException(ReleaseWindow releaseWindow, Exception innerException)
     : base(FormatMessage(releaseWindow), innerException)
 {
 }
 public ReleaseNotSignedOffException(ReleaseWindow releaseWindow)
     : base(FormatMessage(releaseWindow))
 {
 }