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/autorest/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// ElasticPoolsClient is the the Azure SQL Database management API provides a RESTful set of web services that interact
19// with Azure SQL Database services to manage your databases. The API enables you to create, retrieve, update, and
20// delete databases.
21type ElasticPoolsClient struct {
22	BaseClient
23}
24
25// NewElasticPoolsClient creates an instance of the ElasticPoolsClient client.
26func NewElasticPoolsClient(subscriptionID string) ElasticPoolsClient {
27	return NewElasticPoolsClientWithBaseURI(DefaultBaseURI, subscriptionID)
28}
29
30// NewElasticPoolsClientWithBaseURI creates an instance of the ElasticPoolsClient client using a custom endpoint.  Use
31// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
32func NewElasticPoolsClientWithBaseURI(baseURI string, subscriptionID string) ElasticPoolsClient {
33	return ElasticPoolsClient{NewWithBaseURI(baseURI, subscriptionID)}
34}
35
36// CreateOrUpdate creates or updates an elastic pool.
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// elasticPoolName - the name of the elastic pool.
42// parameters - the elastic pool parameters.
43func (client ElasticPoolsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string, parameters ElasticPool) (result ElasticPoolsCreateOrUpdateFuture, err error) {
44	if tracing.IsEnabled() {
45		ctx = tracing.StartSpan(ctx, fqdn+"/ElasticPoolsClient.CreateOrUpdate")
46		defer func() {
47			sc := -1
48			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
49				sc = result.FutureAPI.Response().StatusCode
50			}
51			tracing.EndSpan(ctx, sc, err)
52		}()
53	}
54	if err := validation.Validate([]validation.Validation{
55		{TargetValue: parameters,
56			Constraints: []validation.Constraint{{Target: "parameters.Sku", Name: validation.Null, Rule: false,
57				Chain: []validation.Constraint{{Target: "parameters.Sku.Name", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
58		return result, validation.NewError("sql.ElasticPoolsClient", "CreateOrUpdate", err.Error())
59	}
60
61	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serverName, elasticPoolName, parameters)
62	if err != nil {
63		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "CreateOrUpdate", nil, "Failure preparing request")
64		return
65	}
66
67	result, err = client.CreateOrUpdateSender(req)
68	if err != nil {
69		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "CreateOrUpdate", nil, "Failure sending request")
70		return
71	}
72
73	return
74}
75
76// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
77func (client ElasticPoolsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string, parameters ElasticPool) (*http.Request, error) {
78	pathParameters := map[string]interface{}{
79		"elasticPoolName":   autorest.Encode("path", elasticPoolName),
80		"resourceGroupName": autorest.Encode("path", resourceGroupName),
81		"serverName":        autorest.Encode("path", serverName),
82		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
83	}
84
85	const APIVersion = "2020-08-01-preview"
86	queryParameters := map[string]interface{}{
87		"api-version": APIVersion,
88	}
89
90	parameters.Kind = nil
91	preparer := autorest.CreatePreparer(
92		autorest.AsContentType("application/json; charset=utf-8"),
93		autorest.AsPut(),
94		autorest.WithBaseURL(client.BaseURI),
95		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}", pathParameters),
96		autorest.WithJSON(parameters),
97		autorest.WithQueryParameters(queryParameters))
98	return preparer.Prepare((&http.Request{}).WithContext(ctx))
99}
100
101// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
102// http.Response Body if it receives an error.
103func (client ElasticPoolsClient) CreateOrUpdateSender(req *http.Request) (future ElasticPoolsCreateOrUpdateFuture, err error) {
104	var resp *http.Response
105	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
106	if err != nil {
107		return
108	}
109	var azf azure.Future
110	azf, err = azure.NewFutureFromResponse(resp)
111	future.FutureAPI = &azf
112	future.Result = future.result
113	return
114}
115
116// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
117// closes the http.Response Body.
118func (client ElasticPoolsClient) CreateOrUpdateResponder(resp *http.Response) (result ElasticPool, err error) {
119	err = autorest.Respond(
120		resp,
121		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted),
122		autorest.ByUnmarshallingJSON(&result),
123		autorest.ByClosing())
124	result.Response = autorest.Response{Response: resp}
125	return
126}
127
128// Delete deletes an elastic pool.
129// Parameters:
130// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
131// from the Azure Resource Manager API or the portal.
132// serverName - the name of the server.
133// elasticPoolName - the name of the elastic pool.
134func (client ElasticPoolsClient) Delete(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string) (result ElasticPoolsDeleteFuture, err error) {
135	if tracing.IsEnabled() {
136		ctx = tracing.StartSpan(ctx, fqdn+"/ElasticPoolsClient.Delete")
137		defer func() {
138			sc := -1
139			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
140				sc = result.FutureAPI.Response().StatusCode
141			}
142			tracing.EndSpan(ctx, sc, err)
143		}()
144	}
145	req, err := client.DeletePreparer(ctx, resourceGroupName, serverName, elasticPoolName)
146	if err != nil {
147		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "Delete", nil, "Failure preparing request")
148		return
149	}
150
151	result, err = client.DeleteSender(req)
152	if err != nil {
153		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "Delete", nil, "Failure sending request")
154		return
155	}
156
157	return
158}
159
160// DeletePreparer prepares the Delete request.
161func (client ElasticPoolsClient) DeletePreparer(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string) (*http.Request, error) {
162	pathParameters := map[string]interface{}{
163		"elasticPoolName":   autorest.Encode("path", elasticPoolName),
164		"resourceGroupName": autorest.Encode("path", resourceGroupName),
165		"serverName":        autorest.Encode("path", serverName),
166		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
167	}
168
169	const APIVersion = "2020-08-01-preview"
170	queryParameters := map[string]interface{}{
171		"api-version": APIVersion,
172	}
173
174	preparer := autorest.CreatePreparer(
175		autorest.AsDelete(),
176		autorest.WithBaseURL(client.BaseURI),
177		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}", pathParameters),
178		autorest.WithQueryParameters(queryParameters))
179	return preparer.Prepare((&http.Request{}).WithContext(ctx))
180}
181
182// DeleteSender sends the Delete request. The method will close the
183// http.Response Body if it receives an error.
184func (client ElasticPoolsClient) DeleteSender(req *http.Request) (future ElasticPoolsDeleteFuture, err error) {
185	var resp *http.Response
186	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
187	if err != nil {
188		return
189	}
190	var azf azure.Future
191	azf, err = azure.NewFutureFromResponse(resp)
192	future.FutureAPI = &azf
193	future.Result = future.result
194	return
195}
196
197// DeleteResponder handles the response to the Delete request. The method always
198// closes the http.Response Body.
199func (client ElasticPoolsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
200	err = autorest.Respond(
201		resp,
202		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
203		autorest.ByClosing())
204	result.Response = resp
205	return
206}
207
208// Failover failovers an elastic pool.
209// Parameters:
210// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
211// from the Azure Resource Manager API or the portal.
212// serverName - the name of the server.
213// elasticPoolName - the name of the elastic pool to failover.
214func (client ElasticPoolsClient) Failover(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string) (result ElasticPoolsFailoverFuture, err error) {
215	if tracing.IsEnabled() {
216		ctx = tracing.StartSpan(ctx, fqdn+"/ElasticPoolsClient.Failover")
217		defer func() {
218			sc := -1
219			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
220				sc = result.FutureAPI.Response().StatusCode
221			}
222			tracing.EndSpan(ctx, sc, err)
223		}()
224	}
225	req, err := client.FailoverPreparer(ctx, resourceGroupName, serverName, elasticPoolName)
226	if err != nil {
227		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "Failover", nil, "Failure preparing request")
228		return
229	}
230
231	result, err = client.FailoverSender(req)
232	if err != nil {
233		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "Failover", nil, "Failure sending request")
234		return
235	}
236
237	return
238}
239
240// FailoverPreparer prepares the Failover request.
241func (client ElasticPoolsClient) FailoverPreparer(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string) (*http.Request, error) {
242	pathParameters := map[string]interface{}{
243		"elasticPoolName":   autorest.Encode("path", elasticPoolName),
244		"resourceGroupName": autorest.Encode("path", resourceGroupName),
245		"serverName":        autorest.Encode("path", serverName),
246		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
247	}
248
249	const APIVersion = "2020-08-01-preview"
250	queryParameters := map[string]interface{}{
251		"api-version": APIVersion,
252	}
253
254	preparer := autorest.CreatePreparer(
255		autorest.AsPost(),
256		autorest.WithBaseURL(client.BaseURI),
257		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/failover", pathParameters),
258		autorest.WithQueryParameters(queryParameters))
259	return preparer.Prepare((&http.Request{}).WithContext(ctx))
260}
261
262// FailoverSender sends the Failover request. The method will close the
263// http.Response Body if it receives an error.
264func (client ElasticPoolsClient) FailoverSender(req *http.Request) (future ElasticPoolsFailoverFuture, err error) {
265	var resp *http.Response
266	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
267	if err != nil {
268		return
269	}
270	var azf azure.Future
271	azf, err = azure.NewFutureFromResponse(resp)
272	future.FutureAPI = &azf
273	future.Result = future.result
274	return
275}
276
277// FailoverResponder handles the response to the Failover request. The method always
278// closes the http.Response Body.
279func (client ElasticPoolsClient) FailoverResponder(resp *http.Response) (result autorest.Response, err error) {
280	err = autorest.Respond(
281		resp,
282		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
283		autorest.ByClosing())
284	result.Response = resp
285	return
286}
287
288// Get gets an elastic pool.
289// Parameters:
290// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
291// from the Azure Resource Manager API or the portal.
292// serverName - the name of the server.
293// elasticPoolName - the name of the elastic pool.
294func (client ElasticPoolsClient) Get(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string) (result ElasticPool, err error) {
295	if tracing.IsEnabled() {
296		ctx = tracing.StartSpan(ctx, fqdn+"/ElasticPoolsClient.Get")
297		defer func() {
298			sc := -1
299			if result.Response.Response != nil {
300				sc = result.Response.Response.StatusCode
301			}
302			tracing.EndSpan(ctx, sc, err)
303		}()
304	}
305	req, err := client.GetPreparer(ctx, resourceGroupName, serverName, elasticPoolName)
306	if err != nil {
307		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "Get", nil, "Failure preparing request")
308		return
309	}
310
311	resp, err := client.GetSender(req)
312	if err != nil {
313		result.Response = autorest.Response{Response: resp}
314		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "Get", resp, "Failure sending request")
315		return
316	}
317
318	result, err = client.GetResponder(resp)
319	if err != nil {
320		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "Get", resp, "Failure responding to request")
321		return
322	}
323
324	return
325}
326
327// GetPreparer prepares the Get request.
328func (client ElasticPoolsClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string) (*http.Request, error) {
329	pathParameters := map[string]interface{}{
330		"elasticPoolName":   autorest.Encode("path", elasticPoolName),
331		"resourceGroupName": autorest.Encode("path", resourceGroupName),
332		"serverName":        autorest.Encode("path", serverName),
333		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
334	}
335
336	const APIVersion = "2020-08-01-preview"
337	queryParameters := map[string]interface{}{
338		"api-version": APIVersion,
339	}
340
341	preparer := autorest.CreatePreparer(
342		autorest.AsGet(),
343		autorest.WithBaseURL(client.BaseURI),
344		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}", pathParameters),
345		autorest.WithQueryParameters(queryParameters))
346	return preparer.Prepare((&http.Request{}).WithContext(ctx))
347}
348
349// GetSender sends the Get request. The method will close the
350// http.Response Body if it receives an error.
351func (client ElasticPoolsClient) GetSender(req *http.Request) (*http.Response, error) {
352	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
353}
354
355// GetResponder handles the response to the Get request. The method always
356// closes the http.Response Body.
357func (client ElasticPoolsClient) GetResponder(resp *http.Response) (result ElasticPool, err error) {
358	err = autorest.Respond(
359		resp,
360		azure.WithErrorUnlessStatusCode(http.StatusOK),
361		autorest.ByUnmarshallingJSON(&result),
362		autorest.ByClosing())
363	result.Response = autorest.Response{Response: resp}
364	return
365}
366
367// ListByServer gets all elastic pools in a server.
368// Parameters:
369// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
370// from the Azure Resource Manager API or the portal.
371// serverName - the name of the server.
372// skip - the number of elements in the collection to skip.
373func (client ElasticPoolsClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string, skip *int32) (result ElasticPoolListResultPage, err error) {
374	if tracing.IsEnabled() {
375		ctx = tracing.StartSpan(ctx, fqdn+"/ElasticPoolsClient.ListByServer")
376		defer func() {
377			sc := -1
378			if result.eplr.Response.Response != nil {
379				sc = result.eplr.Response.Response.StatusCode
380			}
381			tracing.EndSpan(ctx, sc, err)
382		}()
383	}
384	result.fn = client.listByServerNextResults
385	req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName, skip)
386	if err != nil {
387		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "ListByServer", nil, "Failure preparing request")
388		return
389	}
390
391	resp, err := client.ListByServerSender(req)
392	if err != nil {
393		result.eplr.Response = autorest.Response{Response: resp}
394		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "ListByServer", resp, "Failure sending request")
395		return
396	}
397
398	result.eplr, err = client.ListByServerResponder(resp)
399	if err != nil {
400		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "ListByServer", resp, "Failure responding to request")
401		return
402	}
403	if result.eplr.hasNextLink() && result.eplr.IsEmpty() {
404		err = result.NextWithContext(ctx)
405		return
406	}
407
408	return
409}
410
411// ListByServerPreparer prepares the ListByServer request.
412func (client ElasticPoolsClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string, skip *int32) (*http.Request, error) {
413	pathParameters := map[string]interface{}{
414		"resourceGroupName": autorest.Encode("path", resourceGroupName),
415		"serverName":        autorest.Encode("path", serverName),
416		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
417	}
418
419	const APIVersion = "2020-08-01-preview"
420	queryParameters := map[string]interface{}{
421		"api-version": APIVersion,
422	}
423	if skip != nil {
424		queryParameters["$skip"] = autorest.Encode("query", *skip)
425	}
426
427	preparer := autorest.CreatePreparer(
428		autorest.AsGet(),
429		autorest.WithBaseURL(client.BaseURI),
430		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools", pathParameters),
431		autorest.WithQueryParameters(queryParameters))
432	return preparer.Prepare((&http.Request{}).WithContext(ctx))
433}
434
435// ListByServerSender sends the ListByServer request. The method will close the
436// http.Response Body if it receives an error.
437func (client ElasticPoolsClient) ListByServerSender(req *http.Request) (*http.Response, error) {
438	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
439}
440
441// ListByServerResponder handles the response to the ListByServer request. The method always
442// closes the http.Response Body.
443func (client ElasticPoolsClient) ListByServerResponder(resp *http.Response) (result ElasticPoolListResult, err error) {
444	err = autorest.Respond(
445		resp,
446		azure.WithErrorUnlessStatusCode(http.StatusOK),
447		autorest.ByUnmarshallingJSON(&result),
448		autorest.ByClosing())
449	result.Response = autorest.Response{Response: resp}
450	return
451}
452
453// listByServerNextResults retrieves the next set of results, if any.
454func (client ElasticPoolsClient) listByServerNextResults(ctx context.Context, lastResults ElasticPoolListResult) (result ElasticPoolListResult, err error) {
455	req, err := lastResults.elasticPoolListResultPreparer(ctx)
456	if err != nil {
457		return result, autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "listByServerNextResults", nil, "Failure preparing next results request")
458	}
459	if req == nil {
460		return
461	}
462	resp, err := client.ListByServerSender(req)
463	if err != nil {
464		result.Response = autorest.Response{Response: resp}
465		return result, autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "listByServerNextResults", resp, "Failure sending next results request")
466	}
467	result, err = client.ListByServerResponder(resp)
468	if err != nil {
469		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "listByServerNextResults", resp, "Failure responding to next results request")
470	}
471	return
472}
473
474// ListByServerComplete enumerates all values, automatically crossing page boundaries as required.
475func (client ElasticPoolsClient) ListByServerComplete(ctx context.Context, resourceGroupName string, serverName string, skip *int32) (result ElasticPoolListResultIterator, err error) {
476	if tracing.IsEnabled() {
477		ctx = tracing.StartSpan(ctx, fqdn+"/ElasticPoolsClient.ListByServer")
478		defer func() {
479			sc := -1
480			if result.Response().Response.Response != nil {
481				sc = result.page.Response().Response.Response.StatusCode
482			}
483			tracing.EndSpan(ctx, sc, err)
484		}()
485	}
486	result.page, err = client.ListByServer(ctx, resourceGroupName, serverName, skip)
487	return
488}
489
490// ListMetricDefinitions returns elastic pool metric definitions.
491// Parameters:
492// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
493// from the Azure Resource Manager API or the portal.
494// serverName - the name of the server.
495// elasticPoolName - the name of the elastic pool.
496func (client ElasticPoolsClient) ListMetricDefinitions(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string) (result MetricDefinitionListResult, err error) {
497	if tracing.IsEnabled() {
498		ctx = tracing.StartSpan(ctx, fqdn+"/ElasticPoolsClient.ListMetricDefinitions")
499		defer func() {
500			sc := -1
501			if result.Response.Response != nil {
502				sc = result.Response.Response.StatusCode
503			}
504			tracing.EndSpan(ctx, sc, err)
505		}()
506	}
507	req, err := client.ListMetricDefinitionsPreparer(ctx, resourceGroupName, serverName, elasticPoolName)
508	if err != nil {
509		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "ListMetricDefinitions", nil, "Failure preparing request")
510		return
511	}
512
513	resp, err := client.ListMetricDefinitionsSender(req)
514	if err != nil {
515		result.Response = autorest.Response{Response: resp}
516		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "ListMetricDefinitions", resp, "Failure sending request")
517		return
518	}
519
520	result, err = client.ListMetricDefinitionsResponder(resp)
521	if err != nil {
522		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "ListMetricDefinitions", resp, "Failure responding to request")
523		return
524	}
525
526	return
527}
528
529// ListMetricDefinitionsPreparer prepares the ListMetricDefinitions request.
530func (client ElasticPoolsClient) ListMetricDefinitionsPreparer(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string) (*http.Request, error) {
531	pathParameters := map[string]interface{}{
532		"elasticPoolName":   autorest.Encode("path", elasticPoolName),
533		"resourceGroupName": autorest.Encode("path", resourceGroupName),
534		"serverName":        autorest.Encode("path", serverName),
535		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
536	}
537
538	const APIVersion = "2014-04-01"
539	queryParameters := map[string]interface{}{
540		"api-version": APIVersion,
541	}
542
543	preparer := autorest.CreatePreparer(
544		autorest.AsGet(),
545		autorest.WithBaseURL(client.BaseURI),
546		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/metricDefinitions", pathParameters),
547		autorest.WithQueryParameters(queryParameters))
548	return preparer.Prepare((&http.Request{}).WithContext(ctx))
549}
550
551// ListMetricDefinitionsSender sends the ListMetricDefinitions request. The method will close the
552// http.Response Body if it receives an error.
553func (client ElasticPoolsClient) ListMetricDefinitionsSender(req *http.Request) (*http.Response, error) {
554	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
555}
556
557// ListMetricDefinitionsResponder handles the response to the ListMetricDefinitions request. The method always
558// closes the http.Response Body.
559func (client ElasticPoolsClient) ListMetricDefinitionsResponder(resp *http.Response) (result MetricDefinitionListResult, err error) {
560	err = autorest.Respond(
561		resp,
562		azure.WithErrorUnlessStatusCode(http.StatusOK),
563		autorest.ByUnmarshallingJSON(&result),
564		autorest.ByClosing())
565	result.Response = autorest.Response{Response: resp}
566	return
567}
568
569// ListMetrics returns elastic pool  metrics.
570// Parameters:
571// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
572// from the Azure Resource Manager API or the portal.
573// serverName - the name of the server.
574// elasticPoolName - the name of the elastic pool.
575// filter - an OData filter expression that describes a subset of metrics to return.
576func (client ElasticPoolsClient) ListMetrics(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string, filter string) (result MetricListResult, err error) {
577	if tracing.IsEnabled() {
578		ctx = tracing.StartSpan(ctx, fqdn+"/ElasticPoolsClient.ListMetrics")
579		defer func() {
580			sc := -1
581			if result.Response.Response != nil {
582				sc = result.Response.Response.StatusCode
583			}
584			tracing.EndSpan(ctx, sc, err)
585		}()
586	}
587	req, err := client.ListMetricsPreparer(ctx, resourceGroupName, serverName, elasticPoolName, filter)
588	if err != nil {
589		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "ListMetrics", nil, "Failure preparing request")
590		return
591	}
592
593	resp, err := client.ListMetricsSender(req)
594	if err != nil {
595		result.Response = autorest.Response{Response: resp}
596		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "ListMetrics", resp, "Failure sending request")
597		return
598	}
599
600	result, err = client.ListMetricsResponder(resp)
601	if err != nil {
602		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "ListMetrics", resp, "Failure responding to request")
603		return
604	}
605
606	return
607}
608
609// ListMetricsPreparer prepares the ListMetrics request.
610func (client ElasticPoolsClient) ListMetricsPreparer(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string, filter string) (*http.Request, error) {
611	pathParameters := map[string]interface{}{
612		"elasticPoolName":   autorest.Encode("path", elasticPoolName),
613		"resourceGroupName": autorest.Encode("path", resourceGroupName),
614		"serverName":        autorest.Encode("path", serverName),
615		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
616	}
617
618	const APIVersion = "2014-04-01"
619	queryParameters := map[string]interface{}{
620		"$filter":     autorest.Encode("query", filter),
621		"api-version": APIVersion,
622	}
623
624	preparer := autorest.CreatePreparer(
625		autorest.AsGet(),
626		autorest.WithBaseURL(client.BaseURI),
627		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/metrics", pathParameters),
628		autorest.WithQueryParameters(queryParameters))
629	return preparer.Prepare((&http.Request{}).WithContext(ctx))
630}
631
632// ListMetricsSender sends the ListMetrics request. The method will close the
633// http.Response Body if it receives an error.
634func (client ElasticPoolsClient) ListMetricsSender(req *http.Request) (*http.Response, error) {
635	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
636}
637
638// ListMetricsResponder handles the response to the ListMetrics request. The method always
639// closes the http.Response Body.
640func (client ElasticPoolsClient) ListMetricsResponder(resp *http.Response) (result MetricListResult, err error) {
641	err = autorest.Respond(
642		resp,
643		azure.WithErrorUnlessStatusCode(http.StatusOK),
644		autorest.ByUnmarshallingJSON(&result),
645		autorest.ByClosing())
646	result.Response = autorest.Response{Response: resp}
647	return
648}
649
650// Update updates an elastic pool.
651// Parameters:
652// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
653// from the Azure Resource Manager API or the portal.
654// serverName - the name of the server.
655// elasticPoolName - the name of the elastic pool.
656// parameters - the elastic pool update parameters.
657func (client ElasticPoolsClient) Update(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string, parameters ElasticPoolUpdate) (result ElasticPoolsUpdateFuture, err error) {
658	if tracing.IsEnabled() {
659		ctx = tracing.StartSpan(ctx, fqdn+"/ElasticPoolsClient.Update")
660		defer func() {
661			sc := -1
662			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
663				sc = result.FutureAPI.Response().StatusCode
664			}
665			tracing.EndSpan(ctx, sc, err)
666		}()
667	}
668	req, err := client.UpdatePreparer(ctx, resourceGroupName, serverName, elasticPoolName, parameters)
669	if err != nil {
670		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "Update", nil, "Failure preparing request")
671		return
672	}
673
674	result, err = client.UpdateSender(req)
675	if err != nil {
676		err = autorest.NewErrorWithError(err, "sql.ElasticPoolsClient", "Update", nil, "Failure sending request")
677		return
678	}
679
680	return
681}
682
683// UpdatePreparer prepares the Update request.
684func (client ElasticPoolsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string, parameters ElasticPoolUpdate) (*http.Request, error) {
685	pathParameters := map[string]interface{}{
686		"elasticPoolName":   autorest.Encode("path", elasticPoolName),
687		"resourceGroupName": autorest.Encode("path", resourceGroupName),
688		"serverName":        autorest.Encode("path", serverName),
689		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
690	}
691
692	const APIVersion = "2020-08-01-preview"
693	queryParameters := map[string]interface{}{
694		"api-version": APIVersion,
695	}
696
697	preparer := autorest.CreatePreparer(
698		autorest.AsContentType("application/json; charset=utf-8"),
699		autorest.AsPatch(),
700		autorest.WithBaseURL(client.BaseURI),
701		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}", pathParameters),
702		autorest.WithJSON(parameters),
703		autorest.WithQueryParameters(queryParameters))
704	return preparer.Prepare((&http.Request{}).WithContext(ctx))
705}
706
707// UpdateSender sends the Update request. The method will close the
708// http.Response Body if it receives an error.
709func (client ElasticPoolsClient) UpdateSender(req *http.Request) (future ElasticPoolsUpdateFuture, err error) {
710	var resp *http.Response
711	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
712	if err != nil {
713		return
714	}
715	var azf azure.Future
716	azf, err = azure.NewFutureFromResponse(resp)
717	future.FutureAPI = &azf
718	future.Result = future.result
719	return
720}
721
722// UpdateResponder handles the response to the Update request. The method always
723// closes the http.Response Body.
724func (client ElasticPoolsClient) UpdateResponder(resp *http.Response) (result ElasticPool, err error) {
725	err = autorest.Respond(
726		resp,
727		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
728		autorest.ByUnmarshallingJSON(&result),
729		autorest.ByClosing())
730	result.Response = autorest.Response{Response: resp}
731	return
732}
733