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// ServiceTierAdvisorsClient 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 ServiceTierAdvisorsClient struct { 32 BaseClient 33} 34 35// NewServiceTierAdvisorsClient creates an instance of the ServiceTierAdvisorsClient client. 36func NewServiceTierAdvisorsClient(subscriptionID string) ServiceTierAdvisorsClient { 37 return NewServiceTierAdvisorsClientWithBaseURI(DefaultBaseURI, subscriptionID) 38} 39 40// NewServiceTierAdvisorsClientWithBaseURI creates an instance of the ServiceTierAdvisorsClient client using a custom 41// endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure 42// stack). 43func NewServiceTierAdvisorsClientWithBaseURI(baseURI string, subscriptionID string) ServiceTierAdvisorsClient { 44 return ServiceTierAdvisorsClient{NewWithBaseURI(baseURI, subscriptionID)} 45} 46 47// Get gets a service tier advisor. 48// Parameters: 49// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 50// from the Azure Resource Manager API or the portal. 51// serverName - the name of the server. 52// databaseName - the name of database. 53// serviceTierAdvisorName - the name of service tier advisor. 54func (client ServiceTierAdvisorsClient) Get(ctx context.Context, resourceGroupName string, serverName string, databaseName string, serviceTierAdvisorName string) (result ServiceTierAdvisor, err error) { 55 if tracing.IsEnabled() { 56 ctx = tracing.StartSpan(ctx, fqdn+"/ServiceTierAdvisorsClient.Get") 57 defer func() { 58 sc := -1 59 if result.Response.Response != nil { 60 sc = result.Response.Response.StatusCode 61 } 62 tracing.EndSpan(ctx, sc, err) 63 }() 64 } 65 req, err := client.GetPreparer(ctx, resourceGroupName, serverName, databaseName, serviceTierAdvisorName) 66 if err != nil { 67 err = autorest.NewErrorWithError(err, "sql.ServiceTierAdvisorsClient", "Get", nil, "Failure preparing request") 68 return 69 } 70 71 resp, err := client.GetSender(req) 72 if err != nil { 73 result.Response = autorest.Response{Response: resp} 74 err = autorest.NewErrorWithError(err, "sql.ServiceTierAdvisorsClient", "Get", resp, "Failure sending request") 75 return 76 } 77 78 result, err = client.GetResponder(resp) 79 if err != nil { 80 err = autorest.NewErrorWithError(err, "sql.ServiceTierAdvisorsClient", "Get", resp, "Failure responding to request") 81 return 82 } 83 84 return 85} 86 87// GetPreparer prepares the Get request. 88func (client ServiceTierAdvisorsClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, serviceTierAdvisorName string) (*http.Request, error) { 89 pathParameters := map[string]interface{}{ 90 "databaseName": autorest.Encode("path", databaseName), 91 "resourceGroupName": autorest.Encode("path", resourceGroupName), 92 "serverName": autorest.Encode("path", serverName), 93 "serviceTierAdvisorName": autorest.Encode("path", serviceTierAdvisorName), 94 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 95 } 96 97 const APIVersion = "2014-04-01" 98 queryParameters := map[string]interface{}{ 99 "api-version": APIVersion, 100 } 101 102 preparer := autorest.CreatePreparer( 103 autorest.AsGet(), 104 autorest.WithBaseURL(client.BaseURI), 105 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/serviceTierAdvisors/{serviceTierAdvisorName}", pathParameters), 106 autorest.WithQueryParameters(queryParameters)) 107 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 108} 109 110// GetSender sends the Get request. The method will close the 111// http.Response Body if it receives an error. 112func (client ServiceTierAdvisorsClient) GetSender(req *http.Request) (*http.Response, error) { 113 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 114} 115 116// GetResponder handles the response to the Get request. The method always 117// closes the http.Response Body. 118func (client ServiceTierAdvisorsClient) GetResponder(resp *http.Response) (result ServiceTierAdvisor, err error) { 119 err = autorest.Respond( 120 resp, 121 azure.WithErrorUnlessStatusCode(http.StatusOK), 122 autorest.ByUnmarshallingJSON(&result), 123 autorest.ByClosing()) 124 result.Response = autorest.Response{Response: resp} 125 return 126} 127 128// ListByDatabase returns service tier advisors for specified database. 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// databaseName - the name of database. 134func (client ServiceTierAdvisorsClient) ListByDatabase(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (result ServiceTierAdvisorListResult, err error) { 135 if tracing.IsEnabled() { 136 ctx = tracing.StartSpan(ctx, fqdn+"/ServiceTierAdvisorsClient.ListByDatabase") 137 defer func() { 138 sc := -1 139 if result.Response.Response != nil { 140 sc = result.Response.Response.StatusCode 141 } 142 tracing.EndSpan(ctx, sc, err) 143 }() 144 } 145 req, err := client.ListByDatabasePreparer(ctx, resourceGroupName, serverName, databaseName) 146 if err != nil { 147 err = autorest.NewErrorWithError(err, "sql.ServiceTierAdvisorsClient", "ListByDatabase", nil, "Failure preparing request") 148 return 149 } 150 151 resp, err := client.ListByDatabaseSender(req) 152 if err != nil { 153 result.Response = autorest.Response{Response: resp} 154 err = autorest.NewErrorWithError(err, "sql.ServiceTierAdvisorsClient", "ListByDatabase", resp, "Failure sending request") 155 return 156 } 157 158 result, err = client.ListByDatabaseResponder(resp) 159 if err != nil { 160 err = autorest.NewErrorWithError(err, "sql.ServiceTierAdvisorsClient", "ListByDatabase", resp, "Failure responding to request") 161 return 162 } 163 164 return 165} 166 167// ListByDatabasePreparer prepares the ListByDatabase request. 168func (client ServiceTierAdvisorsClient) ListByDatabasePreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (*http.Request, error) { 169 pathParameters := map[string]interface{}{ 170 "databaseName": autorest.Encode("path", databaseName), 171 "resourceGroupName": autorest.Encode("path", resourceGroupName), 172 "serverName": autorest.Encode("path", serverName), 173 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 174 } 175 176 const APIVersion = "2014-04-01" 177 queryParameters := map[string]interface{}{ 178 "api-version": APIVersion, 179 } 180 181 preparer := autorest.CreatePreparer( 182 autorest.AsGet(), 183 autorest.WithBaseURL(client.BaseURI), 184 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/serviceTierAdvisors", pathParameters), 185 autorest.WithQueryParameters(queryParameters)) 186 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 187} 188 189// ListByDatabaseSender sends the ListByDatabase request. The method will close the 190// http.Response Body if it receives an error. 191func (client ServiceTierAdvisorsClient) ListByDatabaseSender(req *http.Request) (*http.Response, error) { 192 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 193} 194 195// ListByDatabaseResponder handles the response to the ListByDatabase request. The method always 196// closes the http.Response Body. 197func (client ServiceTierAdvisorsClient) ListByDatabaseResponder(resp *http.Response) (result ServiceTierAdvisorListResult, err error) { 198 err = autorest.Respond( 199 resp, 200 azure.WithErrorUnlessStatusCode(http.StatusOK), 201 autorest.ByUnmarshallingJSON(&result), 202 autorest.ByClosing()) 203 result.Response = autorest.Response{Response: resp} 204 return 205} 206