public void CreateAfdOriginGroup() { try { // availability of load balancing settings parameters bool isSampleSize = this.MyInvocation.BoundParameters.ContainsKey("SampleSize"); bool isSuccessfulSampleRequired = this.MyInvocation.BoundParameters.ContainsKey("SuccessfulSamplesRequired"); bool isAdditionalLatencyInMilliseconds = this.MyInvocation.BoundParameters.ContainsKey("AdditionalLatencyInMillisecond"); // availability of health probe settings parameters bool isProbePath = this.MyInvocation.BoundParameters.ContainsKey("ProbePath"); bool isProbeRequestType = this.MyInvocation.BoundParameters.ContainsKey("ProbeRequestType"); bool isProbeProtocol = this.MyInvocation.BoundParameters.ContainsKey("ProbeProtocol"); bool isProbeIntervalInSeconds = this.MyInvocation.BoundParameters.ContainsKey("ProbeIntervalInSeconds"); // availability of parameters on the origin group bool isTrafficRestorationTimeToHealedOrNewEndpointsInMinutes = this.MyInvocation.BoundParameters.ContainsKey("TrafficRestorationTimeToHealedOrNewEndpointsInMinutes"); AFDOriginGroup afdOriginGroup = new AFDOriginGroup() { LoadBalancingSettings = this.CreateLoadBalancingSettings(isSampleSize, isSuccessfulSampleRequired, isAdditionalLatencyInMilliseconds), HealthProbeSettings = this.CreateHealthProbeSettings(isProbePath, isProbeRequestType, isProbeProtocol, isProbeIntervalInSeconds), TrafficRestorationTimeToHealedOrNewEndpointsInMinutes = isTrafficRestorationTimeToHealedOrNewEndpointsInMinutes ? this.TrafficRestorationTimeToHealedOrNewEndpointsInMinutes : 10 }; PSAfdOriginGroup psAfdOriginGroup = this.CdnManagementClient.AFDOriginGroups.Create(this.ResourceGroupName, this.ProfileName, this.OriginGroupName, afdOriginGroup).ToPSAfdOriginGroup(); WriteObject(psAfdOriginGroup); } catch (AfdErrorResponseException errorResponse) { throw new PSArgumentException(errorResponse.Response.Content); } }
public void AFDOriginGroupListResourceUsageTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); try { // Create a standard Azure frontdoor profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardAzureFrontDoor }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); string originGroupName = TestUtilities.GenerateName("originGroupName"); var originGroupCreateParameters = new AFDOriginGroup(name: originGroupName) { }; var originGroup = cdnMgmtClient.AFDOriginGroups.Create(resourceGroupName, profileName, originGroupName, originGroupCreateParameters); var usageList = cdnMgmtClient.AFDOriginGroups.ListResourceUsage(resourceGroupName, profileName, originGroupName); Assert.Single(usageList); var usage = usageList.First(); Assert.Equal(MaximumAfdOriginCountPerOriginGroup, usage.Limit); Assert.Equal(0, usage.CurrentValue); } finally { // Delete resource group _ = CdnTestUtilities.DeleteResourceGroupAsync(resourcesClient, resourceGroupName); } } }
public void AFDRouteGetListTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); try { // Create a standard Azure frontdoor profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardAzureFrontDoor }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); // Create a standard Azure frontdoor endpoint string endpointName = TestUtilities.GenerateName("endpointName"); var endpointCreateParameters = new AFDEndpoint("WestUs") { EnabledState = "Enabled", OriginResponseTimeoutSeconds = 60, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var endpoint = cdnMgmtClient.AFDEndpoints.Create(resourceGroupName, profileName, endpointName, endpointCreateParameters); // Create a standard Azure frontdoor originGroup string originGroupName = TestUtilities.GenerateName("originGroupName"); var originGroupCreateParameters = new AFDOriginGroup(name: originGroupName) { LoadBalancingSettings = new LoadBalancingSettingsParameters { SampleSize = 5, SuccessfulSamplesRequired = 4, AdditionalLatencyInMilliseconds = 200, }, HealthProbeSettings = new HealthProbeParameters { ProbeIntervalInSeconds = 1, ProbePath = "/", ProbeProtocol = ProbeProtocol.Https, ProbeRequestType = HealthProbeRequestType.GET }, }; var originGroup = cdnMgmtClient.AFDOriginGroups.Create(resourceGroupName, profileName, originGroupName, originGroupCreateParameters); // Create a standard Azure frontdoor origin string originName = TestUtilities.GenerateName("originName"); var hostName = "en.wikipedia.org"; var originCreateParameters = new AFDOrigin(hostName: hostName) { OriginHostHeader = hostName, HttpPort = 80, HttpsPort = 443, Priority = 1, Weight = 1000, }; var origin = cdnMgmtClient.AFDOrigins.Create(resourceGroupName, profileName, originGroupName, originName, originCreateParameters); // Create a standard Azure frontdoor ruleSet string ruleSetName = TestUtilities.GenerateName("ruleSetName"); var ruleSet = cdnMgmtClient.RuleSets.Create(resourceGroupName, profileName, ruleSetName); // Create a standard Azure frontdoor rule string ruleName = TestUtilities.GenerateName("ruleName"); var ruleGroupCreateParameters = new Rule { Conditions = new List <DeliveryRuleCondition>() { new DeliveryRuleRequestUriCondition() { Parameters = new RequestUriMatchConditionParameters() { OperatorProperty = "Any" } } }, Actions = new List <DeliveryRuleAction> { new DeliveryRuleCacheExpirationAction() { Parameters = new CacheExpirationActionParameters() { CacheBehavior = "Override", CacheDuration = "00:00:20" } } } }; var rule = cdnMgmtClient.Rules.Create(resourceGroupName, profileName, ruleSetName, ruleName, ruleGroupCreateParameters); // Create a standard Azure frontdoor route string routeName = TestUtilities.GenerateName("routeName"); var routeCreateParameters = new Route { OriginGroup = new ResourceReference(originGroup.Id), RuleSets = new List <ResourceReference>() { new ResourceReference(ruleSet.Id), }, PatternsToMatch = new List <string>() { "/*" }, LinkToDefaultDomain = "Enabled", EnabledState = "Enabled", }; var route = cdnMgmtClient.Routes.Create(resourceGroupName, profileName, endpointName, routeName, routeCreateParameters); Assert.NotNull(route); Assert.Equal(routeName, route.Name); var getRoute = cdnMgmtClient.Routes.Get(resourceGroupName, profileName, endpointName, routeName); Assert.NotNull(getRoute); Assert.Equal(routeName, getRoute.Name); var routList = cdnMgmtClient.Routes.ListByEndpoint(resourceGroupName, profileName, endpointName); Assert.NotNull(routList); Assert.Single(routList); cdnMgmtClient.Routes.Delete(resourceGroupName, profileName, endpointName, routeName); routList = cdnMgmtClient.Routes.ListByEndpoint(resourceGroupName, profileName, endpointName); Assert.NotNull(routList); Assert.Empty(routList); } finally { // Delete resource group _ = CdnTestUtilities.DeleteResourceGroupAsync(resourcesClient, resourceGroupName); } } }
public void AFDOriginUpdateTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); try { // Create a standard Azure frontdoor profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardAzureFrontDoor }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); string originGroupName = TestUtilities.GenerateName("originGroupName"); var originGroupCreateParameters = new AFDOriginGroup(name: originGroupName) { LoadBalancingSettings = new LoadBalancingSettingsParameters { SampleSize = 5, SuccessfulSamplesRequired = 4, AdditionalLatencyInMilliseconds = 200, }, HealthProbeSettings = new HealthProbeParameters { ProbeIntervalInSeconds = 1, ProbePath = "/", ProbeProtocol = ProbeProtocol.Https, ProbeRequestType = HealthProbeRequestType.GET }, }; var originGroup = cdnMgmtClient.AFDOriginGroups.Create(resourceGroupName, profileName, originGroupName, originGroupCreateParameters); Assert.NotNull(originGroup); Assert.Equal(originGroupName, originGroup.Name); string originName = TestUtilities.GenerateName("originName"); var hostName = "en.wikipedia.org"; var originCreateParameters = new AFDOrigin(hostName: hostName) { OriginHostHeader = hostName, HttpPort = 80, HttpsPort = 443, Priority = 1, Weight = 1000, }; var origin = cdnMgmtClient.AFDOrigins.Create(resourceGroupName, profileName, originGroupName, originName, originCreateParameters); VerifyOriginCreated(originName, originCreateParameters, origin); var originUpdateProperties = new AFDOriginUpdateParameters { HostName = "update." + hostName, OriginHostHeader = "update." + hostName, HttpPort = 81, HttpsPort = 443, Priority = 2, Weight = 100, }; var updatedOrigin = cdnMgmtClient.AFDOrigins.Update(resourceGroupName, profileName, originGroupName, originName, originUpdateProperties); VerifyOriginUpdated(originUpdateProperties, updatedOrigin); } finally { // Delete resource group _ = CdnTestUtilities.DeleteResourceGroupAsync(resourcesClient, resourceGroupName); } } }
/// <summary> /// Creates a new origin group within the specified profile. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// Name of the Resource group within the Azure subscription. /// </param> /// <param name='profileName'> /// Name of the CDN profile which is unique within the resource group. /// </param> /// <param name='originGroupName'> /// Name of the origin group which is unique within the endpoint. /// </param> /// <param name='originGroup'> /// Origin group properties /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <AFDOriginGroup> BeginCreateAsync(this IAFDOriginGroupsOperations operations, string resourceGroupName, string profileName, string originGroupName, AFDOriginGroup originGroup, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.BeginCreateWithHttpMessagesAsync(resourceGroupName, profileName, originGroupName, originGroup, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Creates a new origin group within the specified profile. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// Name of the Resource group within the Azure subscription. /// </param> /// <param name='profileName'> /// Name of the CDN profile which is unique within the resource group. /// </param> /// <param name='originGroupName'> /// Name of the origin group which is unique within the endpoint. /// </param> /// <param name='originGroup'> /// Origin group properties /// </param> public static AFDOriginGroup BeginCreate(this IAFDOriginGroupsOperations operations, string resourceGroupName, string profileName, string originGroupName, AFDOriginGroup originGroup) { return(operations.BeginCreateAsync(resourceGroupName, profileName, originGroupName, originGroup).GetAwaiter().GetResult()); }
private static void VerifyOriginGroupUpdated(AFDOriginGroupUpdateParameters parameters, AFDOriginGroup originGroup) { Assert.Equal(parameters.LoadBalancingSettings.SampleSize, originGroup.LoadBalancingSettings.SampleSize); Assert.Equal(parameters.LoadBalancingSettings.SuccessfulSamplesRequired, originGroup.LoadBalancingSettings.SuccessfulSamplesRequired); Assert.Equal(parameters.LoadBalancingSettings.AdditionalLatencyInMilliseconds, originGroup.LoadBalancingSettings.AdditionalLatencyInMilliseconds); Assert.Equal(parameters.HealthProbeSettings.ProbeIntervalInSeconds, originGroup.HealthProbeSettings.ProbeIntervalInSeconds); Assert.Equal(parameters.HealthProbeSettings.ProbePath, originGroup.HealthProbeSettings.ProbePath); Assert.Equal(parameters.HealthProbeSettings.ProbeProtocol, originGroup.HealthProbeSettings.ProbeProtocol); Assert.Equal(parameters.HealthProbeSettings.ProbeRequestType, originGroup.HealthProbeSettings.ProbeRequestType); }