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// ServerAdvisorsClient is the the Azure SQL Database management API provides a RESTful set of web services that 29// interact with Azure SQL Database services to manage your databases. The API enables you to create, retrieve, update, 30// and delete databases. 31type ServerAdvisorsClient struct { 32 BaseClient 33} 34 35// NewServerAdvisorsClient creates an instance of the ServerAdvisorsClient client. 36func NewServerAdvisorsClient(subscriptionID string) ServerAdvisorsClient { 37 return NewServerAdvisorsClientWithBaseURI(DefaultBaseURI, subscriptionID) 38} 39 40// NewServerAdvisorsClientWithBaseURI creates an instance of the ServerAdvisorsClient client using a custom endpoint. 41// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 42func NewServerAdvisorsClientWithBaseURI(baseURI string, subscriptionID string) ServerAdvisorsClient { 43 return ServerAdvisorsClient{NewWithBaseURI(baseURI, subscriptionID)} 44} 45 46// CreateOrUpdate creates or updates a server advisor. 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// advisorName - the name of the Server Advisor. 52// parameters - the requested advisor resource state. 53func (client ServerAdvisorsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serverName string, advisorName string, parameters Advisor) (result Advisor, err error) { 54 if tracing.IsEnabled() { 55 ctx = tracing.StartSpan(ctx, fqdn+"/ServerAdvisorsClient.CreateOrUpdate") 56 defer func() { 57 sc := -1 58 if result.Response.Response != nil { 59 sc = result.Response.Response.StatusCode 60 } 61 tracing.EndSpan(ctx, sc, err) 62 }() 63 } 64 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serverName, advisorName, parameters) 65 if err != nil { 66 err = autorest.NewErrorWithError(err, "sql.ServerAdvisorsClient", "CreateOrUpdate", nil, "Failure preparing request") 67 return 68 } 69 70 resp, err := client.CreateOrUpdateSender(req) 71 if err != nil { 72 result.Response = autorest.Response{Response: resp} 73 err = autorest.NewErrorWithError(err, "sql.ServerAdvisorsClient", "CreateOrUpdate", resp, "Failure sending request") 74 return 75 } 76 77 result, err = client.CreateOrUpdateResponder(resp) 78 if err != nil { 79 err = autorest.NewErrorWithError(err, "sql.ServerAdvisorsClient", "CreateOrUpdate", resp, "Failure responding to request") 80 return 81 } 82 83 return 84} 85 86// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 87func (client ServerAdvisorsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, advisorName string, parameters Advisor) (*http.Request, error) { 88 pathParameters := map[string]interface{}{ 89 "advisorName": autorest.Encode("path", advisorName), 90 "resourceGroupName": autorest.Encode("path", resourceGroupName), 91 "serverName": autorest.Encode("path", serverName), 92 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 93 } 94 95 const APIVersion = "2014-04-01" 96 queryParameters := map[string]interface{}{ 97 "api-version": APIVersion, 98 } 99 100 parameters.Kind = nil 101 parameters.Location = nil 102 preparer := autorest.CreatePreparer( 103 autorest.AsContentType("application/json; charset=utf-8"), 104 autorest.AsPut(), 105 autorest.WithBaseURL(client.BaseURI), 106 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors/{advisorName}", pathParameters), 107 autorest.WithJSON(parameters), 108 autorest.WithQueryParameters(queryParameters)) 109 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 110} 111 112// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 113// http.Response Body if it receives an error. 114func (client ServerAdvisorsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 115 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 116} 117 118// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 119// closes the http.Response Body. 120func (client ServerAdvisorsClient) CreateOrUpdateResponder(resp *http.Response) (result Advisor, err error) { 121 err = autorest.Respond( 122 resp, 123 azure.WithErrorUnlessStatusCode(http.StatusOK), 124 autorest.ByUnmarshallingJSON(&result), 125 autorest.ByClosing()) 126 result.Response = autorest.Response{Response: resp} 127 return 128} 129 130// Get gets a server advisor. 131// Parameters: 132// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 133// from the Azure Resource Manager API or the portal. 134// serverName - the name of the server. 135// advisorName - the name of the Server Advisor. 136func (client ServerAdvisorsClient) Get(ctx context.Context, resourceGroupName string, serverName string, advisorName string) (result Advisor, err error) { 137 if tracing.IsEnabled() { 138 ctx = tracing.StartSpan(ctx, fqdn+"/ServerAdvisorsClient.Get") 139 defer func() { 140 sc := -1 141 if result.Response.Response != nil { 142 sc = result.Response.Response.StatusCode 143 } 144 tracing.EndSpan(ctx, sc, err) 145 }() 146 } 147 req, err := client.GetPreparer(ctx, resourceGroupName, serverName, advisorName) 148 if err != nil { 149 err = autorest.NewErrorWithError(err, "sql.ServerAdvisorsClient", "Get", nil, "Failure preparing request") 150 return 151 } 152 153 resp, err := client.GetSender(req) 154 if err != nil { 155 result.Response = autorest.Response{Response: resp} 156 err = autorest.NewErrorWithError(err, "sql.ServerAdvisorsClient", "Get", resp, "Failure sending request") 157 return 158 } 159 160 result, err = client.GetResponder(resp) 161 if err != nil { 162 err = autorest.NewErrorWithError(err, "sql.ServerAdvisorsClient", "Get", resp, "Failure responding to request") 163 return 164 } 165 166 return 167} 168 169// GetPreparer prepares the Get request. 170func (client ServerAdvisorsClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, advisorName string) (*http.Request, error) { 171 pathParameters := map[string]interface{}{ 172 "advisorName": autorest.Encode("path", advisorName), 173 "resourceGroupName": autorest.Encode("path", resourceGroupName), 174 "serverName": autorest.Encode("path", serverName), 175 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 176 } 177 178 const APIVersion = "2014-04-01" 179 queryParameters := map[string]interface{}{ 180 "api-version": APIVersion, 181 } 182 183 preparer := autorest.CreatePreparer( 184 autorest.AsGet(), 185 autorest.WithBaseURL(client.BaseURI), 186 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors/{advisorName}", pathParameters), 187 autorest.WithQueryParameters(queryParameters)) 188 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 189} 190 191// GetSender sends the Get request. The method will close the 192// http.Response Body if it receives an error. 193func (client ServerAdvisorsClient) GetSender(req *http.Request) (*http.Response, error) { 194 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 195} 196 197// GetResponder handles the response to the Get request. The method always 198// closes the http.Response Body. 199func (client ServerAdvisorsClient) GetResponder(resp *http.Response) (result Advisor, err error) { 200 err = autorest.Respond( 201 resp, 202 azure.WithErrorUnlessStatusCode(http.StatusOK), 203 autorest.ByUnmarshallingJSON(&result), 204 autorest.ByClosing()) 205 result.Response = autorest.Response{Response: resp} 206 return 207} 208 209// ListByServer gets a list of server advisors. 210// Parameters: 211// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 212// from the Azure Resource Manager API or the portal. 213// serverName - the name of the server. 214func (client ServerAdvisorsClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string) (result AdvisorListResult, err error) { 215 if tracing.IsEnabled() { 216 ctx = tracing.StartSpan(ctx, fqdn+"/ServerAdvisorsClient.ListByServer") 217 defer func() { 218 sc := -1 219 if result.Response.Response != nil { 220 sc = result.Response.Response.StatusCode 221 } 222 tracing.EndSpan(ctx, sc, err) 223 }() 224 } 225 req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName) 226 if err != nil { 227 err = autorest.NewErrorWithError(err, "sql.ServerAdvisorsClient", "ListByServer", nil, "Failure preparing request") 228 return 229 } 230 231 resp, err := client.ListByServerSender(req) 232 if err != nil { 233 result.Response = autorest.Response{Response: resp} 234 err = autorest.NewErrorWithError(err, "sql.ServerAdvisorsClient", "ListByServer", resp, "Failure sending request") 235 return 236 } 237 238 result, err = client.ListByServerResponder(resp) 239 if err != nil { 240 err = autorest.NewErrorWithError(err, "sql.ServerAdvisorsClient", "ListByServer", resp, "Failure responding to request") 241 return 242 } 243 244 return 245} 246 247// ListByServerPreparer prepares the ListByServer request. 248func (client ServerAdvisorsClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) { 249 pathParameters := map[string]interface{}{ 250 "resourceGroupName": autorest.Encode("path", resourceGroupName), 251 "serverName": autorest.Encode("path", serverName), 252 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 253 } 254 255 const APIVersion = "2014-04-01" 256 queryParameters := map[string]interface{}{ 257 "api-version": APIVersion, 258 } 259 260 preparer := autorest.CreatePreparer( 261 autorest.AsGet(), 262 autorest.WithBaseURL(client.BaseURI), 263 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors", pathParameters), 264 autorest.WithQueryParameters(queryParameters)) 265 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 266} 267 268// ListByServerSender sends the ListByServer request. The method will close the 269// http.Response Body if it receives an error. 270func (client ServerAdvisorsClient) ListByServerSender(req *http.Request) (*http.Response, error) { 271 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 272} 273 274// ListByServerResponder handles the response to the ListByServer request. The method always 275// closes the http.Response Body. 276func (client ServerAdvisorsClient) ListByServerResponder(resp *http.Response) (result AdvisorListResult, err error) { 277 err = autorest.Respond( 278 resp, 279 azure.WithErrorUnlessStatusCode(http.StatusOK), 280 autorest.ByUnmarshallingJSON(&result), 281 autorest.ByClosing()) 282 result.Response = autorest.Response{Response: resp} 283 return 284} 285 286// Update updates a server advisor. 287// Parameters: 288// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 289// from the Azure Resource Manager API or the portal. 290// serverName - the name of the server. 291// advisorName - the name of the Server Advisor. 292// parameters - the requested advisor resource state. 293func (client ServerAdvisorsClient) Update(ctx context.Context, resourceGroupName string, serverName string, advisorName string, parameters Advisor) (result Advisor, err error) { 294 if tracing.IsEnabled() { 295 ctx = tracing.StartSpan(ctx, fqdn+"/ServerAdvisorsClient.Update") 296 defer func() { 297 sc := -1 298 if result.Response.Response != nil { 299 sc = result.Response.Response.StatusCode 300 } 301 tracing.EndSpan(ctx, sc, err) 302 }() 303 } 304 req, err := client.UpdatePreparer(ctx, resourceGroupName, serverName, advisorName, parameters) 305 if err != nil { 306 err = autorest.NewErrorWithError(err, "sql.ServerAdvisorsClient", "Update", nil, "Failure preparing request") 307 return 308 } 309 310 resp, err := client.UpdateSender(req) 311 if err != nil { 312 result.Response = autorest.Response{Response: resp} 313 err = autorest.NewErrorWithError(err, "sql.ServerAdvisorsClient", "Update", resp, "Failure sending request") 314 return 315 } 316 317 result, err = client.UpdateResponder(resp) 318 if err != nil { 319 err = autorest.NewErrorWithError(err, "sql.ServerAdvisorsClient", "Update", resp, "Failure responding to request") 320 return 321 } 322 323 return 324} 325 326// UpdatePreparer prepares the Update request. 327func (client ServerAdvisorsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, advisorName string, parameters Advisor) (*http.Request, error) { 328 pathParameters := map[string]interface{}{ 329 "advisorName": autorest.Encode("path", advisorName), 330 "resourceGroupName": autorest.Encode("path", resourceGroupName), 331 "serverName": autorest.Encode("path", serverName), 332 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 333 } 334 335 const APIVersion = "2014-04-01" 336 queryParameters := map[string]interface{}{ 337 "api-version": APIVersion, 338 } 339 340 parameters.Kind = nil 341 parameters.Location = nil 342 preparer := autorest.CreatePreparer( 343 autorest.AsContentType("application/json; charset=utf-8"), 344 autorest.AsPatch(), 345 autorest.WithBaseURL(client.BaseURI), 346 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors/{advisorName}", pathParameters), 347 autorest.WithJSON(parameters), 348 autorest.WithQueryParameters(queryParameters)) 349 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 350} 351 352// UpdateSender sends the Update request. The method will close the 353// http.Response Body if it receives an error. 354func (client ServerAdvisorsClient) UpdateSender(req *http.Request) (*http.Response, error) { 355 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 356} 357 358// UpdateResponder handles the response to the Update request. The method always 359// closes the http.Response Body. 360func (client ServerAdvisorsClient) UpdateResponder(resp *http.Response) (result Advisor, err error) { 361 err = autorest.Respond( 362 resp, 363 azure.WithErrorUnlessStatusCode(http.StatusOK), 364 autorest.ByUnmarshallingJSON(&result), 365 autorest.ByClosing()) 366 result.Response = autorest.Response{Response: resp} 367 return 368} 369