public ScheduledHorizontalScaleForecastWorker(
     IDeployment deployment,
     IOperation operation,
     Guid subscriptionId,
     string certificateThumbprint, 
     string serviceName,
     string deploymentSlot,
     HorizontalScale[] horizontalScales,
     ScheduleDay[] scheduleDays,
     bool treatWarningsAsError,
     string mode,
     int pollingIntervalInMinutes)
     : base(GetWorkerId(serviceName, deploymentSlot))
 {
     this.deployment = deployment;
     this.operation = operation;
     this.subscriptionId = subscriptionId;
     this.certificateThumbprint = certificateThumbprint;
     this.serviceName = serviceName;
     this.deploymentSlot = deploymentSlot;
     this.horizontalScales = horizontalScales;
     this.scheduleDays = scheduleDays;
     this.treatWarningsAsError = treatWarningsAsError;
     this.mode = mode;
     this.pollingIntervalInMinutes = pollingIntervalInMinutes;
 }
Ejemplo n.º 2
0
        private static HorizontalScale[] GetHorizontalScalesFromHorizontalScaleConfiguration(HorizontalScaleConfiguration[] horizontalScaleConfigurations)
        {
            HorizontalScale[] horizontalScales = new HorizontalScale[horizontalScaleConfigurations.Length];
            for (int i = 0; i < horizontalScaleConfigurations.Length; i++)
            {
                horizontalScales[i] = new HorizontalScale
                {
                    RoleName      = horizontalScaleConfigurations[i].RoleName,
                    InstanceCount = horizontalScaleConfigurations[i].InstanceCount
                };
            }

            return(horizontalScales);
        }
Ejemplo n.º 3
0
        private HorizontalScale[] FindHorizontalScaleChangesComparedToWhitelist(ISubscription subscription, string hostedServiceName, WhiteListService whiteListService, string deploymentSlot)
        {
            List <HorizontalScale> horizontalScales = new List <HorizontalScale>();

            foreach (WhiteListRole whiteListRole in whiteListService.Roles)
            {
                if (whiteListRole.MaxInstanceCount.HasValue)
                {
                    int instanceCount = this.deployment.GetInstanceCount(subscription.SubscriptionId, subscription.CertificateThumbprint, hostedServiceName, deploymentSlot, whiteListRole.Name);
                    if (instanceCount > whiteListRole.MaxInstanceCount)
                    {
                        HorizontalScale horizontalScale = new HorizontalScale {
                            InstanceCount = whiteListRole.MaxInstanceCount.Value, RoleName = whiteListRole.Name
                        };
                        horizontalScales.Add(horizontalScale);
                    }
                }
            }

            return(horizontalScales.ToArray());
        }
Ejemplo n.º 4
0
        /// <param name="subscriptionId">The Subscription ID.</param>
        /// <param name="certificateThumbprint">The certificate thumbprint.</param>
        /// <param name="serviceName">The service name.</param>
        /// <param name="deploymentSlot">Either "Production" or "Staging".</param>
        /// <param name="horizontalScales">Role names and required instance counts.</param>
        /// <param name="treatWarningsAsError">Whether to treat any warnings as errors.</param>
        /// <param name="mode">Auto|Manual</param>
        /// <returns>The ID of the request to update the configuration of the deployment. Null if no update was made (if the deployment was already scaled to the specification).</returns>
        public string HorizontallyScale(Guid subscriptionId, string certificateThumbprint, string serviceName, string deploymentSlot, HorizontalScale[] horizontalScales, bool treatWarningsAsError, string mode)
        {
            if (horizontalScales == null)
            {
                throw new ArgumentNullException("horizontalScales");
            }

            XDocument configuration = this.GetConfiguration(subscriptionId, certificateThumbprint, serviceName, deploymentSlot);
            bool configurationHasBeenUpdated = false;
            foreach (HorizontalScale horizontalScale in horizontalScales)
            {
                if (ConfigurationShouldBeUpdated(configuration, horizontalScale.RoleName, horizontalScale.InstanceCount))
                {
                    configuration = UpdateConfiguration(configuration, horizontalScale.RoleName, horizontalScale.InstanceCount);
                    configurationHasBeenUpdated = true;
                }
            }

            if (configurationHasBeenUpdated)
            {
                string changeConfigurationRequestId = this.ChangeConfiguration(subscriptionId, certificateThumbprint, serviceName, deploymentSlot, configuration, treatWarningsAsError, mode);
                return changeConfigurationRequestId;
            }

            return null;
        }
Ejemplo n.º 5
0
 private void HorizontallyScaleDeployedServiceRole(ISubscription subscription, string hostedServiceName, string deploymentSlot, HorizontalScale[] horizontalScales)
 {
     try
     {
         bool exists = this.deployment.CheckExists(subscription.SubscriptionId, subscription.CertificateThumbprint, hostedServiceName, deploymentSlot);
         if (exists)
         {
             string logMessage = string.Format(CultureInfo.CurrentCulture, "{0} '{1}' found a '{2}' deployment for service name '{3}' in subscription '{4}' and the service was not in the white list, the deployed service is being horizontally scaled.", this.GetType().FullName, this.Id, deploymentSlot, hostedServiceName, subscription.SubscriptionId);
             Logger.Warn(logMessage);
             string scaleRequestId = this.deployment.HorizontallyScale(subscription.SubscriptionId, subscription.CertificateThumbprint, hostedServiceName, deploymentSlot, horizontalScales, true, Mode.Auto);
             this.WaitForResultOfRequest(Logger, this.GetType().FullName, this.operation, subscription.SubscriptionId, subscription.CertificateThumbprint, scaleRequestId);
         }
         else
         {
             string logMessage = string.Format(CultureInfo.CurrentCulture, "{0} '{1}' found service name '{2}' in subscription '{3}' and the service was not in the white list, but there was no deployment in '{4}'.", this.GetType().FullName, this.Id, hostedServiceName, subscription.SubscriptionId, deploymentSlot);
             Logger.Info(logMessage);
         }
     }
     catch (Exception e)
     {
         string errorMessage = string.Format(CultureInfo.CurrentCulture, "{0} '{1}' experienced an error horizontally scaling a deployment Subscription ID '{2}', Service Name '{3}' and Deployment Slot '{4}'. The operation will be retried after the next polling interval.", this.GetType().Name, this.Id, subscription.SubscriptionId, hostedServiceName, deploymentSlot);
         Logger.Error(errorMessage, e);
     }
 }
Ejemplo n.º 6
0
        private HorizontalScale[] FindHorizontalScaleChangesComparedToWhitelist(ISubscription subscription, string hostedServiceName, WhiteListService whiteListService, string deploymentSlot)
        {
            List<HorizontalScale> horizontalScales = new List<HorizontalScale>();
            foreach (WhiteListRole whiteListRole in whiteListService.Roles)
            {
                if (whiteListRole.MaxInstanceCount.HasValue)
                {
                    int instanceCount = this.deployment.GetInstanceCount(subscription.SubscriptionId, subscription.CertificateThumbprint, hostedServiceName, deploymentSlot, whiteListRole.Name);
                    if (instanceCount > whiteListRole.MaxInstanceCount)
                    {
                        HorizontalScale horizontalScale = new HorizontalScale { InstanceCount = whiteListRole.MaxInstanceCount.Value, RoleName = whiteListRole.Name };
                        horizontalScales.Add(horizontalScale);
                    }
                }
            }

            return horizontalScales.ToArray();
        }
        private static HorizontalScale[] GetHorizontalScalesFromHorizontalScaleConfiguration(HorizontalScaleConfiguration[] horizontalScaleConfigurations)
        {
            HorizontalScale[] horizontalScales = new HorizontalScale[horizontalScaleConfigurations.Length];
            for (int i = 0; i < horizontalScaleConfigurations.Length; i++)
            {
                horizontalScales[i] = new HorizontalScale
                    {
                        RoleName = horizontalScaleConfigurations[i].RoleName,
                        InstanceCount = horizontalScaleConfigurations[i].InstanceCount
                    };
            }

            return horizontalScales;
        }
 private static void SetupHorizontallyScaleWithStatusCheck(IDeployment mockDeployment, IOperation mockOperation, string serviceName, string deploymentSlot, HorizontalScale[] horizontalScales, string requestId)
 {
     mockDeployment
         .Expect(d => d.CheckExists(SubscriptionId, CertificateThumbprint, serviceName, deploymentSlot))
         .Repeat.Once()
         .Return(true);
     mockDeployment
         .Expect(d => d.HorizontallyScale(SubscriptionId, CertificateThumbprint, serviceName, deploymentSlot, horizontalScales, true, Mode.Auto))
         .Repeat.Once()
         .Return(requestId);
     mockOperation
         .Expect(o => o.StatusCheck(SubscriptionId, CertificateThumbprint, requestId))
         .Repeat.Once()
         .Return(new OperationResult { Status = OperationStatus.Succeeded });
 }