Exemplo n.º 1
0
        public static bool VerifySettings(IConfiguration config, OnlineDeployment onlineDeployment, ILogger log)
        {
            bool invokeScaleOut = false;

            var maxInstances     = onlineDeployment.properties.scaleSettings.Maximum;
            var currentInstances = onlineDeployment.properties.scaleSettings.instanceCount;

            if (string.IsNullOrWhiteSpace(maxInstances))
            {
                log.LogInformation("Cannot scale out. Maximum instances on deployment scale settings is not set.");
            }
            else if (currentInstances >= Convert.ToInt32(maxInstances))
            {
                log.LogInformation("Cannot scale out. Current instances already reached maximum available instances.");
            }
            else if (string.IsNullOrWhiteSpace(config["ScalingPolicy:ScaleOutStep"]))
            {
                log.LogInformation("Cannot scale out. Scale out step is not specified in config.");
            }
            else if (!string.IsNullOrWhiteSpace(config["ScalingPolicy:MaxScale"]))
            {
                var maxInstancesConfig = Convert.ToInt32(config["ScalingPolicy:MaxScale"]);
                if (currentInstances >= maxInstancesConfig)
                {
                    log.LogInformation("Cannot scale out. Current instances already reached maximum instances specified in config.");
                }
            }
            else
            {
                invokeScaleOut = true;
            }

            return(invokeScaleOut);
        }
        public static async Task UpdateDeploymentResource(IConfigurationRoot config, string targetResourceId, OnlineDeployment deployment, ILogger log)
        {
            using (var httpClient = new HttpClient())
            {
                var accessToken = await GetToken(config, targetResourceId);

                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                var resourceUri    = GetResourceUri(config, targetResourceId);
                var deploymentJson = JsonConvert.SerializeObject(deployment);

                var content = new StringContent(deploymentJson, Encoding.UTF8, "application/json");
                await httpClient.PutAsync(resourceUri, content);
            }
        }