Example #1
0
        /// <summary>
        /// A scalar used to determine whether the site should be scaled up down or left alone
        /// </summary>
        /// <returns>Whether the site should be scaled up or down</returns>
        public WasabiWebState Scale(WasabiWebLogicalOperation operation, List <WebsiteMetric> metrics)
        {
            int countScaleDown = 0, countScaleUp = 0;

            // enumerate the rules to determine the usage
            foreach (var rule in _rules)
            {
                // find the metric
                var metric = metrics.Find(a => a.Name == rule.MetricName);
                // for the time being if it doesn't exist just continue
                if (metric == null)
                {
                    continue;
                }
                // if the value is greater than the total then scaleup count
                if (metric.Total > rule.IsGreaterThan)
                {
                    countScaleUp++;
                }
                // if the value is less than the total then scale down count
                if (metric.Total < rule.IsLessThan)
                {
                    countScaleDown++;
                }
            }
            // check to seee whether they should scale up or down
            if (countScaleDown == _rules.Count)
            {
                return(WasabiWebState.ScaleDown);
            }
            // check directly to see whether the rules matches the count
            if (countScaleUp == _rules.Count)
            {
                return(WasabiWebState.ScaleUp);
            }
            // if the logical operation is and but the count is not zero for either of them then fail
            if (WasabiWebLogicalOperation.And == operation && (countScaleDown != 0 || countScaleUp != 0))
            {
                return(WasabiWebState.LeaveUnchanged);
            }
            // if the logical operation is Or then do the greater of the two
            if (WasabiWebLogicalOperation.Or == operation)
            {
                if (countScaleUp > countScaleDown)
                {
                    return(WasabiWebState.ScaleUp);
                }
                if (countScaleDown > countScaleUp)
                {
                    return(WasabiWebState.ScaleDown);
                }
            }

            return(WasabiWebState.LeaveUnchanged);
        }
Example #2
0
 /// <summary>
 /// Used to construct a connector to Fluent Management
 /// </summary>
 public WebsiteManagementConnector(IWasabiWebRulesEngine engine, string subscriptionId, WasabiWebLogicalOperation logicalOperation = WasabiWebLogicalOperation.And,
                                   string publishSettingsFile = null)
 {
     _engine             = engine;
     SubscriptionId      = subscriptionId;
     PublishSettingsFile = publishSettingsFile;
     Operation           = logicalOperation;
     // build the timer here using the samples period
     _timer = new Timer(engine.SamplesPeriodInMins * 60 * 1000)
     {
         AutoReset = true,
         Enabled   = true,
     };
 }
 /// <summary>
 /// Used to construct a connector to Fluent Management
 /// </summary>
 public WebsiteManagementConnector(IWasabiWebRulesEngine engine, string subscriptionId, WasabiWebLogicalOperation logicalOperation = WasabiWebLogicalOperation.And, 
     string publishSettingsFile = null)
 {
     _engine = engine;
     SubscriptionId = subscriptionId;
     PublishSettingsFile = publishSettingsFile;
     Operation = logicalOperation;
     // build the timer here using the samples period
     _timer = new Timer(engine.SamplesPeriodInMins*60*1000)
         {
             AutoReset = true,
             Enabled = true,
         };
 }
        /// <summary>
        /// A scalar used to determine whether the site should be scaled up down or left alone
        /// </summary>
        /// <returns>Whether the site should be scaled up or down</returns>
        public WasabiWebState Scale(WasabiWebLogicalOperation operation, List<WebsiteMetric> metrics)
        {
            int countScaleDown = 0, countScaleUp = 0;

            // enumerate the rules to determine the usage
            foreach (var rule in _rules)
            {
                // find the metric
                var metric = metrics.Find(a => a.Name == rule.MetricName);
                // for the time being if it doesn't exist just continue
                if(metric == null)
                    continue;
                // if the value is greater than the total then scaleup count
                if (metric.Total > rule.IsGreaterThan)
                    countScaleUp++;
                // if the value is less than the total then scale down count
                if (metric.Total < rule.IsLessThan)
                    countScaleDown++;
            }
            // check to seee whether they should scale up or down
            if (countScaleDown == _rules.Count)
                return WasabiWebState.ScaleDown;
            // check directly to see whether the rules matches the count
            if (countScaleUp == _rules.Count)
                return WasabiWebState.ScaleUp;
            // if the logical operation is and but the count is not zero for either of them then fail
            if (WasabiWebLogicalOperation.And == operation && (countScaleDown != 0 || countScaleUp != 0))
            {
                return WasabiWebState.LeaveUnchanged;
            }
            // if the logical operation is Or then do the greater of the two
            if (WasabiWebLogicalOperation.Or == operation)
            {
                if(countScaleUp > countScaleDown)
                    return WasabiWebState.ScaleUp;
                if(countScaleDown > countScaleUp)
                    return WasabiWebState.ScaleDown;
            }

            return WasabiWebState.LeaveUnchanged;
        }