diff --git a/services/preview/sql/mgmt/2015-05-01-preview/sql/models.go b/services/preview/sql/mgmt/2015-05-01-preview/sql/models.go index 45e4f682177f..5621ab55d85b 100644 --- a/services/preview/sql/mgmt/2015-05-01-preview/sql/models.go +++ b/services/preview/sql/mgmt/2015-05-01-preview/sql/models.go @@ -5545,6 +5545,29 @@ func (future *ReplicationLinksFailoverFuture) Result(client ReplicationLinksClie return } +// ReplicationLinksUnlinkFuture an abstraction for monitoring and retrieving the results of a long-running +// operation. +type ReplicationLinksUnlinkFuture struct { + azure.Future +} + +// Result returns the result of the asynchronous operation. +// If the operation has not completed it will return an error. +func (future *ReplicationLinksUnlinkFuture) Result(client ReplicationLinksClient) (ar autorest.Response, err error) { + var done bool + done, err = future.DoneWithContext(context.Background(), client) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.ReplicationLinksUnlinkFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("sql.ReplicationLinksUnlinkFuture") + return + } + ar.Response = future.Response() + return +} + // Resource ARM resource. type Resource struct { // ID - READ-ONLY; Resource ID. @@ -9373,6 +9396,12 @@ type TransparentDataEncryptionProperties struct { Status TransparentDataEncryptionStatus `json:"status,omitempty"` } +// UnlinkParameters represents the parameters for Unlink Replication Link request. +type UnlinkParameters struct { + // ForcedTermination - Determines whether link will be terminated in a forced or a friendly way. + ForcedTermination *bool `json:"forcedTermination,omitempty"` +} + // VirtualCluster an Azure SQL virtual cluster. type VirtualCluster struct { autorest.Response `json:"-"` diff --git a/services/preview/sql/mgmt/2015-05-01-preview/sql/replicationlinks.go b/services/preview/sql/mgmt/2015-05-01-preview/sql/replicationlinks.go index 2e64c7f1a21d..808e563783f6 100644 --- a/services/preview/sql/mgmt/2015-05-01-preview/sql/replicationlinks.go +++ b/services/preview/sql/mgmt/2015-05-01-preview/sql/replicationlinks.go @@ -444,3 +444,86 @@ func (client ReplicationLinksClient) ListByDatabaseResponder(resp *http.Response result.Response = autorest.Response{Response: resp} return } + +// Unlink deletes a database replication link in forced or friendly way. +// Parameters: +// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value +// from the Azure Resource Manager API or the portal. +// serverName - the name of the server. +// databaseName - the name of the database that has the replication link to be failed over. +// linkID - the ID of the replication link to be failed over. +// parameters - the required parameters for unlinking replication link. +func (client ReplicationLinksClient) Unlink(ctx context.Context, resourceGroupName string, serverName string, databaseName string, linkID string, parameters UnlinkParameters) (result ReplicationLinksUnlinkFuture, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationLinksClient.Unlink") + defer func() { + sc := -1 + if result.Response() != nil { + sc = result.Response().StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.UnlinkPreparer(ctx, resourceGroupName, serverName, databaseName, linkID, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Unlink", nil, "Failure preparing request") + return + } + + result, err = client.UnlinkSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Unlink", result.Response(), "Failure sending request") + return + } + + return +} + +// UnlinkPreparer prepares the Unlink request. +func (client ReplicationLinksClient) UnlinkPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, linkID string, parameters UnlinkParameters) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "databaseName": autorest.Encode("path", databaseName), + "linkId": autorest.Encode("path", linkID), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "serverName": autorest.Encode("path", serverName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2014-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/unlink", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UnlinkSender sends the Unlink request. The method will close the +// http.Response Body if it receives an error. +func (client ReplicationLinksClient) UnlinkSender(req *http.Request) (future ReplicationLinksUnlinkFuture, err error) { + var resp *http.Response + resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) + if err != nil { + return + } + future.Future, err = azure.NewFutureFromResponse(resp) + return +} + +// UnlinkResponder handles the response to the Unlink request. The method always +// closes the http.Response Body. +func (client ReplicationLinksClient) UnlinkResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} diff --git a/services/preview/sql/mgmt/2015-05-01-preview/sql/sqlapi/interfaces.go b/services/preview/sql/mgmt/2015-05-01-preview/sql/sqlapi/interfaces.go index 526a55f093fe..265de14f4556 100644 --- a/services/preview/sql/mgmt/2015-05-01-preview/sql/sqlapi/interfaces.go +++ b/services/preview/sql/mgmt/2015-05-01-preview/sql/sqlapi/interfaces.go @@ -172,6 +172,7 @@ type ReplicationLinksClientAPI interface { FailoverAllowDataLoss(ctx context.Context, resourceGroupName string, serverName string, databaseName string, linkID string) (result sql.ReplicationLinksFailoverAllowDataLossFuture, err error) Get(ctx context.Context, resourceGroupName string, serverName string, databaseName string, linkID string) (result sql.ReplicationLink, err error) ListByDatabase(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (result sql.ReplicationLinkListResult, err error) + Unlink(ctx context.Context, resourceGroupName string, serverName string, databaseName string, linkID string, parameters sql.UnlinkParameters) (result sql.ReplicationLinksUnlinkFuture, err error) } var _ ReplicationLinksClientAPI = (*sql.ReplicationLinksClient)(nil)