Esempio n. 1
0
 /// <summary>
 /// Creates a new LoadBalancingSettings with the specified Rule name within the
 /// specified Front Door.
 /// </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='frontDoorName'>
 /// Name of the Front Door which is globally unique.
 /// </param>
 /// <param name='loadBalancingSettingsName'>
 /// Name of the load balancing settings which is unique within the Front Door.
 /// </param>
 /// <param name='loadBalancingSettingsParameters'>
 /// LoadBalancingSettings properties needed to create a new Front Door.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <LoadBalancingSettingsModel> BeginCreateOrUpdateAsync(this ILoadBalancingSettingsOperations operations, string resourceGroupName, string frontDoorName, string loadBalancingSettingsName, LoadBalancingSettingsModel loadBalancingSettingsParameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, frontDoorName, loadBalancingSettingsName, loadBalancingSettingsParameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
        public void FrontDoorCRUDTest()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                // Create clients
                var frontDoorMgmtClient = FrontDoorTestUtilities.GetFrontDoorManagementClient(context, handler1);
                var resourcesClient     = FrontDoorTestUtilities.GetResourceManagementClient(context, handler2);

                // Get subscription id
                string subid = frontDoorMgmtClient.SubscriptionId;

                // Create resource group
                var resourceGroupName = FrontDoorTestUtilities.CreateResourceGroup(resourcesClient);

                // Create two different frontDoor
                string frontDoorName = TestUtilities.GenerateName("frontDoor");

                ForwardingConfiguration forwardingConfiguration = new ForwardingConfiguration(
                    forwardingProtocol: "MatchRequest",
                    backendPool: new refID("/subscriptions/" + subid + "/resourceGroups/" + resourceGroupName + "/providers/Microsoft.Network/frontDoors/" + frontDoorName + "/backendPools/backendPool1"));

                RoutingRule routingrule1 = new RoutingRule(
                    name: "routingrule1",
                    frontendEndpoints: new List <refID> {
                    new refID("/subscriptions/" + subid + "/resourceGroups/" + resourceGroupName + "/providers/Microsoft.Network/frontDoors/" + frontDoorName + "/frontendEndpoints/frontendEndpoint1")
                },
                    acceptedProtocols: new List <string> {
                    "Https"
                },
                    patternsToMatch: new List <string> {
                    "/*"
                },
                    routeConfiguration: forwardingConfiguration,
                    enabledState: "Enabled"
                    );
                HealthProbeSettingsModel healthProbeSettings1 = new HealthProbeSettingsModel(
                    name: "healthProbeSettings1",
                    path: "/",
                    protocol: "Http",
                    intervalInSeconds: 120,
                    healthProbeMethod: "Get",
                    enabledState: "Enabled"
                    );

                LoadBalancingSettingsModel loadBalancingSettings1 = new LoadBalancingSettingsModel(
                    name: "loadBalancingSettings1",
                    additionalLatencyMilliseconds: 0,
                    sampleSize: 4,
                    successfulSamplesRequired: 2
                    );

                Backend backend1 = new Backend(
                    address: "contoso1.azurewebsites.net",
                    httpPort: 80,
                    httpsPort: 443,
                    enabledState: "Enabled",
                    weight: 1,
                    priority: 2
                    );

                BackendPool backendPool1 = new BackendPool(
                    name: "backendPool1",
                    backends: new List <Backend> {
                    backend1
                },
                    loadBalancingSettings: new refID("/subscriptions/" + subid + "/resourceGroups/" + resourceGroupName + "/providers/Microsoft.Network/frontDoors/" + frontDoorName + "/loadBalancingSettings/loadBalancingSettings1"),
                    healthProbeSettings: new refID("/subscriptions/" + subid + "/resourceGroups/" + resourceGroupName + "/providers/Microsoft.Network/frontDoors/" + frontDoorName + "/healthProbeSettings/healthProbeSettings1")
                    );

                BackendPoolsSettings backendPoolsSettings1 = new BackendPoolsSettings(
                    sendRecvTimeoutSeconds: 123
                    );

                FrontendEndpoint frontendEndpoint1 = new FrontendEndpoint(
                    name: "frontendEndpoint1",
                    hostName: frontDoorName + ".azurefd.net",
                    sessionAffinityEnabledState: "Disabled",
                    sessionAffinityTtlSeconds: 0
                    );

                FrontDoorModel createParameters = new FrontDoorModel
                {
                    Location     = "global",
                    FriendlyName = frontDoorName,
                    Tags         = new Dictionary <string, string>
                    {
                        { "key1", "value1" },
                        { "key2", "value2" }
                    },
                    RoutingRules = new List <RoutingRule> {
                        routingrule1
                    },
                    LoadBalancingSettings = new List <LoadBalancingSettingsModel> {
                        loadBalancingSettings1
                    },
                    HealthProbeSettings = new List <HealthProbeSettingsModel> {
                        healthProbeSettings1
                    },
                    FrontendEndpoints = new List <FrontendEndpoint> {
                        frontendEndpoint1
                    },
                    BackendPools = new List <BackendPool> {
                        backendPool1
                    },
                    BackendPoolsSettings = backendPoolsSettings1
                };

                var createdFrontDoor = frontDoorMgmtClient.FrontDoors.CreateOrUpdate(resourceGroupName, frontDoorName, createParameters);

                // validate that correct frontdoor is created
                VerifyFrontDoor(createdFrontDoor, createParameters);

                // Retrieve frontdoor
                var retrievedFrontDoor = frontDoorMgmtClient.FrontDoors.Get(resourceGroupName, frontDoorName);

                // validate that correct frontdoor is retrieved
                VerifyFrontDoor(retrievedFrontDoor, createParameters);

                // update FrontDoor
                retrievedFrontDoor.Tags = new Dictionary <string, string>
                {
                    { "key3", "value3" },
                    { "key4", "value4" }
                };


                var updatedFrontDoor = frontDoorMgmtClient.FrontDoors.CreateOrUpdate(resourceGroupName, frontDoorName, retrievedFrontDoor);

                // validate that frontDoor is correctly updated
                VerifyFrontDoor(updatedFrontDoor, retrievedFrontDoor);

                // Delete frontDoor
                frontDoorMgmtClient.FrontDoors.Delete(resourceGroupName, frontDoorName);

                // Verify that frontDoor is deleted
                Assert.ThrowsAny <ErrorResponseException>(() =>
                {
                    frontDoorMgmtClient.FrontDoors.Get(resourceGroupName, frontDoorName);
                });

                FrontDoorTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Creates a new LoadBalancingSettings with the specified Rule name within the
 /// specified Front Door.
 /// </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='frontDoorName'>
 /// Name of the Front Door which is globally unique.
 /// </param>
 /// <param name='loadBalancingSettingsName'>
 /// Name of the load balancing settings which is unique within the Front Door.
 /// </param>
 /// <param name='loadBalancingSettingsParameters'>
 /// LoadBalancingSettings properties needed to create a new Front Door.
 /// </param>
 public static LoadBalancingSettingsModel BeginCreateOrUpdate(this ILoadBalancingSettingsOperations operations, string resourceGroupName, string frontDoorName, string loadBalancingSettingsName, LoadBalancingSettingsModel loadBalancingSettingsParameters)
 {
     return(operations.BeginCreateOrUpdateAsync(resourceGroupName, frontDoorName, loadBalancingSettingsName, loadBalancingSettingsParameters).GetAwaiter().GetResult());
 }
        public void FrontDoorCRUDTestWithRulesEngine()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                // Create clients
                var frontDoorMgmtClient = FrontDoorTestUtilities.GetFrontDoorManagementClient(context, handler1);
                var resourcesClient     = FrontDoorTestUtilities.GetResourceManagementClient(context, handler2);

                // Get subscription id
                string subid = frontDoorMgmtClient.SubscriptionId;

                // Create resource group
                var resourceGroupName = FrontDoorTestUtilities.CreateResourceGroup(resourcesClient);

                // Create two different frontDoor
                string frontDoorName = TestUtilities.GenerateName("frontDoor");

                ForwardingConfiguration forwardingConfiguration = new ForwardingConfiguration(
                    forwardingProtocol: "MatchRequest",
                    backendPool: new refID("/subscriptions/" + subid + "/resourceGroups/" + resourceGroupName + "/providers/Microsoft.Network/frontDoors/" + frontDoorName + "/backendPools/backendPool1"));

                RoutingRule routingrule1 = new RoutingRule(
                    name: "routingrule1",
                    frontendEndpoints: new List <refID> {
                    new refID("/subscriptions/" + subid + "/resourceGroups/" + resourceGroupName + "/providers/Microsoft.Network/frontDoors/" + frontDoorName + "/frontendEndpoints/frontendEndpoint1")
                },
                    acceptedProtocols: new List <string> {
                    "Https"
                },
                    patternsToMatch: new List <string> {
                    "/*"
                },
                    routeConfiguration: forwardingConfiguration,
                    enabledState: "Enabled"
                    );
                HealthProbeSettingsModel healthProbeSettings1 = new HealthProbeSettingsModel(
                    name: "healthProbeSettings1",
                    path: "/",
                    protocol: "Http",
                    intervalInSeconds: 120,
                    healthProbeMethod: "Get",
                    enabledState: "Enabled"
                    );

                LoadBalancingSettingsModel loadBalancingSettings1 = new LoadBalancingSettingsModel(
                    name: "loadBalancingSettings1",
                    additionalLatencyMilliseconds: 0,
                    sampleSize: 4,
                    successfulSamplesRequired: 2
                    );

                Backend backend1 = new Backend(
                    address: "contoso1.azurewebsites.net",
                    httpPort: 80,
                    httpsPort: 443,
                    enabledState: "Enabled",
                    weight: 1,
                    priority: 2
                    );

                BackendPool backendPool1 = new BackendPool(
                    name: "backendPool1",
                    backends: new List <Backend> {
                    backend1
                },
                    loadBalancingSettings: new refID("/subscriptions/" + subid + "/resourceGroups/" + resourceGroupName + "/providers/Microsoft.Network/frontDoors/" + frontDoorName + "/loadBalancingSettings/loadBalancingSettings1"),
                    healthProbeSettings: new refID("/subscriptions/" + subid + "/resourceGroups/" + resourceGroupName + "/providers/Microsoft.Network/frontDoors/" + frontDoorName + "/healthProbeSettings/healthProbeSettings1")
                    );

                BackendPoolsSettings backendPoolsSettings1 = new BackendPoolsSettings(
                    sendRecvTimeoutSeconds: 123
                    );

                FrontendEndpoint frontendEndpoint1 = new FrontendEndpoint(
                    name: "frontendEndpoint1",
                    hostName: frontDoorName + ".azurefd.net",
                    sessionAffinityEnabledState: "Disabled",
                    sessionAffinityTtlSeconds: 0
                    );

                FrontDoorModel createParameters = new FrontDoorModel
                {
                    Location     = "global",
                    FriendlyName = frontDoorName,
                    Tags         = new Dictionary <string, string>
                    {
                        { "key1", "value1" },
                        { "key2", "value2" }
                    },
                    RoutingRules = new List <RoutingRule> {
                        routingrule1
                    },
                    LoadBalancingSettings = new List <LoadBalancingSettingsModel> {
                        loadBalancingSettings1
                    },
                    HealthProbeSettings = new List <HealthProbeSettingsModel> {
                        healthProbeSettings1
                    },
                    FrontendEndpoints = new List <FrontendEndpoint> {
                        frontendEndpoint1
                    },
                    BackendPools = new List <BackendPool> {
                        backendPool1
                    },
                    BackendPoolsSettings = backendPoolsSettings1
                };

                var createdFrontDoor = frontDoorMgmtClient.FrontDoors.CreateOrUpdate(resourceGroupName, frontDoorName, createParameters);

                // validate that correct frontdoor is created
                VerifyFrontDoor(createdFrontDoor, createParameters);

                // Create rules engine for front door
                RulesEngineAction rulesEngineAction1 = new RulesEngineAction(
                    requestHeaderActions: new List <HeaderAction> {
                },
                    responseHeaderActions: new List <HeaderAction> {
                },
                    routeConfigurationOverride: new ForwardingConfiguration(
                        customForwardingPath: null,
                        forwardingProtocol: "HttpsOnly",
                        cacheConfiguration: new CacheConfiguration(queryParameterStripDirective: "StripNone", dynamicCompression: "Disabled"),
                        backendPool: new refID("/subscriptions/" + subid + "/resourceGroups/" + resourceGroupName + "/providers/Microsoft.Network/frontDoors/" + frontDoorName + "/backendPools/backendPool1")
                        )
                    );

                RulesEngineMatchCondition rulesEngineMatchCondition1 = new RulesEngineMatchCondition(
                    rulesEngineMatchVariable: "RequestHeader",
                    selector: "Rules-engine-action",
                    rulesEngineOperator: "Equal",
                    rulesEngineMatchValue: new List <string> {
                    "Route-override-forwarding"
                },
                    negateCondition: false,
                    transforms: new List <string> {
                }
                    );

                RulesEngineRule rule1 = new RulesEngineRule(
                    priority: 1,
                    name: "Rules1",
                    matchProcessingBehavior: "Stop",
                    action: rulesEngineAction1,
                    matchConditions: new List <RulesEngineMatchCondition> {
                    rulesEngineMatchCondition1
                }
                    );

                RulesEngine rulesEngine1 = new RulesEngine(
                    rules: new List <RulesEngineRule> {
                    rule1
                },
                    name: "RulesEngine1"
                    );

                var rulesEngineParameters = new List <RulesEngine> {
                    rulesEngine1
                };

                var createdRulesEngine = frontDoorMgmtClient.RulesEngines.CreateOrUpdate(resourceGroupName, frontDoorName, rulesEngine1.Name, rulesEngineParameters[0]);

                // Validate correct rules engine created
                VerifyRulesEngine(createdRulesEngine, rulesEngineParameters[0]);

                // Retrieve rules engines for front door
                var retrievedRulesEngines = frontDoorMgmtClient.RulesEngines.ListByFrontDoor(resourceGroupName, frontDoorName).ToList <RulesEngine>();

                // Validate correct rules engines retrieved from front door
                VerifyRulesEngines(retrievedRulesEngines, rulesEngineParameters);

                // Retrieve frontdoor and validate rules engine present
                var retrievedFrontDoor = frontDoorMgmtClient.FrontDoors.Get(resourceGroupName, frontDoorName);

                VerifyFrontDoor(retrievedFrontDoor, createParameters);
                VerifyRulesEngines(retrievedFrontDoor.RulesEngines, rulesEngineParameters);

                // Link rules engine to routing rule
                // why did sdk not autogenerate into subresource?
                retrievedFrontDoor.RoutingRules[0].RulesEngine = new refID("/subscriptions/" + subid + "/resourceGroups/" + resourceGroupName + "/providers/Microsoft.Network/frontDoors/" + frontDoorName + "/rulesEngines/" + rulesEngine1.Name);

                var updatedFrontDoor = frontDoorMgmtClient.FrontDoors.CreateOrUpdate(resourceGroupName, frontDoorName, retrievedFrontDoor);

                // Validate rules engine has been linked.
                VerifyFrontDoor(updatedFrontDoor, retrievedFrontDoor);

                // Unlink rules engine and delete rules engine.
                frontDoorMgmtClient.FrontDoors.CreateOrUpdate(resourceGroupName, frontDoorName, createParameters);
                frontDoorMgmtClient.RulesEngines.Delete(resourceGroupName, frontDoorName, rulesEngine1.Name);

                // Verify rules engine deleted
                retrievedRulesEngines = frontDoorMgmtClient.RulesEngines.ListByFrontDoor(resourceGroupName, frontDoorName).ToList <RulesEngine>();
                Assert.Empty(retrievedRulesEngines);

                // Delete frontDoor
                frontDoorMgmtClient.FrontDoors.Delete(resourceGroupName, frontDoorName);

                // Verify that frontDoor is deleted
                Assert.ThrowsAny <ErrorResponseException>(() =>
                {
                    frontDoorMgmtClient.FrontDoors.Get(resourceGroupName, frontDoorName);
                });

                FrontDoorTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName);
            }
        }