/// <summary> /// Execute the cmdlet /// </summary> public override void ExecuteCmdlet() { WriteWarning("The parameter ScaleActionType has been extended, it receives the following values now: ChangeCount (previous only value and current default), PercentChangeCount, ExactCount. The parameter could become mandatory in future versions."); ScaleRule rule = this.CreateSettingRule(); WriteObject(rule); }
private static AutoscaleSettingResource CreateAutoscaleSetting(string location, string resourceUri, string metricName) { var capacity = new ScaleCapacity("1", "100", "1"); var fixedDate = new TimeWindow(DateTime.Parse("2014-04-15T21:06:11.7882792Z"), DateTime.Parse("2014-04-16T21:06:11.7882792Z")); var recurrence = new Recurrence(RecurrenceFrequency.Week, new RecurrentSchedule("UTC-11", new List <string> { "Monday" }, new List <int> { 0 }, new List <int> { 10 })); var rules = new ScaleRule[] { new ScaleRule(new MetricTrigger( metricName, resourceUri, TimeSpan.FromMinutes(1), MetricStatisticType.Average, TimeSpan.FromHours(1), TimeAggregationType.Maximum, ComparisonOperationType.EqualsValue, threshold: 80.0), new ScaleAction(ScaleDirection.Increase, ScaleType.ChangeCount, "10", cooldown: TimeSpan.FromMinutes(20)) ) }; AutoscaleSettingResource setting = new AutoscaleSettingResource(null, "setting1", null, "", new Dictionary <string, string>(), new AutoscaleProfile[] { //There may have one issue //new AutoscaleProfile("Profile1",capacity,rules,fixedDate,recurrence), new AutoscaleProfile("Profile2", capacity, rules, fixedDate, recurrence) }, new List <AutoscaleNotification>(), true, "setting1", resourceUri); return(setting); }
/// <summary> /// Execute the cmdlet /// </summary> public override void ExecuteCmdlet() { WriteWarning("The parameter ScaleActionType has no effect. It was kept here for backwards compatibility, but it could be removed in the future."); ScaleRule rule = this.CreateSettingRule(); WriteObject(rule); }
private static void AreEqual(ScaleRule exp, ScaleRule act) { if (exp != null) { AreEqual(exp.MetricTrigger, act.MetricTrigger); AreEqual(exp.ScaleAction, act.ScaleAction); } }
/// <summary> /// Execute the cmdlet /// </summary> public override void ExecuteCmdlet() { WriteWarning("This cmdlet is being modified to enable better experience and may contain breaking changes in a future release."); ScaleRule rule = this.CreateSettingRule(); WriteObject(rule); }
/// <summary> /// A string representation of the ScaleRule including indentation /// </summary> /// <param name="scaleRule">The ScaleRule object</param> /// <param name="indentationTabs">The number of tabs to insert in front of each member</param> /// <returns>A string representation of the ScaleRule including indentation</returns> public static string ToString(this ScaleRule scaleRule, int indentationTabs) { StringBuilder output = new StringBuilder(); if (scaleRule != null) { output.AppendLine(); output.AddSpacesInFront(indentationTabs).AppendLine("MetricTrigger : " + scaleRule.MetricTrigger.ToString(indentationTabs + DefaultIndentationTabs)); output.AddSpacesInFront(indentationTabs).Append("ScaleAction : " + scaleRule.ScaleAction.ToString(indentationTabs + DefaultIndentationTabs)); } return(output.ToString()); }
/// <param name='resourceId'> /// Required. The resource ID. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.Monitoring.Autoscale.Models.AutoscaleSettingGetResponse> GetAsync(string resourceId, CancellationToken cancellationToken) { // Validate if (resourceId == null) { throw new ArgumentNullException("resourceId"); } // Tracing bool shouldTrace = CloudContext.Configuration.Tracing.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = Tracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("resourceId", resourceId); Tracing.Enter(invocationId, this, "GetAsync", tracingParameters); } // Construct URL string url = "/" + (this.Client.Credentials.SubscriptionId != null ? this.Client.Credentials.SubscriptionId.Trim() : "") + "/services/monitoring/autoscalesettings?"; url = url + "resourceId=" + Uri.EscapeDataString(resourceId.Trim()); string baseUrl = this.Client.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; url = url.Replace(" ", "%20"); // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Get; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.Add("Accept", "application/json"); httpRequest.Headers.Add("x-ms-version", "2013-10-01"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { Tracing.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { Tracing.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; if (statusCode != HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { Tracing.Error(invocationId, ex); } throw ex; } // Create Result AutoscaleSettingGetResponse result = null; // Deserialize Response cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new AutoscaleSettingGetResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { AutoscaleSetting settingInstance = new AutoscaleSetting(); result.Setting = settingInstance; JToken profilesArray = responseDoc["Profiles"]; if (profilesArray != null && profilesArray.Type != JTokenType.Null) { foreach (JToken profilesValue in ((JArray)profilesArray)) { AutoscaleProfile autoscaleProfileInstance = new AutoscaleProfile(); settingInstance.Profiles.Add(autoscaleProfileInstance); JToken nameValue = profilesValue["Name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { string nameInstance = ((string)nameValue); autoscaleProfileInstance.Name = nameInstance; } JToken capacityValue = profilesValue["Capacity"]; if (capacityValue != null && capacityValue.Type != JTokenType.Null) { ScaleCapacity capacityInstance = new ScaleCapacity(); autoscaleProfileInstance.Capacity = capacityInstance; JToken minimumValue = capacityValue["Minimum"]; if (minimumValue != null && minimumValue.Type != JTokenType.Null) { string minimumInstance = ((string)minimumValue); capacityInstance.Minimum = minimumInstance; } JToken maximumValue = capacityValue["Maximum"]; if (maximumValue != null && maximumValue.Type != JTokenType.Null) { string maximumInstance = ((string)maximumValue); capacityInstance.Maximum = maximumInstance; } JToken defaultValue = capacityValue["Default"]; if (defaultValue != null && defaultValue.Type != JTokenType.Null) { string defaultInstance = ((string)defaultValue); capacityInstance.Default = defaultInstance; } } JToken rulesArray = profilesValue["Rules"]; if (rulesArray != null && rulesArray.Type != JTokenType.Null) { foreach (JToken rulesValue in ((JArray)rulesArray)) { ScaleRule scaleRuleInstance = new ScaleRule(); autoscaleProfileInstance.Rules.Add(scaleRuleInstance); JToken metricTriggerValue = rulesValue["MetricTrigger"]; if (metricTriggerValue != null && metricTriggerValue.Type != JTokenType.Null) { MetricTrigger metricTriggerInstance = new MetricTrigger(); scaleRuleInstance.MetricTrigger = metricTriggerInstance; JToken metricNameValue = metricTriggerValue["MetricName"]; if (metricNameValue != null && metricNameValue.Type != JTokenType.Null) { string metricNameInstance = ((string)metricNameValue); metricTriggerInstance.MetricName = metricNameInstance; } JToken metricNamespaceValue = metricTriggerValue["MetricNamespace"]; if (metricNamespaceValue != null && metricNamespaceValue.Type != JTokenType.Null) { string metricNamespaceInstance = ((string)metricNamespaceValue); metricTriggerInstance.MetricNamespace = metricNamespaceInstance; } JToken metricSourceValue = metricTriggerValue["MetricSource"]; if (metricSourceValue != null && metricSourceValue.Type != JTokenType.Null) { string metricSourceInstance = ((string)metricSourceValue); metricTriggerInstance.MetricSource = metricSourceInstance; } JToken timeGrainValue = metricTriggerValue["TimeGrain"]; if (timeGrainValue != null && timeGrainValue.Type != JTokenType.Null) { TimeSpan timeGrainInstance = TypeConversion.From8601TimeSpan(((string)timeGrainValue)); metricTriggerInstance.TimeGrain = timeGrainInstance; } JToken statisticValue = metricTriggerValue["Statistic"]; if (statisticValue != null && statisticValue.Type != JTokenType.Null) { MetricStatisticType statisticInstance = ((MetricStatisticType)Enum.Parse(typeof(MetricStatisticType), ((string)statisticValue), true)); metricTriggerInstance.Statistic = statisticInstance; } JToken timeWindowValue = metricTriggerValue["TimeWindow"]; if (timeWindowValue != null && timeWindowValue.Type != JTokenType.Null) { TimeSpan timeWindowInstance = TypeConversion.From8601TimeSpan(((string)timeWindowValue)); metricTriggerInstance.TimeWindow = timeWindowInstance; } JToken timeAggregationValue = metricTriggerValue["TimeAggregation"]; if (timeAggregationValue != null && timeAggregationValue.Type != JTokenType.Null) { TimeAggregationType timeAggregationInstance = ((TimeAggregationType)Enum.Parse(typeof(TimeAggregationType), ((string)timeAggregationValue), true)); metricTriggerInstance.TimeAggregation = timeAggregationInstance; } JToken operatorValue = metricTriggerValue["Operator"]; if (operatorValue != null && operatorValue.Type != JTokenType.Null) { ComparisonOperationType operatorInstance = ((ComparisonOperationType)Enum.Parse(typeof(ComparisonOperationType), ((string)operatorValue), true)); metricTriggerInstance.Operator = operatorInstance; } JToken thresholdValue = metricTriggerValue["Threshold"]; if (thresholdValue != null && thresholdValue.Type != JTokenType.Null) { double thresholdInstance = ((double)thresholdValue); metricTriggerInstance.Threshold = thresholdInstance; } } JToken scaleActionValue = rulesValue["ScaleAction"]; if (scaleActionValue != null && scaleActionValue.Type != JTokenType.Null) { ScaleAction scaleActionInstance = new ScaleAction(); scaleRuleInstance.ScaleAction = scaleActionInstance; JToken directionValue = scaleActionValue["Direction"]; if (directionValue != null && directionValue.Type != JTokenType.Null) { ScaleDirection directionInstance = ((ScaleDirection)Enum.Parse(typeof(ScaleDirection), ((string)directionValue), true)); scaleActionInstance.Direction = directionInstance; } JToken typeValue = scaleActionValue["Type"]; if (typeValue != null && typeValue.Type != JTokenType.Null) { ScaleType typeInstance = ((ScaleType)Enum.Parse(typeof(ScaleType), ((string)typeValue), true)); scaleActionInstance.Type = typeInstance; } JToken valueValue = scaleActionValue["Value"]; if (valueValue != null && valueValue.Type != JTokenType.Null) { string valueInstance = ((string)valueValue); scaleActionInstance.Value = valueInstance; } JToken cooldownValue = scaleActionValue["Cooldown"]; if (cooldownValue != null && cooldownValue.Type != JTokenType.Null) { TimeSpan cooldownInstance = TypeConversion.From8601TimeSpan(((string)cooldownValue)); scaleActionInstance.Cooldown = cooldownInstance; } } } } JToken fixedDateValue = profilesValue["FixedDate"]; if (fixedDateValue != null && fixedDateValue.Type != JTokenType.Null) { TimeWindow fixedDateInstance = new TimeWindow(); autoscaleProfileInstance.FixedDate = fixedDateInstance; JToken timeZoneValue = fixedDateValue["TimeZone"]; if (timeZoneValue != null && timeZoneValue.Type != JTokenType.Null) { string timeZoneInstance = ((string)timeZoneValue); fixedDateInstance.TimeZone = timeZoneInstance; } JToken startValue = fixedDateValue["Start"]; if (startValue != null && startValue.Type != JTokenType.Null) { DateTime startInstance = ((DateTime)startValue); fixedDateInstance.Start = startInstance; } JToken endValue = fixedDateValue["End"]; if (endValue != null && endValue.Type != JTokenType.Null) { DateTime endInstance = ((DateTime)endValue); fixedDateInstance.End = endInstance; } } JToken recurrenceValue = profilesValue["Recurrence"]; if (recurrenceValue != null && recurrenceValue.Type != JTokenType.Null) { Recurrence recurrenceInstance = new Recurrence(); autoscaleProfileInstance.Recurrence = recurrenceInstance; JToken frequencyValue = recurrenceValue["Frequency"]; if (frequencyValue != null && frequencyValue.Type != JTokenType.Null) { RecurrenceFrequency frequencyInstance = ((RecurrenceFrequency)Enum.Parse(typeof(RecurrenceFrequency), ((string)frequencyValue), true)); recurrenceInstance.Frequency = frequencyInstance; } JToken scheduleValue = recurrenceValue["Schedule"]; if (scheduleValue != null && scheduleValue.Type != JTokenType.Null) { RecurrentSchedule scheduleInstance = new RecurrentSchedule(); recurrenceInstance.Schedule = scheduleInstance; JToken timeZoneValue2 = scheduleValue["TimeZone"]; if (timeZoneValue2 != null && timeZoneValue2.Type != JTokenType.Null) { string timeZoneInstance2 = ((string)timeZoneValue2); scheduleInstance.TimeZone = timeZoneInstance2; } JToken daysArray = scheduleValue["Days"]; if (daysArray != null && daysArray.Type != JTokenType.Null) { foreach (JToken daysValue in ((JArray)daysArray)) { scheduleInstance.Days.Add(((string)daysValue)); } } JToken hoursArray = scheduleValue["Hours"]; if (hoursArray != null && hoursArray.Type != JTokenType.Null) { foreach (JToken hoursValue in ((JArray)hoursArray)) { scheduleInstance.Hours.Add(((int)hoursValue)); } } JToken minutesArray = scheduleValue["Minutes"]; if (minutesArray != null && minutesArray.Type != JTokenType.Null) { foreach (JToken minutesValue in ((JArray)minutesArray)) { scheduleInstance.Minutes.Add(((int)minutesValue)); } } } } } } JToken enabledValue = responseDoc["Enabled"]; if (enabledValue != null && enabledValue.Type != JTokenType.Null) { bool enabledInstance = ((bool)enabledValue); settingInstance.Enabled = enabledInstance; } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { Tracing.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }
/// <summary> /// Execute the cmdlet /// </summary> public override void ExecuteCmdlet() { ScaleRule rule = this.CreateSettingRule(); WriteObject(rule); }
private static AutoscaleSettingResource CreateAutoscaleSetting(string location, string resourceUri, string metricName) { var capacity = new ScaleCapacity() { DefaultProperty = "1", Maximum = "10", Minimum = "1" }; var fixedDate = new TimeWindow() { End = DateTime.Parse("2014-04-16T21:06:11.7882792Z"), Start = DateTime.Parse("2014-04-15T21:06:11.7882792Z"), TimeZone = TimeZoneInfo.Utc.Id.ToString() }; var recurrence = new Recurrence() { Frequency = RecurrenceFrequency.Week, Schedule = new RecurrentSchedule() { Days = new List <string> { "Monday" }, Hours = new List <int?> { 0 }, Minutes = new List <int?> { 10 }, TimeZone = "UTC-11" } }; var rules = new ScaleRule[] { new ScaleRule() { MetricTrigger = new MetricTrigger { MetricName = metricName, MetricResourceUri = resourceUri, Statistic = MetricStatisticType.Average, Threshold = 80.0, TimeAggregation = TimeAggregationType.Maximum, TimeGrain = TimeSpan.FromMinutes(1), TimeWindow = TimeSpan.FromHours(1) }, ScaleAction = new ScaleAction { Cooldown = TimeSpan.FromMinutes(20), Direction = ScaleDirection.Increase, Value = "1", Type = ScaleType.ChangeCount } } }; var profiles = new AutoscaleProfile[] { new AutoscaleProfile() { Name = "Profile1", Capacity = capacity, FixedDate = fixedDate, Recurrence = null, Rules = rules }, new AutoscaleProfile() { Name = "Profile2", Capacity = capacity, FixedDate = null, Recurrence = recurrence, Rules = rules } }; AutoscaleSettingResource setting = new AutoscaleSettingResource(location: Location, profiles: profiles, name: SettingName) { AutoscaleSettingResourceName = SettingName, TargetResourceUri = resourceUri, Enabled = true, Tags = null, Notifications = null }; return(setting); }
private AutoscaleSettingResource CreateAutoscale( string location, string resourceUri, string metricName, string vmssASMin, string vmssASMax) { var capacity = new ScaleCapacity() { DefaultProperty = "1", Maximum = vmssASMax, Minimum = vmssASMin }; var recurrence = new Recurrence() { Frequency = RecurrenceFrequency.Week, Schedule = new RecurrentSchedule() { Days = new List <string> { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" }, Hours = new List <int?> { 0 }, Minutes = new List <int?> { 10 }, TimeZone = "UTC-11" } }; var rules = new ScaleRule[] { new ScaleRule() { MetricTrigger = new MetricTrigger { MetricName = metricName, MetricResourceUri = resourceUri, Statistic = MetricStatisticType.Average, Threshold = 80.0, OperatorProperty = ComparisonOperationType.GreaterThan, TimeAggregation = TimeAggregationType.Maximum, TimeGrain = TimeSpan.FromMinutes(1), TimeWindow = TimeSpan.FromHours(1) }, ScaleAction = new ScaleAction { Cooldown = TimeSpan.FromMinutes(20), Direction = ScaleDirection.Increase, Value = "10" } }, new ScaleRule() { MetricTrigger = new MetricTrigger { MetricName = metricName, MetricResourceUri = resourceUri, Statistic = MetricStatisticType.Average, Threshold = 30.0, OperatorProperty = ComparisonOperationType.LessThan, TimeAggregation = TimeAggregationType.Maximum, TimeGrain = TimeSpan.FromMinutes(1), TimeWindow = TimeSpan.FromHours(1) }, ScaleAction = new ScaleAction { Cooldown = TimeSpan.FromMinutes(20), Direction = ScaleDirection.Decrease, Value = "2" } } }; AutoscaleSettingResource setting = new AutoscaleSettingResource { Name = TestUtilities.GenerateName("autoscale"), AutoscaleSettingResourceName = "setting1", TargetResourceUri = resourceUri, Enabled = true, Profiles = new AutoscaleProfile[] { new AutoscaleProfile() { Name = TestUtilities.GenerateName("profile"), Capacity = capacity, FixedDate = null, Recurrence = recurrence, Rules = rules } }, Location = location, Tags = null, Notifications = null }; return(setting); }
/// <summary> /// Execute the cmdlet /// </summary> protected override void ProcessRecord() { ScaleRule rule = this.CreateSettingRule(); WriteObject(rule); }
private static AutoscaleSetting CreateAutoscaleSetting(string resourceUri, string metricName, string metricNamespace) { var capacity = new ScaleCapacity { Default = "1", Maximum = "100", Minimum = "1" }; var fixedDate = new TimeWindow() { End = DateTime.Parse("2014-04-16T21:06:11.7882792Z"), Start = DateTime.Parse("2014-04-15T21:06:11.7882792Z"), TimeZone = TimeZoneInfo.Utc.Id.ToString() }; var recurrence = new Recurrence() { Frequency = RecurrenceFrequency.Week, Schedule = new RecurrentSchedule() { Days = new List <string> { "Monday" }, Hours = new List <int> { 0 }, Minutes = new int[] { 10 }, TimeZone = "UTC-11" } }; var rules = new ScaleRule[] { new ScaleRule() { MetricTrigger = new MetricTrigger { MetricName = metricName, MetricNamespace = metricNamespace, MetricResourceUri = resourceUri, Operator = ComparisonOperationType.GreaterThan, Statistic = MetricStatisticType.Average, Threshold = 80.0, TimeAggregation = TimeAggregationType.Maximum, TimeGrain = TimeSpan.FromMinutes(1), TimeWindow = TimeSpan.FromHours(1) }, ScaleAction = new ScaleAction { Cooldown = TimeSpan.FromMinutes(20), Direction = ScaleDirection.Increase, Type = ScaleType.ExactCount, Value = "10" } } }; AutoscaleSetting setting = new AutoscaleSetting { Name = "setting1", TargetResourceUri = resourceUri, Enabled = true, Profiles = new AutoscaleProfile[] { new AutoscaleProfile() { Name = "Profile1", Capacity = capacity, FixedDate = fixedDate, Recurrence = null, Rules = rules }, new AutoscaleProfile() { Name = "Profile2", Capacity = capacity, FixedDate = null, Recurrence = recurrence, Rules = rules } } }; return(setting); }