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 "github.com/gofrs/uuid" 15 "net/http" 16) 17 18// ElasticPoolOperationsClient is the the Azure SQL Database management API provides a RESTful set of web services that 19// interact with Azure SQL Database services to manage your databases. The API enables you to create, retrieve, update, 20// and delete databases. 21type ElasticPoolOperationsClient struct { 22 BaseClient 23} 24 25// NewElasticPoolOperationsClient creates an instance of the ElasticPoolOperationsClient client. 26func NewElasticPoolOperationsClient(subscriptionID string) ElasticPoolOperationsClient { 27 return NewElasticPoolOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID) 28} 29 30// NewElasticPoolOperationsClientWithBaseURI creates an instance of the ElasticPoolOperationsClient client using a 31// custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, 32// Azure stack). 33func NewElasticPoolOperationsClientWithBaseURI(baseURI string, subscriptionID string) ElasticPoolOperationsClient { 34 return ElasticPoolOperationsClient{NewWithBaseURI(baseURI, subscriptionID)} 35} 36 37// Cancel cancels the asynchronous operation on the elastic pool. 38// Parameters: 39// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 40// from the Azure Resource Manager API or the portal. 41// serverName - the name of the server. 42// operationID - the operation identifier. 43func (client ElasticPoolOperationsClient) Cancel(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string, operationID uuid.UUID) (result autorest.Response, err error) { 44 if tracing.IsEnabled() { 45 ctx = tracing.StartSpan(ctx, fqdn+"/ElasticPoolOperationsClient.Cancel") 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.CancelPreparer(ctx, resourceGroupName, serverName, elasticPoolName, operationID) 55 if err != nil { 56 err = autorest.NewErrorWithError(err, "sql.ElasticPoolOperationsClient", "Cancel", nil, "Failure preparing request") 57 return 58 } 59 60 resp, err := client.CancelSender(req) 61 if err != nil { 62 result.Response = resp 63 err = autorest.NewErrorWithError(err, "sql.ElasticPoolOperationsClient", "Cancel", resp, "Failure sending request") 64 return 65 } 66 67 result, err = client.CancelResponder(resp) 68 if err != nil { 69 err = autorest.NewErrorWithError(err, "sql.ElasticPoolOperationsClient", "Cancel", resp, "Failure responding to request") 70 return 71 } 72 73 return 74} 75 76// CancelPreparer prepares the Cancel request. 77func (client ElasticPoolOperationsClient) CancelPreparer(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string, operationID uuid.UUID) (*http.Request, error) { 78 pathParameters := map[string]interface{}{ 79 "elasticPoolName": autorest.Encode("path", elasticPoolName), 80 "operationId": autorest.Encode("path", operationID), 81 "resourceGroupName": autorest.Encode("path", resourceGroupName), 82 "serverName": autorest.Encode("path", serverName), 83 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 84 } 85 86 const APIVersion = "2017-10-01-preview" 87 queryParameters := map[string]interface{}{ 88 "api-version": APIVersion, 89 } 90 91 preparer := autorest.CreatePreparer( 92 autorest.AsPost(), 93 autorest.WithBaseURL(client.BaseURI), 94 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/operations/{operationId}/cancel", pathParameters), 95 autorest.WithQueryParameters(queryParameters)) 96 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 97} 98 99// CancelSender sends the Cancel request. The method will close the 100// http.Response Body if it receives an error. 101func (client ElasticPoolOperationsClient) CancelSender(req *http.Request) (*http.Response, error) { 102 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 103} 104 105// CancelResponder handles the response to the Cancel request. The method always 106// closes the http.Response Body. 107func (client ElasticPoolOperationsClient) CancelResponder(resp *http.Response) (result autorest.Response, err error) { 108 err = autorest.Respond( 109 resp, 110 azure.WithErrorUnlessStatusCode(http.StatusOK), 111 autorest.ByClosing()) 112 result.Response = resp 113 return 114} 115 116// ListByElasticPool gets a list of operations performed on the elastic pool. 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. 121func (client ElasticPoolOperationsClient) ListByElasticPool(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string) (result ElasticPoolOperationListResultPage, err error) { 122 if tracing.IsEnabled() { 123 ctx = tracing.StartSpan(ctx, fqdn+"/ElasticPoolOperationsClient.ListByElasticPool") 124 defer func() { 125 sc := -1 126 if result.epolr.Response.Response != nil { 127 sc = result.epolr.Response.Response.StatusCode 128 } 129 tracing.EndSpan(ctx, sc, err) 130 }() 131 } 132 result.fn = client.listByElasticPoolNextResults 133 req, err := client.ListByElasticPoolPreparer(ctx, resourceGroupName, serverName, elasticPoolName) 134 if err != nil { 135 err = autorest.NewErrorWithError(err, "sql.ElasticPoolOperationsClient", "ListByElasticPool", nil, "Failure preparing request") 136 return 137 } 138 139 resp, err := client.ListByElasticPoolSender(req) 140 if err != nil { 141 result.epolr.Response = autorest.Response{Response: resp} 142 err = autorest.NewErrorWithError(err, "sql.ElasticPoolOperationsClient", "ListByElasticPool", resp, "Failure sending request") 143 return 144 } 145 146 result.epolr, err = client.ListByElasticPoolResponder(resp) 147 if err != nil { 148 err = autorest.NewErrorWithError(err, "sql.ElasticPoolOperationsClient", "ListByElasticPool", resp, "Failure responding to request") 149 return 150 } 151 if result.epolr.hasNextLink() && result.epolr.IsEmpty() { 152 err = result.NextWithContext(ctx) 153 return 154 } 155 156 return 157} 158 159// ListByElasticPoolPreparer prepares the ListByElasticPool request. 160func (client ElasticPoolOperationsClient) ListByElasticPoolPreparer(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string) (*http.Request, error) { 161 pathParameters := map[string]interface{}{ 162 "elasticPoolName": autorest.Encode("path", elasticPoolName), 163 "resourceGroupName": autorest.Encode("path", resourceGroupName), 164 "serverName": autorest.Encode("path", serverName), 165 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 166 } 167 168 const APIVersion = "2017-10-01-preview" 169 queryParameters := map[string]interface{}{ 170 "api-version": APIVersion, 171 } 172 173 preparer := autorest.CreatePreparer( 174 autorest.AsGet(), 175 autorest.WithBaseURL(client.BaseURI), 176 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/operations", pathParameters), 177 autorest.WithQueryParameters(queryParameters)) 178 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 179} 180 181// ListByElasticPoolSender sends the ListByElasticPool request. The method will close the 182// http.Response Body if it receives an error. 183func (client ElasticPoolOperationsClient) ListByElasticPoolSender(req *http.Request) (*http.Response, error) { 184 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 185} 186 187// ListByElasticPoolResponder handles the response to the ListByElasticPool request. The method always 188// closes the http.Response Body. 189func (client ElasticPoolOperationsClient) ListByElasticPoolResponder(resp *http.Response) (result ElasticPoolOperationListResult, err error) { 190 err = autorest.Respond( 191 resp, 192 azure.WithErrorUnlessStatusCode(http.StatusOK), 193 autorest.ByUnmarshallingJSON(&result), 194 autorest.ByClosing()) 195 result.Response = autorest.Response{Response: resp} 196 return 197} 198 199// listByElasticPoolNextResults retrieves the next set of results, if any. 200func (client ElasticPoolOperationsClient) listByElasticPoolNextResults(ctx context.Context, lastResults ElasticPoolOperationListResult) (result ElasticPoolOperationListResult, err error) { 201 req, err := lastResults.elasticPoolOperationListResultPreparer(ctx) 202 if err != nil { 203 return result, autorest.NewErrorWithError(err, "sql.ElasticPoolOperationsClient", "listByElasticPoolNextResults", nil, "Failure preparing next results request") 204 } 205 if req == nil { 206 return 207 } 208 resp, err := client.ListByElasticPoolSender(req) 209 if err != nil { 210 result.Response = autorest.Response{Response: resp} 211 return result, autorest.NewErrorWithError(err, "sql.ElasticPoolOperationsClient", "listByElasticPoolNextResults", resp, "Failure sending next results request") 212 } 213 result, err = client.ListByElasticPoolResponder(resp) 214 if err != nil { 215 err = autorest.NewErrorWithError(err, "sql.ElasticPoolOperationsClient", "listByElasticPoolNextResults", resp, "Failure responding to next results request") 216 } 217 return 218} 219 220// ListByElasticPoolComplete enumerates all values, automatically crossing page boundaries as required. 221func (client ElasticPoolOperationsClient) ListByElasticPoolComplete(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string) (result ElasticPoolOperationListResultIterator, err error) { 222 if tracing.IsEnabled() { 223 ctx = tracing.StartSpan(ctx, fqdn+"/ElasticPoolOperationsClient.ListByElasticPool") 224 defer func() { 225 sc := -1 226 if result.Response().Response.Response != nil { 227 sc = result.page.Response().Response.Response.StatusCode 228 } 229 tracing.EndSpan(ctx, sc, err) 230 }() 231 } 232 result.page, err = client.ListByElasticPool(ctx, resourceGroupName, serverName, elasticPoolName) 233 return 234} 235