internal static AutoscaleSettingResourceCollection DeserializeAutoscaleSettingResourceCollection(JsonElement element) { IReadOnlyList <AutoscaleSettingData> value = default; Optional <string> nextLink = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("value")) { List <AutoscaleSettingData> array = new List <AutoscaleSettingData>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(AutoscaleSettingData.DeserializeAutoscaleSettingData(item)); } value = array; continue; } if (property.NameEquals("nextLink")) { nextLink = property.Value.GetString(); continue; } } return(new AutoscaleSettingResourceCollection(value, nextLink.Value)); }
private async Async.Task <OneFuzzResult <AutoscaleSettingResource> > CreateAutoScaleResourceFor(Guid resourceId, string location, AutoscaleProfile profile) { _logTracer.Info($"Creating auto-scale resource for: {resourceId}"); var resourceGroup = _context.Creds.GetBaseResourceGroup(); var subscription = _context.Creds.GetSubscription(); var scalesetUri = $"/subscriptions/{subscription}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachineScaleSets/{resourceId}"; var parameters = new AutoscaleSettingData(location, new[] { profile }) { TargetResourceId = scalesetUri, Enabled = true }; try { var autoScaleResource = await _context.Creds.GetResourceGroupResource().GetAutoscaleSettings() .CreateOrUpdateAsync(WaitUntil.Completed, Guid.NewGuid().ToString(), parameters); if (autoScaleResource != null && autoScaleResource.HasValue) { _logTracer.Info($"Successfully created auto scale resource {autoScaleResource.Id} for {resourceId}"); return(OneFuzzResult <AutoscaleSettingResource> .Ok(autoScaleResource.Value)); } return(OneFuzzResult <AutoscaleSettingResource> .Error( ErrorCode.UNABLE_TO_CREATE, $"Could not get auto scale resource value after creating for {resourceId}" )); } catch (Exception ex) { _logTracer.Exception(ex); return(OneFuzzResult <AutoscaleSettingResource> .Error( ErrorCode.UNABLE_TO_CREATE, $"unable to create auto scale resource for resource: {resourceId} with profile: {profile}")); } }
public static AutoscaleSettingData GetBasicAutoscaleSettingData(AzureLocation location) { var fixDate = new TimeWindow("UTC", DateTime.Parse("2014-04-15T21:06:11.7882792Z"), DateTime.Parse("2014-04-15T21:06:11.7882792Z")); var Schedule = new RecurrentSchedule("UTC-11", new List <string> { "Monday" }, new List <int> { 0 }, new List <int> { 10 }); var recurrence = new MonitorRecurrence(RecurrenceFrequency.Week, Schedule); ScaleCapacity scaleCapacity = new ScaleCapacity("1", "1", "1"); var metricTtigger = new MetricTrigger("AbandonMessage", "microsoft.servicebus/namespaces", "/subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c/resourceGroups/testservicebusRG-9432/providers/Microsoft.ServiceBus/namespaces/testnamespacemgmt7892", "Eest US 2", TimeSpan.FromMinutes(1), MetricStatisticType.Average, TimeSpan.FromMinutes(10), TimeAggregationType.Average, ComparisonOperationType.GreaterThan, 70, new ChangeTrackingList <ScaleRuleMetricDimension>(), false); IList <ScaleRule> rules = new List <ScaleRule>() { new ScaleRule(metricTtigger, new ScaleAction(ScaleDirection.Increase, ScaleType.ServiceAllowedNextValue, "1", TimeSpan.FromMinutes(5))) }; IEnumerable <AutoscaleProfile> profiles = new List <AutoscaleProfile>() { //new AutoscaleProfile("Profiles2", scaleCapacity, rules) new AutoscaleProfile("Profiles2", scaleCapacity, rules, fixDate, null), new AutoscaleProfile("Profiles3", scaleCapacity, rules, null, recurrence), }; var data = new AutoscaleSettingData(location, profiles) { Enabled = true, TargetResourceLocation = location, TargetResourceId = "/subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c/resourceGroups/testservicebusRG-9432/providers/Microsoft.ServiceBus/namespaces/testnamespacemgmt7892", /*Notifications = * { * new AutoscaleNotification() * { * Operation = "Scale", * Email = new EmailNotification() * { * SendToSubscriptionAdministrator = true, * SendToSubscriptionCoAdministrators = true, * CustomEmails = * { * "*****@*****.**", * "*****@*****.**" * } * }, * Webhooks = * { * new WebhookNotification() * { * ServiceUri = "http://myservice.com", * Properties = {} * } * } * }, * },*/ Tags = {}, }; return(data); }
public async Task <OneFuzzResultVoid> UpdateAutoscale(AutoscaleSettingData autoscale) { _logTracer.Info($"Updating auto scale resource: {autoscale.Name}"); try { var newResource = await _context.Creds.GetResourceGroupResource().GetAutoscaleSettings().CreateOrUpdateAsync( WaitUntil.Started, autoscale.Name, autoscale ); _logTracer.Info($"Successfully updated auto scale resource: {autoscale.Name}"); } catch (RequestFailedException ex) { _logTracer.Exception(ex); return(OneFuzzResultVoid.Error( ErrorCode.UNABLE_TO_UPDATE, $"unable to update auto scale resource with name: {autoscale.Name} and profile: {JsonSerializer.Serialize(autoscale)}" )); } return(OneFuzzResultVoid.Ok); }
public static void AssertAutoscaleSetting(AutoscaleSettingData setting1, AutoscaleSettingData setting2) { AssertTrackedResource(setting1, setting2); Assert.AreEqual(setting1.NamePropertiesName, setting2.NamePropertiesName); }