1package sql
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/tracing"
14	"net/http"
15)
16
17// ReplicationLinksClient is the the Azure SQL Database management API provides a RESTful set of web services that
18// interact with Azure SQL Database services to manage your databases. The API enables you to create, retrieve, update,
19// and delete databases.
20type ReplicationLinksClient struct {
21	BaseClient
22}
23
24// NewReplicationLinksClient creates an instance of the ReplicationLinksClient client.
25func NewReplicationLinksClient(subscriptionID string) ReplicationLinksClient {
26	return NewReplicationLinksClientWithBaseURI(DefaultBaseURI, subscriptionID)
27}
28
29// NewReplicationLinksClientWithBaseURI creates an instance of the ReplicationLinksClient client using a custom
30// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
31// stack).
32func NewReplicationLinksClientWithBaseURI(baseURI string, subscriptionID string) ReplicationLinksClient {
33	return ReplicationLinksClient{NewWithBaseURI(baseURI, subscriptionID)}
34}
35
36// Delete deletes a database replication link. Cannot be done during failover.
37// Parameters:
38// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
39// from the Azure Resource Manager API or the portal.
40// serverName - the name of the server.
41// databaseName - the name of the database that has the replication link to be dropped.
42// linkID - the ID of the replication link to be deleted.
43func (client ReplicationLinksClient) Delete(ctx context.Context, resourceGroupName string, serverName string, databaseName string, linkID string) (result autorest.Response, err error) {
44	if tracing.IsEnabled() {
45		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationLinksClient.Delete")
46		defer func() {
47			sc := -1
48			if result.Response != nil {
49				sc = result.Response.StatusCode
50			}
51			tracing.EndSpan(ctx, sc, err)
52		}()
53	}
54	req, err := client.DeletePreparer(ctx, resourceGroupName, serverName, databaseName, linkID)
55	if err != nil {
56		err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Delete", nil, "Failure preparing request")
57		return
58	}
59
60	resp, err := client.DeleteSender(req)
61	if err != nil {
62		result.Response = resp
63		err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Delete", resp, "Failure sending request")
64		return
65	}
66
67	result, err = client.DeleteResponder(resp)
68	if err != nil {
69		err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Delete", resp, "Failure responding to request")
70		return
71	}
72
73	return
74}
75
76// DeletePreparer prepares the Delete request.
77func (client ReplicationLinksClient) DeletePreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, linkID string) (*http.Request, error) {
78	pathParameters := map[string]interface{}{
79		"databaseName":      autorest.Encode("path", databaseName),
80		"linkId":            autorest.Encode("path", linkID),
81		"resourceGroupName": autorest.Encode("path", resourceGroupName),
82		"serverName":        autorest.Encode("path", serverName),
83		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
84	}
85
86	const APIVersion = "2014-04-01"
87	queryParameters := map[string]interface{}{
88		"api-version": APIVersion,
89	}
90
91	preparer := autorest.CreatePreparer(
92		autorest.AsDelete(),
93		autorest.WithBaseURL(client.BaseURI),
94		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}", pathParameters),
95		autorest.WithQueryParameters(queryParameters))
96	return preparer.Prepare((&http.Request{}).WithContext(ctx))
97}
98
99// DeleteSender sends the Delete request. The method will close the
100// http.Response Body if it receives an error.
101func (client ReplicationLinksClient) DeleteSender(req *http.Request) (*http.Response, error) {
102	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
103}
104
105// DeleteResponder handles the response to the Delete request. The method always
106// closes the http.Response Body.
107func (client ReplicationLinksClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
108	err = autorest.Respond(
109		resp,
110		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
111		autorest.ByClosing())
112	result.Response = resp
113	return
114}
115
116// Failover sets which replica database is primary by failing over from the current primary replica database.
117// Parameters:
118// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
119// from the Azure Resource Manager API or the portal.
120// serverName - the name of the server.
121// databaseName - the name of the database that has the replication link to be failed over.
122// linkID - the ID of the replication link to be failed over.
123func (client ReplicationLinksClient) Failover(ctx context.Context, resourceGroupName string, serverName string, databaseName string, linkID string) (result ReplicationLinksFailoverFuture, err error) {
124	if tracing.IsEnabled() {
125		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationLinksClient.Failover")
126		defer func() {
127			sc := -1
128			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
129				sc = result.FutureAPI.Response().StatusCode
130			}
131			tracing.EndSpan(ctx, sc, err)
132		}()
133	}
134	req, err := client.FailoverPreparer(ctx, resourceGroupName, serverName, databaseName, linkID)
135	if err != nil {
136		err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Failover", nil, "Failure preparing request")
137		return
138	}
139
140	result, err = client.FailoverSender(req)
141	if err != nil {
142		err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Failover", nil, "Failure sending request")
143		return
144	}
145
146	return
147}
148
149// FailoverPreparer prepares the Failover request.
150func (client ReplicationLinksClient) FailoverPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, linkID string) (*http.Request, error) {
151	pathParameters := map[string]interface{}{
152		"databaseName":      autorest.Encode("path", databaseName),
153		"linkId":            autorest.Encode("path", linkID),
154		"resourceGroupName": autorest.Encode("path", resourceGroupName),
155		"serverName":        autorest.Encode("path", serverName),
156		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
157	}
158
159	const APIVersion = "2014-04-01"
160	queryParameters := map[string]interface{}{
161		"api-version": APIVersion,
162	}
163
164	preparer := autorest.CreatePreparer(
165		autorest.AsPost(),
166		autorest.WithBaseURL(client.BaseURI),
167		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/failover", pathParameters),
168		autorest.WithQueryParameters(queryParameters))
169	return preparer.Prepare((&http.Request{}).WithContext(ctx))
170}
171
172// FailoverSender sends the Failover request. The method will close the
173// http.Response Body if it receives an error.
174func (client ReplicationLinksClient) FailoverSender(req *http.Request) (future ReplicationLinksFailoverFuture, err error) {
175	var resp *http.Response
176	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
177	if err != nil {
178		return
179	}
180	var azf azure.Future
181	azf, err = azure.NewFutureFromResponse(resp)
182	future.FutureAPI = &azf
183	future.Result = future.result
184	return
185}
186
187// FailoverResponder handles the response to the Failover request. The method always
188// closes the http.Response Body.
189func (client ReplicationLinksClient) FailoverResponder(resp *http.Response) (result autorest.Response, err error) {
190	err = autorest.Respond(
191		resp,
192		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
193		autorest.ByClosing())
194	result.Response = resp
195	return
196}
197
198// FailoverAllowDataLoss sets which replica database is primary by failing over from the current primary replica
199// database. This operation might result in data loss.
200// Parameters:
201// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
202// from the Azure Resource Manager API or the portal.
203// serverName - the name of the server.
204// databaseName - the name of the database that has the replication link to be failed over.
205// linkID - the ID of the replication link to be failed over.
206func (client ReplicationLinksClient) FailoverAllowDataLoss(ctx context.Context, resourceGroupName string, serverName string, databaseName string, linkID string) (result ReplicationLinksFailoverAllowDataLossFuture, err error) {
207	if tracing.IsEnabled() {
208		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationLinksClient.FailoverAllowDataLoss")
209		defer func() {
210			sc := -1
211			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
212				sc = result.FutureAPI.Response().StatusCode
213			}
214			tracing.EndSpan(ctx, sc, err)
215		}()
216	}
217	req, err := client.FailoverAllowDataLossPreparer(ctx, resourceGroupName, serverName, databaseName, linkID)
218	if err != nil {
219		err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "FailoverAllowDataLoss", nil, "Failure preparing request")
220		return
221	}
222
223	result, err = client.FailoverAllowDataLossSender(req)
224	if err != nil {
225		err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "FailoverAllowDataLoss", nil, "Failure sending request")
226		return
227	}
228
229	return
230}
231
232// FailoverAllowDataLossPreparer prepares the FailoverAllowDataLoss request.
233func (client ReplicationLinksClient) FailoverAllowDataLossPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, linkID string) (*http.Request, error) {
234	pathParameters := map[string]interface{}{
235		"databaseName":      autorest.Encode("path", databaseName),
236		"linkId":            autorest.Encode("path", linkID),
237		"resourceGroupName": autorest.Encode("path", resourceGroupName),
238		"serverName":        autorest.Encode("path", serverName),
239		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
240	}
241
242	const APIVersion = "2014-04-01"
243	queryParameters := map[string]interface{}{
244		"api-version": APIVersion,
245	}
246
247	preparer := autorest.CreatePreparer(
248		autorest.AsPost(),
249		autorest.WithBaseURL(client.BaseURI),
250		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/forceFailoverAllowDataLoss", pathParameters),
251		autorest.WithQueryParameters(queryParameters))
252	return preparer.Prepare((&http.Request{}).WithContext(ctx))
253}
254
255// FailoverAllowDataLossSender sends the FailoverAllowDataLoss request. The method will close the
256// http.Response Body if it receives an error.
257func (client ReplicationLinksClient) FailoverAllowDataLossSender(req *http.Request) (future ReplicationLinksFailoverAllowDataLossFuture, err error) {
258	var resp *http.Response
259	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
260	if err != nil {
261		return
262	}
263	var azf azure.Future
264	azf, err = azure.NewFutureFromResponse(resp)
265	future.FutureAPI = &azf
266	future.Result = future.result
267	return
268}
269
270// FailoverAllowDataLossResponder handles the response to the FailoverAllowDataLoss request. The method always
271// closes the http.Response Body.
272func (client ReplicationLinksClient) FailoverAllowDataLossResponder(resp *http.Response) (result autorest.Response, err error) {
273	err = autorest.Respond(
274		resp,
275		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
276		autorest.ByClosing())
277	result.Response = resp
278	return
279}
280
281// Get gets a database replication link.
282// Parameters:
283// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
284// from the Azure Resource Manager API or the portal.
285// serverName - the name of the server.
286// databaseName - the name of the database to get the link for.
287// linkID - the replication link ID to be retrieved.
288func (client ReplicationLinksClient) Get(ctx context.Context, resourceGroupName string, serverName string, databaseName string, linkID string) (result ReplicationLink, err error) {
289	if tracing.IsEnabled() {
290		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationLinksClient.Get")
291		defer func() {
292			sc := -1
293			if result.Response.Response != nil {
294				sc = result.Response.Response.StatusCode
295			}
296			tracing.EndSpan(ctx, sc, err)
297		}()
298	}
299	req, err := client.GetPreparer(ctx, resourceGroupName, serverName, databaseName, linkID)
300	if err != nil {
301		err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Get", nil, "Failure preparing request")
302		return
303	}
304
305	resp, err := client.GetSender(req)
306	if err != nil {
307		result.Response = autorest.Response{Response: resp}
308		err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Get", resp, "Failure sending request")
309		return
310	}
311
312	result, err = client.GetResponder(resp)
313	if err != nil {
314		err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Get", resp, "Failure responding to request")
315		return
316	}
317
318	return
319}
320
321// GetPreparer prepares the Get request.
322func (client ReplicationLinksClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, linkID string) (*http.Request, error) {
323	pathParameters := map[string]interface{}{
324		"databaseName":      autorest.Encode("path", databaseName),
325		"linkId":            autorest.Encode("path", linkID),
326		"resourceGroupName": autorest.Encode("path", resourceGroupName),
327		"serverName":        autorest.Encode("path", serverName),
328		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
329	}
330
331	const APIVersion = "2014-04-01"
332	queryParameters := map[string]interface{}{
333		"api-version": APIVersion,
334	}
335
336	preparer := autorest.CreatePreparer(
337		autorest.AsGet(),
338		autorest.WithBaseURL(client.BaseURI),
339		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}", pathParameters),
340		autorest.WithQueryParameters(queryParameters))
341	return preparer.Prepare((&http.Request{}).WithContext(ctx))
342}
343
344// GetSender sends the Get request. The method will close the
345// http.Response Body if it receives an error.
346func (client ReplicationLinksClient) GetSender(req *http.Request) (*http.Response, error) {
347	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
348}
349
350// GetResponder handles the response to the Get request. The method always
351// closes the http.Response Body.
352func (client ReplicationLinksClient) GetResponder(resp *http.Response) (result ReplicationLink, err error) {
353	err = autorest.Respond(
354		resp,
355		azure.WithErrorUnlessStatusCode(http.StatusOK),
356		autorest.ByUnmarshallingJSON(&result),
357		autorest.ByClosing())
358	result.Response = autorest.Response{Response: resp}
359	return
360}
361
362// ListByDatabase lists a database's replication links.
363// Parameters:
364// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
365// from the Azure Resource Manager API or the portal.
366// serverName - the name of the server.
367// databaseName - the name of the database to retrieve links for.
368func (client ReplicationLinksClient) ListByDatabase(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (result ReplicationLinkListResult, err error) {
369	if tracing.IsEnabled() {
370		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationLinksClient.ListByDatabase")
371		defer func() {
372			sc := -1
373			if result.Response.Response != nil {
374				sc = result.Response.Response.StatusCode
375			}
376			tracing.EndSpan(ctx, sc, err)
377		}()
378	}
379	req, err := client.ListByDatabasePreparer(ctx, resourceGroupName, serverName, databaseName)
380	if err != nil {
381		err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "ListByDatabase", nil, "Failure preparing request")
382		return
383	}
384
385	resp, err := client.ListByDatabaseSender(req)
386	if err != nil {
387		result.Response = autorest.Response{Response: resp}
388		err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "ListByDatabase", resp, "Failure sending request")
389		return
390	}
391
392	result, err = client.ListByDatabaseResponder(resp)
393	if err != nil {
394		err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "ListByDatabase", resp, "Failure responding to request")
395		return
396	}
397
398	return
399}
400
401// ListByDatabasePreparer prepares the ListByDatabase request.
402func (client ReplicationLinksClient) ListByDatabasePreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (*http.Request, error) {
403	pathParameters := map[string]interface{}{
404		"databaseName":      autorest.Encode("path", databaseName),
405		"resourceGroupName": autorest.Encode("path", resourceGroupName),
406		"serverName":        autorest.Encode("path", serverName),
407		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
408	}
409
410	const APIVersion = "2014-04-01"
411	queryParameters := map[string]interface{}{
412		"api-version": APIVersion,
413	}
414
415	preparer := autorest.CreatePreparer(
416		autorest.AsGet(),
417		autorest.WithBaseURL(client.BaseURI),
418		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks", pathParameters),
419		autorest.WithQueryParameters(queryParameters))
420	return preparer.Prepare((&http.Request{}).WithContext(ctx))
421}
422
423// ListByDatabaseSender sends the ListByDatabase request. The method will close the
424// http.Response Body if it receives an error.
425func (client ReplicationLinksClient) ListByDatabaseSender(req *http.Request) (*http.Response, error) {
426	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
427}
428
429// ListByDatabaseResponder handles the response to the ListByDatabase request. The method always
430// closes the http.Response Body.
431func (client ReplicationLinksClient) ListByDatabaseResponder(resp *http.Response) (result ReplicationLinkListResult, err error) {
432	err = autorest.Respond(
433		resp,
434		azure.WithErrorUnlessStatusCode(http.StatusOK),
435		autorest.ByUnmarshallingJSON(&result),
436		autorest.ByClosing())
437	result.Response = autorest.Response{Response: resp}
438	return
439}
440
441// Unlink deletes a database replication link in forced or friendly way.
442// Parameters:
443// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
444// from the Azure Resource Manager API or the portal.
445// serverName - the name of the server.
446// databaseName - the name of the database that has the replication link to be failed over.
447// linkID - the ID of the replication link to be failed over.
448// parameters - the required parameters for unlinking replication link.
449func (client ReplicationLinksClient) Unlink(ctx context.Context, resourceGroupName string, serverName string, databaseName string, linkID string, parameters UnlinkParameters) (result ReplicationLinksUnlinkFuture, err error) {
450	if tracing.IsEnabled() {
451		ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationLinksClient.Unlink")
452		defer func() {
453			sc := -1
454			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
455				sc = result.FutureAPI.Response().StatusCode
456			}
457			tracing.EndSpan(ctx, sc, err)
458		}()
459	}
460	req, err := client.UnlinkPreparer(ctx, resourceGroupName, serverName, databaseName, linkID, parameters)
461	if err != nil {
462		err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Unlink", nil, "Failure preparing request")
463		return
464	}
465
466	result, err = client.UnlinkSender(req)
467	if err != nil {
468		err = autorest.NewErrorWithError(err, "sql.ReplicationLinksClient", "Unlink", nil, "Failure sending request")
469		return
470	}
471
472	return
473}
474
475// UnlinkPreparer prepares the Unlink request.
476func (client ReplicationLinksClient) UnlinkPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, linkID string, parameters UnlinkParameters) (*http.Request, error) {
477	pathParameters := map[string]interface{}{
478		"databaseName":      autorest.Encode("path", databaseName),
479		"linkId":            autorest.Encode("path", linkID),
480		"resourceGroupName": autorest.Encode("path", resourceGroupName),
481		"serverName":        autorest.Encode("path", serverName),
482		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
483	}
484
485	const APIVersion = "2014-04-01"
486	queryParameters := map[string]interface{}{
487		"api-version": APIVersion,
488	}
489
490	preparer := autorest.CreatePreparer(
491		autorest.AsContentType("application/json; charset=utf-8"),
492		autorest.AsPost(),
493		autorest.WithBaseURL(client.BaseURI),
494		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/unlink", pathParameters),
495		autorest.WithJSON(parameters),
496		autorest.WithQueryParameters(queryParameters))
497	return preparer.Prepare((&http.Request{}).WithContext(ctx))
498}
499
500// UnlinkSender sends the Unlink request. The method will close the
501// http.Response Body if it receives an error.
502func (client ReplicationLinksClient) UnlinkSender(req *http.Request) (future ReplicationLinksUnlinkFuture, err error) {
503	var resp *http.Response
504	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
505	if err != nil {
506		return
507	}
508	var azf azure.Future
509	azf, err = azure.NewFutureFromResponse(resp)
510	future.FutureAPI = &azf
511	future.Result = future.result
512	return
513}
514
515// UnlinkResponder handles the response to the Unlink request. The method always
516// closes the http.Response Body.
517func (client ReplicationLinksClient) UnlinkResponder(resp *http.Response) (result autorest.Response, err error) {
518	err = autorest.Respond(
519		resp,
520		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
521		autorest.ByClosing())
522	result.Response = resp
523	return
524}
525