Esempio n. 1
0
        /// <summary>
        /// Patch updates an Azure Sql Database FailoverGroup.
        /// </summary>
        /// <param name="resourceGroup">The name of the resource group</param>
        /// <param name="serverName">The name of the Azure Sql Database Server</param>
        /// <param name="model">The input parameters for the create/update operation</param>
        /// <returns>The upserted Azure Sql Database FailoverGroup</returns>
        internal AzureSqlFailoverGroupModel PatchUpdateFailoverGroup(AzureSqlFailoverGroupModel model)
        {
            ReadOnlyEndpoint readOnlyEndpoint = new ReadOnlyEndpoint();

            readOnlyEndpoint.FailoverPolicy = model.ReadOnlyFailoverPolicy;

            ReadWriteEndpoint readWriteEndpoint = new ReadWriteEndpoint();

            readWriteEndpoint.FailoverPolicy = model.ReadWriteFailoverPolicy;

            if (model.FailoverWithDataLossGracePeriodHours.HasValue)
            {
                readWriteEndpoint.FailoverWithDataLossGracePeriodMinutes = checked (model.FailoverWithDataLossGracePeriodHours * 60);
            }

            var resp = Communicator.PatchUpdate(model.ResourceGroupName, model.ServerName, model.FailoverGroupName, new FailoverGroupPatchUpdateParameters()
            {
                Location   = model.Location,
                Properties = new FailoverGroupPatchUpdateProperties()
                {
                    ReadOnlyEndpoint  = readOnlyEndpoint,
                    ReadWriteEndpoint = readWriteEndpoint,
                }
            });

            return(CreateFailoverGroupModelFromResponse(resp));
        }
        /// <summary>
        /// Patch updates an Azure Sql Database FailoverGroup.
        /// </summary>
        /// <param name="resourceGroup">The name of the resource group</param>
        /// <param name="serverName">The name of the Azure Sql Database Server</param>
        /// <param name="model">The input parameters for the create/update operation</param>
        /// <returns>The upserted Azure Sql Database FailoverGroup</returns>
        internal AzureSqlFailoverGroupModel PatchUpdateFailoverGroup(AzureSqlFailoverGroupModel model)
        {
            ReadOnlyEndpoint readOnlyEndpoint = new ReadOnlyEndpoint();

            readOnlyEndpoint.FailoverPolicy = model.ReadOnlyFailoverPolicy;

            ReadWriteEndpoint readWriteEndpoint = new ReadWriteEndpoint();

            readWriteEndpoint.FailoverPolicy = model.ReadWriteFailoverPolicy;

            if (!string.Equals(model.ReadWriteFailoverPolicy, FailoverPolicy.Manual.ToString()))
            {
                readWriteEndpoint.FailoverWithDataLossGracePeriodMinutes = model.FailoverWithDataLossGracePeriodHours * 60;
            }
            else
            {
                readWriteEndpoint.FailoverWithDataLossGracePeriodMinutes = null;
            }


            var resp = Communicator.PatchUpdate(model.ResourceGroupName, model.ServerName, model.FailoverGroupName, Util.GenerateTracingId(), new FailoverGroupPatchUpdateParameters()
            {
                Location   = model.Location,
                Tags       = model.Tags,
                Properties = new FailoverGroupPatchUpdateProperties()
                {
                    ReadOnlyEndpoint  = readOnlyEndpoint,
                    ReadWriteEndpoint = readWriteEndpoint,
                }
            });

            return(CreateFailoverGroupModelFromResponse(model.ResourceGroupName, model.ServerName, resp));
        }
Esempio n. 3
0
        /// <summary>
        /// Creates or updates an Azure Sql Database FailoverGroup.
        /// </summary>
        /// <param name="resourceGroup">The name of the resource group</param>
        /// <param name="serverName">The name of the Azure Sql Database Server</param>
        /// <param name="model">The input parameters for the create/update operation</param>
        /// <returns>The upserted Azure Sql Database FailoverGroup</returns>
        internal AzureSqlFailoverGroupModel UpsertFailoverGroup(AzureSqlFailoverGroupModel model)
        {
            List <FailoverGroupPartnerServer> partnerServers = new List <FailoverGroupPartnerServer>();
            FailoverGroupPartnerServer        partnerServer  = new FailoverGroupPartnerServer();

            partnerServer.Id = string.Format(
                AzureSqlFailoverGroupModel.PartnerServerIdTemplate,
                _subscription.Id.ToString(),
                model.PartnerResourceGroupName,
                model.PartnerServerName);
            partnerServers.Add(partnerServer);

            ReadOnlyEndpoint readOnlyEndpoint = new ReadOnlyEndpoint();

            readOnlyEndpoint.FailoverPolicy = model.ReadOnlyFailoverPolicy;
            ReadWriteEndpoint readWriteEndpoint = new ReadWriteEndpoint();

            readWriteEndpoint.FailoverPolicy = model.ReadWriteFailoverPolicy;

            if (model.FailoverWithDataLossGracePeriodHours.HasValue)
            {
                readWriteEndpoint.FailoverWithDataLossGracePeriodMinutes = model.FailoverWithDataLossGracePeriodHours * 60;
            }
            else
            {
                readWriteEndpoint.FailoverWithDataLossGracePeriodMinutes = null;
            }

            var resp = Communicator.CreateOrUpdate(model.ResourceGroupName, model.ServerName, model.FailoverGroupName, Util.GenerateTracingId(), new FailoverGroupCreateOrUpdateParameters()
            {
                Location   = model.Location,
                Tags       = model.Tags,
                Properties = new FailoverGroupCreateOrUpdateProperties()
                {
                    PartnerServers    = partnerServers,
                    ReadOnlyEndpoint  = readOnlyEndpoint,
                    ReadWriteEndpoint = readWriteEndpoint,
                }
            });

            return(CreateFailoverGroupModelFromResponse(model.ResourceGroupName, model.ServerName, resp));
        }
        public void FailoverGroupCrud()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                string failoverGroupName  = TestUtilities.GenerateName("csm-sql-fgcrud1");
                string failoverGroup2Name = TestUtilities.GenerateName("csm-sql-fgcrud2");
                string serverName         = TestUtilities.GenerateName("csm-sql-fgcrud-server");
                string partnerServerName  = TestUtilities.GenerateName("csm-sql-fgcrud-server");

                // Create the resource group.

                //resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()

                //{
                //    Location = serverLocation,
                //});

                Sql2ScenarioHelper.RunServerTestInEnvironment(
                    handler,
                    "12.0",
                    "North Europe",
                    (sqlClient, resGroupName, server) =>
                {
                    // Variables for partner server create

                    string serverLocation = "North Europe";
                    string adminLogin     = "******";
                    string adminPass      = "******";
                    string version        = "12.0";

                    // Create partner server for test.
                    var createServerResponse = sqlClient.Servers.CreateOrUpdate(resGroupName, partnerServerName, new ServerCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new ServerCreateOrUpdateProperties()
                        {
                            AdministratorLogin         = adminLogin,
                            AdministratorLoginPassword = adminPass,
                            Version = version,
                        }
                    });


                    // Create Failover Group Test with all values specified (Default values)
                    ReadOnlyEndpoint readOnlyEndpoint   = new ReadOnlyEndpoint();
                    readOnlyEndpoint.FailoverPolicy     = "Disabled";
                    ReadWriteEndpoint readWriteEndpoint = new ReadWriteEndpoint();
                    readWriteEndpoint.FailoverPolicy    = "Automatic";
                    readWriteEndpoint.FailoverWithDataLossGracePeriodMinutes = 5;

                    FailoverGroupPartnerServer partnerServer = new FailoverGroupPartnerServer();
                    partnerServer.ReplicationRole            = "Secondary";
                    partnerServer.Id       = createServerResponse.Server.Id;
                    partnerServer.Location = "North Europe";

                    List <FailoverGroupPartnerServer> partnerServers = new List <FailoverGroupPartnerServer>();
                    partnerServers.Add(partnerServer);

                    var failoverGroup1Properties = new FailoverGroupCreateOrUpdateProperties()
                    {
                        ReadOnlyEndpoint  = readOnlyEndpoint,
                        ReadWriteEndpoint = readWriteEndpoint,
                        PartnerServers    = partnerServers,
                    };

                    var failoverGroup1 = sqlClient.FailoverGroups.CreateOrUpdate(resGroupName, server.Name, failoverGroupName, new FailoverGroupCreateOrUpdateParameters()
                    {
                        Location   = server.Location,
                        Properties = failoverGroup1Properties
                    });

                    TestUtilities.ValidateOperationResponse(failoverGroup1, HttpStatusCode.Created);

                    var failoverGroup2 = sqlClient.FailoverGroups.CreateOrUpdate(resGroupName, server.Name, failoverGroup2Name, new FailoverGroupCreateOrUpdateParameters()
                    {
                        Location   = server.Location,
                        Properties = failoverGroup1Properties
                    });

                    TestUtilities.ValidateOperationResponse(failoverGroup2, HttpStatusCode.Created);
                    ValidateFailoverGroup(
                        failoverGroup2.FailoverGroup,
                        failoverGroup2Name,
                        readOnlyEndpoint.FailoverPolicy,
                        readWriteEndpoint.FailoverPolicy,
                        readWriteEndpoint.FailoverWithDataLossGracePeriodMinutes,
                        partnerServer.ReplicationRole,
                        partnerServer.Id);

                    //////////////////////////////////////////////////////////////////////
                    // Update Failover Group Test
                    failoverGroup1Properties.ReadOnlyEndpoint.FailoverPolicy  = "Enabled";
                    failoverGroup1Properties.ReadWriteEndpoint.FailoverPolicy = "Manual";
                    failoverGroup1Properties.ReadWriteEndpoint.FailoverWithDataLossGracePeriodMinutes = null;

                    var failoverGroup3 = sqlClient.FailoverGroups.CreateOrUpdate(resGroupName, server.Name, failoverGroupName, new FailoverGroupCreateOrUpdateParameters()
                    {
                        Location   = server.Location,
                        Properties = failoverGroup1Properties
                    });


                    TestUtilities.ValidateOperationResponse(failoverGroup3, HttpStatusCode.Created);
                    ValidateFailoverGroup(
                        failoverGroup3.FailoverGroup,
                        failoverGroupName,
                        failoverGroup1Properties.ReadOnlyEndpoint.FailoverPolicy,
                        failoverGroup1Properties.ReadWriteEndpoint.FailoverPolicy,
                        failoverGroup1Properties.ReadWriteEndpoint.FailoverWithDataLossGracePeriodMinutes,
                        failoverGroup1Properties.PartnerServers.First().ReplicationRole,
                        failoverGroup1Properties.PartnerServers.First().Id);

                    //////////////////////////////////////////////////////////////////////
                    // Get Failover group.
                    var failoverGroup4 = sqlClient.FailoverGroups.Get(resGroupName, server.Name, failoverGroupName);


                    TestUtilities.ValidateOperationResponse(failoverGroup4, HttpStatusCode.Created);
                    ValidateFailoverGroup(
                        failoverGroup3.FailoverGroup,
                        failoverGroupName,
                        failoverGroup1Properties.ReadOnlyEndpoint.FailoverPolicy,
                        failoverGroup1Properties.ReadWriteEndpoint.FailoverPolicy,
                        failoverGroup1Properties.ReadWriteEndpoint.FailoverWithDataLossGracePeriodMinutes,
                        failoverGroup1Properties.PartnerServers.First().ReplicationRole,
                        failoverGroup1Properties.PartnerServers.First().Id);

                    //////////////////////////////////////////////////////////////////////
                    // Get Failover Groups Test.
                    var failoverGroups = sqlClient.FailoverGroups.List(resGroupName, server.Name);

                    TestUtilities.ValidateOperationResponse(failoverGroups, HttpStatusCode.OK);
                    Assert.Equal(2, failoverGroups.FailoverGroups.Count);

                    //////////////////////////////////////////////////////////////////////
                    // Delete Failover Group Test.
                    //var resp = sqlClient.FailoverGroups.Delete(resGroupName, server.Name, failoverGroupName);
                    //TestUtilities.ValidateOperationResponse(resp, HttpStatusCode.OK);

                    //var resp2 = sqlClient.FailoverGroups.Delete(resGroupName, server.Name, failoverGroup2Name);
                    //TestUtilities.ValidateOperationResponse(resp2, HttpStatusCode.OK);
                });
            }
        }
        public void FailoverGroupDatabaseOperations()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                string failoverGroupName = TestUtilities.GenerateName("csm-sql-fgdb");
                string serverName        = TestUtilities.GenerateName("csm-sql-fgdb-server");
                var    databaseName      = TestUtilities.GenerateName("csm-sql-fgdb-db");
                var    database2Name     = TestUtilities.GenerateName("csm-sql-fgdb-db");

                Sql2ScenarioHelper.RunServerTestInEnvironment(
                    handler,
                    "12.0",
                    "North Europe",
                    (sqlClient, resGroupName, server) =>
                {
                    // Variables for partner server create
                    string serverLocation = "North Europe";
                    string adminLogin     = "******";
                    string adminPass      = "******";
                    string version        = "12.0";

                    //////////////////////////////////////////////////////////////////////
                    // Create server for test.
                    var createServerResponse = sqlClient.Servers.CreateOrUpdate(resGroupName, serverName, new ServerCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new ServerCreateOrUpdateProperties()
                        {
                            AdministratorLogin         = adminLogin,
                            AdministratorLoginPassword = adminPass,
                            Version = version,
                        }
                    });

                    //////////////////////////////////////////////////////////////////////
                    // Create Failover Group with all values specified (Default values)

                    ReadOnlyEndpoint readOnlyEndpoint   = new ReadOnlyEndpoint();
                    readOnlyEndpoint.FailoverPolicy     = "Disabled";
                    ReadWriteEndpoint readWriteEndpoint = new ReadWriteEndpoint();
                    readWriteEndpoint.FailoverPolicy    = "Automatic";
                    readWriteEndpoint.FailoverWithDataLossGracePeriodMinutes = 5;

                    FailoverGroupPartnerServer partnerServer = new FailoverGroupPartnerServer();
                    partnerServer.ReplicationRole            = "Secondary";
                    partnerServer.Id       = createServerResponse.Server.Id;
                    partnerServer.Location = "North Europe";

                    List <FailoverGroupPartnerServer> partnerServers = new List <FailoverGroupPartnerServer>();
                    partnerServers.Add(partnerServer);


                    var failoverGroup1Properties = new FailoverGroupCreateOrUpdateProperties()
                    {
                        ReadOnlyEndpoint  = readOnlyEndpoint,
                        ReadWriteEndpoint = readWriteEndpoint,
                        PartnerServers    = partnerServers,
                    };

                    var failoverGroup1 = sqlClient.FailoverGroups.CreateOrUpdate(resGroupName, server.Name, failoverGroupName, new FailoverGroupCreateOrUpdateParameters()
                    {
                        Location   = server.Location,
                        Properties = failoverGroup1Properties
                    });
                    TestUtilities.ValidateOperationResponse(failoverGroup1, HttpStatusCode.Created);

                    ////////////////////////////////////////////////////////////////////
                    // Create database
                    var db1 = sqlClient.Databases.CreateOrUpdate(resGroupName, server.Name, databaseName, new DatabaseCreateOrUpdateParameters()
                    {
                        Location   = server.Location,
                        Properties = new DatabaseCreateOrUpdateProperties()
                        {
                            Edition = "Premium"
                        }
                    });

                    TestUtilities.ValidateOperationResponse(db1, HttpStatusCode.Created);

                    var db2 = sqlClient.Databases.CreateOrUpdate(resGroupName, server.Name, database2Name, new DatabaseCreateOrUpdateParameters()
                    {
                        Location   = server.Location,
                        Properties = new DatabaseCreateOrUpdateProperties()
                        {
                            Edition = "Basic"
                        }
                    });

                    TestUtilities.ValidateOperationResponse(db2, HttpStatusCode.Created);

                    //Add database ids into a list
                    List <string> dbs = new List <string>();
                    dbs.Add(db1.Database.Id);
                    dbs.Add(db2.Database.Id);

                    //////////////////////////////////////////////////////////////////////
                    // Move database into failover group

                    var moveResult = sqlClient.FailoverGroups.PatchUpdate(resGroupName, server.Name, failoverGroupName, new FailoverGroupPatchUpdateParameters()
                    {
                        Location   = server.Location,
                        Properties = new FailoverGroupPatchUpdateProperties
                        {
                            Databases = dbs,
                        }
                    });

                    TestUtilities.ValidateOperationResponse(moveResult, HttpStatusCode.OK);
                    Assert.True(VerifyDbsEqual(moveResult.FailoverGroup.Properties.Databases, dbs));

                    //////////////////////////////////////////////////////////////////////
                    // Delete databases from failover group

                    dbs.RemoveAt(1);
                    var removeResult = sqlClient.FailoverGroups.PatchUpdate(resGroupName, server.Name, failoverGroupName, new FailoverGroupPatchUpdateParameters()
                    {
                        Location   = server.Location,
                        Properties = new FailoverGroupPatchUpdateProperties
                        {
                            Databases = dbs,
                        }
                    });

                    TestUtilities.ValidateOperationResponse(moveResult, HttpStatusCode.OK);
                    Assert.True(VerifyDbsEqual(removeResult.FailoverGroup.Properties.Databases, dbs));

                    //////////////////////////////////////////////////////////////////////
                    // Failover Test.
                    //var failoverResult = sqlClient.FailoverGroups.Failover(resGroupName, server.Name, failoverGroupName);
                    //TestUtilities.ValidateOperationResponse(failoverResult, HttpStatusCode.OK);

                    //var failoverWithDatalossResult = sqlClient.FailoverGroups.ForceFailoverAllowDataLoss(resGroupName, server.Name, failoverGroupName);
                    //TestUtilities.ValidateOperationResponse(failoverWithDatalossResult, HttpStatusCode.OK);
                });
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Gets the status of an Azure Sql Database Failover Group Force
        /// Failover operation.
        /// </summary>
        /// <param name='operationStatusLink'>
        /// Required. Location value returned by the Begin operation
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// Response for long running Azure Sql Database Failover Group
        /// operation.
        /// </returns>
        public async Task <FailoverGroupForceFailoverResponse> GetFailoverGroupForceFailoverAllowDataLossOperationStatusAsync(string operationStatusLink, CancellationToken cancellationToken)
        {
            // Validate
            if (operationStatusLink == null)
            {
                throw new ArgumentNullException("operationStatusLink");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("operationStatusLink", operationStatusLink);
                TracingAdapter.Enter(invocationId, this, "GetFailoverGroupForceFailoverAllowDataLossOperationStatusAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + operationStatusLink;
            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

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        TracingAdapter.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.Accepted && statusCode != HttpStatusCode.NoContent)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    FailoverGroupForceFailoverResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK || statusCode == HttpStatusCode.Accepted || statusCode == HttpStatusCode.NoContent)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new FailoverGroupForceFailoverResponse();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            ErrorResponse errorInstance = new ErrorResponse();
                            result.Error = errorInstance;

                            JToken codeValue = responseDoc["code"];
                            if (codeValue != null && codeValue.Type != JTokenType.Null)
                            {
                                string codeInstance = ((string)codeValue);
                                errorInstance.Code = codeInstance;
                            }

                            JToken messageValue = responseDoc["message"];
                            if (messageValue != null && messageValue.Type != JTokenType.Null)
                            {
                                string messageInstance = ((string)messageValue);
                                errorInstance.Message = messageInstance;
                            }

                            JToken targetValue = responseDoc["target"];
                            if (targetValue != null && targetValue.Type != JTokenType.Null)
                            {
                                string targetInstance = ((string)targetValue);
                                errorInstance.Target = targetInstance;
                            }

                            FailoverGroup failoverGroupInstance = new FailoverGroup();
                            result.FailoverGroup = failoverGroupInstance;

                            JToken propertiesValue = responseDoc["properties"];
                            if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
                            {
                                FailoverGroupProperties propertiesInstance = new FailoverGroupProperties();
                                failoverGroupInstance.Properties = propertiesInstance;

                                JToken readOnlyEndpointValue = propertiesValue["readOnlyEndpoint"];
                                if (readOnlyEndpointValue != null && readOnlyEndpointValue.Type != JTokenType.Null)
                                {
                                    ReadOnlyEndpoint readOnlyEndpointInstance = new ReadOnlyEndpoint();
                                    propertiesInstance.ReadOnlyEndpoint = readOnlyEndpointInstance;

                                    JToken failoverPolicyValue = readOnlyEndpointValue["failoverPolicy"];
                                    if (failoverPolicyValue != null && failoverPolicyValue.Type != JTokenType.Null)
                                    {
                                        string failoverPolicyInstance = ((string)failoverPolicyValue);
                                        readOnlyEndpointInstance.FailoverPolicy = failoverPolicyInstance;
                                    }
                                }

                                JToken readWriteEndpointValue = propertiesValue["readWriteEndpoint"];
                                if (readWriteEndpointValue != null && readWriteEndpointValue.Type != JTokenType.Null)
                                {
                                    ReadWriteEndpoint readWriteEndpointInstance = new ReadWriteEndpoint();
                                    propertiesInstance.ReadWriteEndpoint = readWriteEndpointInstance;

                                    JToken failoverPolicyValue2 = readWriteEndpointValue["failoverPolicy"];
                                    if (failoverPolicyValue2 != null && failoverPolicyValue2.Type != JTokenType.Null)
                                    {
                                        string failoverPolicyInstance2 = ((string)failoverPolicyValue2);
                                        readWriteEndpointInstance.FailoverPolicy = failoverPolicyInstance2;
                                    }

                                    JToken failoverWithDataLossGracePeriodMinutesValue = readWriteEndpointValue["failoverWithDataLossGracePeriodMinutes"];
                                    if (failoverWithDataLossGracePeriodMinutesValue != null && failoverWithDataLossGracePeriodMinutesValue.Type != JTokenType.Null)
                                    {
                                        int failoverWithDataLossGracePeriodMinutesInstance = ((int)failoverWithDataLossGracePeriodMinutesValue);
                                        readWriteEndpointInstance.FailoverWithDataLossGracePeriodMinutes = failoverWithDataLossGracePeriodMinutesInstance;
                                    }
                                }

                                JToken replicationRoleValue = propertiesValue["replicationRole"];
                                if (replicationRoleValue != null && replicationRoleValue.Type != JTokenType.Null)
                                {
                                    string replicationRoleInstance = ((string)replicationRoleValue);
                                    propertiesInstance.ReplicationRole = replicationRoleInstance;
                                }

                                JToken replicationStateValue = propertiesValue["replicationState"];
                                if (replicationStateValue != null && replicationStateValue.Type != JTokenType.Null)
                                {
                                    string replicationStateInstance = ((string)replicationStateValue);
                                    propertiesInstance.ReplicationState = replicationStateInstance;
                                }

                                JToken partnerServersArray = propertiesValue["partnerServers"];
                                if (partnerServersArray != null && partnerServersArray.Type != JTokenType.Null)
                                {
                                    foreach (JToken partnerServersValue in ((JArray)partnerServersArray))
                                    {
                                        FailoverGroupPartnerServer failoverGroupPartnerServerInstance = new FailoverGroupPartnerServer();
                                        propertiesInstance.PartnerServers.Add(failoverGroupPartnerServerInstance);

                                        JToken idValue = partnerServersValue["id"];
                                        if (idValue != null && idValue.Type != JTokenType.Null)
                                        {
                                            string idInstance = ((string)idValue);
                                            failoverGroupPartnerServerInstance.Id = idInstance;
                                        }

                                        JToken locationValue = partnerServersValue["location"];
                                        if (locationValue != null && locationValue.Type != JTokenType.Null)
                                        {
                                            string locationInstance = ((string)locationValue);
                                            failoverGroupPartnerServerInstance.Location = locationInstance;
                                        }

                                        JToken replicationRoleValue2 = partnerServersValue["replicationRole"];
                                        if (replicationRoleValue2 != null && replicationRoleValue2.Type != JTokenType.Null)
                                        {
                                            string replicationRoleInstance2 = ((string)replicationRoleValue2);
                                            failoverGroupPartnerServerInstance.ReplicationRole = replicationRoleInstance2;
                                        }
                                    }
                                }

                                JToken databasesArray = propertiesValue["databases"];
                                if (databasesArray != null && databasesArray.Type != JTokenType.Null)
                                {
                                    foreach (JToken databasesValue in ((JArray)databasesArray))
                                    {
                                        propertiesInstance.Databases.Add(((string)databasesValue));
                                    }
                                }
                            }

                            JToken idValue2 = responseDoc["id"];
                            if (idValue2 != null && idValue2.Type != JTokenType.Null)
                            {
                                string idInstance2 = ((string)idValue2);
                                failoverGroupInstance.Id = idInstance2;
                            }

                            JToken nameValue = responseDoc["name"];
                            if (nameValue != null && nameValue.Type != JTokenType.Null)
                            {
                                string nameInstance = ((string)nameValue);
                                failoverGroupInstance.Name = nameInstance;
                            }

                            JToken typeValue = responseDoc["type"];
                            if (typeValue != null && typeValue.Type != JTokenType.Null)
                            {
                                string typeInstance = ((string)typeValue);
                                failoverGroupInstance.Type = typeInstance;
                            }

                            JToken locationValue2 = responseDoc["location"];
                            if (locationValue2 != null && locationValue2.Type != JTokenType.Null)
                            {
                                string locationInstance2 = ((string)locationValue2);
                                failoverGroupInstance.Location = locationInstance2;
                            }

                            JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
                            if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
                            {
                                foreach (JProperty property in tagsSequenceElement)
                                {
                                    string tagsKey   = ((string)property.Name);
                                    string tagsValue = ((string)property.Value);
                                    failoverGroupInstance.Tags.Add(tagsKey, tagsValue);
                                }
                            }
                        }
                    }
                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }
                    if (statusCode == HttpStatusCode.NoContent)
                    {
                        result.Status = OperationStatus.Succeeded;
                    }
                    if (statusCode == HttpStatusCode.OK)
                    {
                        result.Status = OperationStatus.Succeeded;
                    }
                    if (statusCode == HttpStatusCode.Accepted)
                    {
                        result.Status = OperationStatus.Succeeded;
                    }

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }