1package sql
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/tracing"
25	"net/http"
26)
27
28// SyncGroupsClient is the the Azure SQL Database management API provides a RESTful set of web services that interact
29// with Azure SQL Database services to manage your databases. The API enables you to create, retrieve, update, and
30// delete databases.
31type SyncGroupsClient struct {
32	BaseClient
33}
34
35// NewSyncGroupsClient creates an instance of the SyncGroupsClient client.
36func NewSyncGroupsClient(subscriptionID string) SyncGroupsClient {
37	return NewSyncGroupsClientWithBaseURI(DefaultBaseURI, subscriptionID)
38}
39
40// NewSyncGroupsClientWithBaseURI creates an instance of the SyncGroupsClient client using a custom endpoint.  Use this
41// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
42func NewSyncGroupsClientWithBaseURI(baseURI string, subscriptionID string) SyncGroupsClient {
43	return SyncGroupsClient{NewWithBaseURI(baseURI, subscriptionID)}
44}
45
46// CancelSync cancels a sync group synchronization.
47// Parameters:
48// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
49// from the Azure Resource Manager API or the portal.
50// serverName - the name of the server.
51// databaseName - the name of the database on which the sync group is hosted.
52// syncGroupName - the name of the sync group.
53func (client SyncGroupsClient) CancelSync(ctx context.Context, resourceGroupName string, serverName string, databaseName string, syncGroupName string) (result autorest.Response, err error) {
54	if tracing.IsEnabled() {
55		ctx = tracing.StartSpan(ctx, fqdn+"/SyncGroupsClient.CancelSync")
56		defer func() {
57			sc := -1
58			if result.Response != nil {
59				sc = result.Response.StatusCode
60			}
61			tracing.EndSpan(ctx, sc, err)
62		}()
63	}
64	req, err := client.CancelSyncPreparer(ctx, resourceGroupName, serverName, databaseName, syncGroupName)
65	if err != nil {
66		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "CancelSync", nil, "Failure preparing request")
67		return
68	}
69
70	resp, err := client.CancelSyncSender(req)
71	if err != nil {
72		result.Response = resp
73		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "CancelSync", resp, "Failure sending request")
74		return
75	}
76
77	result, err = client.CancelSyncResponder(resp)
78	if err != nil {
79		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "CancelSync", resp, "Failure responding to request")
80		return
81	}
82
83	return
84}
85
86// CancelSyncPreparer prepares the CancelSync request.
87func (client SyncGroupsClient) CancelSyncPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, syncGroupName string) (*http.Request, error) {
88	pathParameters := map[string]interface{}{
89		"databaseName":      autorest.Encode("path", databaseName),
90		"resourceGroupName": autorest.Encode("path", resourceGroupName),
91		"serverName":        autorest.Encode("path", serverName),
92		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
93		"syncGroupName":     autorest.Encode("path", syncGroupName),
94	}
95
96	const APIVersion = "2015-05-01-preview"
97	queryParameters := map[string]interface{}{
98		"api-version": APIVersion,
99	}
100
101	preparer := autorest.CreatePreparer(
102		autorest.AsPost(),
103		autorest.WithBaseURL(client.BaseURI),
104		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/cancelSync", pathParameters),
105		autorest.WithQueryParameters(queryParameters))
106	return preparer.Prepare((&http.Request{}).WithContext(ctx))
107}
108
109// CancelSyncSender sends the CancelSync request. The method will close the
110// http.Response Body if it receives an error.
111func (client SyncGroupsClient) CancelSyncSender(req *http.Request) (*http.Response, error) {
112	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
113}
114
115// CancelSyncResponder handles the response to the CancelSync request. The method always
116// closes the http.Response Body.
117func (client SyncGroupsClient) CancelSyncResponder(resp *http.Response) (result autorest.Response, err error) {
118	err = autorest.Respond(
119		resp,
120		azure.WithErrorUnlessStatusCode(http.StatusOK),
121		autorest.ByClosing())
122	result.Response = resp
123	return
124}
125
126// CreateOrUpdate creates or updates a sync group.
127// Parameters:
128// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
129// from the Azure Resource Manager API or the portal.
130// serverName - the name of the server.
131// databaseName - the name of the database on which the sync group is hosted.
132// syncGroupName - the name of the sync group.
133// parameters - the requested sync group resource state.
134func (client SyncGroupsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serverName string, databaseName string, syncGroupName string, parameters SyncGroup) (result SyncGroupsCreateOrUpdateFuture, err error) {
135	if tracing.IsEnabled() {
136		ctx = tracing.StartSpan(ctx, fqdn+"/SyncGroupsClient.CreateOrUpdate")
137		defer func() {
138			sc := -1
139			if result.Response() != nil {
140				sc = result.Response().StatusCode
141			}
142			tracing.EndSpan(ctx, sc, err)
143		}()
144	}
145	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serverName, databaseName, syncGroupName, parameters)
146	if err != nil {
147		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "CreateOrUpdate", nil, "Failure preparing request")
148		return
149	}
150
151	result, err = client.CreateOrUpdateSender(req)
152	if err != nil {
153		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "CreateOrUpdate", nil, "Failure sending request")
154		return
155	}
156
157	return
158}
159
160// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
161func (client SyncGroupsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, syncGroupName string, parameters SyncGroup) (*http.Request, error) {
162	pathParameters := map[string]interface{}{
163		"databaseName":      autorest.Encode("path", databaseName),
164		"resourceGroupName": autorest.Encode("path", resourceGroupName),
165		"serverName":        autorest.Encode("path", serverName),
166		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
167		"syncGroupName":     autorest.Encode("path", syncGroupName),
168	}
169
170	const APIVersion = "2015-05-01-preview"
171	queryParameters := map[string]interface{}{
172		"api-version": APIVersion,
173	}
174
175	preparer := autorest.CreatePreparer(
176		autorest.AsContentType("application/json; charset=utf-8"),
177		autorest.AsPut(),
178		autorest.WithBaseURL(client.BaseURI),
179		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}", pathParameters),
180		autorest.WithJSON(parameters),
181		autorest.WithQueryParameters(queryParameters))
182	return preparer.Prepare((&http.Request{}).WithContext(ctx))
183}
184
185// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
186// http.Response Body if it receives an error.
187func (client SyncGroupsClient) CreateOrUpdateSender(req *http.Request) (future SyncGroupsCreateOrUpdateFuture, err error) {
188	var resp *http.Response
189	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
190	if err != nil {
191		return
192	}
193	var azf azure.Future
194	azf, err = azure.NewFutureFromResponse(resp)
195	future.FutureAPI = &azf
196	future.Result = func(client SyncGroupsClient) (sg SyncGroup, err error) {
197		var done bool
198		done, err = future.DoneWithContext(context.Background(), client)
199		if err != nil {
200			err = autorest.NewErrorWithError(err, "sql.SyncGroupsCreateOrUpdateFuture", "Result", future.Response(), "Polling failure")
201			return
202		}
203		if !done {
204			err = azure.NewAsyncOpIncompleteError("sql.SyncGroupsCreateOrUpdateFuture")
205			return
206		}
207		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
208		if sg.Response.Response, err = future.GetResult(sender); err == nil && sg.Response.Response.StatusCode != http.StatusNoContent {
209			sg, err = client.CreateOrUpdateResponder(sg.Response.Response)
210			if err != nil {
211				err = autorest.NewErrorWithError(err, "sql.SyncGroupsCreateOrUpdateFuture", "Result", sg.Response.Response, "Failure responding to request")
212			}
213		}
214		return
215	}
216	return
217}
218
219// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
220// closes the http.Response Body.
221func (client SyncGroupsClient) CreateOrUpdateResponder(resp *http.Response) (result SyncGroup, err error) {
222	err = autorest.Respond(
223		resp,
224		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted),
225		autorest.ByUnmarshallingJSON(&result),
226		autorest.ByClosing())
227	result.Response = autorest.Response{Response: resp}
228	return
229}
230
231// Delete deletes a sync group.
232// Parameters:
233// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
234// from the Azure Resource Manager API or the portal.
235// serverName - the name of the server.
236// databaseName - the name of the database on which the sync group is hosted.
237// syncGroupName - the name of the sync group.
238func (client SyncGroupsClient) Delete(ctx context.Context, resourceGroupName string, serverName string, databaseName string, syncGroupName string) (result SyncGroupsDeleteFuture, err error) {
239	if tracing.IsEnabled() {
240		ctx = tracing.StartSpan(ctx, fqdn+"/SyncGroupsClient.Delete")
241		defer func() {
242			sc := -1
243			if result.Response() != nil {
244				sc = result.Response().StatusCode
245			}
246			tracing.EndSpan(ctx, sc, err)
247		}()
248	}
249	req, err := client.DeletePreparer(ctx, resourceGroupName, serverName, databaseName, syncGroupName)
250	if err != nil {
251		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "Delete", nil, "Failure preparing request")
252		return
253	}
254
255	result, err = client.DeleteSender(req)
256	if err != nil {
257		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "Delete", nil, "Failure sending request")
258		return
259	}
260
261	return
262}
263
264// DeletePreparer prepares the Delete request.
265func (client SyncGroupsClient) DeletePreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, syncGroupName string) (*http.Request, error) {
266	pathParameters := map[string]interface{}{
267		"databaseName":      autorest.Encode("path", databaseName),
268		"resourceGroupName": autorest.Encode("path", resourceGroupName),
269		"serverName":        autorest.Encode("path", serverName),
270		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
271		"syncGroupName":     autorest.Encode("path", syncGroupName),
272	}
273
274	const APIVersion = "2015-05-01-preview"
275	queryParameters := map[string]interface{}{
276		"api-version": APIVersion,
277	}
278
279	preparer := autorest.CreatePreparer(
280		autorest.AsDelete(),
281		autorest.WithBaseURL(client.BaseURI),
282		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}", pathParameters),
283		autorest.WithQueryParameters(queryParameters))
284	return preparer.Prepare((&http.Request{}).WithContext(ctx))
285}
286
287// DeleteSender sends the Delete request. The method will close the
288// http.Response Body if it receives an error.
289func (client SyncGroupsClient) DeleteSender(req *http.Request) (future SyncGroupsDeleteFuture, err error) {
290	var resp *http.Response
291	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
292	if err != nil {
293		return
294	}
295	var azf azure.Future
296	azf, err = azure.NewFutureFromResponse(resp)
297	future.FutureAPI = &azf
298	future.Result = func(client SyncGroupsClient) (ar autorest.Response, err error) {
299		var done bool
300		done, err = future.DoneWithContext(context.Background(), client)
301		if err != nil {
302			err = autorest.NewErrorWithError(err, "sql.SyncGroupsDeleteFuture", "Result", future.Response(), "Polling failure")
303			return
304		}
305		if !done {
306			err = azure.NewAsyncOpIncompleteError("sql.SyncGroupsDeleteFuture")
307			return
308		}
309		ar.Response = future.Response()
310		return
311	}
312	return
313}
314
315// DeleteResponder handles the response to the Delete request. The method always
316// closes the http.Response Body.
317func (client SyncGroupsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
318	err = autorest.Respond(
319		resp,
320		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
321		autorest.ByClosing())
322	result.Response = resp
323	return
324}
325
326// Get gets a sync group.
327// Parameters:
328// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
329// from the Azure Resource Manager API or the portal.
330// serverName - the name of the server.
331// databaseName - the name of the database on which the sync group is hosted.
332// syncGroupName - the name of the sync group.
333func (client SyncGroupsClient) Get(ctx context.Context, resourceGroupName string, serverName string, databaseName string, syncGroupName string) (result SyncGroup, err error) {
334	if tracing.IsEnabled() {
335		ctx = tracing.StartSpan(ctx, fqdn+"/SyncGroupsClient.Get")
336		defer func() {
337			sc := -1
338			if result.Response.Response != nil {
339				sc = result.Response.Response.StatusCode
340			}
341			tracing.EndSpan(ctx, sc, err)
342		}()
343	}
344	req, err := client.GetPreparer(ctx, resourceGroupName, serverName, databaseName, syncGroupName)
345	if err != nil {
346		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "Get", nil, "Failure preparing request")
347		return
348	}
349
350	resp, err := client.GetSender(req)
351	if err != nil {
352		result.Response = autorest.Response{Response: resp}
353		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "Get", resp, "Failure sending request")
354		return
355	}
356
357	result, err = client.GetResponder(resp)
358	if err != nil {
359		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "Get", resp, "Failure responding to request")
360		return
361	}
362
363	return
364}
365
366// GetPreparer prepares the Get request.
367func (client SyncGroupsClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, syncGroupName string) (*http.Request, error) {
368	pathParameters := map[string]interface{}{
369		"databaseName":      autorest.Encode("path", databaseName),
370		"resourceGroupName": autorest.Encode("path", resourceGroupName),
371		"serverName":        autorest.Encode("path", serverName),
372		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
373		"syncGroupName":     autorest.Encode("path", syncGroupName),
374	}
375
376	const APIVersion = "2015-05-01-preview"
377	queryParameters := map[string]interface{}{
378		"api-version": APIVersion,
379	}
380
381	preparer := autorest.CreatePreparer(
382		autorest.AsGet(),
383		autorest.WithBaseURL(client.BaseURI),
384		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}", pathParameters),
385		autorest.WithQueryParameters(queryParameters))
386	return preparer.Prepare((&http.Request{}).WithContext(ctx))
387}
388
389// GetSender sends the Get request. The method will close the
390// http.Response Body if it receives an error.
391func (client SyncGroupsClient) GetSender(req *http.Request) (*http.Response, error) {
392	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
393}
394
395// GetResponder handles the response to the Get request. The method always
396// closes the http.Response Body.
397func (client SyncGroupsClient) GetResponder(resp *http.Response) (result SyncGroup, err error) {
398	err = autorest.Respond(
399		resp,
400		azure.WithErrorUnlessStatusCode(http.StatusOK),
401		autorest.ByUnmarshallingJSON(&result),
402		autorest.ByClosing())
403	result.Response = autorest.Response{Response: resp}
404	return
405}
406
407// ListByDatabase lists sync groups under a hub database.
408// Parameters:
409// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
410// from the Azure Resource Manager API or the portal.
411// serverName - the name of the server.
412// databaseName - the name of the database on which the sync group is hosted.
413func (client SyncGroupsClient) ListByDatabase(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (result SyncGroupListResultPage, err error) {
414	if tracing.IsEnabled() {
415		ctx = tracing.StartSpan(ctx, fqdn+"/SyncGroupsClient.ListByDatabase")
416		defer func() {
417			sc := -1
418			if result.sglr.Response.Response != nil {
419				sc = result.sglr.Response.Response.StatusCode
420			}
421			tracing.EndSpan(ctx, sc, err)
422		}()
423	}
424	result.fn = client.listByDatabaseNextResults
425	req, err := client.ListByDatabasePreparer(ctx, resourceGroupName, serverName, databaseName)
426	if err != nil {
427		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "ListByDatabase", nil, "Failure preparing request")
428		return
429	}
430
431	resp, err := client.ListByDatabaseSender(req)
432	if err != nil {
433		result.sglr.Response = autorest.Response{Response: resp}
434		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "ListByDatabase", resp, "Failure sending request")
435		return
436	}
437
438	result.sglr, err = client.ListByDatabaseResponder(resp)
439	if err != nil {
440		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "ListByDatabase", resp, "Failure responding to request")
441		return
442	}
443	if result.sglr.hasNextLink() && result.sglr.IsEmpty() {
444		err = result.NextWithContext(ctx)
445		return
446	}
447
448	return
449}
450
451// ListByDatabasePreparer prepares the ListByDatabase request.
452func (client SyncGroupsClient) ListByDatabasePreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (*http.Request, error) {
453	pathParameters := map[string]interface{}{
454		"databaseName":      autorest.Encode("path", databaseName),
455		"resourceGroupName": autorest.Encode("path", resourceGroupName),
456		"serverName":        autorest.Encode("path", serverName),
457		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
458	}
459
460	const APIVersion = "2015-05-01-preview"
461	queryParameters := map[string]interface{}{
462		"api-version": APIVersion,
463	}
464
465	preparer := autorest.CreatePreparer(
466		autorest.AsGet(),
467		autorest.WithBaseURL(client.BaseURI),
468		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups", pathParameters),
469		autorest.WithQueryParameters(queryParameters))
470	return preparer.Prepare((&http.Request{}).WithContext(ctx))
471}
472
473// ListByDatabaseSender sends the ListByDatabase request. The method will close the
474// http.Response Body if it receives an error.
475func (client SyncGroupsClient) ListByDatabaseSender(req *http.Request) (*http.Response, error) {
476	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
477}
478
479// ListByDatabaseResponder handles the response to the ListByDatabase request. The method always
480// closes the http.Response Body.
481func (client SyncGroupsClient) ListByDatabaseResponder(resp *http.Response) (result SyncGroupListResult, err error) {
482	err = autorest.Respond(
483		resp,
484		azure.WithErrorUnlessStatusCode(http.StatusOK),
485		autorest.ByUnmarshallingJSON(&result),
486		autorest.ByClosing())
487	result.Response = autorest.Response{Response: resp}
488	return
489}
490
491// listByDatabaseNextResults retrieves the next set of results, if any.
492func (client SyncGroupsClient) listByDatabaseNextResults(ctx context.Context, lastResults SyncGroupListResult) (result SyncGroupListResult, err error) {
493	req, err := lastResults.syncGroupListResultPreparer(ctx)
494	if err != nil {
495		return result, autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "listByDatabaseNextResults", nil, "Failure preparing next results request")
496	}
497	if req == nil {
498		return
499	}
500	resp, err := client.ListByDatabaseSender(req)
501	if err != nil {
502		result.Response = autorest.Response{Response: resp}
503		return result, autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "listByDatabaseNextResults", resp, "Failure sending next results request")
504	}
505	result, err = client.ListByDatabaseResponder(resp)
506	if err != nil {
507		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "listByDatabaseNextResults", resp, "Failure responding to next results request")
508	}
509	return
510}
511
512// ListByDatabaseComplete enumerates all values, automatically crossing page boundaries as required.
513func (client SyncGroupsClient) ListByDatabaseComplete(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (result SyncGroupListResultIterator, err error) {
514	if tracing.IsEnabled() {
515		ctx = tracing.StartSpan(ctx, fqdn+"/SyncGroupsClient.ListByDatabase")
516		defer func() {
517			sc := -1
518			if result.Response().Response.Response != nil {
519				sc = result.page.Response().Response.Response.StatusCode
520			}
521			tracing.EndSpan(ctx, sc, err)
522		}()
523	}
524	result.page, err = client.ListByDatabase(ctx, resourceGroupName, serverName, databaseName)
525	return
526}
527
528// ListHubSchemas gets a collection of hub database schemas.
529// Parameters:
530// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
531// from the Azure Resource Manager API or the portal.
532// serverName - the name of the server.
533// databaseName - the name of the database on which the sync group is hosted.
534// syncGroupName - the name of the sync group.
535func (client SyncGroupsClient) ListHubSchemas(ctx context.Context, resourceGroupName string, serverName string, databaseName string, syncGroupName string) (result SyncFullSchemaPropertiesListResultPage, err error) {
536	if tracing.IsEnabled() {
537		ctx = tracing.StartSpan(ctx, fqdn+"/SyncGroupsClient.ListHubSchemas")
538		defer func() {
539			sc := -1
540			if result.sfsplr.Response.Response != nil {
541				sc = result.sfsplr.Response.Response.StatusCode
542			}
543			tracing.EndSpan(ctx, sc, err)
544		}()
545	}
546	result.fn = client.listHubSchemasNextResults
547	req, err := client.ListHubSchemasPreparer(ctx, resourceGroupName, serverName, databaseName, syncGroupName)
548	if err != nil {
549		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "ListHubSchemas", nil, "Failure preparing request")
550		return
551	}
552
553	resp, err := client.ListHubSchemasSender(req)
554	if err != nil {
555		result.sfsplr.Response = autorest.Response{Response: resp}
556		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "ListHubSchemas", resp, "Failure sending request")
557		return
558	}
559
560	result.sfsplr, err = client.ListHubSchemasResponder(resp)
561	if err != nil {
562		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "ListHubSchemas", resp, "Failure responding to request")
563		return
564	}
565	if result.sfsplr.hasNextLink() && result.sfsplr.IsEmpty() {
566		err = result.NextWithContext(ctx)
567		return
568	}
569
570	return
571}
572
573// ListHubSchemasPreparer prepares the ListHubSchemas request.
574func (client SyncGroupsClient) ListHubSchemasPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, syncGroupName string) (*http.Request, error) {
575	pathParameters := map[string]interface{}{
576		"databaseName":      autorest.Encode("path", databaseName),
577		"resourceGroupName": autorest.Encode("path", resourceGroupName),
578		"serverName":        autorest.Encode("path", serverName),
579		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
580		"syncGroupName":     autorest.Encode("path", syncGroupName),
581	}
582
583	const APIVersion = "2015-05-01-preview"
584	queryParameters := map[string]interface{}{
585		"api-version": APIVersion,
586	}
587
588	preparer := autorest.CreatePreparer(
589		autorest.AsGet(),
590		autorest.WithBaseURL(client.BaseURI),
591		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/hubSchemas", pathParameters),
592		autorest.WithQueryParameters(queryParameters))
593	return preparer.Prepare((&http.Request{}).WithContext(ctx))
594}
595
596// ListHubSchemasSender sends the ListHubSchemas request. The method will close the
597// http.Response Body if it receives an error.
598func (client SyncGroupsClient) ListHubSchemasSender(req *http.Request) (*http.Response, error) {
599	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
600}
601
602// ListHubSchemasResponder handles the response to the ListHubSchemas request. The method always
603// closes the http.Response Body.
604func (client SyncGroupsClient) ListHubSchemasResponder(resp *http.Response) (result SyncFullSchemaPropertiesListResult, err error) {
605	err = autorest.Respond(
606		resp,
607		azure.WithErrorUnlessStatusCode(http.StatusOK),
608		autorest.ByUnmarshallingJSON(&result),
609		autorest.ByClosing())
610	result.Response = autorest.Response{Response: resp}
611	return
612}
613
614// listHubSchemasNextResults retrieves the next set of results, if any.
615func (client SyncGroupsClient) listHubSchemasNextResults(ctx context.Context, lastResults SyncFullSchemaPropertiesListResult) (result SyncFullSchemaPropertiesListResult, err error) {
616	req, err := lastResults.syncFullSchemaPropertiesListResultPreparer(ctx)
617	if err != nil {
618		return result, autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "listHubSchemasNextResults", nil, "Failure preparing next results request")
619	}
620	if req == nil {
621		return
622	}
623	resp, err := client.ListHubSchemasSender(req)
624	if err != nil {
625		result.Response = autorest.Response{Response: resp}
626		return result, autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "listHubSchemasNextResults", resp, "Failure sending next results request")
627	}
628	result, err = client.ListHubSchemasResponder(resp)
629	if err != nil {
630		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "listHubSchemasNextResults", resp, "Failure responding to next results request")
631	}
632	return
633}
634
635// ListHubSchemasComplete enumerates all values, automatically crossing page boundaries as required.
636func (client SyncGroupsClient) ListHubSchemasComplete(ctx context.Context, resourceGroupName string, serverName string, databaseName string, syncGroupName string) (result SyncFullSchemaPropertiesListResultIterator, err error) {
637	if tracing.IsEnabled() {
638		ctx = tracing.StartSpan(ctx, fqdn+"/SyncGroupsClient.ListHubSchemas")
639		defer func() {
640			sc := -1
641			if result.Response().Response.Response != nil {
642				sc = result.page.Response().Response.Response.StatusCode
643			}
644			tracing.EndSpan(ctx, sc, err)
645		}()
646	}
647	result.page, err = client.ListHubSchemas(ctx, resourceGroupName, serverName, databaseName, syncGroupName)
648	return
649}
650
651// ListLogs gets a collection of sync group logs.
652// Parameters:
653// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
654// from the Azure Resource Manager API or the portal.
655// serverName - the name of the server.
656// databaseName - the name of the database on which the sync group is hosted.
657// syncGroupName - the name of the sync group.
658// startTime - get logs generated after this time.
659// endTime - get logs generated before this time.
660// typeParameter - the types of logs to retrieve.
661// continuationToken - the continuation token for this operation.
662func (client SyncGroupsClient) ListLogs(ctx context.Context, resourceGroupName string, serverName string, databaseName string, syncGroupName string, startTime string, endTime string, typeParameter string, continuationToken string) (result SyncGroupLogListResultPage, err error) {
663	if tracing.IsEnabled() {
664		ctx = tracing.StartSpan(ctx, fqdn+"/SyncGroupsClient.ListLogs")
665		defer func() {
666			sc := -1
667			if result.sgllr.Response.Response != nil {
668				sc = result.sgllr.Response.Response.StatusCode
669			}
670			tracing.EndSpan(ctx, sc, err)
671		}()
672	}
673	result.fn = client.listLogsNextResults
674	req, err := client.ListLogsPreparer(ctx, resourceGroupName, serverName, databaseName, syncGroupName, startTime, endTime, typeParameter, continuationToken)
675	if err != nil {
676		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "ListLogs", nil, "Failure preparing request")
677		return
678	}
679
680	resp, err := client.ListLogsSender(req)
681	if err != nil {
682		result.sgllr.Response = autorest.Response{Response: resp}
683		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "ListLogs", resp, "Failure sending request")
684		return
685	}
686
687	result.sgllr, err = client.ListLogsResponder(resp)
688	if err != nil {
689		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "ListLogs", resp, "Failure responding to request")
690		return
691	}
692	if result.sgllr.hasNextLink() && result.sgllr.IsEmpty() {
693		err = result.NextWithContext(ctx)
694		return
695	}
696
697	return
698}
699
700// ListLogsPreparer prepares the ListLogs request.
701func (client SyncGroupsClient) ListLogsPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, syncGroupName string, startTime string, endTime string, typeParameter string, continuationToken string) (*http.Request, error) {
702	pathParameters := map[string]interface{}{
703		"databaseName":      autorest.Encode("path", databaseName),
704		"resourceGroupName": autorest.Encode("path", resourceGroupName),
705		"serverName":        autorest.Encode("path", serverName),
706		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
707		"syncGroupName":     autorest.Encode("path", syncGroupName),
708	}
709
710	const APIVersion = "2015-05-01-preview"
711	queryParameters := map[string]interface{}{
712		"api-version": APIVersion,
713		"endTime":     autorest.Encode("query", endTime),
714		"startTime":   autorest.Encode("query", startTime),
715		"type":        autorest.Encode("query", typeParameter),
716	}
717	if len(continuationToken) > 0 {
718		queryParameters["continuationToken"] = autorest.Encode("query", continuationToken)
719	}
720
721	preparer := autorest.CreatePreparer(
722		autorest.AsGet(),
723		autorest.WithBaseURL(client.BaseURI),
724		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/logs", pathParameters),
725		autorest.WithQueryParameters(queryParameters))
726	return preparer.Prepare((&http.Request{}).WithContext(ctx))
727}
728
729// ListLogsSender sends the ListLogs request. The method will close the
730// http.Response Body if it receives an error.
731func (client SyncGroupsClient) ListLogsSender(req *http.Request) (*http.Response, error) {
732	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
733}
734
735// ListLogsResponder handles the response to the ListLogs request. The method always
736// closes the http.Response Body.
737func (client SyncGroupsClient) ListLogsResponder(resp *http.Response) (result SyncGroupLogListResult, err error) {
738	err = autorest.Respond(
739		resp,
740		azure.WithErrorUnlessStatusCode(http.StatusOK),
741		autorest.ByUnmarshallingJSON(&result),
742		autorest.ByClosing())
743	result.Response = autorest.Response{Response: resp}
744	return
745}
746
747// listLogsNextResults retrieves the next set of results, if any.
748func (client SyncGroupsClient) listLogsNextResults(ctx context.Context, lastResults SyncGroupLogListResult) (result SyncGroupLogListResult, err error) {
749	req, err := lastResults.syncGroupLogListResultPreparer(ctx)
750	if err != nil {
751		return result, autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "listLogsNextResults", nil, "Failure preparing next results request")
752	}
753	if req == nil {
754		return
755	}
756	resp, err := client.ListLogsSender(req)
757	if err != nil {
758		result.Response = autorest.Response{Response: resp}
759		return result, autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "listLogsNextResults", resp, "Failure sending next results request")
760	}
761	result, err = client.ListLogsResponder(resp)
762	if err != nil {
763		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "listLogsNextResults", resp, "Failure responding to next results request")
764	}
765	return
766}
767
768// ListLogsComplete enumerates all values, automatically crossing page boundaries as required.
769func (client SyncGroupsClient) ListLogsComplete(ctx context.Context, resourceGroupName string, serverName string, databaseName string, syncGroupName string, startTime string, endTime string, typeParameter string, continuationToken string) (result SyncGroupLogListResultIterator, err error) {
770	if tracing.IsEnabled() {
771		ctx = tracing.StartSpan(ctx, fqdn+"/SyncGroupsClient.ListLogs")
772		defer func() {
773			sc := -1
774			if result.Response().Response.Response != nil {
775				sc = result.page.Response().Response.Response.StatusCode
776			}
777			tracing.EndSpan(ctx, sc, err)
778		}()
779	}
780	result.page, err = client.ListLogs(ctx, resourceGroupName, serverName, databaseName, syncGroupName, startTime, endTime, typeParameter, continuationToken)
781	return
782}
783
784// ListSyncDatabaseIds gets a collection of sync database ids.
785// Parameters:
786// locationName - the name of the region where the resource is located.
787func (client SyncGroupsClient) ListSyncDatabaseIds(ctx context.Context, locationName string) (result SyncDatabaseIDListResultPage, err error) {
788	if tracing.IsEnabled() {
789		ctx = tracing.StartSpan(ctx, fqdn+"/SyncGroupsClient.ListSyncDatabaseIds")
790		defer func() {
791			sc := -1
792			if result.sdilr.Response.Response != nil {
793				sc = result.sdilr.Response.Response.StatusCode
794			}
795			tracing.EndSpan(ctx, sc, err)
796		}()
797	}
798	result.fn = client.listSyncDatabaseIdsNextResults
799	req, err := client.ListSyncDatabaseIdsPreparer(ctx, locationName)
800	if err != nil {
801		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "ListSyncDatabaseIds", nil, "Failure preparing request")
802		return
803	}
804
805	resp, err := client.ListSyncDatabaseIdsSender(req)
806	if err != nil {
807		result.sdilr.Response = autorest.Response{Response: resp}
808		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "ListSyncDatabaseIds", resp, "Failure sending request")
809		return
810	}
811
812	result.sdilr, err = client.ListSyncDatabaseIdsResponder(resp)
813	if err != nil {
814		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "ListSyncDatabaseIds", resp, "Failure responding to request")
815		return
816	}
817	if result.sdilr.hasNextLink() && result.sdilr.IsEmpty() {
818		err = result.NextWithContext(ctx)
819		return
820	}
821
822	return
823}
824
825// ListSyncDatabaseIdsPreparer prepares the ListSyncDatabaseIds request.
826func (client SyncGroupsClient) ListSyncDatabaseIdsPreparer(ctx context.Context, locationName string) (*http.Request, error) {
827	pathParameters := map[string]interface{}{
828		"locationName":   autorest.Encode("path", locationName),
829		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
830	}
831
832	const APIVersion = "2015-05-01-preview"
833	queryParameters := map[string]interface{}{
834		"api-version": APIVersion,
835	}
836
837	preparer := autorest.CreatePreparer(
838		autorest.AsGet(),
839		autorest.WithBaseURL(client.BaseURI),
840		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/syncDatabaseIds", pathParameters),
841		autorest.WithQueryParameters(queryParameters))
842	return preparer.Prepare((&http.Request{}).WithContext(ctx))
843}
844
845// ListSyncDatabaseIdsSender sends the ListSyncDatabaseIds request. The method will close the
846// http.Response Body if it receives an error.
847func (client SyncGroupsClient) ListSyncDatabaseIdsSender(req *http.Request) (*http.Response, error) {
848	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
849}
850
851// ListSyncDatabaseIdsResponder handles the response to the ListSyncDatabaseIds request. The method always
852// closes the http.Response Body.
853func (client SyncGroupsClient) ListSyncDatabaseIdsResponder(resp *http.Response) (result SyncDatabaseIDListResult, err error) {
854	err = autorest.Respond(
855		resp,
856		azure.WithErrorUnlessStatusCode(http.StatusOK),
857		autorest.ByUnmarshallingJSON(&result),
858		autorest.ByClosing())
859	result.Response = autorest.Response{Response: resp}
860	return
861}
862
863// listSyncDatabaseIdsNextResults retrieves the next set of results, if any.
864func (client SyncGroupsClient) listSyncDatabaseIdsNextResults(ctx context.Context, lastResults SyncDatabaseIDListResult) (result SyncDatabaseIDListResult, err error) {
865	req, err := lastResults.syncDatabaseIDListResultPreparer(ctx)
866	if err != nil {
867		return result, autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "listSyncDatabaseIdsNextResults", nil, "Failure preparing next results request")
868	}
869	if req == nil {
870		return
871	}
872	resp, err := client.ListSyncDatabaseIdsSender(req)
873	if err != nil {
874		result.Response = autorest.Response{Response: resp}
875		return result, autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "listSyncDatabaseIdsNextResults", resp, "Failure sending next results request")
876	}
877	result, err = client.ListSyncDatabaseIdsResponder(resp)
878	if err != nil {
879		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "listSyncDatabaseIdsNextResults", resp, "Failure responding to next results request")
880	}
881	return
882}
883
884// ListSyncDatabaseIdsComplete enumerates all values, automatically crossing page boundaries as required.
885func (client SyncGroupsClient) ListSyncDatabaseIdsComplete(ctx context.Context, locationName string) (result SyncDatabaseIDListResultIterator, err error) {
886	if tracing.IsEnabled() {
887		ctx = tracing.StartSpan(ctx, fqdn+"/SyncGroupsClient.ListSyncDatabaseIds")
888		defer func() {
889			sc := -1
890			if result.Response().Response.Response != nil {
891				sc = result.page.Response().Response.Response.StatusCode
892			}
893			tracing.EndSpan(ctx, sc, err)
894		}()
895	}
896	result.page, err = client.ListSyncDatabaseIds(ctx, locationName)
897	return
898}
899
900// RefreshHubSchema refreshes a hub database schema.
901// Parameters:
902// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
903// from the Azure Resource Manager API or the portal.
904// serverName - the name of the server.
905// databaseName - the name of the database on which the sync group is hosted.
906// syncGroupName - the name of the sync group.
907func (client SyncGroupsClient) RefreshHubSchema(ctx context.Context, resourceGroupName string, serverName string, databaseName string, syncGroupName string) (result SyncGroupsRefreshHubSchemaFuture, err error) {
908	if tracing.IsEnabled() {
909		ctx = tracing.StartSpan(ctx, fqdn+"/SyncGroupsClient.RefreshHubSchema")
910		defer func() {
911			sc := -1
912			if result.Response() != nil {
913				sc = result.Response().StatusCode
914			}
915			tracing.EndSpan(ctx, sc, err)
916		}()
917	}
918	req, err := client.RefreshHubSchemaPreparer(ctx, resourceGroupName, serverName, databaseName, syncGroupName)
919	if err != nil {
920		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "RefreshHubSchema", nil, "Failure preparing request")
921		return
922	}
923
924	result, err = client.RefreshHubSchemaSender(req)
925	if err != nil {
926		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "RefreshHubSchema", nil, "Failure sending request")
927		return
928	}
929
930	return
931}
932
933// RefreshHubSchemaPreparer prepares the RefreshHubSchema request.
934func (client SyncGroupsClient) RefreshHubSchemaPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, syncGroupName string) (*http.Request, error) {
935	pathParameters := map[string]interface{}{
936		"databaseName":      autorest.Encode("path", databaseName),
937		"resourceGroupName": autorest.Encode("path", resourceGroupName),
938		"serverName":        autorest.Encode("path", serverName),
939		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
940		"syncGroupName":     autorest.Encode("path", syncGroupName),
941	}
942
943	const APIVersion = "2015-05-01-preview"
944	queryParameters := map[string]interface{}{
945		"api-version": APIVersion,
946	}
947
948	preparer := autorest.CreatePreparer(
949		autorest.AsPost(),
950		autorest.WithBaseURL(client.BaseURI),
951		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/refreshHubSchema", pathParameters),
952		autorest.WithQueryParameters(queryParameters))
953	return preparer.Prepare((&http.Request{}).WithContext(ctx))
954}
955
956// RefreshHubSchemaSender sends the RefreshHubSchema request. The method will close the
957// http.Response Body if it receives an error.
958func (client SyncGroupsClient) RefreshHubSchemaSender(req *http.Request) (future SyncGroupsRefreshHubSchemaFuture, err error) {
959	var resp *http.Response
960	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
961	if err != nil {
962		return
963	}
964	var azf azure.Future
965	azf, err = azure.NewFutureFromResponse(resp)
966	future.FutureAPI = &azf
967	future.Result = func(client SyncGroupsClient) (ar autorest.Response, err error) {
968		var done bool
969		done, err = future.DoneWithContext(context.Background(), client)
970		if err != nil {
971			err = autorest.NewErrorWithError(err, "sql.SyncGroupsRefreshHubSchemaFuture", "Result", future.Response(), "Polling failure")
972			return
973		}
974		if !done {
975			err = azure.NewAsyncOpIncompleteError("sql.SyncGroupsRefreshHubSchemaFuture")
976			return
977		}
978		ar.Response = future.Response()
979		return
980	}
981	return
982}
983
984// RefreshHubSchemaResponder handles the response to the RefreshHubSchema request. The method always
985// closes the http.Response Body.
986func (client SyncGroupsClient) RefreshHubSchemaResponder(resp *http.Response) (result autorest.Response, err error) {
987	err = autorest.Respond(
988		resp,
989		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
990		autorest.ByClosing())
991	result.Response = resp
992	return
993}
994
995// TriggerSync triggers a sync group synchronization.
996// Parameters:
997// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
998// from the Azure Resource Manager API or the portal.
999// serverName - the name of the server.
1000// databaseName - the name of the database on which the sync group is hosted.
1001// syncGroupName - the name of the sync group.
1002func (client SyncGroupsClient) TriggerSync(ctx context.Context, resourceGroupName string, serverName string, databaseName string, syncGroupName string) (result autorest.Response, err error) {
1003	if tracing.IsEnabled() {
1004		ctx = tracing.StartSpan(ctx, fqdn+"/SyncGroupsClient.TriggerSync")
1005		defer func() {
1006			sc := -1
1007			if result.Response != nil {
1008				sc = result.Response.StatusCode
1009			}
1010			tracing.EndSpan(ctx, sc, err)
1011		}()
1012	}
1013	req, err := client.TriggerSyncPreparer(ctx, resourceGroupName, serverName, databaseName, syncGroupName)
1014	if err != nil {
1015		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "TriggerSync", nil, "Failure preparing request")
1016		return
1017	}
1018
1019	resp, err := client.TriggerSyncSender(req)
1020	if err != nil {
1021		result.Response = resp
1022		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "TriggerSync", resp, "Failure sending request")
1023		return
1024	}
1025
1026	result, err = client.TriggerSyncResponder(resp)
1027	if err != nil {
1028		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "TriggerSync", resp, "Failure responding to request")
1029		return
1030	}
1031
1032	return
1033}
1034
1035// TriggerSyncPreparer prepares the TriggerSync request.
1036func (client SyncGroupsClient) TriggerSyncPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, syncGroupName string) (*http.Request, error) {
1037	pathParameters := map[string]interface{}{
1038		"databaseName":      autorest.Encode("path", databaseName),
1039		"resourceGroupName": autorest.Encode("path", resourceGroupName),
1040		"serverName":        autorest.Encode("path", serverName),
1041		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
1042		"syncGroupName":     autorest.Encode("path", syncGroupName),
1043	}
1044
1045	const APIVersion = "2015-05-01-preview"
1046	queryParameters := map[string]interface{}{
1047		"api-version": APIVersion,
1048	}
1049
1050	preparer := autorest.CreatePreparer(
1051		autorest.AsPost(),
1052		autorest.WithBaseURL(client.BaseURI),
1053		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/triggerSync", pathParameters),
1054		autorest.WithQueryParameters(queryParameters))
1055	return preparer.Prepare((&http.Request{}).WithContext(ctx))
1056}
1057
1058// TriggerSyncSender sends the TriggerSync request. The method will close the
1059// http.Response Body if it receives an error.
1060func (client SyncGroupsClient) TriggerSyncSender(req *http.Request) (*http.Response, error) {
1061	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
1062}
1063
1064// TriggerSyncResponder handles the response to the TriggerSync request. The method always
1065// closes the http.Response Body.
1066func (client SyncGroupsClient) TriggerSyncResponder(resp *http.Response) (result autorest.Response, err error) {
1067	err = autorest.Respond(
1068		resp,
1069		azure.WithErrorUnlessStatusCode(http.StatusOK),
1070		autorest.ByClosing())
1071	result.Response = resp
1072	return
1073}
1074
1075// Update updates a sync group.
1076// Parameters:
1077// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
1078// from the Azure Resource Manager API or the portal.
1079// serverName - the name of the server.
1080// databaseName - the name of the database on which the sync group is hosted.
1081// syncGroupName - the name of the sync group.
1082// parameters - the requested sync group resource state.
1083func (client SyncGroupsClient) Update(ctx context.Context, resourceGroupName string, serverName string, databaseName string, syncGroupName string, parameters SyncGroup) (result SyncGroupsUpdateFuture, err error) {
1084	if tracing.IsEnabled() {
1085		ctx = tracing.StartSpan(ctx, fqdn+"/SyncGroupsClient.Update")
1086		defer func() {
1087			sc := -1
1088			if result.Response() != nil {
1089				sc = result.Response().StatusCode
1090			}
1091			tracing.EndSpan(ctx, sc, err)
1092		}()
1093	}
1094	req, err := client.UpdatePreparer(ctx, resourceGroupName, serverName, databaseName, syncGroupName, parameters)
1095	if err != nil {
1096		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "Update", nil, "Failure preparing request")
1097		return
1098	}
1099
1100	result, err = client.UpdateSender(req)
1101	if err != nil {
1102		err = autorest.NewErrorWithError(err, "sql.SyncGroupsClient", "Update", nil, "Failure sending request")
1103		return
1104	}
1105
1106	return
1107}
1108
1109// UpdatePreparer prepares the Update request.
1110func (client SyncGroupsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, syncGroupName string, parameters SyncGroup) (*http.Request, error) {
1111	pathParameters := map[string]interface{}{
1112		"databaseName":      autorest.Encode("path", databaseName),
1113		"resourceGroupName": autorest.Encode("path", resourceGroupName),
1114		"serverName":        autorest.Encode("path", serverName),
1115		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
1116		"syncGroupName":     autorest.Encode("path", syncGroupName),
1117	}
1118
1119	const APIVersion = "2015-05-01-preview"
1120	queryParameters := map[string]interface{}{
1121		"api-version": APIVersion,
1122	}
1123
1124	preparer := autorest.CreatePreparer(
1125		autorest.AsContentType("application/json; charset=utf-8"),
1126		autorest.AsPatch(),
1127		autorest.WithBaseURL(client.BaseURI),
1128		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}", pathParameters),
1129		autorest.WithJSON(parameters),
1130		autorest.WithQueryParameters(queryParameters))
1131	return preparer.Prepare((&http.Request{}).WithContext(ctx))
1132}
1133
1134// UpdateSender sends the Update request. The method will close the
1135// http.Response Body if it receives an error.
1136func (client SyncGroupsClient) UpdateSender(req *http.Request) (future SyncGroupsUpdateFuture, err error) {
1137	var resp *http.Response
1138	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
1139	if err != nil {
1140		return
1141	}
1142	var azf azure.Future
1143	azf, err = azure.NewFutureFromResponse(resp)
1144	future.FutureAPI = &azf
1145	future.Result = func(client SyncGroupsClient) (sg SyncGroup, err error) {
1146		var done bool
1147		done, err = future.DoneWithContext(context.Background(), client)
1148		if err != nil {
1149			err = autorest.NewErrorWithError(err, "sql.SyncGroupsUpdateFuture", "Result", future.Response(), "Polling failure")
1150			return
1151		}
1152		if !done {
1153			err = azure.NewAsyncOpIncompleteError("sql.SyncGroupsUpdateFuture")
1154			return
1155		}
1156		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
1157		if sg.Response.Response, err = future.GetResult(sender); err == nil && sg.Response.Response.StatusCode != http.StatusNoContent {
1158			sg, err = client.UpdateResponder(sg.Response.Response)
1159			if err != nil {
1160				err = autorest.NewErrorWithError(err, "sql.SyncGroupsUpdateFuture", "Result", sg.Response.Response, "Failure responding to request")
1161			}
1162		}
1163		return
1164	}
1165	return
1166}
1167
1168// UpdateResponder handles the response to the Update request. The method always
1169// closes the http.Response Body.
1170func (client SyncGroupsClient) UpdateResponder(resp *http.Response) (result SyncGroup, err error) {
1171	err = autorest.Respond(
1172		resp,
1173		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
1174		autorest.ByUnmarshallingJSON(&result),
1175		autorest.ByClosing())
1176	result.Response = autorest.Response{Response: resp}
1177	return
1178}
1179